Edit File by line
/home/zeestwma/redstone.../wp-inclu...
File: theme-previews.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Theme previews using the Site Editor for block themes.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Filters the blog option to return the path for the previewed theme.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 6.3.0
[10] Fix | Delete
*
[11] Fix | Delete
* @param string $current_stylesheet The current theme's stylesheet or template path.
[12] Fix | Delete
* @return string The previewed theme's stylesheet or template path.
[13] Fix | Delete
*/
[14] Fix | Delete
function wp_get_theme_preview_path( $current_stylesheet = null ) {
[15] Fix | Delete
if ( ! current_user_can( 'switch_themes' ) ) {
[16] Fix | Delete
return $current_stylesheet;
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
$preview_stylesheet = ! empty( $_GET['wp_theme_preview'] ) ? sanitize_text_field( wp_unslash( $_GET['wp_theme_preview'] ) ) : null;
[20] Fix | Delete
$wp_theme = wp_get_theme( $preview_stylesheet );
[21] Fix | Delete
if ( ! is_wp_error( $wp_theme->errors() ) ) {
[22] Fix | Delete
if ( current_filter() === 'template' ) {
[23] Fix | Delete
$theme_path = $wp_theme->get_template();
[24] Fix | Delete
} else {
[25] Fix | Delete
$theme_path = $wp_theme->get_stylesheet();
[26] Fix | Delete
}
[27] Fix | Delete
[28] Fix | Delete
return sanitize_text_field( $theme_path );
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
return $current_stylesheet;
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Adds a middleware to `apiFetch` to set the theme for the preview.
[36] Fix | Delete
* This adds a `wp_theme_preview` URL parameter to API requests from the Site Editor, so they also respond as if the theme is set to the value of the parameter.
[37] Fix | Delete
*
[38] Fix | Delete
* @since 6.3.0
[39] Fix | Delete
*/
[40] Fix | Delete
function wp_attach_theme_preview_middleware() {
[41] Fix | Delete
// Don't allow non-admins to preview themes.
[42] Fix | Delete
if ( ! current_user_can( 'switch_themes' ) ) {
[43] Fix | Delete
return;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
wp_add_inline_script(
[47] Fix | Delete
'wp-api-fetch',
[48] Fix | Delete
sprintf(
[49] Fix | Delete
'wp.apiFetch.use( wp.apiFetch.createThemePreviewMiddleware( %s ) );',
[50] Fix | Delete
wp_json_encode( sanitize_text_field( wp_unslash( $_GET['wp_theme_preview'] ) ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
[51] Fix | Delete
),
[52] Fix | Delete
'after'
[53] Fix | Delete
);
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Set a JavaScript constant for theme activation.
[58] Fix | Delete
*
[59] Fix | Delete
* Sets the JavaScript global WP_BLOCK_THEME_ACTIVATE_NONCE containing the nonce
[60] Fix | Delete
* required to activate a theme. For use within the site editor.
[61] Fix | Delete
*
[62] Fix | Delete
* @see https://github.com/WordPress/gutenberg/pull/41836
[63] Fix | Delete
*
[64] Fix | Delete
* @since 6.3.0
[65] Fix | Delete
* @access private
[66] Fix | Delete
*/
[67] Fix | Delete
function wp_block_theme_activate_nonce() {
[68] Fix | Delete
$nonce_handle = 'switch-theme_' . wp_get_theme_preview_path();
[69] Fix | Delete
?>
[70] Fix | Delete
<script type="text/javascript">
[71] Fix | Delete
window.WP_BLOCK_THEME_ACTIVATE_NONCE = <?php echo wp_json_encode( wp_create_nonce( $nonce_handle ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ); ?>;
[72] Fix | Delete
</script>
[73] Fix | Delete
<?php
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Add filters and actions to enable Block Theme Previews in the Site Editor.
[78] Fix | Delete
*
[79] Fix | Delete
* The filters and actions should be added after `pluggable.php` is included as they may
[80] Fix | Delete
* trigger code that uses `current_user_can()` which requires functionality from `pluggable.php`.
[81] Fix | Delete
*
[82] Fix | Delete
* @since 6.3.2
[83] Fix | Delete
*/
[84] Fix | Delete
function wp_initialize_theme_preview_hooks() {
[85] Fix | Delete
if ( ! empty( $_GET['wp_theme_preview'] ) ) {
[86] Fix | Delete
add_filter( 'stylesheet', 'wp_get_theme_preview_path' );
[87] Fix | Delete
add_filter( 'template', 'wp_get_theme_preview_path' );
[88] Fix | Delete
add_action( 'init', 'wp_attach_theme_preview_middleware' );
[89] Fix | Delete
add_action( 'admin_head', 'wp_block_theme_activate_nonce' );
[90] Fix | Delete
}
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function