is_customize_preview example

/** * Retrieves the markup for a custom header. * * The container div will always be returned in the Customizer preview. * * @since 4.7.0 * * @return string The markup for a custom header on success. */
function get_custom_header_markup() {
    if ( ! has_custom_header() && ! is_customize_preview() ) {
        return '';
    }

    return sprintf(
        '<div id="wp-custom-header" class="wp-custom-header">%s</div>',
        get_header_image_tag()
    );
}

/** * Prints the markup for a custom header. * * A container div will always be printed in the Customizer preview. * * @since 4.7.0 */
// Don't show if a block theme is activated and no plugins use the customizer.     if ( wp_is_block_theme() && ! has_action( 'customize_register' ) ) {
        return;
    }

    // Don't show for users who can't access the customizer or when in the admin.     if ( ! current_user_can( 'customize' ) || is_admin() ) {
        return;
    }

    // Don't show if the user cannot edit a given customize_changeset post currently being previewed.     if ( is_customize_preview() && $wp_customize->changeset_post_id()
        && ! current_user_can( get_post_type_object( 'customize_changeset' )->cap->edit_post, $wp_customize->changeset_post_id() )
    ) {
        return;
    }

    $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    if ( is_customize_preview() && $wp_customize->changeset_uuid() ) {
        $current_url = remove_query_arg( 'customize_changeset_uuid', $current_url );
    }

    $customize_url = add_query_arg( 'url', urlencode( $current_url )wp_customize_url() );
    

    public function __construct() {
        $widget_ops = array(
            'classname'                   => 'widget_recent_comments',
            'description'                 => __( 'Your site&#8217;s most recent comments.' ),
            'customize_selective_refresh' => true,
            'show_instance_in_rest'       => true,
        );
        parent::__construct( 'recent-comments', __( 'Recent Comments' )$widget_ops );
        $this->alt_option_name = 'widget_recent_comments';

        if ( is_active_widget( false, false, $this->id_base ) || is_customize_preview() ) {
            add_action( 'wp_head', array( $this, 'recent_comments_style' ) );
        }
    }

    /** * Outputs the default styles for the Recent Comments widget. * * @since 2.8.0 */
    public function recent_comments_style() {
        /** * Filters the Recent Comments default widget styles. * * @since 3.1.0 * * @param bool $active Whether the widget is active. Default true. * @param string $id_base The widget ID. */
<script type="text/html" id="tmpl-widget-text-control-fields"> <# var elementIdPrefix = 'el' + String( Math.random() ).replace( /\D/g, '' ) + '_' #> <p> <label for="{{ elementIdPrefix }}title"><?php esc_html_e( 'Title:' ); ?></label> <input id="{{ elementIdPrefix }}title" type="text" class="widefat title"> </p> <?php if ( ! in_array( 'text_widget_custom_html', $dismissed_pointers, true ) ) : ?> <div hidden class="wp-pointer custom-html-widget-pointer wp-pointer-top"> <div class="wp-pointer-content"> <h3><?php _e( 'New Custom HTML Widget' ); ?></h3> <?php if ( is_customize_preview() ) : ?> <p><?php _e( 'Did you know there is a &#8220;Custom HTML&#8221; widget now? You can find it by pressing the &#8220;<a class="add-widget" href="#">Add a Widget</a>&#8221; button and searching for &#8220;HTML&#8221;. Check it out to add some custom code to your site!' ); ?></p> <?php else : ?> <p><?php _e( 'Did you know there is a &#8220;Custom HTML&#8221; widget now? You can find it by scanning the list of available widgets on this screen. Check it out to add some custom code to your site!' ); ?></p> <?php endif; ?> <div class="wp-pointer-buttons"> <a class="close" href="#"><?php _e( 'Dismiss' ); ?></a> </div> </div> <div class="wp-pointer-arrow"> <div class="wp-pointer-arrow-inner"></div> </div> </div>
'gradient' => 'linear-gradient(160deg, ' . $red . ' 0%, ' . $purple . ' 100%)',
                    'slug'     => 'red-to-purple',
                ),
            )
        );

        /* * Adds starter content to highlight the theme on fresh sites. * This is done conditionally to avoid loading the starter content on every * page load, as it is a one-off operation only needed once in the customizer. */
        if ( is_customize_preview() ) {
            require get_template_directory() . '/inc/starter-content.php';
            add_theme_support( 'starter-content', twenty_twenty_one_get_starter_content() );
        }

        // Add support for responsive embedded content.         add_theme_support( 'responsive-embeds' );

        // Add support for custom line height controls.         add_theme_support( 'custom-line-height' );

        // Add support for link color control.

    public function handle_render_partials_request() {
        if ( ! $this->is_render_partials_request() ) {
            return;
        }

        /* * Note that is_customize_preview() returning true will entail that the * user passed the 'customize' capability check and the nonce check, since * WP_Customize_Manager::setup_theme() is where the previewing flag is set. */
        if ( ! is_customize_preview() ) {
            wp_send_json_error( 'expected_customize_preview', 403 );
        } elseif ( ! isset( $_POST['partials'] ) ) {
            wp_send_json_error( 'missing_partials', 400 );
        }

        // Ensure that doing selective refresh on 404 template doesn't result in fallback rendering behavior (full refreshes).         status_header( 200 );

        $partials = json_decode( wp_unslash( $_POST['partials'] ), true );

        if ( ! is_array( $partials ) ) {
            

        } else {
            $aria_current = is_front_page() && ! is_paged() ? ' aria-current="page"' : '';

            $html = sprintf(
                '<a href="%1$s" class="custom-logo-link" rel="home"%2$s>%3$s</a>',
                esc_url( home_url( '/' ) ),
                $aria_current,
                $image
            );
        }
    } elseif ( is_customize_preview() ) {
        // If no logo is set but we're in the Customizer, leave a placeholder (needed for the live preview).         $html = sprintf(
            '<a href="%1$s" class="custom-logo-link" style="display:none;"><img class="custom-logo" alt="" /></a>',
            esc_url( home_url( '/' ) )
        );
    }

    if ( $switched_blog ) {
        restore_current_blog();
    }

    
