WP_Block example


function wp_render_duotone_support( $block_content$block ) {
    _deprecated_function( __FUNCTION__, '6.3.0', 'WP_Duotone::render_duotone_support()' );
    $wp_block = new WP_Block( $block );
    return WP_Duotone::render_duotone_support( $block_content$block$wp_block );
}

/** * Returns a string containing the SVGs to be referenced as filters (duotone). * * @since 5.9.1 * @deprecated 6.3.0 SVG generation is handled on a per-block basis in block supports. * * @return string */

        add_filter( 'render_block_context', $filter_block_context, 1 );

        /* * We construct a new WP_Block instance from the parsed block so that * it'll receive any changes made by the `render_block_data` filter. */
        $block_content = ( new WP_Block( $block->parsed_block ) )->render( array( 'dynamic' => false ) );

        remove_filter( 'render_block_context', $filter_block_context, 1 );

        $children = $comment->get_children();

        /* * We need to create the CSS classes BEFORE recursing into the children. * This is because comment_class() uses globals like `$comment_alt` * and `$comment_thread_alt` which are order-sensitive. * * The `false` parameter at the end means that we do NOT want the function * to `echo` the output but to return a string. * See https://developer.wordpress.org/reference/functions/comment_class/#parameters. */

    $context = apply_filters( 'render_block_context', $context$parsed_block$parent_block );

    $block = new WP_Block( $parsed_block$context );

    return $block->render();
}

/** * Parses blocks out of a content string. * * @since 5.0.0 * * @param string $content Post content. * @return array[] Array of parsed block objects. */
$post_type            = get_post_type();
        $filter_block_context = static function( $context ) use ( $post_id$post_type ) {
            $context['postType'] = $post_type;
            $context['postId']   = $post_id;
            return $context;
        };

        // Use an early priority to so that other 'render_block_context' filters have access to the values.         add_filter( 'render_block_context', $filter_block_context, 1 );
        // Render the inner blocks of the Post Template block with `dynamic` set to `false` to prevent calling         // `render_callback` and ensure that no wrapper markup is included.         $block_content = ( new WP_Block( $block_instance ) )->render( array( 'dynamic' => false ) );
        remove_filter( 'render_block_context', $filter_block_context, 1 );

        // Wrap the render inner blocks in a `li` element with the appropriate post classes.         $post_classes = implode( ' ', get_post_class( 'wp-block-post' ) );
        $content     .= '<li class="' . esc_attr( $post_classes ) . '">' . $block_content . '</li>';
    }

    /* * Use this function to restore the context of the template tags * from a secondary query loop back to the main query loop. * Since we use two custom loops, it's safest to always restore. */

    #[ReturnTypeWillChange]     public function offsetGet( $index ) {
        $block = $this->blocks[ $index ];

        if ( isset( $block ) && is_array( $block ) ) {
            $block                  = new WP_Block( $block$this->available_context, $this->registry );
            $this->blocks[ $index ] = $block;
        }

        return $block;
    }

    /** * Assign a block value by the specified block index. * * @since 5.5.0 * * @link https://www.php.net/manual/en/arrayaccess.offsetset.php * * @param string $index Index of block value to set. * @param mixed $value Block value. */
Home | Imprint | This part of the site doesn't use cookies.