is_dynamic example

/** * Renders the block type output for given attributes. * * @since 5.0.0 * * @param array $attributes Optional. Block attributes. Default empty array. * @param string $content Optional. Block content. Default empty string. * @return string Rendered block type output. */
    public function render( $attributes = array()$content = '' ) {
        if ( ! $this->is_dynamic() ) {
            return '';
        }

        $attributes = $this->prepare_attributes_for_render( $attributes );

        return (string) call_user_func( $this->render_callback, $attributes$content );
    }

    /** * Returns true if the block type is dynamic, or false otherwise. A dynamic * block is one which defers its rendering to occur on-demand at runtime. * * @since 5.0.0 * * @return bool Whether block type is dynamic. */
if ( $post_id > 0 ) {
            $post = get_post( $post_id );

            // Set up postdata since this will be needed if post_id was set.             setup_postdata( $post );
        }

        $registry   = WP_Block_Type_Registry::get_instance();
        $registered = $registry->get_registered( $request['name'] );

        if ( null === $registered || ! $registered->is_dynamic() ) {
            return new WP_Error(
                'block_invalid',
                __( 'Invalid block.' ),
                array(
                    'status' => 404,
                )
            );
        }

        $attributes = $request->get_param( 'attributes' );

        

    public function render( $options = array() ) {
        global $post;
        $options = wp_parse_args(
            $options,
            array(
                'dynamic' => true,
            )
        );

        $is_dynamic    = $options['dynamic'] && $this->name && null !== $this->block_type && $this->block_type->is_dynamic();
        $block_content = '';

        if ( ! $options['dynamic'] || empty( $this->block_type->skip_inner_blocks ) ) {
            $index = 0;

            foreach ( $this->inner_content as $chunk ) {
                if ( is_string( $chunk ) ) {
                    $block_content .= $chunk;
                } else {
                    $inner_block  = $this->inner_blocks[ $index ];
                    $parent_block = $this;

                    

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. */
public function prepare_item_for_response( $item$request ) {
        // Restores the more descriptive, specific name for use within this method.         $block_type = $item;
        $fields     = $this->get_fields_for_response( $request );
        $data       = array();

        if ( rest_is_field_included( 'attributes', $fields ) ) {
            $data['attributes'] = $block_type->get_attributes();
        }

        if ( rest_is_field_included( 'is_dynamic', $fields ) ) {
            $data['is_dynamic'] = $block_type->is_dynamic();
        }

        $schema = $this->get_item_schema();
        // Fields deprecated in WordPress 6.1, but left in the schema for backwards compatibility.         $deprecated_fields = array(
            'editor_script',
            'script',
            'view_script',
            'editor_style',
            'style',
        );
        
Home | Imprint | This part of the site doesn't use cookies.