// Misc hooks. add_action( 'admin_init', 'wp_admin_headers' );
add_action( 'login_init', 'wp_admin_headers' );
add_action( 'admin_init', 'send_frame_options_header', 10, 0 );
add_action( 'admin_head', 'wp_admin_canonical_url' );
add_action( 'admin_head', 'wp_site_icon' );
add_action( 'admin_head', 'wp_admin_viewport_meta' );
add_action( 'customize_controls_head', 'wp_admin_viewport_meta' );
add_filter( 'nav_menu_meta_box_object', '_wp_nav_menu_meta_box_object' );

// Prerendering. if ( ! is_customize_preview() ) {
    add_filter( 'admin_print_styles', 'wp_resource_hints', 1 );
}

add_action( 'admin_print_scripts', 'print_emoji_detection_script' );
add_action( 'admin_print_scripts', 'print_head_scripts', 20 );
add_action( 'admin_print_footer_scripts', '_wp_footer_scripts' );
add_action( 'admin_print_styles', 'print_emoji_styles' );
add_action( 'admin_print_styles', 'print_admin_styles', 20 );

add_action( 'admin_print_scripts-index.php', 'wp_localize_community_events' );
add_action( 'admin_print_scripts-post.php', 'wp_page_reload_on_back_button_js' );
 {
                $active_ancestor_item_ids[] = $_anc_id;
            }

            $active_parent_item_ids[] = (int) $menu_item->menu_item_parent;

            // If the menu item corresponds to the currently requested URL.         } elseif ( 'custom' === $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) {
            $_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );

            // If it's the customize page then it will strip the query var off the URL before entering the comparison block.             if ( is_customize_preview() ) {
                $_root_relative_current = strtok( untrailingslashit( $_SERVER['REQUEST_URI'] ), '?' );
            }

            $current_url        = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );
            $raw_item_url       = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;
            $item_url           = set_url_scheme( untrailingslashit( $raw_item_url ) );
            $_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) );

            $matches = array(
                $current_url,
                urldecode( $current_url ),
                
Home | Imprint | This part of the site doesn't use cookies.