Skip to content

Commit

Permalink
Move the notice delay to an option
Browse files Browse the repository at this point in the history
  • Loading branch information
gikaragia committed Oct 2, 2023
1 parent 3cefefc commit 3ac64ce
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 34 deletions.
1 change: 1 addition & 0 deletions includes/class-wp-job-manager-data-cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class WP_Job_Manager_Data_Cleaner {
'job_manager_default_salary_unit',
'job_manager_enable_salary_currency',
'job_manager_default_salary_currency',
'job_manager_display_usage_tracking_once',
];

/**
Expand Down
6 changes: 6 additions & 0 deletions includes/class-wp-job-manager-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 0 additions & 17 deletions includes/class-wp-job-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,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();
}

Expand All @@ -139,11 +138,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();
}
}
Expand Down Expand Up @@ -603,15 +597,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() );
}
}
26 changes: 9 additions & 17 deletions lib/usage-tracking/class-usage-tracking-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand All @@ -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.
Expand All @@ -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 ) { ?>
<div id="<?php echo esc_attr( $this->get_prefix() ); ?>-usage-tracking-notice" class="notice notice-info"
data-nonce="<?php echo esc_attr( wp_create_nonce( 'tracking-opt-in' ) ); ?>">
<p>
Expand Down

0 comments on commit 3ac64ce

Please sign in to comment.