on_own_screen() ) { return $text; } $state = (array) get_option( self::OPTION, array() ); if ( ! empty( $state['rated'] ) ) { return $text; } $link = ''; return sprintf( /* translators: 1: opening link tag to the WordPress.org review form, 2: closing link tag. */ esc_html__( 'Enjoying Advanced Testimonial? Leave us a %1$s★★★★★ review%2$s — it keeps development going.', 'advanced-testimonial' ), $link, '' ); } /** * Record when the plugin was first seen in the admin, so existing installs * also wait a full period after updating to a version with this notice. * * @return void */ public function start_clock() { $state = get_option( self::OPTION ); if ( ! is_array( $state ) || empty( $state['since'] ) ) { update_option( self::OPTION, array( 'since' => time() ), false ); } } /** * Process the notice's action links. * * Clicking "Rate it" only records that the review page was opened — the * plugin cannot see WordPress.org reviews, so the prompts stop for good * only after the user confirms "Yes, I left a review". * * @return void */ public function handle_actions() { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- the nonce is checked immediately below, once we know this is our request. if ( empty( $_GET['at_review'] ) || ! current_user_can( 'manage_options' ) ) { return; } check_admin_referer( 'at_review_notice' ); $state = (array) get_option( self::OPTION, array() ); $action = sanitize_key( wp_unslash( $_GET['at_review'] ) ); if ( 'rated' === $action ) { $state['rated'] = true; } elseif ( 'rate' === $action ) { // Opened the review form: ask for confirmation on the next visit. $state['asked'] = true; unset( $state['snooze_until'] ); } else { $state['snooze_until'] = time() + self::SNOOZE_DAYS * DAY_IN_SECONDS; } update_option( self::OPTION, $state, false ); wp_safe_redirect( remove_query_arg( array( 'at_review', '_wpnonce' ) ) ); exit; } /** * Render the notice when every polite condition is met. * * @return void */ public function maybe_render() { if ( ! current_user_can( 'manage_options' ) || ! $this->should_show() ) { return; } $state = (array) get_option( self::OPTION, array() ); $later = wp_nonce_url( add_query_arg( 'at_review', 'later' ), 'at_review_notice' ); $rate = wp_nonce_url( add_query_arg( 'at_review', 'rate' ), 'at_review_notice' ); $rated = wp_nonce_url( add_query_arg( 'at_review', 'rated' ), 'at_review_notice' ); if ( empty( $state['asked'] ) ) { $message = '' . esc_html__( 'Enjoying Advanced Testimonial?', 'advanced-testimonial' ) . ' ' . esc_html__( 'A quick 5-star review helps other people find the plugin and keeps development going. Thank you!', 'advanced-testimonial' ); } else { $message = '' . esc_html__( 'Did you get a chance to leave that review?', 'advanced-testimonial' ) . ' ' . esc_html__( 'If you did — thank you! Confirm below and we will never ask again.', 'advanced-testimonial' ); } ?>

array() ) ); ?>

on_own_screen() ) { return false; } $state = (array) get_option( self::OPTION, array() ); if ( ! empty( $state['rated'] ) ) { return false; } if ( ! empty( $state['snooze_until'] ) && time() < (int) $state['snooze_until'] ) { return false; } if ( empty( $state['since'] ) || time() < (int) $state['since'] + self::WAIT_DAYS * DAY_IN_SECONDS ) { return false; } // Only ask people who actually use the plugin: at least one published // testimonial. $testimonials = get_posts( array( 'post_type' => CPT::POST_TYPE, 'post_status' => 'publish', 'posts_per_page' => 1, 'fields' => 'ids', ) ); return ! empty( $testimonials ); } /** * Whether the current admin screen belongs to this plugin — the post list, * the editor, the taxonomy screen or any of its submenu pages, which all * hang off edit.php?post_type=testimonial. * * @return bool */ private function on_own_screen() { $screen = function_exists( 'get_current_screen' ) ? get_current_screen() : null; return $screen && CPT::POST_TYPE === $screen->post_type; } }