%1$s %2$s
', esc_html__( 'xSpeed could not turn the page cache on.', 'xspeed' ), esc_html( $refused ) ); return; } if ( ! self::applies() ) { return; } self::$shown = true; // Turning the cache on replaces any advanced-cache.php already there. // The dashboard names its owner before that happens (QA on #642: one // click here took over WP Super Cache's cache without a word), so the // notice does too, and only its takeover link counts as consent. $disclosure = Page_Cache_Detector::dropin_disclosure(); $on_url = admin_url( 'admin-post.php?action=' . self::ACTION_ON ); if ( $disclosure['replaceable'] ) { $on_url = add_query_arg( 'takeover', '1', $on_url ); if ( null !== $disclosure['label'] ) { $body = sprintf( /* translators: %s: the page-caching plugin that owns advanced-cache.php. */ __( 'Every visitor gets a page built from scratch. %s owns the page-cache file now. Turning xSpeed\'s cache on replaces it, and xSpeed serves the cached pages instead.', 'xspeed' ), $disclosure['label'] ); /* translators: %s: the page-caching plugin that owns advanced-cache.php. */ $button = sprintf( __( 'Take over from %s', 'xspeed' ), $disclosure['label'] ); } else { $body = __( 'Every visitor gets a page built from scratch. Another page-cache file is in wp-content now. Turning xSpeed\'s cache on replaces it.', 'xspeed' ); $button = __( 'Replace it and turn on', 'xspeed' ); } } else { $body = __( 'Every visitor gets a page built from scratch. Turn it on unless your host already caches pages for this site.', 'xspeed' ); $button = __( 'Turn it on', 'xspeed' ); } printf( '', esc_html__( "xSpeed's page cache is off.", 'xspeed' ), esc_html( $body ), esc_url( wp_nonce_url( $on_url, self::ACTION_ON ) ), esc_html( $button ), esc_url( admin_url( 'admin.php?page=' . Admin::PAGE_SLUG . '#/cache/cache' ) ), esc_html__( 'Page cache settings', 'xspeed' ), esc_url( wp_nonce_url( admin_url( 'admin-post.php?action=' . self::ACTION_DISMISS ), self::ACTION_DISMISS ) ), esc_html__( 'Dismiss', 'xspeed' ) ); // The dashboard keeps its screen in the URL fragment, which no // referer carries, so the redirect back landed on Overview. The // links pass the fragment along when clicked. echo ""; } /** * "Turn it on": the same Cache::toggle() the dashboard switch calls, so a * drop-in or WP_CACHE line owned by another plugin is refused the same * way. A refusal is shown on the next page instead of the notice. * * Another plugin's drop-in is taken over only from the link that named it. * If one appeared after the notice was printed, the toggle refuses and * says whose it is. */ public static function handle_on(): void { self::authorize( self::ACTION_ON ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- authorize() checked the nonce. $takeover = isset( $_GET['takeover'] ) && '1' === $_GET['takeover']; $state = Cache::toggle( true, $takeover ); if ( ! empty( $state['blocked'] ) ) { $reason = isset( $state['blocked_reason'] ) && is_string( $state['blocked_reason'] ) ? $state['blocked_reason'] : ''; set_transient( self::REFUSED_PREFIX . get_current_user_id(), '' !== $reason ? $reason : __( 'Open the page cache settings to see why.', 'xspeed' ), 5 * MINUTE_IN_SECONDS ); } self::back(); } public static function handle_dismiss(): void { self::authorize( self::ACTION_DISMISS ); update_option( self::OPT_DISMISSED, time(), false ); self::back(); } private static function authorize( string $action ): void { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You are not allowed to do that.', 'xspeed' ), '', array( 'response' => 403 ) ); } check_admin_referer( $action ); } private static function back(): void { $referer = wp_get_referer(); $target = $referer ? $referer : admin_url(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- authorize() checked the nonce. $route = isset( $_GET[ self::ROUTE_PARAM ] ) ? sanitize_text_field( wp_unslash( (string) $_GET[ self::ROUTE_PARAM ] ) ) : ''; if ( false === strpos( $target, '#' ) && preg_match( '~^#/[A-Za-z0-9/_-]*$~', $route ) ) { $target .= $route; } wp_safe_redirect( $target ); exit; } }