/** * AJAX action for searching posts by category and title/content */ public function action_customize_control_post_search() { check_ajax_referer(); if (current_user_can(Builder::get_capability())) { wp_send_json_success(wp_list_pluck((new \WP_Query(['post_type' => !empty($_GET['post_type']) ? sanitize_text_field($_GET['post_type']) : 'post', 'cat' => !empty($_GET['category']) ? absint($_GET['category']) : 0, 'paged' => !empty($_GET['page']) ? absint($_GET['page']) : 1, 's' => !empty($_GET['s']) && String::length($s = sanitize_text_field($_GET['s'])) > static::MIN_CHARACTERS_NUMBER ? $s : '', 'update_post_meta_cache' => false, 'post__not_in' => array_values(Posts::get_ids())]))->get_posts(), 'post_title', 'ID')); } wp_send_json_error(__('You are not allowed to do it.')); }
protected function _get_labels() { $singular_name = String::capitalize($this->_name); $plural_name = $this->_pluralize ? String::pluralize($singular_name) : $singular_name; $lowercase_singular_name = String::lowercase($singular_name); $lowercase_plural_name = String::lowercase($plural_name); $default_labels = ['name' => $plural_name, 'singular_name' => $singular_name, 'add_new' => __("Add New", 'wpkit'), 'add_new_item' => sprintf(__("Add New %s", 'wpkit'), $lowercase_singular_name), 'edit_item' => sprintf(__("Edit %s", 'wpkit'), $lowercase_singular_name), 'new_item' => sprintf(__("New %s", 'wpkit'), $lowercase_singular_name), 'all_items' => sprintf(__("All %s", 'wpkit'), $lowercase_plural_name), 'view_item' => sprintf(__("View %s", 'wpkit'), $lowercase_singular_name), 'search_items' => sprintf(__("Search %s", 'wpkit'), $lowercase_plural_name), 'not_found' => sprintf(__("No %s found", 'wpkit'), $lowercase_plural_name), 'not_found_in_trash' => sprintf(__("No %s found in Trash", 'wpkit'), $lowercase_plural_name), 'parent_item_colon' => null, 'menu_name' => $plural_name]; return wp_parse_args($this->_custom_labels, $default_labels); }
private function _register_actions() { foreach (get_class_methods($this) as $method) { if (String::position($method, 'action_') === 0) { $action = String::sub_string($method, 7); add_action('wp_ajax_' . $this->get_prefix() . '_' . $action, [$this, $method]); add_action('wp_ajax_nopriv_' . $this->get_prefix() . '_' . $action, [$this, $method]); } } }
private function _execute_add_action_methods() { foreach (get_class_methods($this) as $method) { if (String::position($method, 'add_action_') === 0 || String::position($method, 'add_filter_') === 0) { $action_name = str_replace(['add_filter_', 'add_action_'], '', $method); $reflection = new \ReflectionMethod($this, $method); $params_count = $reflection->getNumberOfParameters(); add_filter($action_name, [$this, $method], 10, $params_count); } } }
protected function _is_default_page() { $reflection = new \ReflectionClass(__CLASS__); if (in_array($this->_page, $reflection->getConstants()) && String::position($_SERVER['REQUEST_URI'], "options-{$this->_page}.php") !== false) { return true; } return false; }
protected function _get_labels() { $singular_name = String::capitalize($this->_name); $plural_name = $this->_pluralize ? String::pluralize($singular_name) : $singular_name; $lowercase_plural_name = String::lowercase($plural_name); return wp_parse_args($this->_custom_labels, ['name' => $plural_name, 'singular_name' => $singular_name, 'search_items' => sprintf(__("Search %s", 'wpkit'), $plural_name), 'popular_items' => sprintf(__("Popular %s", 'wpkit'), $plural_name), 'all_items' => sprintf(__("All %s", 'wpkit'), $plural_name), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => sprintf(__("Edit %s", 'wpkit'), $singular_name), 'update_item' => sprintf(__("Update %s", 'wpkit'), $singular_name), 'add_new_item' => sprintf(__("Add New %s", 'wpkit'), $singular_name), 'new_item_name' => sprintf(__("New %s Name", 'wpkit'), $singular_name), 'separate_items_with_commas' => sprintf(__("Separate %s with commas", 'wpkit'), $lowercase_plural_name), 'add_or_remove_items' => sprintf(__("Add or remove %s", 'wpkit'), $lowercase_plural_name), 'choose_from_most_used' => sprintf(__("Choose from the most used %s", 'wpkit'), $lowercase_plural_name), 'not_found' => sprintf(__("No %s found", 'wpkit'), $lowercase_plural_name), 'menu_name' => $plural_name]); }
/** * Init autoload for classes in modules */ private function _init_module_autoloader() { spl_autoload_register(function ($class_name) { if (String::position($class_name, "modules") !== false) { $filename = TEMPLATEPATH . DIRECTORY_SEPARATOR . ltrim(str_replace("\\", DIRECTORY_SEPARATOR, $class_name), DIRECTORY_SEPARATOR) . ".php"; if (is_file($filename)) { require_once $filename; return true; } } return false; }); }