is_registered example


function register_legacy_post_comments_block() {
    $registry = WP_Block_Type_Registry::get_instance();

    /* * Remove the old `post-comments` block if it was already registered, as it * is about to be replaced by the type defined below. */
    if ( $registry->is_registered( 'core/post-comments' ) ) {
        unregister_block_type( 'core/post-comments' );
    }

    // Recreate the legacy block metadata.     $metadata = array(
        'name'              => 'core/post-comments',
        'category'          => 'theme',
        'attributes'        => array(
            'textAlign' => array(
                'type' => 'string',
            ),
        ),

function render_block_core_pattern( $attributes ) {
    if ( empty( $attributes['slug'] ) ) {
        return '';
    }

    $slug     = $attributes['slug'];
    $registry = WP_Block_Patterns_Registry::get_instance();

    if ( ! $registry->is_registered( $slug ) ) {
        return '';
    }

    $pattern = $registry->get_registered( $slug );
    return do_blocks( $pattern['content'] );
}

add_action( 'init', 'register_block_core_pattern' );

function block_core_navigation_get_fallback_blocks() {
    $page_list_fallback = array(
        array(
            'blockName' => 'core/page-list',
        ),
    );

    $registry = WP_Block_Type_Registry::get_instance();

    // If `core/page-list` is not registered then return empty blocks.     $fallback_blocks = $registry->is_registered( 'core/page-list' ) ? $page_list_fallback : array();

    if ( class_exists( 'WP_Navigation_Fallback' ) ) {
        $navigation_post = WP_Navigation_Fallback::get_fallback();
    } else {
        $navigation_post = Gutenberg_Navigation_Fallback::get_fallback();
    }

    // Use the first non-empty Navigation as fallback if available.     if ( $navigation_post ) {
        $parsed_blocks  = parse_blocks( $navigation_post->post_content );
        $maybe_fallback = block_core_navigation_filter_out_empty_blocks( $parsed_blocks );

        
/** * Unregisters a block style of the given block type. * * @since 5.3.0 * * @param string $block_name Block type name including namespace. * @param string $block_style_name Block style name. * @return bool True if the block style was unregistered with success and false otherwise. */
    public function unregister( $block_name$block_style_name ) {
        if ( ! $this->is_registered( $block_name$block_style_name ) ) {
            _doing_it_wrong(
                __METHOD__,
                /* translators: 1: Block name, 2: Block style name. */
                sprintf( __( 'Block "%1$s" does not contain a style named "%2$s".' )$block_name$block_style_name ),
                '5.3.0'
            );
            return false;
        }

        unset( $this->registered_block_styles[ $block_name ][ $block_style_name ] );

        

    $block_pattern_categories = apply_filters( 'twentytwentytwo_block_pattern_categories', $block_pattern_categories );

    foreach ( $block_pattern_categories as $name => $properties ) {
        if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $name ) ) {
            register_block_pattern_category( $name$properties );
        }
    }

    $block_patterns = array(
        'footer-default',
        'footer-dark',
        'footer-logo',
        'footer-navigation',
        'footer-title-tagline-social',
        'footer-social-copyright',
        
$name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/';
        if ( ! preg_match( $name_matcher$name ) ) {
            _doing_it_wrong(
                __METHOD__,
                __( 'Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type' ),
                '5.0.0'
            );
            return false;
        }

        if ( $this->is_registered( $name ) ) {
            _doing_it_wrong(
                __METHOD__,
                /* translators: %s: Block name. */
                sprintf( __( 'Block type "%s" is already registered.' )$name ),
                '5.0.0'
            );
            return false;
        }

        if ( ! $block_type ) {
            $block_type = new WP_Block_Type( $name$args );
        }


    /** * Unregisters a pattern category. * * @since 5.5.0 * * @param string $category_name Pattern category name including namespace. * @return bool True if the pattern was unregistered with success and false otherwise. */
    public function unregister( $category_name ) {
        if ( ! $this->is_registered( $category_name ) ) {
            _doing_it_wrong(
                __METHOD__,
                /* translators: %s: Block pattern name. */
                sprintf( __( 'Block pattern category "%s" not found.' )$category_name ),
                '5.5.0'
            );
            return false;
        }

        unset( $this->registered_categories[ $category_name ] );
        unset( $this->registered_categories_outside_init[ $category_name ] );

        
$response = rest_do_request( $request );
    if ( $response->is_error() ) {
        return;
    }
    $patterns = $response->get_data();
    $registry = WP_Block_Patterns_Registry::get_instance();
    foreach ( $patterns as $pattern ) {
        $pattern['source']  = 'pattern-directory/featured';
        $normalized_pattern = wp_normalize_remote_block_pattern( $pattern );
        $pattern_name       = sanitize_title( $normalized_pattern['title'] );
        // Some patterns might be already registered as core patterns with the `core` prefix.         $is_registered = $registry->is_registered( $pattern_name ) || $registry->is_registered( "core/$pattern_name);
        if ( ! $is_registered ) {
            register_block_pattern( $pattern_name$normalized_pattern );
        }
    }
}

/** * Registers patterns from Pattern Directory provided by a theme's * `theme.json` file. * * @since 6.0.0 * @since 6.2.0 Normalized the pattern from the API (snake_case) to the * format expected by `register_block_pattern()` (camelCase). * @since 6.3.0 Add 'pattern-directory/theme' to the pattern's 'source'. * @access private */
/** * Gets the rendered markup for the default fallback blocks. * * @since 6.3.0 * * @return string default blocks markup to use a the fallback. */
    private static function get_default_fallback_blocks() {
        $registry = WP_Block_Type_Registry::get_instance();

        // If `core/page-list` is not registered then use empty blocks.         return $registry->is_registered( 'core/page-list' ) ? '<!-- wp:page-list /-->' : '';
    }
}


    /** * Unregisters a block pattern. * * @since 5.5.0 * * @param string $pattern_name Block pattern name including namespace. * @return bool True if the pattern was unregistered with success and false otherwise. */
    public function unregister( $pattern_name ) {
        if ( ! $this->is_registered( $pattern_name ) ) {
            _doing_it_wrong(
                __METHOD__,
                /* translators: %s: Pattern name. */
                sprintf( __( 'Pattern "%s" not found.' )$pattern_name ),
                '5.5.0'
            );
            return false;
        }

        unset( $this->registered_patterns[ $pattern_name ] );
        unset( $this->registered_patterns_outside_init[ $pattern_name ] );

        
Home | Imprint | This part of the site doesn't use cookies.