From fd8792e3c636f026002466becb7f661944f7e52d Mon Sep 17 00:00:00 2001 From: Mikey Arce Date: Sat, 23 Sep 2023 11:54:13 -0700 Subject: [PATCH 01/20] Open links in new window --- includes/admin/views/html-admin-setup-step-1.php | 2 +- includes/class-wp-job-manager-usage-tracking.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/admin/views/html-admin-setup-step-1.php b/includes/admin/views/html-admin-setup-step-1.php index ca51606de..d9abc37ca 100644 --- a/includes/admin/views/html-admin-setup-step-1.php +++ b/includes/admin/views/html-admin-setup-step-1.php @@ -16,7 +16,7 @@

documentation will walk you through each step.', 'wp-job-manager' ), 'https://wpjobmanager.com/documentation/' ) ); + echo wp_kses_post( sprintf( __( 'If you\'d prefer to skip this and set up your pages manually, our documentation will walk you through each step.', 'wp-job-manager' ), 'https://wpjobmanager.com/documentation/' ) ); ?>

diff --git a/includes/class-wp-job-manager-usage-tracking.php b/includes/class-wp-job-manager-usage-tracking.php index e4a51398e..c658812b1 100644 --- a/includes/class-wp-job-manager-usage-tracking.php +++ b/includes/class-wp-job-manager-usage-tracking.php @@ -227,7 +227,7 @@ protected function opt_in_dialog_text() { // translators: Placeholder %s is a URL to the document on wpjobmanager.com with info on usage tracking. __( 'We\'d love if you helped us make WP Job Manager better by allowing us to collect - usage tracking data. No sensitive information is + usage tracking data. No sensitive information is collected, and you can opt out at any time.', 'wp-job-manager' ), @@ -266,7 +266,7 @@ public function opt_in_checkbox_text() { // translators: the href tag contains the URL for the page telling users what data WPJM tracks. __( 'Help us make WP Job Manager better by allowing us to collect - usage tracking data. + usage tracking data. No sensitive information is collected.', 'wp-job-manager' ), From 4f257ed038329d581576bd3205d0506914c43b1c Mon Sep 17 00:00:00 2001 From: Mikey Arce Date: Sat, 23 Sep 2023 11:54:58 -0700 Subject: [PATCH 02/20] Check usage tracking box by default --- includes/admin/views/html-admin-setup-step-1.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/includes/admin/views/html-admin-setup-step-1.php b/includes/admin/views/html-admin-setup-step-1.php index d9abc37ca..cc6990465 100644 --- a/includes/admin/views/html-admin-setup-step-1.php +++ b/includes/admin/views/html-admin-setup-step-1.php @@ -11,6 +11,16 @@ ?>

+ +

WP Job Manager! Let\'s get your site ready to accept job listings.', 'wp-job-manager' ) ); ?>

From 01caa23edc28b0f4f81325b0577cd976fc7145cd Mon Sep 17 00:00:00 2001 From: Mikey Arce Date: Sat, 23 Sep 2023 11:55:47 -0700 Subject: [PATCH 03/20] =?UTF-8?q?Make=20the=20=E2=80=9Csave=20and=20skip?= =?UTF-8?q?=E2=80=9D=20button=20save=20the=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/admin/class-wp-job-manager-setup.php | 2 +- includes/admin/views/html-admin-setup-step-1.php | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/includes/admin/class-wp-job-manager-setup.php b/includes/admin/class-wp-job-manager-setup.php index 4358852ca..44718eb06 100644 --- a/includes/admin/class-wp-job-manager-setup.php +++ b/includes/admin/class-wp-job-manager-setup.php @@ -119,7 +119,7 @@ public function setup_page() { } // Handle step 2 -> step 3 (setting up pages). - if ( 3 === $step && ! empty( $_POST ) ) { + if ( 3 === $step && ! empty( $_POST ) && empty( $_POST['skip-setup'] ) ) { if ( ! isset( $_REQUEST['setup_wizard'] ) || false === wp_verify_nonce( wp_unslash( $_REQUEST['setup_wizard'] ), 'step_3' ) // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce should not be modified. diff --git a/includes/admin/views/html-admin-setup-step-1.php b/includes/admin/views/html-admin-setup-step-1.php index cc6990465..581822db0 100644 --- a/includes/admin/views/html-admin-setup-step-1.php +++ b/includes/admin/views/html-admin-setup-step-1.php @@ -30,13 +30,15 @@ ?>

-
+ maybe_output_opt_in_checkbox(); ?>

- - + + + +

