*/ namespace RankMath\Admin; use RankMath\KB; use RankMath\Helper; use RankMath\Traits\Ajax; use RankMath\Traits\Hooker; defined( 'ABSPATH' ) || exit; /** * Pro_Notice class. */ class Pro_Notice { use Hooker, Ajax; /** * Now. * * @var string */ public $current_time = ''; /** * Rank Math plugin install date. * * @var string */ public $install_date = ''; /** * Date of release of version 1.0.69. Turned into a timestamp in the constructor. * * @var string */ public $record_date = '2021-07-30 13:00'; /** * Constructor method. */ public function __construct() { $this->current_time = current_time( 'timestamp' ); $this->record_date = strtotime( $this->record_date ); $this->install_date = get_option( 'rank_math_install_date' ); if ( false === $this->install_date ) { $this->install_date = $this->current_time; } } /** * Register hooks. */ public function hooks() { $this->ajax( 'dismiss_pro_notice', 'dismiss' ); // Admin notice. $notice_date = $this->get_notice_date(); if ( $this->current_time > $notice_date ) { if ( get_option( 'rank_math_pro_notice_added' ) === false && ! Helper::has_notification( 'rank_math_review_plugin_notice' ) ) { $this->add_notice( (int) get_option( 'rank_math_pro_notice_delayed' ) ); } // Make dismiss button work like the "Maybe later" link. $this->action( 'wp_helpers_notification_dismissed', 'pro_notice_after_dismiss' ); $this->action( 'admin_footer', 'pro_notice_js', 15 ); } } /** * Add inline JS & CSS related to the Pro notice. * * @return void */ public function pro_notice_js() { if ( ! Helper::has_notification( 'rank_math_pro_notice' ) ) { return; } ?> get_notice_text( $variant ); Helper::add_notification( $message, [ 'type' => 'info', 'id' => 'rank_math_pro_notice', 'capability' => 'install_plugins', ] ); update_option( 'rank_math_pro_notice_added', '1', false ); } /** * Get notice texts. * * @param integer $variant Message variant. * @return string */ public function get_notice_text( $variant = 0 ) { $message = ''; switch ( (int) $variant ) { case 1: $message = '
'; $message .= esc_html__( 'Rank Your Content With the Power of PRO & A.I.', 'rank-math' ); $message .= '
'; $message .= '' . esc_html__( 'Yes, I want to learn more', 'rank-math' ) . '' . esc_html__( 'No, I don\'t want it', 'rank-math' ) . '' . esc_html__( 'I already upgraded', 'rank-math' ) . '
'; break; default: $message = ''; $message .= esc_html__( 'Rank Your Content With the Power of PRO & A.I.', 'rank-math' ); $message .= '
'; $message .= '
' . esc_html__( 'Yes, I want better SEO', 'rank-math' ) . '' . esc_html__( 'No, maybe later', 'rank-math' ) . '' . esc_html__( 'I already purchased', 'rank-math' ) . '
'; break; } return $message; } /** * Set "delayed" flag after the user dismisses the notice. * * @param string $notification_id Dismissed notice ID. * @return void */ public function pro_notice_after_dismiss( $notification_id ) { if ( 'rank_math_pro_notice' !== $notification_id ) { return; } // If it has already been delayed once then dismiss it forever. if ( get_option( 'rank_math_pro_notice_delayed' ) ) { update_option( 'rank_math_already_upgraded', current_time( 'timestamp' ) ); return; } delete_option( 'rank_math_pro_notice_date' ); delete_option( 'rank_math_pro_notice_added' ); update_option( 'rank_math_pro_notice_delayed', 1, false ); } /** * Get stored notice start date. * * @return int */ public function get_notice_date() { $notice_date = get_option( 'rank_math_pro_notice_date' ); if ( false !== $notice_date ) { return $notice_date; } $delay_days = 10; if ( $this->install_date < $this->record_date && ! get_option( 'rank_math_pro_notice_delayed' ) ) { $delay_days = wp_rand( 7, 30 ); } $notice_date = $this->current_time + ( $delay_days * DAY_IN_SECONDS ); update_option( 'rank_math_pro_notice_date', $notice_date, false ); return $notice_date; } /** * Set the "already upgraded" flag. * This also sets the "already reviewed" flag, so the review notice will not show up anymore either. */ public function dismiss() { check_ajax_referer( 'rank-math-ajax-nonce', 'security' ); $this->has_cap_ajax( 'onpage_general' ); update_option( 'rank_math_already_upgraded', current_time( 'timestamp' ) ); update_option( 'rank_math_already_reviewed', current_time( 'timestamp' ) ); $this->success( 'success' ); } }