From 2d56c344a35874d5bf9fe6b1a100fafdbffb05f9 Mon Sep 17 00:00:00 2001 From: olatechpro Date: Thu, 10 Oct 2024 15:03:22 +0100 Subject: [PATCH 1/2] Keep some plugin files under 80kb --- modules/calendar/calendar.php | 287 +---------------- modules/calendar/library/calendar-methods.php | 1 - .../calendar/library/calendar-utilities.php | 291 ++++++++++++++++++ modules/content-board/content-board.php | 38 +-- .../library/content-board-methods.php | 36 +++ modules/content-overview/content-overview.php | 246 ++------------- .../library/content-overview-utilities.php | 191 ------------ 7 files changed, 367 insertions(+), 723 deletions(-) diff --git a/modules/calendar/calendar.php b/modules/calendar/calendar.php index d91273ec..1f7ee9b9 100644 --- a/modules/calendar/calendar.php +++ b/modules/calendar/calendar.php @@ -321,9 +321,6 @@ public function init() add_action('admin_print_styles', [$this->content_calendar_methods, 'add_admin_styles']); add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']); - // Ajax insert post placeholder for a specific date - add_action('wp_ajax_pp_insert_post', [$this, 'handle_ajax_insert_post']); - add_action('wp_ajax_publishpress_calendar_search_authors', ['PP_Calendar_Utilities', 'searchAuthors']); add_action('wp_ajax_publishpress_calendar_search_terms', ['PP_Calendar_Utilities', 'searchTerms']); add_action('wp_ajax_publishpress_calendar_get_data', [$this, 'fetchCalendarDataJson']); @@ -341,7 +338,7 @@ public function init() add_filter('pp_calendar_after_form_submission_sanitize_content', [$this, 'sanitize_text_input'], 10, 1); add_filter('pp_calendar_after_form_submission_sanitize_author', [$this, 'sanitize_author_input'], 10, 1); add_filter('pp_calendar_after_form_submission_validate_author', [$this, 'validateAuthorForPost'], 10, 1); - add_filter('admin_body_class', [$this, 'add_admin_body_class']); + add_filter('admin_body_class', ['PP_Calendar_Utilities', 'add_admin_body_class']); } // Clear li cache for a post when post cache is cleared @@ -351,14 +348,6 @@ public function init() $this->default_date_time_format = get_option('date_format') . ' ' . get_option('time_format'); } - public function add_admin_body_class($classes) { - global $pagenow; - if ('admin.php' === $pagenow && isset($_GET['page']) && $_GET['page'] === self::MENU_SLUG) { - $classes .= ' pp-content-calendar-page'; - } - return $classes; - } - /** * @param $original_template * @@ -534,28 +523,6 @@ public function enqueue_admin_scripts() } } - private function getTimezoneString() - { - $timezoneString = get_option('timezone_string'); - - if (empty($timezoneString)) { - $offset = get_option('gmt_offset'); - - if ($offset > 0) { - $offset = '+' . $offset; - } - - if (2 === strlen($offset)) { - $offset .= ':00'; - } - - $timezoneString = new DateTimeZone($offset); - $timezoneString = $timezoneString->getName(); - } - - return $timezoneString; - } - /** * After checking that the request is valid, do an .ics file * @@ -840,22 +807,6 @@ public function update_user_filters($request_filter = []) return $user_filters; } - /** - * Set all post types as selected, to be used as the default option. - * - * @return array - */ - protected function pre_select_all_post_types() - { - $list = get_post_types(null, 'objects'); - - foreach ($list as $type => $value) { - $list[$type] = 'on'; - } - - return $list; - } - /** * Get an array of the selected post types. * @@ -1057,46 +1008,10 @@ public function get_content_calendar_form_filters() { $content_calendar_datas = $this->content_calendar_datas; - $filters = []; - // custom filters - $filters['custom'] = [ - 'title' => esc_html__('Custom filters', 'publishpress'), - 'message' => esc_html__('Click the "Add New" button to create new filters.', 'publishpress'), - 'filters' => $content_calendar_datas['content_calendar_custom_filters'] - ]; - - // default filters - $filters['default'] = [ - 'title' => esc_html__('Inbuilt filters', 'publishpress'), - 'filters' => [ - 'post_status' => esc_html__('Post Status', 'publishpress'), - 'author' => esc_html__('Author', 'publishpress'), - 'cpt' => esc_html__('Post Type', 'publishpress') - ] - ]; + $args = []; + $args['content_calendar_datas'] = $content_calendar_datas; - // editorial fields filters - if (isset($content_calendar_datas['editorial_metadata'])) { - $filters['editorial_metadata'] = [ - 'title' => esc_html__('Editorial Fields', 'publishpress'), - 'message' => esc_html__('You do not have any editorial fields enabled', 'publishpress'), - 'filters' => $content_calendar_datas['editorial_metadata'] - ]; - } - - $filters['taxonomies'] = [ - 'title' => esc_html__('Taxonomies', 'publishpress'), - 'message' => esc_html__('You do not have any public taxonomies', 'publishpress'), - 'filters' => $content_calendar_datas['taxonomies'] - ]; - - /** - * @param array $filters - * @param array $content_calendar_datas - * - * @return $filters - */ - $filters = apply_filters('publishpress_content_calendar_form_filters', $filters, $content_calendar_datas); + $filters = PP_Calendar_Utilities::get_content_calendar_form_filters($args); $this->form_filters = $filters; @@ -1161,105 +1076,8 @@ public function render_admin_page() add_thickbox(); ob_start(); ?> - - - - - '; @@ -1825,91 +1643,16 @@ public function getPostData() wp_send_json(null, 404); } - $authorsNames = apply_filters( - 'publishpress_post_authors_names', - [get_the_author_meta('display_name', $post->post_author)], - $id - ); - - $categories = $this->getPostCategoriesNames($id); - $tags = $this->getPostTagsNames($id); - - $data = [ - 'id' => $id, - 'status' => $post->post_status, - 'fields' => [ - 'type' => [ - 'label' => __('Post Type', 'publishpress'), - 'value' => $this->getPostTypeName($post->post_type), - 'type' => 'type', - ], - 'id' => [ - 'label' => __('ID', 'publishpress'), - 'value' => $id, - 'type' => 'number', - ], - 'date' => [ - 'label' => __('Date', 'publishpress'), - 'value' => $post->post_date, - 'valueString' => get_the_date(get_option('date_format', 'Y-m-d H:i:s'), $post), - 'type' => 'date', - ], - 'status' => [ - 'label' => __('Post Status', 'publishpress'), - 'value' => $this->getPostStatusName($post->post_status), - 'type' => 'status', - ], - 'authors' => [ - 'label' => _n('Author', 'Authors', count($authorsNames), 'publishpress'), - 'value' => $authorsNames, - 'type' => 'authors', - ], - 'categories' => [ - 'label' => _n('Category', 'Categories', count($categories), 'publishpress'), - 'value' => $categories, - 'type' => 'taxonomy', - ], - 'tags' => [ - 'label' => _n('Tag', 'Tags', count($tags), 'publishpress'), - 'value' => $tags, - 'type' => 'taxonomy', - ], - ], - 'links' => [] - ]; - - $postTypeObject = get_post_type_object($post->post_type); - - if (current_user_can($postTypeObject->cap->edit_post, $post->ID)) { - $data['links']['edit'] = [ - 'label' => __('Edit', 'publishpress'), - 'url' => htmlspecialchars_decode(get_edit_post_link($id)) - ]; - } - - if (current_user_can($postTypeObject->cap->delete_post, $post->ID)) { - $data['links']['trash'] = [ - 'label' => __('Trash', 'publishpress'), - 'url' => htmlspecialchars_decode(get_delete_post_link($id)), - ]; - } - - if (current_user_can($postTypeObject->cap->read_post, $post->ID)) { - if ($post->post_status === 'publish') { - $label = __('View', 'publishpress'); - $link = get_permalink($id); - } else { - $label = __('Preview', 'publishpress'); - $link = get_preview_post_link($id); - } - - $data['links']['view'] = [ - 'label' => $label, - 'url' => htmlspecialchars_decode($link), - ]; - } - - $data = apply_filters('publishpress_calendar_get_post_data', $data, $post); + $args = []; + $args['id'] = $id; + $args['post'] = $post; + $args['type'] = $this->getPostTypeName($post->post_type); + $args['date'] = get_the_date(get_option('date_format', 'Y-m-d H:i:s'), $post); + $args['status'] = $this->getPostStatusName($post->post_status); + $args['categories'] = $this->getPostCategoriesNames($id); + $args['tags'] = $this->getPostTagsNames($id); + + $data = PP_Calendar_Utilities::getPostData($args); wp_send_json($data, 202); } diff --git a/modules/calendar/library/calendar-methods.php b/modules/calendar/library/calendar-methods.php index 6341d571..b5df65d1 100644 --- a/modules/calendar/library/calendar-methods.php +++ b/modules/calendar/library/calendar-methods.php @@ -996,7 +996,6 @@ public function enqueue_admin_scripts($method_args) ); - if (! isset($wp_scripts->queue['react'])) { wp_enqueue_script( 'react', diff --git a/modules/calendar/library/calendar-utilities.php b/modules/calendar/library/calendar-utilities.php index 2888964a..e4c69170 100644 --- a/modules/calendar/library/calendar-utilities.php +++ b/modules/calendar/library/calendar-utilities.php @@ -1004,6 +1004,297 @@ public static function get_ending_of_week($date, $format = 'Y-m-d', $week = 1) return $formatted_end_of_week; } + public static function getPostData($args) { + $id = $args['id']; + $post = $args['post']; + $type = $args['type']; + $date = $args['date']; + $status = $args['status']; + $categories = $args['categories']; + $tags = $args['tags']; + + $authorsNames = apply_filters( + 'publishpress_post_authors_names', + [get_the_author_meta('display_name', $post->post_author)], + $id + ); + + $data = [ + 'id' => $id, + 'status' => $post->post_status, + 'fields' => [ + 'type' => [ + 'label' => __('Post Type', 'publishpress'), + 'value' => $type, + 'type' => 'type', + ], + 'id' => [ + 'label' => __('ID', 'publishpress'), + 'value' => $id, + 'type' => 'number', + ], + 'date' => [ + 'label' => __('Date', 'publishpress'), + 'value' => $post->post_date, + 'valueString' => $date, + 'type' => 'date', + ], + 'status' => [ + 'label' => __('Post Status', 'publishpress'), + 'value' => $status, + 'type' => 'status', + ], + 'authors' => [ + 'label' => _n('Author', 'Authors', count($authorsNames), 'publishpress'), + 'value' => $authorsNames, + 'type' => 'authors', + ], + 'categories' => [ + 'label' => _n('Category', 'Categories', count($categories), 'publishpress'), + 'value' => $categories, + 'type' => 'taxonomy', + ], + 'tags' => [ + 'label' => _n('Tag', 'Tags', count($tags), 'publishpress'), + 'value' => $tags, + 'type' => 'taxonomy', + ], + ], + 'links' => [] + ]; + + $postTypeObject = get_post_type_object($post->post_type); + + if (current_user_can($postTypeObject->cap->edit_post, $post->ID)) { + $data['links']['edit'] = [ + 'label' => __('Edit', 'publishpress'), + 'url' => htmlspecialchars_decode(get_edit_post_link($id)) + ]; + } + + if (current_user_can($postTypeObject->cap->delete_post, $post->ID)) { + $data['links']['trash'] = [ + 'label' => __('Trash', 'publishpress'), + 'url' => htmlspecialchars_decode(get_delete_post_link($id)), + ]; + } + + if (current_user_can($postTypeObject->cap->read_post, $post->ID)) { + if ($post->post_status === 'publish') { + $label = __('View', 'publishpress'); + $link = get_permalink($id); + } else { + $label = __('Preview', 'publishpress'); + $link = get_preview_post_link($id); + } + + $data['links']['view'] = [ + 'label' => $label, + 'url' => htmlspecialchars_decode($link), + ]; + } + + $data = apply_filters('publishpress_calendar_get_post_data', $data, $post); + + return $data; + } + + public static function add_admin_body_class($classes) { + global $pagenow; + if ('admin.php' === $pagenow && isset($_GET['page']) && $_GET['page'] === 'pp-calendar') { + $classes .= ' pp-content-calendar-page'; + } + return $classes; + } + + public static function getTimezoneString() + { + $timezoneString = get_option('timezone_string'); + + if (empty($timezoneString)) { + $offset = get_option('gmt_offset'); + + if ($offset > 0) { + $offset = '+' . $offset; + } + + if (2 === strlen($offset)) { + $offset .= ':00'; + } + + $timezoneString = new DateTimeZone($offset); + $timezoneString = $timezoneString->getName(); + } + + return $timezoneString; + } + + /** + * Set all post types as selected, to be used as the default option. + * + * @return array + */ + public static function pre_select_all_post_types() + { + $list = get_post_types(null, 'objects'); + + foreach ($list as $type => $value) { + $list[$type] = 'on'; + } + + return $list; + } + + public static function get_content_calendar_form_filters($args) + { + $content_calendar_datas = $args['content_calendar_datas']; + // custom filters + $filters['custom'] = [ + 'title' => esc_html__('Custom filters', 'publishpress'), + 'message' => esc_html__('Click the "Add New" button to create new filters.', 'publishpress'), + 'filters' => $content_calendar_datas['content_calendar_custom_filters'] + ]; + + // default filters + $filters['default'] = [ + 'title' => esc_html__('Inbuilt filters', 'publishpress'), + 'filters' => [ + 'post_status' => esc_html__('Post Status', 'publishpress'), + 'author' => esc_html__('Author', 'publishpress'), + 'cpt' => esc_html__('Post Type', 'publishpress') + ] + ]; + + // editorial fields filters + if (isset($content_calendar_datas['editorial_metadata'])) { + $filters['editorial_metadata'] = [ + 'title' => esc_html__('Editorial Fields', 'publishpress'), + 'message' => esc_html__('You do not have any editorial fields enabled', 'publishpress'), + 'filters' => $content_calendar_datas['editorial_metadata'] + ]; + } + + $filters['taxonomies'] = [ + 'title' => esc_html__('Taxonomies', 'publishpress'), + 'message' => esc_html__('You do not have any public taxonomies', 'publishpress'), + 'filters' => $content_calendar_datas['taxonomies'] + ]; + + /** + * @param array $filters + * @param array $content_calendar_datas + * + * @return $filters + */ + $filters = apply_filters('publishpress_content_calendar_form_filters', $filters, $content_calendar_datas); + + return $filters; + } + + public static function calendar_ics_subs_html($subscription_link) { + ?> + + + + + + + content_board_methods, 'handle_form_date_range_change']); // Register our settings - add_action('admin_init', [$this, 'register_settings']); + add_action('admin_init', [$this->content_board_methods, 'register_settings']); add_action('wp_ajax_publishpress_content_board_search_authors', [$this, 'sendJsonSearchAuthors']); add_action('wp_ajax_publishpress_content_board_search_categories', [$this, 'sendJsonSearchCategories']); @@ -253,42 +253,6 @@ public function setDefaultCapabilities() } } - /** - * Register settings for notifications so we can partially use the Settings API - * (We use the Settings API for form generation, but not saving) - * - * @since 0.7 - * @uses add_settings_section(), add_settings_field() - */ - public function register_settings() - { - add_settings_section( - $this->module->options_group_name . '_general', - false, - '__return_false', - $this->module->options_group_name - ); - - add_settings_field( - 'post_types', - esc_html__('Post types to show:', 'publishpress'), - [$this, 'settings_post_types_option'], - $this->module->options_group_name, - $this->module->options_group_name . '_general' - ); - } - - /** - * Choose the post types for editorial fields - * - * @since 0.7 - */ - public function settings_post_types_option() - { - global $publishpress; - $publishpress->settings->helper_option_custom_post_type($this->module); - } - /** * Get the post types for editorial fields * diff --git a/modules/content-board/library/content-board-methods.php b/modules/content-board/library/content-board-methods.php index 3db7c689..c871b35c 100644 --- a/modules/content-board/library/content-board-methods.php +++ b/modules/content-board/library/content-board-methods.php @@ -423,6 +423,42 @@ public function action_enqueue_admin_styles() } } + /** + * Register settings for notifications so we can partially use the Settings API + * (We use the Settings API for form generation, but not saving) + * + * @since 0.7 + * @uses add_settings_section(), add_settings_field() + */ + public function register_settings() + { + add_settings_section( + $this->module->options_group_name . '_general', + false, + '__return_false', + $this->module->options_group_name + ); + + add_settings_field( + 'post_types', + esc_html__('Post types to show:', 'publishpress'), + [$this, 'settings_post_types_option'], + $this->module->options_group_name, + $this->module->options_group_name . '_general' + ); + } + + /** + * Choose the post types for editorial fields + * + * @since 0.7 + */ + public function settings_post_types_option() + { + global $publishpress; + $publishpress->settings->helper_option_custom_post_type($this->module); + } + } } diff --git a/modules/content-overview/content-overview.php b/modules/content-overview/content-overview.php index a8cc7b1a..bc502375 100644 --- a/modules/content-overview/content-overview.php +++ b/modules/content-overview/content-overview.php @@ -77,6 +77,7 @@ class PP_Content_Overview extends PP_Module * @var [type] */ public $module; + public $module_url; /** * [$no_matching_posts description] @@ -136,6 +137,13 @@ class PP_Content_Overview extends PP_Module */ public $content_overview_datas; + /** + * Content calendar methods + * + * @var [type] + */ + private $content_overview_methods; + /** * Register the module with PublishPress but don't do anything else */ @@ -174,6 +182,14 @@ public function __construct() ]; $this->module = PublishPress()->register_module('content_overview', $args); + + // Load utilities files. + $this->load_utilities_files(); + + $this->content_overview_methods = new PP_Overview_Methods([ + 'module' => $this->module, + 'module_url' => $this->module_url + ]); } /** @@ -191,39 +207,28 @@ public function init() return; } - // Load utilities files. - $this->load_utilities_files(); - // Filter to allow users to pick a taxonomy other than 'category' for sorting their posts $this->taxonomy_used = apply_filters('PP_Content_Overview_taxonomy_used', $this->taxonomy_used); add_action('admin_init', [$this, 'handle_form_date_range_change']); // Register our settings - add_action('admin_init', [$this, 'register_settings']); + add_action('admin_init', [$this->content_overview_methods, 'register_settings']); add_action('wp_ajax_publishpress_content_overview_search_authors', [$this, 'sendJsonSearchAuthors']); add_action('wp_ajax_publishpress_content_overview_search_categories', [$this, 'sendJsonSearchCategories']); add_action('wp_ajax_publishpress_content_overview_get_form_fields', [$this, 'getFormFieldAjaxHandler']); // Menu - add_filter('publishpress_admin_menu_slug', [$this, 'filter_admin_menu_slug'], 20); + add_filter('publishpress_admin_menu_slug', [$this->content_overview_methods, 'filter_admin_menu_slug'], 20); add_action('publishpress_admin_menu_page', [$this, 'action_admin_menu_page'], 20); add_action('publishpress_admin_submenu', [$this, 'action_admin_submenu'], 20); // Load necessary scripts and stylesheets - add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']); - add_action('admin_enqueue_scripts', [$this, 'action_enqueue_admin_styles']); + add_action('admin_enqueue_scripts', [$this->content_overview_methods, 'enqueue_admin_scripts']); + add_action('admin_enqueue_scripts', [$this->content_overview_methods, 'action_enqueue_admin_styles']); // Content Board body class - add_filter('admin_body_class', [$this, 'add_admin_body_class']); - } - - public function add_admin_body_class($classes) { - global $pagenow; - if ('admin.php' === $pagenow && isset($_GET['page']) && $_GET['page'] === 'pp-content-overview') { - $classes .= ' pp-content-overview-page'; - } - return $classes; + add_filter('admin_body_class', [$this->content_overview_methods, 'add_admin_body_class']); } private function getViewCapability() @@ -247,42 +252,6 @@ public function setDefaultCapabilities() } } - /** - * Register settings for notifications so we can partially use the Settings API - * (We use the Settings API for form generation, but not saving) - * - * @since 0.7 - * @uses add_settings_section(), add_settings_field() - */ - public function register_settings() - { - add_settings_section( - $this->module->options_group_name . '_general', - false, - '__return_false', - $this->module->options_group_name - ); - - add_settings_field( - 'post_types', - esc_html__('Post types to show:', 'publishpress'), - [$this, 'settings_post_types_option'], - $this->module->options_group_name, - $this->module->options_group_name . '_general' - ); - } - - /** - * Choose the post types for editorial fields - * - * @since 0.7 - */ - public function settings_post_types_option() - { - global $publishpress; - $publishpress->settings->helper_option_custom_post_type($this->module); - } - /** * Get the post types for editorial fields * @@ -392,22 +361,6 @@ public function upgrade($previous_version) } } - /** - * Filters the menu slug. - * - * @param $menu_slug - * - * @return string - */ - public function filter_admin_menu_slug($menu_slug) - { - if (empty($menu_slug) && $this->module_enabled('content_overview')) { - $menu_slug = self::MENU_SLUG; - } - - return $menu_slug; - } - /** * Creates the admin menu if there is no menu set. */ @@ -446,118 +399,6 @@ public function action_admin_submenu() ); } - /** - * Enqueue necessary admin scripts only on the content overview page. - * - * @uses enqueue_admin_script() - */ - public function enqueue_admin_scripts() - { - global $pagenow; - - // Only load content overview styles on the content overview page - if ('admin.php' === $pagenow && isset($_GET['page']) && $_GET['page'] === 'pp-content-overview') { // phpcs:ignore WordPress.Security.NonceVerification.Recommended - - $this->enqueue_datepicker_resources(); - - wp_enqueue_script( - 'publishpress-admin', - PUBLISHPRESS_URL . 'common/js/publishpress-admin.js', - ['jquery'], - PUBLISHPRESS_VERSION - ); - - wp_enqueue_script( - 'publishpress-content_overview', - $this->module_url . 'lib/content-overview.js', - ['jquery', 'publishpress-date_picker', 'publishpress-select2', 'jquery-ui-sortable'], - PUBLISHPRESS_VERSION, - true - ); - - wp_enqueue_script( - 'publishpress-select2-utils', - PUBLISHPRESS_URL . 'common/libs/select2-v4.0.13.1/js/select2-utils.min.js', - ['jquery'], - PUBLISHPRESS_VERSION - ); - - wp_enqueue_script( - 'publishpress-select2', - PUBLISHPRESS_URL . 'common/libs/select2-v4.0.13.1/js/select2.min.js', - ['jquery', 'publishpress-select2-utils'], - PUBLISHPRESS_VERSION - ); - - - wp_enqueue_script( - 'publishpress-floating-scroll', - PUBLISHPRESS_URL . 'common/libs/floating-scroll/js/jquery.floatingscroll.min.js', - ['jquery'], - PUBLISHPRESS_VERSION - ); - - wp_localize_script( - 'publishpress-content_overview', - 'PPContentOverview', - [ - 'nonce' => wp_create_nonce('content_overview_filter_nonce'), - 'moduleUrl' => $this->module_url, - 'publishpressUrl' => PUBLISHPRESS_URL, - ] - ); - } - } - - /** - * Enqueue a screen and print stylesheet for the content overview. - */ - public function action_enqueue_admin_styles() - { - global $pagenow; - - // Only load calendar styles on the calendar page - if ('admin.php' === $pagenow && isset($_GET['page']) && $_GET['page'] === 'pp-content-overview') { // phpcs:ignore WordPress.Security.NonceVerification.Recommended - wp_enqueue_style( - 'pp-admin-css', - PUBLISHPRESS_URL . 'common/css/publishpress-admin.css', - ['publishpress-select2'], - PUBLISHPRESS_VERSION, - 'screen' - ); - wp_enqueue_style( - 'publishpress-content_overview-styles', - $this->module_url . 'lib/content-overview.css', - false, - PUBLISHPRESS_VERSION, - 'screen' - ); - wp_enqueue_style( - 'publishpress-content_overview-print-styles', - $this->module_url . 'lib/content-overview-print.css', - false, - PUBLISHPRESS_VERSION, - 'print' - ); - - wp_enqueue_style( - 'publishpress-select2', - PUBLISHPRESS_URL . 'common/libs/select2-v4.0.13.1/css/select2.min.css', - false, - PUBLISHPRESS_VERSION, - 'screen' - ); - - wp_enqueue_style( - 'publishpress-floating-scroll', - PUBLISHPRESS_URL . 'common/libs/floating-scroll/css/jquery.floatingscroll.css', - false, - PUBLISHPRESS_VERSION, - 'screen' - ); - } - } - /** * Create the content overview view. This calls lots of other methods to do its work. This will * output any messages, create the table navigation, then print the columns.. @@ -612,7 +453,7 @@ public function render_admin_page()
print_messages(); ?> + $this->content_overview_methods->print_messages(); ?> table_navigation(); ?> @@ -788,46 +629,6 @@ public function handle_form_date_range_change() $this->update_user_meta($current_user->ID, self::USERMETA_KEY_PREFIX . 'filters', $user_filters); } - /** - * Print any messages that should appear based on the action performed - */ - public function print_messages() - { - // phpcs:disable WordPress.Security.NonceVerification.Recommended - if (isset($_GET['trashed']) || isset($_GET['untrashed'])) { - echo '

'; - - // Following mostly stolen from edit.php - if (isset($_GET['trashed']) && (int)$_GET['trashed']) { - $count = (int)$_GET['trashed']; - - echo esc_html(_n('Item moved to the trash.', '%d items moved to the trash.', $count)); - $ids = isset($_GET['ids']) ? sanitize_text_field($_GET['ids']) : 0; - echo ' ' . esc_html__('Undo', 'publishpress') . '
'; - unset($_GET['trashed']); - } - - if (isset($_GET['untrashed']) && (int)$_GET['untrashed']) { - $count = (int)$_GET['untrashed']; - - echo esc_html(_n( - 'Item restored from the Trash.', - '%d items restored from the Trash.', - $count - )); - unset($_GET['undeleted']); - } - - echo '

'; - } - // phpcs:enable - } - /** * Update content overview form action * @@ -1226,6 +1027,7 @@ public function get_editable_post_types() { */ private function load_utilities_files() { require_once dirname(__FILE__) . "/library/content-overview-utilities.php"; + require_once dirname(__FILE__) . "/library/content-overview-methods.php"; } /** @@ -1259,7 +1061,7 @@ public function table_navigation() $args['post_form'] = PP_Content_Overview_Utilities::content_overview_get_post_form($args); } - PP_Content_Overview_Utilities::table_navigation($args); + $this->content_overview_methods::table_navigation($args); } public function content_overview_filters() diff --git a/modules/content-overview/library/content-overview-utilities.php b/modules/content-overview/library/content-overview-utilities.php index 8939acee..fd02fd40 100644 --- a/modules/content-overview/library/content-overview-utilities.php +++ b/modules/content-overview/library/content-overview-utilities.php @@ -7,197 +7,6 @@ class PP_Content_Overview_Utilities { - /** - * Print the table navigation and filter controls, using the current user's filters if any are set. - */ - public static function table_navigation($args) - { - $editable_post_types = $args['editable_post_types']; - $user_filters = $args['user_filters']; - $overview_filters = $args['overview_filters']; - $posts_per_page = $args['posts_per_page']; - ?> -
-
- -
- -
- -
- -
- - -
- -
- - - -
- -
- -
-
- - -
- -
- - -
- -
-
-
-
-
- - - -
- - - - $select_name) { - $modal_id++; - $args['select_id'] = $select_id; - $args['select_name'] = $select_name; - $filter_data = self::content_overview_filter_options($args); - $active_class = !empty($filter_data['selected_value']) ? 'active-filter' : ''; - $button_label = $filter_data['filter_label']; - $button_label .= !empty($filter_data['selected_value']) ? ': ' . $filter_data['selected_value'] : ''; - ?> - - - - - - - - -
-
- -
- - - - - - - - - $select_name) { - echo ''; - } ?> - '; - $start_date_value .= ''; - - $end_date_value = ''; - $end_date_value .= ''; - - $nonce = wp_nonce_field('change-date', 'nonce', 'change-date-nonce', false); - - echo $start_date_value . $end_date_value . $nonce; - ?> - -
- Date: Thu, 10 Oct 2024 15:04:07 +0100 Subject: [PATCH 2/2] Increase version and update new file --- includes.php | 2 +- .../library/content-overview-methods.php | 433 ++++++++++++++++++ 2 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 modules/content-overview/library/content-overview-methods.php diff --git a/includes.php b/includes.php index 294b4c03..91f2fa68 100644 --- a/includes.php +++ b/includes.php @@ -34,7 +34,7 @@ if (! defined('PP_LOADED')) { if (! defined('PUBLISHPRESS_VERSION')) { // Define constants - define('PUBLISHPRESS_VERSION', '4.5.0'); + define('PUBLISHPRESS_VERSION', '4.5.0.1'); define('PUBLISHPRESS_BASE_PATH', __DIR__); define('PUBLISHPRESS_VIEWS_PATH', __DIR__ . '/views'); define('PUBLISHPRESS_FILE_PATH', PUBLISHPRESS_BASE_PATH . '/publishpress.php'); diff --git a/modules/content-overview/library/content-overview-methods.php b/modules/content-overview/library/content-overview-methods.php new file mode 100644 index 00000000..6733fc0d --- /dev/null +++ b/modules/content-overview/library/content-overview-methods.php @@ -0,0 +1,433 @@ +module_url = $args['module_url']; + $this->module = $args['module']; + } + + public function add_admin_body_class($classes) { + global $pagenow; + if ('admin.php' === $pagenow && isset($_GET['page']) && $_GET['page'] === 'pp-content-overview') { + $classes .= ' pp-content-overview-page'; + } + return $classes; + } + + /** + * Enqueue necessary admin scripts only on the content overview page. + * + * @uses enqueue_admin_script() + */ + public function enqueue_admin_scripts() + { + global $pagenow; + + // Only load content overview styles on the content overview page + if ('admin.php' === $pagenow && isset($_GET['page']) && $_GET['page'] === 'pp-content-overview') { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + + $this->enqueue_datepicker_resources(); + + wp_enqueue_script( + 'publishpress-admin', + PUBLISHPRESS_URL . 'common/js/publishpress-admin.js', + ['jquery'], + PUBLISHPRESS_VERSION + ); + + wp_enqueue_script( + 'publishpress-content_overview', + $this->module_url . 'lib/content-overview.js', + ['jquery', 'publishpress-date_picker', 'publishpress-select2', 'jquery-ui-sortable'], + PUBLISHPRESS_VERSION, + true + ); + + wp_enqueue_script( + 'publishpress-select2-utils', + PUBLISHPRESS_URL . 'common/libs/select2-v4.0.13.1/js/select2-utils.min.js', + ['jquery'], + PUBLISHPRESS_VERSION + ); + + wp_enqueue_script( + 'publishpress-select2', + PUBLISHPRESS_URL . 'common/libs/select2-v4.0.13.1/js/select2.min.js', + ['jquery', 'publishpress-select2-utils'], + PUBLISHPRESS_VERSION + ); + + + wp_enqueue_script( + 'publishpress-floating-scroll', + PUBLISHPRESS_URL . 'common/libs/floating-scroll/js/jquery.floatingscroll.min.js', + ['jquery'], + PUBLISHPRESS_VERSION + ); + + wp_localize_script( + 'publishpress-content_overview', + 'PPContentOverview', + [ + 'nonce' => wp_create_nonce('content_overview_filter_nonce'), + 'moduleUrl' => $this->module_url, + 'publishpressUrl' => PUBLISHPRESS_URL, + ] + ); + } + } + + /** + * Enqueue a screen and print stylesheet for the content overview. + */ + public function action_enqueue_admin_styles() + { + global $pagenow; + + // Only load calendar styles on the calendar page + if ('admin.php' === $pagenow && isset($_GET['page']) && $_GET['page'] === 'pp-content-overview') { // phpcs:ignore WordPress.Security.NonceVerification.Recommended + wp_enqueue_style( + 'pp-admin-css', + PUBLISHPRESS_URL . 'common/css/publishpress-admin.css', + ['publishpress-select2'], + PUBLISHPRESS_VERSION, + 'screen' + ); + wp_enqueue_style( + 'publishpress-content_overview-styles', + $this->module_url . 'lib/content-overview.css', + false, + PUBLISHPRESS_VERSION, + 'screen' + ); + wp_enqueue_style( + 'publishpress-content_overview-print-styles', + $this->module_url . 'lib/content-overview-print.css', + false, + PUBLISHPRESS_VERSION, + 'print' + ); + + wp_enqueue_style( + 'publishpress-select2', + PUBLISHPRESS_URL . 'common/libs/select2-v4.0.13.1/css/select2.min.css', + false, + PUBLISHPRESS_VERSION, + 'screen' + ); + + wp_enqueue_style( + 'publishpress-floating-scroll', + PUBLISHPRESS_URL . 'common/libs/floating-scroll/css/jquery.floatingscroll.css', + false, + PUBLISHPRESS_VERSION, + 'screen' + ); + } + } + + /** + * Register settings for notifications so we can partially use the Settings API + * (We use the Settings API for form generation, but not saving) + * + * @since 0.7 + * @uses add_settings_section(), add_settings_field() + */ + public function register_settings() + { + add_settings_section( + $this->module->options_group_name . '_general', + false, + '__return_false', + $this->module->options_group_name + ); + + add_settings_field( + 'post_types', + esc_html__('Post types to show:', 'publishpress'), + [$this, 'settings_post_types_option'], + $this->module->options_group_name, + $this->module->options_group_name . '_general' + ); + } + + /** + * Choose the post types for editorial fields + * + * @since 0.7 + */ + public function settings_post_types_option() + { + global $publishpress; + $publishpress->settings->helper_option_custom_post_type($this->module); + } + + /** + * Filters the menu slug. + * + * @param $menu_slug + * + * @return string + */ + public function filter_admin_menu_slug($menu_slug) + { + if (empty($menu_slug) && $this->module_enabled('content_overview')) { + $menu_slug = 'pp-content-overview'; + } + + return $menu_slug; + } + + /** + * Print any messages that should appear based on the action performed + */ + public function print_messages() + { + // phpcs:disable WordPress.Security.NonceVerification.Recommended + if (isset($_GET['trashed']) || isset($_GET['untrashed'])) { + echo '

'; + + // Following mostly stolen from edit.php + if (isset($_GET['trashed']) && (int)$_GET['trashed']) { + $count = (int)$_GET['trashed']; + + echo esc_html(_n('Item moved to the trash.', '%d items moved to the trash.', $count)); + $ids = isset($_GET['ids']) ? sanitize_text_field($_GET['ids']) : 0; + echo ' ' . esc_html__('Undo', 'publishpress') . '
'; + unset($_GET['trashed']); + } + + if (isset($_GET['untrashed']) && (int)$_GET['untrashed']) { + $count = (int)$_GET['untrashed']; + + echo esc_html(_n( + 'Item restored from the Trash.', + '%d items restored from the Trash.', + $count + )); + unset($_GET['undeleted']); + } + + echo '

'; + } + // phpcs:enable + } + + /** + * Print the table navigation and filter controls, using the current user's filters if any are set. + */ + public static function table_navigation($args) + { + $editable_post_types = $args['editable_post_types']; + $user_filters = $args['user_filters']; + $overview_filters = $args['overview_filters']; + $posts_per_page = $args['posts_per_page']; + ?> +
+
+ +
+ +
+ +
+ +
+ + +
+ +
+ + + +
+ +
+ +
+
+ + +
+ +
+ + +
+ +
+
+
+
+
+ + + +
+ + + + $select_name) { + $modal_id++; + $args['select_id'] = $select_id; + $args['select_name'] = $select_name; + $filter_data = PP_Content_Overview_Utilities::content_overview_filter_options($args); + $active_class = !empty($filter_data['selected_value']) ? 'active-filter' : ''; + $button_label = $filter_data['filter_label']; + $button_label .= !empty($filter_data['selected_value']) ? ': ' . $filter_data['selected_value'] : ''; + ?> + + + + + + + + +
+
+ +
+ + + + + + + + + $select_name) { + echo ''; + } ?> + '; + $start_date_value .= ''; + + $end_date_value = ''; + $end_date_value .= ''; + + $nonce = wp_nonce_field('change-date', 'nonce', 'change-date-nonce', false); + + echo $start_date_value . $end_date_value . $nonce; + ?> + +
+