wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren
wp_attach_theme_preview_middleware › WordPress Function
Seit6.3.0
Veraltetn/v
› wp_attach_theme_preview_middleware ( Keine Parameter )
| Definiert in: |
|
| Codex: |
Adds a middleware to `apiFetch` to set the theme for the preview.
This adds awp_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.Quellcode
function wp_attach_theme_preview_middleware() {
// Don't allow non-admins to preview themes.
if ( ! current_user_can( 'switch_themes' ) ) {
return;
}
wp_add_inline_script(
'wp-api-fetch',
sprintf(
'wp.apiFetch.use( wp.apiFetch.createThemePreviewMiddleware( %s ) );',
wp_json_encode( sanitize_text_field( wp_unslash( $_GET['wp_theme_preview'] ) ), JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
),
'after'
);
}