From e17ff910211065dbc8074cc1dd7287507b990b61 Mon Sep 17 00:00:00 2001 From: Richa Ferry Setyawan Date: Sat, 27 Jul 2024 05:27:21 +0700 Subject: [PATCH] fix freeze webpage because dropdown composer update composer update fix code scanning alert revert global-checklists.js --- .prettierrc | 28 +-- core/Requirement/Base_multiple.php | 5 +- core/Requirement/Prohibited_categories.php | 159 +++++++++++++++++- core/Requirement/Prohibited_tags.php | 147 +++++++++++++++- core/Requirement/Required_categories.php | 158 ++++++++++++++++- core/Requirement/Required_tags.php | 147 +++++++++++++++- lib/vendor/composer/installed.php | 4 +- .../checklists/assets/js/global-checklists.js | 2 +- modules/checklists/checklists.php | 11 +- modules/permissions/assets/css/admin.css | 6 +- modules/permissions/assets/js/admin.js | 31 ++++ publishpress-checklists.php | 2 +- 12 files changed, 650 insertions(+), 50 deletions(-) diff --git a/.prettierrc b/.prettierrc index 6d449448..62f6dbbb 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,16 +1,16 @@ { - "printWidth": 120, - "tabWidth": 2, - "useTabs": false, - "semi": true, - "singleQuote": true, - "quoteProps": "as-needed", - "jsxSingleQuote": false, - "trailingComma": "all", - "bracketSpacing": true, - "jsxBracketSameLine": false, - "arrowParens": "always", - "proseWrap": "preserve", - "htmlWhitespaceSensitivity": "css", - "endOfLine": "lf" + "printWidth": 120, + "tabWidth": 4, + "useTabs": false, + "semi": true, + "singleQuote": true, + "quoteProps": "as-needed", + "jsxSingleQuote": false, + "trailingComma": "all", + "bracketSpacing": true, + "jsxBracketSameLine": false, + "arrowParens": "always", + "proseWrap": "preserve", + "htmlWhitespaceSensitivity": "css", + "endOfLine": "lf" } diff --git a/core/Requirement/Base_multiple.php b/core/Requirement/Base_multiple.php index 27939902..e83f5142 100644 --- a/core/Requirement/Base_multiple.php +++ b/core/Requirement/Base_multiple.php @@ -104,9 +104,10 @@ public function get_setting_field_html($css_class = '') } $html .= sprintf( - '', $id, - $name + $name, + $css_class ); $labels = $this->get_setting_drop_down_labels(); diff --git a/core/Requirement/Prohibited_categories.php b/core/Requirement/Prohibited_categories.php index b07cedce..daa7c541 100644 --- a/core/Requirement/Prohibited_categories.php +++ b/core/Requirement/Prohibited_categories.php @@ -39,6 +39,28 @@ class Prohibited_categories extends Base_multiple */ private $DELIMITER = '__'; + public function __construct($module, $post_type) + { + parent::__construct($module, $post_type); + $this->init_hooks(); + } + + /** + * Initialize the hooks for the requirement + * + * @return void + */ + public function init_hooks() { + // Check if the hooks were already initialized + if (isset($this->hooks_initialized) && $this->hooks_initialized) return; + + // Add the AJAX action to get the list of categories + add_action('wp_ajax_pp_checklists_prohibited_category', [$this, 'get_list_category_ajax']); + + // Set the initialization flag to true + $this->hooks_initialized = true; + } + /** * Initialize the language strings for the instance * @@ -66,6 +88,129 @@ public function get_current_status($post, $option_value) return empty(array_intersect($option_ids, $categories)); } + /** + * Get selected values from the settings + * + * @return array + */ + public function get_selected_values() + { + // Option names + $option_name_multiple = $this->name . '_' . $this->field_name; + $option_value = array(); + if (isset($this->module->options->{$option_name_multiple}[$this->post_type])) { + $option_value = $this->module->options->{$option_name_multiple}[$this->post_type]; + } + $selected_categories = array(); + foreach ($option_value as $category_str) { + [$category_id, $category_name] = explode($this->DELIMITER, $category_str); + $selected_categories[] = $category_id; + } + + return $selected_categories; + } + + /** + * Get the list of categories + * + * @param array $args + * @return WP_Term[] + */ + public function get_list_categories($args = array('page' => 1, 'per_page' => 10, 'q' => '')) + { + // Get selected categories from the settings + $selected_categories = $this->get_selected_values(); + + // Retrieve selected categories only on the first page + $categories_selected = array(); + if($args['page'] === 1) { + $args_selected = array( + 'orderby' => 'name', + 'order' => 'ASC', + 'hide_empty' => 0, + 'include' => $selected_categories, + 'search' => $args['q'], + ); + $categories_selected = $this->get_categories_hierarchical($args_selected); + } + + // Retrieve categories with a limit of 10 rows + $args_limited = array( + 'type' => 'post', + 'hide_empty' => 0, + 'hierarchical' => 1, + 'taxonomy' => 'category', + 'pad_counts' => false, + 'orderby' => 'name', + 'order' => 'ASC', + 'hide_empty' => 0, + 'search' => $args['q'], + 'number' => $args['per_page'], + 'offset' => ($args['page'] - 1) * $args['per_page'] + ); + $categories_limited = $this->get_categories_hierarchical($args_limited); + + // Merge the two arrays + $categories = array_merge($categories_limited, $categories_selected); + + // Remove duplicates based on term_id + $categories = array_values(array_reduce($categories, function ($carry, $item) { + if (!isset($carry[$item->term_id])) { + $carry[$item->term_id] = $item; + } + return $carry; + }, [])); + + // Sort the array by name + usort($categories, function ($a, $b) { + return strcasecmp($a->name, $b->name); + }); + + return $categories; + } + + /** + * Get the list of categories via AJAX + * + * @return void + */ + public function get_list_category_ajax() + { + // Check if the request is valid + check_ajax_referer('pp-checklists-rules', 'nonce'); + + // Get the search query and page number from the request + $search = isset($_POST['q']) ? sanitize_text_field($_POST['q']) : ''; + $page = isset($_POST['page']) ? intval($_POST['page']) : 1; + $per_page = 10; + + // Get the categories + $categories = $this->get_list_categories(['page' => $page ,'per_page' => $per_page, 'q' => $search]); + $results = array(); + + foreach ($categories as $category) { + $results[] = array( + 'id' => $category->term_id . $this->DELIMITER . $category->name, + 'text' => $category->name, + ); + if(isset($category->children)) { + foreach ($category->children as $child) { + $results[] = array( + 'id' => $child->term_id . $this->DELIMITER . $child->name, + 'text' => '— ' . $child->name, + ); + } + } + } + + // Check if there are more categories + $total_categories = wp_count_terms('category', array('search' => $search, 'hide_empty' => 0)); + $has_next = ($page * $per_page) < $total_categories; + + wp_send_json_success(['items' => $results, 'has_next' => $has_next]); + wp_die(); + } + /** * Get Categories Hierarchical List * @@ -99,7 +244,7 @@ private function transform_categories($categories = array()) $labels[$category->term_id . $this->DELIMITER . $category->name] = $category->name; if(isset($category->children)) { foreach ($category->children as $child) { - $labels[$child->term_id . $this->DELIMITER . $child->name] = "- {$child->name}"; + $labels[$child->term_id . $this->DELIMITER . $child->name] = "— {$child->name}"; } } } @@ -114,11 +259,7 @@ private function transform_categories($categories = array()) */ public function get_setting_drop_down_labels() { - $categories = $this->get_categories_hierarchical(array( - 'orderby' => 'name', - 'order' => 'ASC', - 'hide_empty' => 0, - )); + $categories = $this->get_list_categories(); return $this->transform_categories($categories); } @@ -196,4 +337,10 @@ public function filter_requirements_list($requirements, $post) return $requirements; } + + + public function get_setting_field_html($css_class = '') + { + return parent::get_setting_field_html('pp-checklists-full-width'); + } } diff --git a/core/Requirement/Prohibited_tags.php b/core/Requirement/Prohibited_tags.php index b31d6d02..c17aa141 100644 --- a/core/Requirement/Prohibited_tags.php +++ b/core/Requirement/Prohibited_tags.php @@ -39,6 +39,28 @@ class Prohibited_tags extends Base_multiple */ private $DELIMITER = '__'; + public function __construct($module, $post_type) + { + parent::__construct($module, $post_type); + $this->init_hooks(); + } + + /** + * Initialize the hooks for the requirement + * + * @return void + */ + public function init_hooks() { + // Check if the hooks were already initialized + if (isset($this->hooks_initialized) && $this->hooks_initialized) return; + + // Add the AJAX action to get the list of tags + add_action('wp_ajax_pp_checklists_prohibited_tag', [$this, 'get_list_tag_ajax']); + + // Set the initialization flag to true + $this->hooks_initialized = true; + } + /** * Initialize the language strings for the instance * @@ -66,6 +88,117 @@ public function get_current_status($post, $option_value) return empty(array_intersect($option_ids, $tags)); } + /** + * Get selected values from the settings + * + * @return array + */ + public function get_selected_values() + { + // Option names + $option_name_multiple = $this->name . '_' . $this->field_name; + $option_value = array(); + if (isset($this->module->options->{$option_name_multiple}[$this->post_type])) { + $option_value = $this->module->options->{$option_name_multiple}[$this->post_type]; + } + $selected_tags = array(); + foreach ($option_value as $tag_str) { + [$tag_id, $tag_name] = explode($this->DELIMITER, $tag_str); + $selected_tags[] = $tag_id; + } + + return $selected_tags; + } + + /** + * Get the list of tags + * + * @param array $args + * @return WP_Term[] + */ + public function get_list_tags($args = array('page' => 1, 'per_page' => 10, 'q' => '')) + { + // Get selected tags from the settings + $selected_tags = $this->get_selected_values(); + + // Retrieve selected tags only on the first page + $tags_selected = array(); + + if($args['page'] === 1 && !empty($selected_tags)) { + $args_selected = array( + 'taxonomy' => 'post_tag', + 'hide_empty' => 0, + 'include' => $selected_tags, + 'search' => $args['q'], + ); + $tags_selected = get_tags($args_selected); + } + + // Retrieve tags with a limit of 10 rows + $args_limited = array( + 'taxonomy' => 'post_tag', + 'hide_empty' => 0, + 'exclude' => $selected_tags, + 'search' => $args['q'], + 'number' => $args['per_page'], + 'offset' => ($args['page'] - 1) * $args['per_page'], + ); + + $tags_limited = get_tags($args_limited); + + // Merge the two arrays + $tags = array_merge($tags_limited, $tags_selected); + + // Remove duplicates based on term_id + $tags = array_values(array_reduce($tags, function ($carry, $item) { + if (!isset($carry[$item->term_id])) { + $carry[$item->term_id] = $item; + } + return $carry; + }, [])); + + // Sort the array by name + usort($tags, function ($a, $b) { + return strcasecmp($a->name, $b->name); + }); + + return $tags; + } + + /** + * Get the list of tags via AJAX + * + * @return void + */ + public function get_list_tag_ajax() + { + // Check if the request is valid + check_ajax_referer('pp-checklists-rules', 'nonce'); + + // Get the search query and page number from the request + $search = isset($_POST['q']) ? sanitize_text_field($_POST['q']) : ''; + $page = isset($_POST['page']) ? intval($_POST['page']) : 1; + $per_page = 10; + + // Get the tags + $tags = $this->get_list_tags(['page' => $page ,'per_page' => $per_page, 'q' => $search]); + $results = array(); + + foreach ($tags as $tag) { + $results[] = array( + 'id' => $tag->term_id . $this->DELIMITER . $tag->name, + 'text' => $tag->name, + ); + } + + // Check if there are more tags + $total_tags = wp_count_terms('post_tag', array('search' => $search, 'hide_empty' => 0)); + $has_next = ($page * $per_page) < $total_tags; + + wp_send_json_success(['items' => $results, 'has_next' => $has_next]); + wp_die(); + } + /** * Transform tags to labels * @@ -80,7 +213,7 @@ private function transform_tags($tags = array()) $labels[$tag->term_id . $this->DELIMITER . $tag->name] = $tag->name; if(isset($tag->children)) { foreach ($tag->children as $child) { - $labels[$child->term_id . $this->DELIMITER . $child->name] = "- {$child->name}"; + $labels[$child->term_id . $this->DELIMITER . $child->name] = "— {$child->name}"; } } } @@ -95,11 +228,7 @@ private function transform_tags($tags = array()) */ public function get_setting_drop_down_labels() { - $tags = get_tags(array( - 'orderby' => 'name', - 'order' => 'ASC', - 'hide_empty' => 0, - )); + $tags = $this->get_list_tags(); return $this->transform_tags($tags); } @@ -177,4 +306,10 @@ public function filter_requirements_list($requirements, $post) return $requirements; } + + + public function get_setting_field_html($css_class = '') + { + return parent::get_setting_field_html('pp-checklists-full-width'); + } } diff --git a/core/Requirement/Required_categories.php b/core/Requirement/Required_categories.php index c522e7b8..a9f6784d 100644 --- a/core/Requirement/Required_categories.php +++ b/core/Requirement/Required_categories.php @@ -39,6 +39,28 @@ class Required_categories extends Base_multiple */ private $DELIMITER = '__'; + public function __construct($module, $post_type) + { + parent::__construct($module, $post_type); + $this->init_hooks(); + } + + /** + * Initialize the hooks for the requirement + * + * @return void + */ + public function init_hooks() { + // Check if the hooks were already initialized + if (isset($this->hooks_initialized) && $this->hooks_initialized) return; + + // Add the AJAX action to get the list of categories + add_action('wp_ajax_pp_checklists_required_category', [$this, 'get_list_category_ajax']); + + // Set the initialization flag to true + $this->hooks_initialized = true; + } + /** * Initialize the language strings for the instance * @@ -66,6 +88,129 @@ public function get_current_status($post, $option_value) return !empty(array_intersect($option_ids, $categories)); } + /** + * Get selected values from the settings + * + * @return array + */ + public function get_selected_values() + { + // Option names + $option_name_multiple = $this->name . '_' . $this->field_name; + $option_value = array(); + if (isset($this->module->options->{$option_name_multiple}[$this->post_type])) { + $option_value = $this->module->options->{$option_name_multiple}[$this->post_type]; + } + $selected_categories = array(); + foreach ($option_value as $category_str) { + [$category_id, $category_name] = explode($this->DELIMITER, $category_str); + $selected_categories[] = $category_id; + } + + return $selected_categories; + } + + /** + * Get the list of categories + * + * @param array $args + * @return WP_Term[] + */ + public function get_list_categories($args = array('page' => 1, 'per_page' => 10, 'q' => '')) + { + // Get selected categories from the settings + $selected_categories = $this->get_selected_values(); + + // Retrieve selected categories only on the first page + $categories_selected = array(); + if($args['page'] === 1) { + $args_selected = array( + 'orderby' => 'name', + 'order' => 'ASC', + 'hide_empty' => 0, + 'include' => $selected_categories, + 'search' => $args['q'], + ); + $categories_selected = $this->get_categories_hierarchical($args_selected); + } + + // Retrieve categories with a limit of 10 rows + $args_limited = array( + 'type' => 'post', + 'hide_empty' => 0, + 'hierarchical' => 1, + 'taxonomy' => 'category', + 'pad_counts' => false, + 'orderby' => 'name', + 'order' => 'ASC', + 'hide_empty' => 0, + 'search' => $args['q'], + 'number' => $args['per_page'], + 'offset' => ($args['page'] - 1) * $args['per_page'] + ); + $categories_limited = $this->get_categories_hierarchical($args_limited); + + // Merge the two arrays + $categories = array_merge($categories_limited, $categories_selected); + + // Remove duplicates based on term_id + $categories = array_values(array_reduce($categories, function ($carry, $item) { + if (!isset($carry[$item->term_id])) { + $carry[$item->term_id] = $item; + } + return $carry; + }, [])); + + // Sort the array by name + usort($categories, function ($a, $b) { + return strcasecmp($a->name, $b->name); + }); + + return $categories; + } + + /** + * Get the list of categories via AJAX + * + * @return void + */ + public function get_list_category_ajax() + { + // Check if the request is valid + check_ajax_referer('pp-checklists-rules', 'nonce'); + + // Get the search query and page number from the request + $search = isset($_POST['q']) ? sanitize_text_field($_POST['q']) : ''; + $page = isset($_POST['page']) ? intval($_POST['page']) : 1; + $per_page = 10; + + // Get the categories + $categories = $this->get_list_categories(['page' => $page ,'per_page' => $per_page, 'q' => $search]); + $results = array(); + + foreach ($categories as $category) { + $results[] = array( + 'id' => $category->term_id . $this->DELIMITER . $category->name, + 'text' => $category->name, + ); + if(isset($category->children)) { + foreach ($category->children as $child) { + $results[] = array( + 'id' => $child->term_id . $this->DELIMITER . $child->name, + 'text' => '— ' . $child->name, + ); + } + } + } + + // Check if there are more categories + $total_categories = wp_count_terms('category', array('search' => $search, 'hide_empty' => 0)); + $has_next = ($page * $per_page) < $total_categories; + + wp_send_json_success(['items' => $results, 'has_next' => $has_next]); + wp_die(); + } + /** * Get Categories Hierarchical List * @@ -99,7 +244,7 @@ private function transform_categories($categories = array()) $labels[$category->term_id . $this->DELIMITER . $category->name] = $category->name; if(isset($category->children)) { foreach ($category->children as $child) { - $labels[$child->term_id . $this->DELIMITER . $child->name] = "- {$child->name}"; + $labels[$child->term_id . $this->DELIMITER . $child->name] = "— {$child->name}"; } } } @@ -114,11 +259,7 @@ private function transform_categories($categories = array()) */ public function get_setting_drop_down_labels() { - $categories = $this->get_categories_hierarchical(array( - 'orderby' => 'name', - 'order' => 'ASC', - 'hide_empty' => 0, - )); + $categories = $this->get_list_categories(); return $this->transform_categories($categories); } @@ -196,4 +337,9 @@ public function filter_requirements_list($requirements, $post) return $requirements; } + + public function get_setting_field_html($css_class = '') + { + return parent::get_setting_field_html('pp-checklists-full-width'); + } } diff --git a/core/Requirement/Required_tags.php b/core/Requirement/Required_tags.php index 48a4004c..fbd09ab7 100644 --- a/core/Requirement/Required_tags.php +++ b/core/Requirement/Required_tags.php @@ -39,6 +39,28 @@ class Required_tags extends Base_multiple */ private $DELIMITER = '__'; + public function __construct($module, $post_type) + { + parent::__construct($module, $post_type); + $this->init_hooks(); + } + + /** + * Initialize the hooks for the requirement + * + * @return void + */ + public function init_hooks() { + // Check if the hooks were already initialized + if (isset($this->hooks_initialized) && $this->hooks_initialized) return; + + // Add the AJAX action to get the list of tags + add_action('wp_ajax_pp_checklists_required_tag', [$this, 'get_list_tag_ajax']); + + // Set the initialization flag to true + $this->hooks_initialized = true; + } + /** * Initialize the language strings for the instance * @@ -66,6 +88,117 @@ public function get_current_status($post, $option_value) return !empty(array_intersect($option_ids, $tags)); } + /** + * Get selected values from the settings + * + * @return array + */ + public function get_selected_values() + { + // Option names + $option_name_multiple = $this->name . '_' . $this->field_name; + $option_value = array(); + if (isset($this->module->options->{$option_name_multiple}[$this->post_type])) { + $option_value = $this->module->options->{$option_name_multiple}[$this->post_type]; + } + $selected_tags = array(); + foreach ($option_value as $tag_str) { + [$tag_id, $tag_name] = explode($this->DELIMITER, $tag_str); + $selected_tags[] = $tag_id; + } + + return $selected_tags; + } + + /** + * Get the list of tags + * + * @param array $args + * @return WP_Term[] + */ + public function get_list_tags($args = array('page' => 1, 'per_page' => 10, 'q' => '')) + { + // Get selected tags from the settings + $selected_tags = $this->get_selected_values(); + + // Retrieve selected tags only on the first page + $tags_selected = array(); + + if($args['page'] === 1 && !empty($selected_tags)) { + $args_selected = array( + 'taxonomy' => 'post_tag', + 'hide_empty' => 0, + 'include' => $selected_tags, + 'search' => $args['q'], + ); + $tags_selected = get_tags($args_selected); + } + + // Retrieve tags with a limit of 10 rows + $args_limited = array( + 'taxonomy' => 'post_tag', + 'hide_empty' => 0, + 'exclude' => $selected_tags, + 'search' => $args['q'], + 'number' => $args['per_page'], + 'offset' => ($args['page'] - 1) * $args['per_page'], + ); + + $tags_limited = get_tags($args_limited); + + // Merge the two arrays + $tags = array_merge($tags_limited, $tags_selected); + + // Remove duplicates based on term_id + $tags = array_values(array_reduce($tags, function ($carry, $item) { + if (!isset($carry[$item->term_id])) { + $carry[$item->term_id] = $item; + } + return $carry; + }, [])); + + // Sort the array by name + usort($tags, function ($a, $b) { + return strcasecmp($a->name, $b->name); + }); + + return $tags; + } + + /** + * Get the list of tags via AJAX + * + * @return void + */ + public function get_list_tag_ajax() + { + // Check if the request is valid + check_ajax_referer('pp-checklists-rules', 'nonce'); + + // Get the search query and page number from the request + $search = isset($_POST['q']) ? sanitize_text_field($_POST['q']) : ''; + $page = isset($_POST['page']) ? intval($_POST['page']) : 1; + $per_page = 10; + + // Get the tags + $tags = $this->get_list_tags(['page' => $page ,'per_page' => $per_page, 'q' => $search]); + $results = array(); + + foreach ($tags as $tag) { + $results[] = array( + 'id' => $tag->term_id . $this->DELIMITER . $tag->name, + 'text' => $tag->name, + ); + } + + // Check if there are more tags + $total_tags = wp_count_terms('post_tag', array('search' => $search, 'hide_empty' => 0)); + $has_next = ($page * $per_page) < $total_tags; + + wp_send_json_success(['items' => $results, 'has_next' => $has_next]); + wp_die(); + } + /** * Transform tags to labels * @@ -80,7 +213,7 @@ private function transform_tags($tags = array()) $labels[$tag->term_id . $this->DELIMITER . $tag->name] = $tag->name; if(isset($tag->children)) { foreach ($tag->children as $child) { - $labels[$child->term_id . $this->DELIMITER . $child->name] = "- {$child->name}"; + $labels[$child->term_id . $this->DELIMITER . $child->name] = "— {$child->name}"; } } } @@ -95,11 +228,7 @@ private function transform_tags($tags = array()) */ public function get_setting_drop_down_labels() { - $tags = get_tags(array( - 'orderby' => 'name', - 'order' => 'ASC', - 'hide_empty' => 0, - )); + $tags = $this->get_list_tags(); return $this->transform_tags($tags); } @@ -177,4 +306,10 @@ public function filter_requirements_list($requirements, $post) return $requirements; } + + + public function get_setting_field_html($css_class = '') + { + return parent::get_setting_field_html('pp-checklists-full-width'); + } } diff --git a/lib/vendor/composer/installed.php b/lib/vendor/composer/installed.php index ee62244a..e6212405 100644 --- a/lib/vendor/composer/installed.php +++ b/lib/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'e7ee5b46b80afb6e01a9bc70d32dfad105ef0905', + 'reference' => '5532c13c04101d76b93ddc8015b2482b9e75f0e3', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'e7ee5b46b80afb6e01a9bc70d32dfad105ef0905', + 'reference' => '5532c13c04101d76b93ddc8015b2482b9e75f0e3', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), diff --git a/modules/checklists/assets/js/global-checklists.js b/modules/checklists/assets/js/global-checklists.js index 46c24ce6..f2f2fbbc 100644 --- a/modules/checklists/assets/js/global-checklists.js +++ b/modules/checklists/assets/js/global-checklists.js @@ -436,4 +436,4 @@ return text.trim(); } -})(jQuery, objectL10n_checklists_global_checklist); +})(jQuery, objectL10n_checklists_global_checklist); \ No newline at end of file diff --git a/modules/checklists/checklists.php b/modules/checklists/checklists.php index d6e2e162..651fc802 100644 --- a/modules/checklists/checklists.php +++ b/modules/checklists/checklists.php @@ -119,7 +119,6 @@ public function __construct() ); $this->module = $legacyPlugin->register_module($this->module_name, $args); - } public function migrateLegacyOptions() @@ -353,13 +352,13 @@ public function filter_post_type_requirements($requirements, $post_type) $taxonomies_map = [ 'category' => [ '\\PublishPress\\Checklists\\Core\\Requirement\\Categories_count', - // '\\PublishPress\\Checklists\\Core\\Requirement\\Required_categories', - // '\\PublishPress\\Checklists\\Core\\Requirement\\Prohibited_categories', + '\\PublishPress\\Checklists\\Core\\Requirement\\Required_categories', + '\\PublishPress\\Checklists\\Core\\Requirement\\Prohibited_categories', ], 'post_tag' => [ '\\PublishPress\\Checklists\\Core\\Requirement\\Tags_count', - // '\\PublishPress\\Checklists\\Core\\Requirement\\Required_tags', - // '\\PublishPress\\Checklists\\Core\\Requirement\\Prohibited_tags', + '\\PublishPress\\Checklists\\Core\\Requirement\\Required_tags', + '\\PublishPress\\Checklists\\Core\\Requirement\\Prohibited_tags', ], ]; @@ -599,6 +598,8 @@ public function add_admin_scripts() 'roles' => $roles, 'first_post_type' => current($postTypes), 'required_rules' => $required_rules, + 'ajaxurl' => admin_url('admin-ajax.php'), + 'nonce' => wp_create_nonce('pp-checklists-rules'), 'submit_error' => esc_html__( 'Please make sure to complete the settings for', 'publishpress-checklists' diff --git a/modules/permissions/assets/css/admin.css b/modules/permissions/assets/css/admin.css index 5af07b2b..b3c797b6 100644 --- a/modules/permissions/assets/css/admin.css +++ b/modules/permissions/assets/css/admin.css @@ -9,4 +9,8 @@ .pp-checklists-can-ignore { min-width: 250px; -} \ No newline at end of file +} + +.pp-checklists-full-width { + width: 400px !important; +} diff --git a/modules/permissions/assets/js/admin.js b/modules/permissions/assets/js/admin.js index c25f7c1c..b9ba8b6e 100644 --- a/modules/permissions/assets/js/admin.js +++ b/modules/permissions/assets/js/admin.js @@ -1,3 +1,34 @@ jQuery(function ($) { $('#pp-checklists-global select').select2(); + // Re-initialize select 2 with ajax + function initializeSelect2(selector, identifier) { + $(selector).select2({ + ajax: { + url: objectL10n_checklists_global_checklist.ajaxurl, + dataType: 'json', + delay: 250, + type: 'POST', + cache: true, + data: function (params) { + return { + action: 'pp_checklists_' + identifier, + nonce: objectL10n_checklists_global_checklist.nonce, + q: params.term, + page: params.page || 1, + }; + }, + processResults: function (res, params) { + params.page = params.page || 1; + return { + results: res.data.items, + pagination: { more: res.data.has_next }, + }; + }, + }, + }); + } + initializeSelect2('#post-checklists-required_categories_multiple', 'required_category'); + initializeSelect2('#post-checklists-prohibited_categories_multiple', 'prohibited_category'); + initializeSelect2('#post-checklists-required_tags_multiple', 'required_tag'); + initializeSelect2('#post-checklists-prohibited_tags_multiple', 'prohibited_tag'); }); diff --git a/publishpress-checklists.php b/publishpress-checklists.php index c832f678..e0f95943 100644 --- a/publishpress-checklists.php +++ b/publishpress-checklists.php @@ -5,7 +5,7 @@ * Description: Add support for checklists in WordPress * Author: PublishPress * Author URI: https://publishpress.com - * Version: 2.11.1 + * Version: 2.12.0-beta.1 * Text Domain: publishpress-checklists * Domain Path: /languages * Requires at least: 5.5