$now ) ) { return false; } $installed = (int) get_option( self::INSTALLED, $now ); if ( $now - $installed < self::WAIT_DAYS * DAY_IN_SECONDS ) { return false; } return ( null === $fixed ? self::fixed() : (int) $fixed ) > 0; } /** * Issues fixed so far, from the (cached) summary. * * @return int */ private static function fixed() { $summary = Store::summary(); return isset( $summary['fixed'] ) ? (int) $summary['fixed'] : 0; } /** * Prints the request on a Fixlight screen when it is due. */ public static function render() { if ( ! self::due() ) { return; } $fixed = self::fixed(); $link = static function ( $answer ) { return wp_nonce_url( admin_url( 'admin-post.php?action=fixlight_review_ask&answer=' . $answer ), 'fixlight_review_ask' ); }; echo '

'; echo esc_html( sprintf( /* translators: %s: number of issues fixed. */ _n( 'Fixlight has fixed %s accessibility issue on your site. If it helps you, a review on WordPress.org helps other site owners find it.', 'Fixlight has fixed %s accessibility issues on your site. If it helps you, a review on WordPress.org helps other site owners find it.', $fixed, 'fixlight' ), number_format_i18n( $fixed ) ) ); echo '

'; printf( '%2$s %3$s %5$s %7$s', esc_url( $link( 'review' ) ), esc_html__( 'Write a review', 'fixlight' ), esc_html__( '(opens in a new tab)', 'fixlight' ), esc_url( $link( 'later' ) ), esc_html__( 'Maybe later', 'fixlight' ), esc_url( $link( 'never' ) ), esc_html__( 'Don\'t ask again', 'fixlight' ) ); echo '

'; } /** * Records the answer, then opens the review form or goes back. */ public static function action() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do this.', 'fixlight' ), '', array( 'response' => 403 ) ); } check_admin_referer( 'fixlight_review_ask' ); $answer = isset( $_GET['answer'] ) ? sanitize_key( wp_unslash( $_GET['answer'] ) ) : ''; $value = self::answer_value( $answer, time() ); if ( null !== $value ) { update_user_meta( get_current_user_id(), self::META, $value ); } if ( 'review' === $answer ) { add_filter( 'allowed_redirect_hosts', static function ( $hosts ) { $hosts[] = 'wordpress.org'; return $hosts; } ); wp_safe_redirect( self::URL ); exit; } $back = wp_get_referer(); wp_safe_redirect( $back ? $back : admin_url( 'admin.php?page=' . Admin::SLUG ) ); exit; } /** * What an answer stores, or null for an unknown answer. * * @param string $answer review, later or never. * @param int $now Current time. * @return string|null */ public static function answer_value( $answer, $now ) { switch ( $answer ) { case 'review': return 'done'; case 'never': return 'never'; case 'later': return (string) ( (int) $now + self::LATER_DAYS * DAY_IN_SECONDS ); } return null; } }