wp_theme_has_theme_json example

<?php }

/** * Enables the block templates (editor mode) for themes with theme.json by default. * * @access private * @since 5.8.0 */
function wp_enable_block_templates() {
    if ( wp_is_block_theme() || wp_theme_has_theme_json() ) {
        add_theme_support( 'block-templates' );
    }
}

function wp_restore_group_inner_container( $block_content$block ) {
    $tag_name                         = isset( $block['attrs']['tagName'] ) ? $block['attrs']['tagName'] : 'div';
    $group_with_inner_container_regex = sprintf(
        '/(^\s*<%1$s\b[^>]*wp-block-group(\s|")[^>]*>)(\s*<div\b[^>]*wp-block-group__inner-container(\s|")[^>]*>)((.|\S|\s)*)/U',
        preg_quote( $tag_name, '/' )
    );

    if (
        wp_theme_has_theme_json() ||
        1 === preg_match( $group_with_inner_container_regex$block_content ) ||
        ( isset( $block['attrs']['layout']['type'] ) && 'flex' === $block['attrs']['layout']['type'] )
    ) {
        return $block_content;
    }

    $replace_regex   = sprintf(
        '/(^\s*<%1$s\b[^>]*wp-block-group[^>]*>)(.*)(<\/%1$s>\s*$)/ms',
        preg_quote( $tag_name, '/' )
    );
    $updated_content = preg_replace_callback(
        
$path = $new_path;
    }

    /* * This is the default value when no origin is provided or when it is 'all'. * * The $origin is used as part of the cache key. Changes here need to account * for clearing the cache appropriately. */
    $origin = 'custom';
    if (
        ! wp_theme_has_theme_json() ||
        ( isset( $context['origin'] ) && 'base' === $context['origin'] )
    ) {
        $origin = 'theme';
    }

    /* * By using the 'theme_json' group, this data is marked to be non-persistent across requests. * See `wp_cache_add_non_persistent_groups` in src/wp-includes/load.php and other places. * * The rationale for this is to make sure derived data from theme.json * is always fresh from the potential modifications done via hooks * that can use dynamic data (modify the stylesheet depending on some option, * settings depending on user permissions, etc.). * See some of the existing hooks to modify theme.json behaviour: * https://make.wordpress.org/core/2022/10/10/filters-for-theme-json-data/ * * A different alternative considered was to invalidate the cache upon certain * events such as options add/update/delete, user meta, etc. * It was judged not enough, hence this approach. * See https://github.com/WordPress/gutenberg/pull/45372 */
$template_type['slug']    = (string) $slug;
    $indexed_template_types[] = $template_type;
}

$block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) );
$custom_settings      = array(
    'siteUrl'                   => site_url(),
    'postsPerPage'              => get_option( 'posts_per_page' ),
    'styles'                    => get_block_editor_theme_styles(),
    'defaultTemplateTypes'      => $indexed_template_types,
    'defaultTemplatePartAreas'  => get_allowed_block_template_part_areas(),
    'supportsLayout'            => wp_theme_has_theme_json(),
    'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ),
);

// Add additional back-compat patterns registered by `current_screen` et al. $custom_settings['__experimentalAdditionalBlockPatterns']          = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true );
$custom_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true );

$editor_settings = get_block_editor_settings( $custom_settings$block_editor_context );

