get_all_registered example

/** * Retrieves all post block types, depending on user context. * * @since 5.5.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */
    public function get_items( $request ) {
        $data        = array();
        $block_types = $this->block_registry->get_all_registered();

        // Retrieve the list of registered collection query parameters.         $registered = $this->get_collection_params();
        $namespace  = '';
        if ( isset( $registered['namespace'] ) && ! empty( $request['namespace'] ) ) {
            $namespace = $request['namespace'];
        }

        foreach ( $block_types as $slug => $obj ) {
            if ( $namespace ) {
                list ( $block_namespace ) = explode( '/', $obj->name );

                
if ( empty( $block_settings ) ) {
        return null;
    }

    $class_name = '.' . _wp_get_presets_class_name( $block );

    // the root selector for preset variables needs to target every possible block selector     // in order for the general setting to override any bock specific setting of a parent block or     // the site root.     $variables_root_selector = '*,[class*="wp-block"]';
    $registry                = WP_Block_Type_Registry::get_instance();
    $blocks                  = $registry->get_all_registered();
    foreach ( $blocks as $block_type ) {
        /* * We only want to append selectors for blocks using custom selectors * i.e. not `wp-block-<name>`. */
        $has_custom_selector =
            ( isset( $block_type->supports['__experimentalSelector'] ) && is_string( $block_type->supports['__experimentalSelector'] ) ) ||
            ( isset( $block_type->selectors['root'] ) && is_string( $block_type->selectors['root'] ) );

        if ( $has_custom_selector ) {
            $variables_root_selector .= ',' . wp_get_block_css_selector( $block_type );
        }
$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'] );
    if ( ! $post_type ) {
        wp_die( __( 'Invalid post type.' ) );
    }
}


    protected static function get_blocks_metadata() {
        $registry = WP_Block_Type_Registry::get_instance();
        $blocks   = $registry->get_all_registered();

        // Is there metadata for all currently registered blocks?         $blocks = array_diff_key( $blocksstatic::$blocks_metadata );
        if ( empty( $blocks ) ) {
            return static::$blocks_metadata;
        }

        foreach ( $blocks as $block_name => $block_type ) {
            $root_selector = wp_get_block_css_selector( $block_type );

            static::$blocks_metadata[ $block_name ]['selector']  = $root_selector;
            
return $output;
    }

    /** * Registers the block attributes required by the different block supports. * * @since 5.6.0 */
    private function register_attributes() {
        $block_registry         = WP_Block_Type_Registry::get_instance();
        $registered_block_types = $block_registry->get_all_registered();
        foreach ( $registered_block_types as $block_type ) {
            if ( ! property_exists( $block_type, 'supports' ) ) {
                continue;
            }
            if ( ! $block_type->attributes ) {
                $block_type->attributes = array();
            }

            foreach ( $this->block_supports as $block_support_config ) {
                if ( ! isset( $block_support_config['register_attribute'] ) ) {
                    continue;
                }
/** * Returns an array of the names of all registered dynamic block types. * * @since 5.0.0 * * @return string[] Array of dynamic block names. */
function get_dynamic_block_names() {
    $dynamic_block_names = array();

    $block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();
    foreach ( $block_types as $block_type ) {
        if ( $block_type->is_dynamic() ) {
            $dynamic_block_names[] = $block_type->name;
        }
    }

    return $dynamic_block_names;
}

/** * Given an array of attributes, returns a string in the serialized attributes * format prepared for post content. * * The serialized result is a JSON-encoded string, with unicode escape sequence * substitution for characters which might otherwise interfere with embedding * the result in an HTML comment. * * This function must produce output that remains in sync with the output of * the serializeAttributes JavaScript function in the block editor in order * to ensure consistent operation between PHP and JavaScript. * * @since 5.3.1 * * @param array $block_attributes Attributes object. * @return string Serialized attributes. */

    protected static function has_same_registered_blocks( $origin ) {
        // Bail out if the origin is invalid.         if ( ! isset( static::$blocks_cache[ $origin ] ) ) {
            return false;
        }

        $registry = WP_Block_Type_Registry::get_instance();
        $blocks   = $registry->get_all_registered();

        // Is there metadata for all currently registered blocks?         $block_diff = array_diff_key( $blocksstatic::$blocks_cache[ $origin ] );
        if ( empty( $block_diff ) ) {
            return true;
        }

        foreach ( $blocks as $block_name => $block_type ) {
            static::$blocks_cache[ $origin ][ $block_name ] = true;
        }

        
'supports'         => 'supports',
        'category'         => 'category',
        'styles'           => 'styles',
        'textdomain'       => 'textdomain',
        'parent'           => 'parent',
        'ancestor'         => 'ancestor',
        'keywords'         => 'keywords',
        'example'          => 'example',
        'variations'       => 'variations',
    );

    foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
        foreach ( $fields_to_pick as $field => $key ) {
            if ( ! isset( $block_type->{ $field } ) ) {
                continue;
            }

            if ( ! isset( $blocks[ $block_name ] ) ) {
                $blocks[ $block_name ] = array();
            }

            $blocks[ $block_name ][ $key ] = $block_type->{ $field };
        }
    }

    add_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' );
    do_action( 'enqueue_block_assets' );
    remove_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' );

    $block_registry = WP_Block_Type_Registry::get_instance();

    /* * Additionally, do enqueue `editorStyle` assets for all blocks, which * contains editor-only styling for blocks (editor content). */
    foreach ( $block_registry->get_all_registered() as $block_type ) {
        if ( isset( $block_type->editor_style_handles ) && is_array( $block_type->editor_style_handles ) ) {
            foreach ( $block_type->editor_style_handles as $style_handle ) {
                wp_enqueue_style( $style_handle );
            }
        }
    }

    ob_start();
    wp_print_styles();
    $styles = ob_get_clean();

    
'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 );

$autosave = wp_get_post_autosave( $post->ID );
if ( $autosave ) {
    if ( mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) {
        $editor_settings['autosave'] = array(
            'editLink' => get_edit_post_link( $autosave->ID ),
        );
    } else {
        wp_delete_post_revision( $autosave->ID );
    }
}
public function get_items( $request ) {
        if ( ! $this->remote_patterns_loaded ) {
            // Load block patterns from w.org.             _load_remote_block_patterns(); // Patterns with the `core` keyword.             _load_remote_featured_patterns(); // Patterns in the `featured` category.             _register_remote_theme_patterns(); // Patterns requested by current theme.
            $this->remote_patterns_loaded = true;
        }

        $response = array();
        $patterns = WP_Block_Patterns_Registry::get_instance()->get_all_registered();
        foreach ( $patterns as $pattern ) {
            $migrated_pattern = $this->migrate_pattern_categories( $pattern );
            $prepared_pattern = $this->prepare_item_for_response( $migrated_pattern$request );
            $response[]       = $this->prepare_response_for_collection( $prepared_pattern );
        }
        return rest_ensure_response( $response );
    }

    /** * Migrates old core pattern categories to the new categories. * * Core pattern categories are revamped. Migration is needed to ensure * backwards compatibility. * * @since 6.2.0 * * @param array $pattern Raw pattern as registered, before applying any changes. * @return array Migrated pattern. */

function wp_enqueue_registered_block_scripts_and_styles() {
    global $current_screen;

    if ( wp_should_load_separate_core_block_assets() ) {
        return;
    }

    $load_editor_scripts_and_styles = is_admin() && wp_should_load_block_editor_scripts_and_styles();

    $block_registry = WP_Block_Type_Registry::get_instance();
    foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
        // Front-end and editor styles.         foreach ( $block_type->style_handles as $style_handle ) {
            wp_enqueue_style( $style_handle );
        }

        // Front-end and editor scripts.         foreach ( $block_type->script_handles as $script_handle ) {
            wp_enqueue_script( $script_handle );
        }

        if ( $load_editor_scripts_and_styles ) {
            
/** * Retrieves all block pattern categories. * * @since 6.0.0 * * @param WP_REST_Request $request Full details about the request. * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure. */
    public function get_items( $request ) {
        $response   = array();
        $categories = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered();
        foreach ( $categories as $category ) {
            $prepared_category = $this->prepare_item_for_response( $category$request );
            $response[]        = $this->prepare_response_for_collection( $prepared_category );
        }

        return rest_ensure_response( $response );
    }

    /** * Prepare a raw block pattern category before it gets output in a REST API response. * * @since 6.0.0 * * @param array $item Raw category as registered, before any changes. * @param WP_REST_Request $request Request object. * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */
Home | Imprint | This part of the site doesn't use cookies.