From 4ae200e01105270a73fe1652386e91231fa53501 Mon Sep 17 00:00:00 2001 From: Mikey Arce Date: Sat, 23 Sep 2023 11:56:03 -0700 Subject: [PATCH 04/20] Delay usage tracking for 1 week after plugin is activated --- includes/class-wp-job-manager.php | 16 +++++++++++++++ .../class-usage-tracking-base.php | 20 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/includes/class-wp-job-manager.php b/includes/class-wp-job-manager.php index 9eba2cb7a..6e5a43e36 100644 --- a/includes/class-wp-job-manager.php +++ b/includes/class-wp-job-manager.php @@ -141,6 +141,7 @@ public function activate() { $this->post_types->register_post_types(); remove_filter( 'pre_option_job_manager_enable_types', '__return_true' ); WP_Job_Manager_Install::install(); + $this->set_activation_time(); flush_rewrite_rules(); } @@ -615,4 +616,19 @@ public function include_admin_files() { include_once JOB_MANAGER_PLUGIN_DIR . '/includes/admin/class-wp-job-manager-admin.php'; } } + + /** + * Sets a transient to track the activation time of WP Job Manager plugin. + * + * @return void + * + * @since 1.0.0 + * + * @author Your Name + * + * @see set_transient() + */ + public function set_activation_time() { + set_transient( 'job_manager_activation_time', time() ); + } } diff --git a/lib/usage-tracking/class-usage-tracking-base.php b/lib/usage-tracking/class-usage-tracking-base.php index 6af940fe1..1470a6929 100644 --- a/lib/usage-tracking/class-usage-tracking-base.php +++ b/lib/usage-tracking/class-usage-tracking-base.php @@ -451,6 +451,23 @@ protected function opt_in_dialog_text_allowed_html() { ); } + /** + * Check if the plugin option is active. + * + * @return bool Returns true if the plugin option is active, false otherwise. + * + * @since 1.0.0 + * + * @author /Users/mikeyarce/Local Sites/wpjm/app/public/wp-content/plugins/WP-Job-Manager/lib/usage-tracking/class-usage-tracking-base.php + */ + function delay_tracking_notice() { + $activation_time = get_transient( 'job_manager_activation_time' ); + if ( $activation_time && ( time() - $activation_time ) > 604800 ) { + return true; + } + return false; + } + /** * If needed, display opt-in dialog to enable tracking. Should not be * called externally. @@ -459,8 +476,9 @@ public function maybe_display_tracking_opt_in() { $opt_in_hidden = $this->is_opt_in_hidden(); $user_tracking_enabled = $this->is_tracking_enabled(); $can_manage_tracking = $this->current_user_can_manage_tracking(); + $delay_tracking_notice = $this->delay_tracking_notice(); - if ( ! $user_tracking_enabled && ! $opt_in_hidden && $can_manage_tracking ) { ?> + if ( ! $user_tracking_enabled && ! $opt_in_hidden && $can_manage_tracking && ! $delay_tracking_notice ) { ?>

From 5a8d2bb28c9c80054711b299818f3d7b923f25b0 Mon Sep 17 00:00:00 2001 From: Mikey Arce Date: Tue, 26 Sep 2023 13:57:55 -0700 Subject: [PATCH 05/20] Set the usage tracking notice visible on plugin update, but only once. --- includes/class-wp-job-manager.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/class-wp-job-manager.php b/includes/class-wp-job-manager.php index 6e5a43e36..76c4af803 100644 --- a/includes/class-wp-job-manager.php +++ b/includes/class-wp-job-manager.php @@ -152,6 +152,11 @@ public function updater() { if ( version_compare( JOB_MANAGER_VERSION, get_option( 'wp_job_manager_version' ), '>' ) ) { WP_Job_Manager_Install::install(); + // Set the Usage Tracking notice to show again, but only do it one time. + if ( ! get_option( 'display_usage_tracking_on_update_once' ) ) { + update_option( 'job_manager_usage_tracking_opt_in_hide', false ); + add_option( 'display_usage_tracking_on_update_once', true ); + } flush_rewrite_rules(); } } From 2c4f4e8a04aac2fb492a75dee3fc54653a0d9fb6 Mon Sep 17 00:00:00 2001 From: Mikey Arce Date: Tue, 26 Sep 2023 14:04:28 -0700 Subject: [PATCH 06/20] Update since version --- includes/class-wp-job-manager.php | 2 +- lib/usage-tracking/class-usage-tracking-base.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/class-wp-job-manager.php b/includes/class-wp-job-manager.php index 76c4af803..a2eee3462 100644 --- a/includes/class-wp-job-manager.php +++ b/includes/class-wp-job-manager.php @@ -627,7 +627,7 @@ public function include_admin_files() { * * @return void * - * @since 1.0.0 + * @since $$next-version$$ * * @author Your Name * diff --git a/lib/usage-tracking/class-usage-tracking-base.php b/lib/usage-tracking/class-usage-tracking-base.php index 1470a6929..e25ea0565 100644 --- a/lib/usage-tracking/class-usage-tracking-base.php +++ b/lib/usage-tracking/class-usage-tracking-base.php @@ -456,7 +456,7 @@ protected function opt_in_dialog_text_allowed_html() { * * @return bool Returns true if the plugin option is active, false otherwise. * - * @since 1.0.0 + * @since $$next-version$$ * * @author /Users/mikeyarce/Local Sites/wpjm/app/public/wp-content/plugins/WP-Job-Manager/lib/usage-tracking/class-usage-tracking-base.php */ From 8108a25ea1b8d0cd96a44ec776f6cee20a65fdc9 Mon Sep 17 00:00:00 2001 From: Mikey Arce Date: Tue, 26 Sep 2023 14:06:04 -0700 Subject: [PATCH 07/20] Update doc blocks --- includes/class-wp-job-manager.php | 4 ---- lib/usage-tracking/class-usage-tracking-base.php | 6 ++---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/includes/class-wp-job-manager.php b/includes/class-wp-job-manager.php index a2eee3462..c039bf884 100644 --- a/includes/class-wp-job-manager.php +++ b/includes/class-wp-job-manager.php @@ -628,10 +628,6 @@ public function include_admin_files() { * @return void * * @since $$next-version$$ - * - * @author Your Name - * - * @see set_transient() */ public function set_activation_time() { set_transient( 'job_manager_activation_time', time() ); diff --git a/lib/usage-tracking/class-usage-tracking-base.php b/lib/usage-tracking/class-usage-tracking-base.php index e25ea0565..2edb5b60a 100644 --- a/lib/usage-tracking/class-usage-tracking-base.php +++ b/lib/usage-tracking/class-usage-tracking-base.php @@ -452,13 +452,11 @@ protected function opt_in_dialog_text_allowed_html() { } /** - * Check if the plugin option is active. + * Check if the plugin has been active for more than a week. * - * @return bool Returns true if the plugin option is active, false otherwise. + * @return bool Returns true if the plugin has been active for more than a week, false otherwise. * * @since $$next-version$$ - * - * @author /Users/mikeyarce/Local Sites/wpjm/app/public/wp-content/plugins/WP-Job-Manager/lib/usage-tracking/class-usage-tracking-base.php */ function delay_tracking_notice() { $activation_time = get_transient( 'job_manager_activation_time' ); From 7668b4231996f90efacd61b39d5106ba4fe6a374 Mon Sep 17 00:00:00 2001 From: gkaragia <53191348+gkaragia@users.noreply.github.com> Date: Mon, 2 Oct 2023 15:20:54 +0300 Subject: [PATCH 08/20] Do not use JS to set a default value --- .../views/html-admin-setup-opt-in-usage-tracking.php | 3 ++- includes/admin/views/html-admin-setup-step-1.php | 10 ---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/includes/admin/views/html-admin-setup-opt-in-usage-tracking.php b/includes/admin/views/html-admin-setup-opt-in-usage-tracking.php index a803611ab..bec373679 100644 --- a/includes/admin/views/html-admin-setup-opt-in-usage-tracking.php +++ b/includes/admin/views/html-admin-setup-opt-in-usage-tracking.php @@ -14,7 +14,8 @@ + value="1" + checked="checked" /> opt_in_text(), diff --git a/includes/admin/views/html-admin-setup-step-1.php b/includes/admin/views/html-admin-setup-step-1.php index 581822db0..f97eab095 100644 --- a/includes/admin/views/html-admin-setup-step-1.php +++ b/includes/admin/views/html-admin-setup-step-1.php @@ -11,16 +11,6 @@ ?>

- -

WP Job Manager! Let\'s get your site ready to accept job listings.', 'wp-job-manager' ) ); ?>

From d1f17e602d3501c2039c7e120760474eb34144b8 Mon Sep 17 00:00:00 2001 From: gkaragia <53191348+gkaragia@users.noreply.github.com> Date: Mon, 2 Oct 2023 17:51:26 +0300 Subject: [PATCH 09/20] Move the notice delay to an option --- .../class-wp-job-manager-data-cleaner.php | 1 + includes/class-wp-job-manager-install.php | 6 +++++ includes/class-wp-job-manager.php | 17 ------------ .../class-usage-tracking-base.php | 26 +++++++------------ 4 files changed, 16 insertions(+), 34 deletions(-) diff --git a/includes/class-wp-job-manager-data-cleaner.php b/includes/class-wp-job-manager-data-cleaner.php index 907aab8cb..118e47c89 100644 --- a/includes/class-wp-job-manager-data-cleaner.php +++ b/includes/class-wp-job-manager-data-cleaner.php @@ -114,6 +114,7 @@ class WP_Job_Manager_Data_Cleaner { 'job_manager_promoted_jobs_status_update_last_check', 'job_manager_promoted_jobs_webhook_interval', 'job_manager_promoted_jobs_cron_interval', + 'job_manager_display_usage_tracking_once', ]; /** diff --git a/includes/class-wp-job-manager-install.php b/includes/class-wp-job-manager-install.php index b04c7d891..7d4d2da84 100644 --- a/includes/class-wp-job-manager-install.php +++ b/includes/class-wp-job-manager-install.php @@ -34,6 +34,12 @@ public static function install() { $is_new_install = true; } + // On new installs display the usage tracking notice with one week delay and for existing installs display it right away. + if ( false === get_option( 'job_manager_display_usage_tracking_once' ) ) { + $time_to_show_notice = $is_new_install ? time() + WEEK_IN_SECONDS : time() - 10; + update_option( 'job_manager_display_usage_tracking_once', $time_to_show_notice ); + } + // Update featured posts ordering. if ( version_compare( get_option( 'wp_job_manager_version', JOB_MANAGER_VERSION ), '1.22.0', '<' ) ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- One time data update. diff --git a/includes/class-wp-job-manager.php b/includes/class-wp-job-manager.php index c039bf884..9eba2cb7a 100644 --- a/includes/class-wp-job-manager.php +++ b/includes/class-wp-job-manager.php @@ -141,7 +141,6 @@ public function activate() { $this->post_types->register_post_types(); remove_filter( 'pre_option_job_manager_enable_types', '__return_true' ); WP_Job_Manager_Install::install(); - $this->set_activation_time(); flush_rewrite_rules(); } @@ -152,11 +151,6 @@ public function updater() { if ( version_compare( JOB_MANAGER_VERSION, get_option( 'wp_job_manager_version' ), '>' ) ) { WP_Job_Manager_Install::install(); - // Set the Usage Tracking notice to show again, but only do it one time. - if ( ! get_option( 'display_usage_tracking_on_update_once' ) ) { - update_option( 'job_manager_usage_tracking_opt_in_hide', false ); - add_option( 'display_usage_tracking_on_update_once', true ); - } flush_rewrite_rules(); } } @@ -621,15 +615,4 @@ public function include_admin_files() { include_once JOB_MANAGER_PLUGIN_DIR . '/includes/admin/class-wp-job-manager-admin.php'; } } - - /** - * Sets a transient to track the activation time of WP Job Manager plugin. - * - * @return void - * - * @since $$next-version$$ - */ - public function set_activation_time() { - set_transient( 'job_manager_activation_time', time() ); - } } diff --git a/lib/usage-tracking/class-usage-tracking-base.php b/lib/usage-tracking/class-usage-tracking-base.php index 2edb5b60a..12bd9ec95 100644 --- a/lib/usage-tracking/class-usage-tracking-base.php +++ b/lib/usage-tracking/class-usage-tracking-base.php @@ -430,6 +430,14 @@ protected function hide_tracking_opt_in() { * @return bool true if the opt-in is hidden, false otherwise. **/ protected function is_opt_in_hidden() { + $delayed_notice_timestamp = (int) get_option( 'job_manager_display_usage_tracking_once' ); + + // Display only once they delayed notice regardless if the user has declined in the past. + if ( $delayed_notice_timestamp > 0 && $delayed_notice_timestamp < time() ) { + update_option('job_manager_display_usage_tracking_once', 0 ); + update_option( $this->hide_tracking_opt_in_option_name, false ); + } + return (bool) get_option( $this->hide_tracking_opt_in_option_name ); } @@ -451,21 +459,6 @@ protected function opt_in_dialog_text_allowed_html() { ); } - /** - * Check if the plugin has been active for more than a week. - * - * @return bool Returns true if the plugin has been active for more than a week, false otherwise. - * - * @since $$next-version$$ - */ - function delay_tracking_notice() { - $activation_time = get_transient( 'job_manager_activation_time' ); - if ( $activation_time && ( time() - $activation_time ) > 604800 ) { - return true; - } - return false; - } - /** * If needed, display opt-in dialog to enable tracking. Should not be * called externally. @@ -474,9 +467,8 @@ public function maybe_display_tracking_opt_in() { $opt_in_hidden = $this->is_opt_in_hidden(); $user_tracking_enabled = $this->is_tracking_enabled(); $can_manage_tracking = $this->current_user_can_manage_tracking(); - $delay_tracking_notice = $this->delay_tracking_notice(); - if ( ! $user_tracking_enabled && ! $opt_in_hidden && $can_manage_tracking && ! $delay_tracking_notice ) { ?> + if ( ! $user_tracking_enabled && ! $opt_in_hidden && $can_manage_tracking ) { ?>

From 8ff9777a21114d15ad9bba76097c5597dfa5a29b Mon Sep 17 00:00:00 2001 From: gkaragia <53191348+gkaragia@users.noreply.github.com> Date: Tue, 3 Oct 2023 10:58:55 +0300 Subject: [PATCH 10/20] Update phpcs rules --- phpcs.xml.dist | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 23f7860d4..dfff1d357 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -15,10 +15,8 @@ tmp/ build/ assets/dist/ - - + lib/emogrifier templates/ - lib/ @@ -29,23 +27,16 @@ + + + - - includes/class-wp-job-manager-dependency-checker.php - /wp-job-manager.php - /uninstall.php - - - - includes/class-wp-job-manager-dependency-checker.php - /wp-job-manager.php - /uninstall.php - + From f974f8976d898d2771a35392fcc93f1579789c63 Mon Sep 17 00:00:00 2001 From: gkaragia <53191348+gkaragia@users.noreply.github.com> Date: Tue, 3 Oct 2023 12:01:02 +0300 Subject: [PATCH 11/20] Run phpcbf --- ...lass-wp-job-manager-dependency-checker.php | 12 ++-- .../class-usage-tracking-base.php | 65 ++++++++++--------- uninstall.php | 4 +- wp-job-manager.php | 6 +- 4 files changed, 45 insertions(+), 42 deletions(-) diff --git a/includes/class-wp-job-manager-dependency-checker.php b/includes/class-wp-job-manager-dependency-checker.php index 2bf05761d..72edc8680 100644 --- a/includes/class-wp-job-manager-dependency-checker.php +++ b/includes/class-wp-job-manager-dependency-checker.php @@ -26,15 +26,15 @@ class WP_Job_Manager_Dependency_Checker { */ public static function check_dependencies() { if ( ! self::check_php() ) { - add_action( 'admin_notices', array( 'WP_Job_Manager_Dependency_Checker', 'add_php_notice' ) ); - add_action( 'admin_init', array( __CLASS__, 'deactivate_self' ) ); + add_action( 'admin_notices', [ 'WP_Job_Manager_Dependency_Checker', 'add_php_notice' ] ); + add_action( 'admin_init', [ __CLASS__, 'deactivate_self' ] ); return false; } if ( ! self::check_wp() ) { - add_action( 'admin_notices', array( 'WP_Job_Manager_Dependency_Checker', 'add_wp_notice' ) ); - add_filter( 'plugin_action_links_' . JOB_MANAGER_PLUGIN_BASENAME, array( 'WP_Job_Manager_Dependency_Checker', 'wp_version_plugin_action_notice' ) ); + add_action( 'admin_notices', [ 'WP_Job_Manager_Dependency_Checker', 'add_wp_notice' ] ); + add_filter( 'plugin_action_links_' . JOB_MANAGER_PLUGIN_BASENAME, [ 'WP_Job_Manager_Dependency_Checker', 'wp_version_plugin_action_notice' ] ); } return true; @@ -66,7 +66,7 @@ public static function add_php_notice() { $message = sprintf( __( 'WP Job Manager requires a minimum PHP version of %1$s, but you are running %2$s.', 'wp-job-manager' ), self::MINIMUM_PHP_VERSION, phpversion() ); echo '

'; - echo wp_kses( $message, array( 'strong' => array() ) ); + echo wp_kses( $message, [ 'strong' => [] ] ); $php_update_url = 'https://wordpress.org/support/update-php/'; if ( function_exists( 'wp_get_update_php_url' ) ) { $php_update_url = wp_get_update_php_url(); @@ -146,6 +146,6 @@ public static function wp_version_plugin_action_notice( $actions ) { * @return array */ private static function get_critical_screen_ids() { - return array( 'dashboard', 'plugins', 'plugins-network', 'edit-job_listing', 'job_listing_page_job-manager-settings' ); + return [ 'dashboard', 'plugins', 'plugins-network', 'edit-job_listing', 'job_listing_page_job-manager-settings' ]; } } diff --git a/lib/usage-tracking/class-usage-tracking-base.php b/lib/usage-tracking/class-usage-tracking-base.php index 12bd9ec95..2b8a9114c 100644 --- a/lib/usage-tracking/class-usage-tracking-base.php +++ b/lib/usage-tracking/class-usage-tracking-base.php @@ -50,7 +50,7 @@ abstract class WP_Job_Manager_Usage_Tracking_Base { * * @var array **/ - private static $instances = array(); + private static $instances = []; /** * Gets the singleton instance of this class. Subclasses should implement @@ -128,7 +128,7 @@ abstract protected function opt_in_dialog_text(); * @return array */ protected function get_base_system_data() { - return array(); + return []; } /* @@ -150,14 +150,14 @@ protected function __construct() { $this->job_name = $this->get_prefix() . '_usage_tracking_send_usage_data'; // Set up the opt-in dialog. - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_script_deps' ) ); - add_action( 'admin_footer', array( $this, 'output_opt_in_js' ) ); - add_action( 'admin_notices', array( $this, 'maybe_display_tracking_opt_in' ) ); - add_action( 'wp_ajax_' . $this->get_prefix() . '_handle_tracking_opt_in', array( $this, 'handle_tracking_opt_in' ) ); + add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_script_deps' ] ); + add_action( 'admin_footer', [ $this, 'output_opt_in_js' ] ); + add_action( 'admin_notices', [ $this, 'maybe_display_tracking_opt_in' ] ); + add_action( 'wp_ajax_' . $this->get_prefix() . '_handle_tracking_opt_in', [ $this, 'handle_tracking_opt_in' ] ); // Set up schedule and action needed for cron job. - add_filter( 'cron_schedules', array( $this, 'add_usage_tracking_two_week_schedule' ) ); - add_action( $this->job_name, array( $this, 'send_usage_data' ) ); + add_filter( 'cron_schedules', [ $this, 'add_usage_tracking_two_week_schedule' ] ); + add_action( $this->job_name, [ $this, 'send_usage_data' ] ); } /** @@ -200,7 +200,7 @@ public function set_callback( $callback ) { * * @return null|WP_Error **/ - public function send_event( $event, $properties = array(), $event_timestamp = null ) { + public function send_event( $event, $properties = [], $event_timestamp = null ) { // Only continue if tracking is enabled. if ( ! $this->is_tracking_enabled() ) { @@ -225,7 +225,7 @@ public function send_event( $event, $properties = array(), $event_timestamp = nu $properties['_en'] = $event_name; $properties['_ts'] = $event_timestamp . '000'; $properties['_rt'] = round( microtime( true ) * 1000 ); // log time. - $p = array(); + $p = []; foreach ( $properties as $key => $value ) { $p[] = rawurlencode( $key ) . '=' . rawurlencode( $value ); @@ -234,13 +234,13 @@ public function send_event( $event, $properties = array(), $event_timestamp = nu $pixel .= '?' . implode( '&', $p ) . '&_=_'; // EOF marker. $response = wp_remote_get( $pixel, - array( + [ 'blocking' => true, 'timeout' => 1, 'redirection' => 2, 'httpversion' => '1.1', 'user-agent' => $this->get_event_prefix() . '_usage_tracking', - ) + ] ); if ( is_wp_error( $response ) ) { @@ -329,10 +329,10 @@ protected function get_event_prefix() { **/ public function add_usage_tracking_two_week_schedule( $schedules ) { $day_in_seconds = 86400; - $schedules[ $this->get_prefix() . '_usage_tracking_two_weeks' ] = array( + $schedules[ $this->get_prefix() . '_usage_tracking_two_weeks' ] = [ 'interval' => 15 * $day_in_seconds, 'display' => esc_html__( 'Every Two Weeks', $this->get_text_domain() ), - ); + ]; return $schedules; } @@ -376,7 +376,7 @@ public function get_system_data() { * @return array List of plugins. Index is friendly name, value is version. */ protected function get_plugin_data() { - $plugins = array(); + $plugins = []; foreach ( $this->get_plugins() as $plugin_basename => $plugin ) { $plugin_name = $this->get_plugin_name( $plugin_basename ); $plugins[ $plugin_name ] = $plugin['Version']; @@ -430,11 +430,11 @@ protected function hide_tracking_opt_in() { * @return bool true if the opt-in is hidden, false otherwise. **/ protected function is_opt_in_hidden() { - $delayed_notice_timestamp = (int) get_option( 'job_manager_display_usage_tracking_once' ); + $delayed_notice_timestamp = (int) get_option( 'job_manager_display_usage_tracking_once' ); // Display only once they delayed notice regardless if the user has declined in the past. if ( $delayed_notice_timestamp > 0 && $delayed_notice_timestamp < time() ) { - update_option('job_manager_display_usage_tracking_once', 0 ); + update_option( 'job_manager_display_usage_tracking_once', 0 ); update_option( $this->hide_tracking_opt_in_option_name, false ); } @@ -448,15 +448,15 @@ protected function is_opt_in_hidden() { * @return array the html tags. **/ protected function opt_in_dialog_text_allowed_html() { - return array( - 'a' => array( - 'href' => array(), - 'title' => array(), - 'target' => array(), - ), - 'em' => array(), - 'strong' => array(), - ); + return [ + 'a' => [ + 'href' => [], + 'title' => [], + 'target' => [], + ], + 'em' => [], + 'strong' => [], + ]; } /** @@ -493,7 +493,7 @@ public function maybe_display_tracking_opt_in() {

- get_prefix() . '_usage-tracking-notice', '', - array( 'jquery' ), null, true + $this->get_prefix() . '_usage-tracking-notice', + '', + [ 'jquery' ], + null, + true ); } @@ -532,7 +535,7 @@ public function enqueue_script_deps() { * externally. **/ public function output_opt_in_js() { -?> + ?> - 'ids', 'update_site_cache' => false, - ) + ] ); $original_blog_id = get_current_blog_id(); diff --git a/wp-job-manager.php b/wp-job-manager.php index 4f6cbf5ca..5d1afbf00 100644 --- a/wp-job-manager.php +++ b/wp-job-manager.php @@ -48,8 +48,8 @@ function WPJM() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName $GLOBALS['job_manager'] = WPJM(); // Activation - works with symlinks. -register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), array( WPJM(), 'activate' ) ); +register_activation_hook( basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ), [ WPJM(), 'activate' ] ); // Cleanup on deactivation. -register_deactivation_hook( __FILE__, array( WPJM(), 'unschedule_cron_jobs' ) ); -register_deactivation_hook( __FILE__, array( WPJM(), 'usage_tracking_cleanup' ) ); +register_deactivation_hook( __FILE__, [ WPJM(), 'unschedule_cron_jobs' ] ); +register_deactivation_hook( __FILE__, [ WPJM(), 'usage_tracking_cleanup' ] ); From 445caec6bc9e63b90cd31bca9348abcd6bfd4c57 Mon Sep 17 00:00:00 2001 From: gkaragia <53191348+gkaragia@users.noreply.github.com> Date: Tue, 3 Oct 2023 12:02:07 +0300 Subject: [PATCH 12/20] Add .git-blame-ignore-revs file --- .git-blame-ignore-revs | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .git-blame-ignore-revs diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 000000000..4241a99f7 --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,4 @@ +# .git-blame-ignore-revs +# Re-format PHP files with PHPCBF +2dc64b85a9a640f4fa1878f4c2e2a1b34c85f432 + From 8dd36aab424c2396b4dfda40e5080d9a6a5d519f Mon Sep 17 00:00:00 2001 From: gkaragia <53191348+gkaragia@users.noreply.github.com> Date: Tue, 3 Oct 2023 12:22:07 +0300 Subject: [PATCH 13/20] Fix linter issues --- includes/admin/class-wp-job-manager-cpt.php | 3 +++ .../class-wp-job-manager-data-cleaner.php | 4 ++-- ...ass-wp-job-manager-email-notifications.php | 2 +- includes/class-wp-job-manager-post-types.php | 8 ++++---- includes/class-wp-job-manager-shortcodes.php | 1 + ...ass-wp-job-manager-usage-tracking-data.php | 10 +++++----- ...ss-wp-job-manager-usage-tracking-base.php} | 20 +++++++++++-------- .../class-usage-tracking-test-subclass.php | 4 ---- wp-job-manager-functions.php | 8 ++++---- 9 files changed, 32 insertions(+), 28 deletions(-) rename lib/usage-tracking/{class-usage-tracking-base.php => class-wp-job-manager-usage-tracking-base.php} (96%) diff --git a/includes/admin/class-wp-job-manager-cpt.php b/includes/admin/class-wp-job-manager-cpt.php index c823f0e64..73149d235 100644 --- a/includes/admin/class-wp-job-manager-cpt.php +++ b/includes/admin/class-wp-job-manager-cpt.php @@ -700,6 +700,7 @@ public function sortable_columns( $columns ) { * @return array */ public function sort_columns( $vars ) { + // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Query used in admin only. if ( isset( $vars['orderby'] ) ) { if ( 'job_expires' === $vars['orderby'] ) { $vars = array_merge( @@ -719,6 +720,8 @@ public function sort_columns( $vars ) { ); } } + // phpcs:enable WordPress.DB.SlowDBQuery.slow_db_query_meta_key + return $vars; } diff --git a/includes/class-wp-job-manager-data-cleaner.php b/includes/class-wp-job-manager-data-cleaner.php index 118e47c89..f24ec2ad8 100644 --- a/includes/class-wp-job-manager-data-cleaner.php +++ b/includes/class-wp-job-manager-data-cleaner.php @@ -381,9 +381,9 @@ private static function cleanup_user_meta() { global $wpdb; foreach ( self::$user_meta_keys as $meta_key ) { - // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery -- Delete data across all users. + // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Delete data across all users. $wpdb->delete( $wpdb->usermeta, [ 'meta_key' => $meta_key ] ); - // phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery + // phpcs:enable WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.SlowDBQuery.slow_db_query_meta_key } } diff --git a/includes/class-wp-job-manager-email-notifications.php b/includes/class-wp-job-manager-email-notifications.php index 9f6dfa76b..b76eaab5b 100644 --- a/includes/class-wp-job-manager-email-notifications.php +++ b/includes/class-wp-job-manager-email-notifications.php @@ -600,7 +600,7 @@ private static function send_expiring_notice( $email_notification_key, $days_not 'post_status' => 'publish', 'fields' => 'ids', 'posts_per_page' => -1, - 'meta_query' => [ + 'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Used in production with no issues. [ 'key' => '_job_expires', 'value' => $notice_before_datetime->format( 'Y-m-d' ), diff --git a/includes/class-wp-job-manager-post-types.php b/includes/class-wp-job-manager-post-types.php index 88e6b2f93..bc8cb5e0d 100644 --- a/includes/class-wp-job-manager-post-types.php +++ b/includes/class-wp-job-manager-post-types.php @@ -584,8 +584,8 @@ public function job_feed() { 'ignore_sticky_posts' => 1, 'posts_per_page' => $input_posts_per_page, 'paged' => absint( get_query_var( 'paged', 1 ) ), - 'tax_query' => [], - 'meta_query' => [], + 'tax_query' => [], // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Empty. + 'meta_query' => [], //// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Empty. ]; if ( ! empty( $input_search_location ) ) { @@ -739,7 +739,7 @@ public function check_for_expired_jobs() { 'post_status' => 'publish', 'fields' => 'ids', 'posts_per_page' => -1, - 'meta_query' => [ + 'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Used in production with no issues. 'relation' => 'AND', [ 'key' => '_job_expires', @@ -1370,7 +1370,7 @@ public function sitemaps_maybe_hide_filled( $query_args, $post_type ) { } if ( ! isset( $query_args['meta_query'] ) ) { - $query_args['meta_query'] = []; + $query_args['meta_query'] = []; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Empty. } $query_args['meta_query'][] = [ diff --git a/includes/class-wp-job-manager-shortcodes.php b/includes/class-wp-job-manager-shortcodes.php index cb8879fc1..cd0f4cc9d 100644 --- a/includes/class-wp-job-manager-shortcodes.php +++ b/includes/class-wp-job-manager-shortcodes.php @@ -905,6 +905,7 @@ public function output_job_summary( $atts ) { $args['posts_per_page'] = $atts['limit']; $args['orderby'] = 'rand'; if ( ! is_null( $atts['featured'] ) ) { + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Query results are limited. $args['meta_query'] = [ [ 'key' => '_featured', diff --git a/includes/class-wp-job-manager-usage-tracking-data.php b/includes/class-wp-job-manager-usage-tracking-data.php index 3520a6c19..32a5b378d 100644 --- a/includes/class-wp-job-manager-usage-tracking-data.php +++ b/includes/class-wp-job-manager-usage-tracking-data.php @@ -191,7 +191,7 @@ private static function get_jobs_by_type_count( $job_type ) { 'post_type' => 'job_listing', 'post_status' => [ 'expired', 'publish' ], 'fields' => 'ids', - 'tax_query' => [ + 'tax_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Used in production with no issues. [ 'field' => 'slug', 'taxonomy' => 'job_listing_type', @@ -217,7 +217,7 @@ private static function get_company_logo_count() { 'post_type' => 'job_listing', 'post_status' => [ 'expired', 'publish' ], 'fields' => 'ids', - 'meta_query' => [ + 'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Used in production with no issues. [ 'key' => '_thumbnail_id', 'compare' => 'EXISTS', @@ -242,7 +242,7 @@ private static function get_job_type_count() { 'post_type' => 'job_listing', 'post_status' => [ 'expired', 'publish' ], 'fields' => 'ids', - 'tax_query' => [ + 'tax_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Used in production with no issues. [ 'taxonomy' => 'job_listing_type', 'operator' => 'EXISTS', @@ -267,7 +267,7 @@ private static function get_jobs_count_with_meta( $meta_key ) { 'post_type' => 'job_listing', 'post_status' => [ 'publish', 'expired' ], 'fields' => 'ids', - 'meta_query' => [ + 'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Used in production with no issues. [ 'key' => $meta_key, 'value' => '[^[:space:]]', @@ -294,7 +294,7 @@ private static function get_jobs_count_with_checked_meta( $meta_key ) { 'post_type' => 'job_listing', 'post_status' => [ 'publish', 'expired' ], 'fields' => 'ids', - 'meta_query' => [ + 'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Used in production with no issues. [ 'key' => $meta_key, 'value' => '1', diff --git a/lib/usage-tracking/class-usage-tracking-base.php b/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php similarity index 96% rename from lib/usage-tracking/class-usage-tracking-base.php rename to lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php index 2b8a9114c..b1d0463b9 100644 --- a/lib/usage-tracking/class-usage-tracking-base.php +++ b/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php @@ -2,6 +2,8 @@ /** * Reusable Usage Tracking library. For sending plugin usage data and events to * Tracks. + * + * @package wp-job-manager **/ if ( ! defined( 'ABSPATH' ) ) { @@ -64,6 +66,8 @@ abstract class WP_Job_Manager_Usage_Tracking_Base { * * This function cannot be abstract (because it is static) but it *must* be * implemented by subclasses. + * + * @throws Exception When get_instance is not implemented. */ public static function get_instance() { throw new Exception( 'Usage Tracking subclasses must implement get_instance. See class-usage-tracking-base.php' ); @@ -328,10 +332,9 @@ protected function get_event_prefix() { * @return array of $schedules. **/ public function add_usage_tracking_two_week_schedule( $schedules ) { - $day_in_seconds = 86400; $schedules[ $this->get_prefix() . '_usage_tracking_two_weeks' ] = [ - 'interval' => 15 * $day_in_seconds, - 'display' => esc_html__( 'Every Two Weeks', $this->get_text_domain() ), + 'interval' => 15 * DAY_IN_SECONDS, + 'display' => esc_html__( 'Every Two Weeks', 'wp-job-manager' ), ]; return $schedules; @@ -476,22 +479,22 @@ public function maybe_display_tracking_opt_in() {

get_prefix() . '_usage-tracking-notice', '', diff --git a/lib/usage-tracking/tests/support/class-usage-tracking-test-subclass.php b/lib/usage-tracking/tests/support/class-usage-tracking-test-subclass.php index 6c7784a92..f6d7b72b9 100644 --- a/lib/usage-tracking/tests/support/class-usage-tracking-test-subclass.php +++ b/lib/usage-tracking/tests/support/class-usage-tracking-test-subclass.php @@ -18,10 +18,6 @@ public function get_prefix() { return 'testing'; } - public function get_text_domain() { - return 'text-domain'; - } - public function get_tracking_enabled() { return get_option( self::TRACKING_ENABLED_OPTION_NAME ) || false; } diff --git a/wp-job-manager-functions.php b/wp-job-manager-functions.php index 331a43ed3..c450976d8 100644 --- a/wp-job-manager-functions.php +++ b/wp-job-manager-functions.php @@ -62,8 +62,8 @@ function get_job_listings( $args = [] ) { 'posts_per_page' => intval( $args['posts_per_page'] ), // phpcs:ignore WordPress.WP.PostsPerPage.posts_per_page_posts_per_page -- Known slow query. 'orderby' => $args['orderby'], 'order' => $args['order'], - 'tax_query' => [], - 'meta_query' => [], + 'tax_query' => [], // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Empty. + 'meta_query' => [], // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Empty. 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false, @@ -390,8 +390,8 @@ function get_featured_job_ids() { 'suppress_filters' => false, 'post_type' => 'job_listing', 'post_status' => 'publish', - 'meta_key' => '_featured', - 'meta_value' => '1', + 'meta_key' => '_featured', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Used in production with no issues. + 'meta_value' => '1', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value -- Used in production with no issues. 'fields' => 'ids', ] ); From d19e818943f5a0df2eb443fc8103e4a0950c04a1 Mon Sep 17 00:00:00 2001 From: gkaragia <53191348+gkaragia@users.noreply.github.com> Date: Tue, 3 Oct 2023 12:29:59 +0300 Subject: [PATCH 14/20] Rename usages of tracking base class --- includes/class-wp-job-manager-usage-tracking.php | 6 ++++-- .../class-wp-job-manager-usage-tracking-base.php | 10 +--------- .../support/class-usage-tracking-test-subclass.php | 4 ++-- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/includes/class-wp-job-manager-usage-tracking.php b/includes/class-wp-job-manager-usage-tracking.php index c658812b1..18d4d996b 100644 --- a/includes/class-wp-job-manager-usage-tracking.php +++ b/includes/class-wp-job-manager-usage-tracking.php @@ -9,7 +9,7 @@ exit; } -require dirname( __FILE__ ) . '/../lib/usage-tracking/class-usage-tracking-base.php'; +require dirname( __FILE__ ) . '/../lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php'; /** * WPJM Usage Tracking subclass. @@ -182,7 +182,9 @@ protected function get_event_prefix() { } /** - * Get the text domain used in the plugin. + * Get the text domain used in the plugin. Deprecated - use 'wp-job-manager' directly. + * + * @deprecated 1.41.1 * * @return string */ diff --git a/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php b/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php index b1d0463b9..2bccf8628 100644 --- a/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php +++ b/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php @@ -70,7 +70,7 @@ abstract class WP_Job_Manager_Usage_Tracking_Base { * @throws Exception When get_instance is not implemented. */ public static function get_instance() { - throw new Exception( 'Usage Tracking subclasses must implement get_instance. See class-usage-tracking-base.php' ); + throw new Exception( 'Usage Tracking subclasses must implement get_instance. See class-wp-job-manager-usage-tracking-base.php' ); } @@ -86,14 +86,6 @@ public static function get_instance() { **/ abstract protected function get_prefix(); - /** - * Get the text domain used by this plugin. This class will add some - * strings to be translated. - * - * @return string The text domain string. - **/ - abstract protected function get_text_domain(); - /** * Determine whether usage tracking is enabled. * diff --git a/lib/usage-tracking/tests/support/class-usage-tracking-test-subclass.php b/lib/usage-tracking/tests/support/class-usage-tracking-test-subclass.php index f6d7b72b9..0caaa0123 100644 --- a/lib/usage-tracking/tests/support/class-usage-tracking-test-subclass.php +++ b/lib/usage-tracking/tests/support/class-usage-tracking-test-subclass.php @@ -1,10 +1,10 @@ Date: Tue, 3 Oct 2023 13:30:33 +0300 Subject: [PATCH 15/20] Fix typo --- lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php b/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php index 2bccf8628..c1b245478 100644 --- a/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php +++ b/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php @@ -427,7 +427,7 @@ protected function hide_tracking_opt_in() { protected function is_opt_in_hidden() { $delayed_notice_timestamp = (int) get_option( 'job_manager_display_usage_tracking_once' ); - // Display only once they delayed notice regardless if the user has declined in the past. + // Display only once the delayed notice regardless if the user has declined in the past. if ( $delayed_notice_timestamp > 0 && $delayed_notice_timestamp < time() ) { update_option( 'job_manager_display_usage_tracking_once', 0 ); update_option( $this->hide_tracking_opt_in_option_name, false ); From c576d10348cb0f535b746e5894d6704c9dab4b33 Mon Sep 17 00:00:00 2001 From: gkaragia <53191348+gkaragia@users.noreply.github.com> Date: Tue, 3 Oct 2023 13:56:04 +0300 Subject: [PATCH 16/20] Introduce const for option name --- includes/class-wp-job-manager-install.php | 4 ++-- .../class-wp-job-manager-usage-tracking-base.php | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/includes/class-wp-job-manager-install.php b/includes/class-wp-job-manager-install.php index 7d4d2da84..3058d245c 100644 --- a/includes/class-wp-job-manager-install.php +++ b/includes/class-wp-job-manager-install.php @@ -35,9 +35,9 @@ public static function install() { } // On new installs display the usage tracking notice with one week delay and for existing installs display it right away. - if ( false === get_option( 'job_manager_display_usage_tracking_once' ) ) { + if ( false === get_option( WP_Job_Manager_Usage_Tracking_Base::DISPLAY_ONCE_OPTION ) ) { $time_to_show_notice = $is_new_install ? time() + WEEK_IN_SECONDS : time() - 10; - update_option( 'job_manager_display_usage_tracking_once', $time_to_show_notice ); + update_option( WP_Job_Manager_Usage_Tracking_Base::DISPLAY_ONCE_OPTION, $time_to_show_notice ); } // Update featured posts ordering. diff --git a/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php b/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php index c1b245478..ffe778f13 100644 --- a/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php +++ b/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php @@ -17,6 +17,8 @@ abstract class WP_Job_Manager_Usage_Tracking_Base { const PLUGIN_PREFIX = 'plugin_'; + const DISPLAY_ONCE_OPTION = 'job_manager_display_usage_tracking_once'; + /* * Instance variables. */ @@ -425,11 +427,11 @@ protected function hide_tracking_opt_in() { * @return bool true if the opt-in is hidden, false otherwise. **/ protected function is_opt_in_hidden() { - $delayed_notice_timestamp = (int) get_option( 'job_manager_display_usage_tracking_once' ); + $delayed_notice_timestamp = (int) get_option( self::DISPLAY_ONCE_OPTION ); // Display only once the delayed notice regardless if the user has declined in the past. if ( $delayed_notice_timestamp > 0 && $delayed_notice_timestamp < time() ) { - update_option( 'job_manager_display_usage_tracking_once', 0 ); + update_option( self::DISPLAY_ONCE_OPTION, 0 ); update_option( $this->hide_tracking_opt_in_option_name, false ); } From 26c2d8fa9a4b025f0cb5ac3c0d54a6fcfa673397 Mon Sep 17 00:00:00 2001 From: gkaragia <53191348+gkaragia@users.noreply.github.com> Date: Tue, 3 Oct 2023 14:48:48 +0300 Subject: [PATCH 17/20] Fix display notice logic --- includes/class-wp-job-manager-install.php | 2 ++ includes/class-wp-job-manager-usage-tracking.php | 2 +- .../class-wp-job-manager-usage-tracking-base.php | 14 +++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/includes/class-wp-job-manager-install.php b/includes/class-wp-job-manager-install.php index 3058d245c..f6c90c7fb 100644 --- a/includes/class-wp-job-manager-install.php +++ b/includes/class-wp-job-manager-install.php @@ -34,6 +34,8 @@ public static function install() { $is_new_install = true; } + require_once __DIR__ . '/../lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php'; + // On new installs display the usage tracking notice with one week delay and for existing installs display it right away. if ( false === get_option( WP_Job_Manager_Usage_Tracking_Base::DISPLAY_ONCE_OPTION ) ) { $time_to_show_notice = $is_new_install ? time() + WEEK_IN_SECONDS : time() - 10; diff --git a/includes/class-wp-job-manager-usage-tracking.php b/includes/class-wp-job-manager-usage-tracking.php index 18d4d996b..e4fb750f4 100644 --- a/includes/class-wp-job-manager-usage-tracking.php +++ b/includes/class-wp-job-manager-usage-tracking.php @@ -9,7 +9,7 @@ exit; } -require dirname( __FILE__ ) . '/../lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php'; +require_once __DIR__ . '/../lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php'; /** * WPJM Usage Tracking subclass. diff --git a/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php b/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php index ffe778f13..fa985e1c3 100644 --- a/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php +++ b/lib/usage-tracking/class-wp-job-manager-usage-tracking-base.php @@ -429,13 +429,21 @@ protected function hide_tracking_opt_in() { protected function is_opt_in_hidden() { $delayed_notice_timestamp = (int) get_option( self::DISPLAY_ONCE_OPTION ); - // Display only once the delayed notice regardless if the user has declined in the past. - if ( $delayed_notice_timestamp > 0 && $delayed_notice_timestamp < time() ) { + // The delay has passed, hide the notice if the user refused. + if ( 0 === $delayed_notice_timestamp ) { + return (bool) get_option( $this->hide_tracking_opt_in_option_name ); + } + + // When the delay passes, display the tracking notice regardless if the user refused to enable usage tracking in the past. + if ( $delayed_notice_timestamp < time() ) { update_option( self::DISPLAY_ONCE_OPTION, 0 ); update_option( $this->hide_tracking_opt_in_option_name, false ); + + return false; } - return (bool) get_option( $this->hide_tracking_opt_in_option_name ); + // The delay hasn't passed, hide the notice. + return true; } /** From b1aee78c309616f0f1c9599f8c8f708c4ccb56b6 Mon Sep 17 00:00:00 2001 From: gkaragia <53191348+gkaragia@users.noreply.github.com> Date: Wed, 4 Oct 2023 12:57:33 +0300 Subject: [PATCH 18/20] Use $$next-version$$ instead of specific version Co-authored-by: Fernando Jorge Mota --- includes/class-wp-job-manager-usage-tracking.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wp-job-manager-usage-tracking.php b/includes/class-wp-job-manager-usage-tracking.php index e4fb750f4..c469a29e4 100644 --- a/includes/class-wp-job-manager-usage-tracking.php +++ b/includes/class-wp-job-manager-usage-tracking.php @@ -184,7 +184,7 @@ protected function get_event_prefix() { /** * Get the text domain used in the plugin. Deprecated - use 'wp-job-manager' directly. * - * @deprecated 1.41.1 + * @deprecated $$next-version$$ * * @return string */ From 55b537b9567a41554671316c6e4408d7b87c9ecf Mon Sep 17 00:00:00 2001 From: gkaragia <53191348+gkaragia@users.noreply.github.com> Date: Wed, 4 Oct 2023 12:58:34 +0300 Subject: [PATCH 19/20] Update includes/class-wp-job-manager-post-types.php Co-authored-by: Fernando Jorge Mota --- includes/class-wp-job-manager-post-types.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wp-job-manager-post-types.php b/includes/class-wp-job-manager-post-types.php index bc8cb5e0d..29d25c548 100644 --- a/includes/class-wp-job-manager-post-types.php +++ b/includes/class-wp-job-manager-post-types.php @@ -585,7 +585,7 @@ public function job_feed() { 'posts_per_page' => $input_posts_per_page, 'paged' => absint( get_query_var( 'paged', 1 ) ), 'tax_query' => [], // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Empty. - 'meta_query' => [], //// phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Empty. + 'meta_query' => [], // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Empty. ]; if ( ! empty( $input_search_location ) ) { From ca6bc669bd0013f9662e4c773afae129a2bdc6e5 Mon Sep 17 00:00:00 2001 From: gkaragia <53191348+gkaragia@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:19:19 +0300 Subject: [PATCH 20/20] Ignore slow query warnings --- .../promoted-jobs/class-wp-job-manager-promoted-jobs-api.php | 2 +- includes/promoted-jobs/class-wp-job-manager-promoted-jobs.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/promoted-jobs/class-wp-job-manager-promoted-jobs-api.php b/includes/promoted-jobs/class-wp-job-manager-promoted-jobs-api.php index 2bc251290..b003d5c60 100644 --- a/includes/promoted-jobs/class-wp-job-manager-promoted-jobs-api.php +++ b/includes/promoted-jobs/class-wp-job-manager-promoted-jobs-api.php @@ -187,7 +187,7 @@ public function get_items() { 'no_found_rows' => true, 'ignore_sticky_posts' => true, 'posts_per_page' => -1, - 'meta_query' => [ + 'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Returns promoted jobs only which should be a small number. [ 'key' => WP_Job_Manager_Promoted_Jobs::PROMOTED_META_KEY, 'compare' => 'EXISTS', diff --git a/includes/promoted-jobs/class-wp-job-manager-promoted-jobs.php b/includes/promoted-jobs/class-wp-job-manager-promoted-jobs.php index b2281f388..58cb72201 100644 --- a/includes/promoted-jobs/class-wp-job-manager-promoted-jobs.php +++ b/includes/promoted-jobs/class-wp-job-manager-promoted-jobs.php @@ -213,7 +213,7 @@ public static function query_promoted_jobs_count( $args = [] ) { 'post_status' => 'any', 'posts_per_page' => 1, 'fields' => 'ids', - 'meta_query' => [ + 'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Returns promoted jobs only which should be a small number. [ 'key' => self::PROMOTED_META_KEY, 'value' => '1',