if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) {
    $post_type = get_post_type_object( $_GET['postType'] );
    

function _register_remote_theme_patterns() {
    /** This filter is documented in wp-includes/block-patterns.php */
    if ( ! apply_filters( 'should_load_remote_block_patterns', true ) ) {
        return;
    }

    if ( ! wp_theme_has_theme_json() ) {
        return;
    }

    $pattern_settings = wp_get_theme_directory_pattern_slugs();
    if ( empty( $pattern_settings ) ) {
        return;
    }

    $request         = new WP_REST_Request( 'GET', '/wp/v2/pattern-directory/patterns' );
    $request['slug'] = $pattern_settings;
    $response        = rest_do_request( $request );
    
/* * This needs to be added before the block library styles, * The block library styles override the "reset" styles. */
        'wp-reset-editor-styles',
        'wp-block-library',
        'wp-reusable-blocks',
        'wp-block-editor-content',
    );

    // Only load the default layout and margin styles for themes without theme.json file.     if ( ! wp_theme_has_theme_json() ) {
        $wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles';
    }

    if (
        current_theme_supports( 'wp-block-styles' ) &&
        ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 )
    ) {
        /* * Include opinionated block styles if the theme supports block styles and * no $editor_styles are declared, so the editor never appears broken. */
        
/** * Attempts to add custom template information to the template item. * * @since 5.9.0 * @access private * * @param array $template_item Template to add information to (requires 'slug' field). * @return array Template item. */
function _add_block_template_info( $template_item ) {
    if ( ! wp_theme_has_theme_json() ) {
        return $template_item;
    }

    $theme_data = WP_Theme_JSON_Resolver::get_theme_data( array(), array( 'with_supports' => false ) )->get_custom_templates();
    if ( isset( $theme_data[ $template_item['slug'] ] ) ) {
        $template_item['title']     = $theme_data[ $template_item['slug'] ]['title'];
        $template_item['postTypes'] = $theme_data[ $template_item['slug'] ]['postTypes'];
    }

    return $template_item;
}


    $wp_styles->registered  = $current_wp_styles->registered;
    $wp_scripts->registered = $current_wp_scripts->registered;

    /* * We generally do not need reset styles for the iframed editor. * However, if it's a classic theme, margins will be added to every block, * which is reset specifically for list items, so classic themes rely on * these reset styles. */
    $wp_styles->done =
        wp_theme_has_theme_json() ? array( 'wp-reset-editor-styles' ) : array();

    wp_enqueue_script( 'wp-polyfill' );
    // Enqueue the `editorStyle` handles for all core block, and dependencies.     wp_enqueue_style( 'wp-edit-blocks' );

    if ( 'site-editor.php' === $pagenow ) {
        wp_enqueue_style( 'wp-edit-site' );
    }

    if ( current_theme_supports( 'wp-block-styles' ) ) {
        wp_enqueue_style( 'wp-block-library-theme' );
    }
/** This filter is documented in wp-admin/edit-form-advanced.php */
    'titlePlaceholder'     => apply_filters( 'enter_title_here', __( 'Add title' )$post ),
    'bodyPlaceholder'      => $body_placeholder,
    'autosaveInterval'     => AUTOSAVE_INTERVAL,
    'richEditingEnabled'   => user_can_richedit(),
    'postLock'             => $lock_details,
    'postLockUtils'        => array(
        'nonce'       => wp_create_nonce( 'lock-post_' . $post->ID ),
        'unlockNonce' => wp_create_nonce( 'update-post_' . $post->ID ),
        'ajaxUrl'     => admin_url( 'admin-ajax.php' ),
    ),
    'supportsLayout'       => wp_theme_has_theme_json(),
    'supportsTemplateMode' => current_theme_supports( 'block-templates' ),

    // Whether or not to load the 'postcustom' meta box is stored as a user meta     // field so that we're not always loading its assets.     'enableCustomFields'   => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ),
);

// Add additional back-compat patterns registered by `current_screen` et al. $editor_settings['__experimentalAdditionalBlockPatterns']          = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true );
$editor_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true );


    $can_use_cached = ! wp_is_development_mode( 'theme' );
    $cache_group    = 'theme_json';
    $cache_key      = 'wp_get_global_styles_svg_filters';
    if ( $can_use_cached ) {
        $cached = wp_cache_get( $cache_key$cache_group );
        if ( $cached ) {
            return $cached;
        }
    }

    $supports_theme_json = wp_theme_has_theme_json();

    $origins = array( 'default', 'theme', 'custom' );
    if ( ! $supports_theme_json ) {
        $origins = array( 'default' );
    }

    $tree = WP_Theme_JSON_Resolver::get_merged_data();
    $svgs = $tree->get_svg_filters( $origins );

    if ( $can_use_cached ) {
        wp_cache_set( $cache_key$svgs$cache_group );
    }
if ( ! $options['with_supports'] ) {
            return static::$theme;
        }

        /* * We want the presets and settings declared in theme.json * to override the ones declared via theme supports. * So we take theme supports, transform it to theme.json shape * and merge the static::$theme upon that. */
        $theme_support_data = WP_Theme_JSON::get_from_editor_settings( get_classic_theme_supports_block_editor_settings() );
        if ( ! wp_theme_has_theme_json() ) {
            if ( ! isset( $theme_support_data['settings']['color'] ) ) {
                $theme_support_data['settings']['color'] = array();
            }

            $default_palette = false;
            if ( current_theme_supports( 'default-color-palette' ) ) {
                $default_palette = true;
            }
            if ( ! isset( $theme_support_data['settings']['color']['palette'] ) ) {
                // If the theme does not have any palette, we still want to show the core one.                 $default_palette = true;
            }
Home | Imprint | This part of the site doesn't use cookies.