args = wp_parse_args( $args, [ 'plugin_name' => '', 'plugin_prefix' => '', 'review_url' => '', 'threshold_days' => 14, 'remind_days' => 7, ] ); if ( empty( $this->args['plugin_prefix'] ) || empty( $this->args['review_url'] ) ) { return; } // Record this prefix so the AJAX handler can validate against known prefixes. self::$registered_prefixes[ $this->args['plugin_prefix'] ] = true; add_action( 'admin_notices', [ $this, 'display_review_notice' ] ); add_action( 'wp_ajax_ddfw_dismiss_review_notice', [ $this, 'dismiss_review_notice' ] ); } /** * Check if the notice should be displayed. * * @return bool */ protected function should_display() { // Only shown to users who can manage the plugin, so it never reaches customers or subscribers. if ( ! current_user_can( 'manage_options' ) && ! current_user_can( 'manage_woocommerce' ) ) { return false; } $prefix = $this->args['plugin_prefix']; // Check if dismissed permanently. if ( 'yes' === get_option( "ddfw_review_notice_dismissed_{$prefix}" ) ) { return false; } // Check install time. $installed_at = get_option( "{$prefix}_installed_at" ); if ( ! $installed_at ) { return false; } $current_time = time(); $threshold_time = $this->args['threshold_days'] * DAY_IN_SECONDS; if ( ( $current_time - $installed_at ) < $threshold_time ) { return false; } // Check "Maybe Later" delay. $remind_at = get_option( "ddfw_review_notice_remind_at_{$prefix}" ); if ( $remind_at && $current_time < $remind_at ) { return false; } return true; } /** * Display the review notice. * * @return void */ public function display_review_notice() { if ( ! $this->should_display() ) { return; } $prefix = $this->args['plugin_prefix']; $plugin_name = $this->args['plugin_name']; $review_url = $this->args['review_url']; $script_path = DDFW_FILE . 'assets/js/review-notice.js'; wp_enqueue_script( 'ddfw-review-notice', DDFW_URL . 'assets/js/review-notice.js', [], filemtime( $script_path ), true ); ?>
args['remind_days'] * DAY_IN_SECONDS ); update_option( "ddfw_review_notice_remind_at_{$prefix}", $remind_at ); } else { update_option( "ddfw_review_notice_dismissed_{$prefix}", 'yes' ); } wp_send_json_success(); } } }