wp_get_post_content_block_attributes

The timeline below displays how wordpress function wp_get_post_content_block_attributes has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Retrieves Post Content block attributes from the current post template.
 *
 * @since 6.3.0
 * @since 6.4.0 Return null if there is no post content block.
 * @access private
 *
 * @global int $post_ID
 *
 * @return array|null Post Content block attributes array or null if Post Content block doesn't exist.
 */
function wp_get_post_content_block_attributes()
{
    global $post_ID;
    $is_block_theme = wp_is_block_theme();
    if (!$is_block_theme || !$post_ID) {
        return null;
    }
    $template_slug = get_page_template_slug($post_ID);
    if (!$template_slug) {
        $post_slug = 'singular';
        $page_slug = 'singular';
        $template_types = get_block_templates();
        foreach ($template_types as $template_type) {
            if ('page' === $template_type->slug) {
                $page_slug = 'page';
            }
            if ('single' === $template_type->slug) {
                $post_slug = 'single';
            }
        }
        $what_post_type = get_post_type($post_ID);
        switch ($what_post_type) {
            case 'page':
                $template_slug = $page_slug;
                break;
            default:
                $template_slug = $post_slug;
                break;
        }
    }
    $current_template = get_block_templates(array('slug__in' => array($template_slug)));
    if (!empty($current_template)) {
        $template_blocks = parse_blocks($current_template[0]->content);
        $post_content_block = wp_get_first_block($template_blocks, 'core/post-content');
        if (isset($post_content_block['attrs'])) {
            return $post_content_block['attrs'];
        }
    }
    return null;
}

WordPress Version: 6.3

/**
 * Retrieves Post Content block attributes from the current post template.
 *
 * @since 6.3.0
 * @access private
 *
 * @global int $post_ID
 *
 * @return array Post Content block attributes or empty array if they don't exist.
 */
function wp_get_post_content_block_attributes()
{
    global $post_ID;
    $is_block_theme = wp_is_block_theme();
    if (!$is_block_theme || !$post_ID) {
        return array();
    }
    $template_slug = get_page_template_slug($post_ID);
    if (!$template_slug) {
        $post_slug = 'singular';
        $page_slug = 'singular';
        $template_types = get_block_templates();
        foreach ($template_types as $template_type) {
            if ('page' === $template_type->slug) {
                $page_slug = 'page';
            }
            if ('single' === $template_type->slug) {
                $post_slug = 'single';
            }
        }
        $what_post_type = get_post_type($post_ID);
        switch ($what_post_type) {
            case 'page':
                $template_slug = $page_slug;
                break;
            default:
                $template_slug = $post_slug;
                break;
        }
    }
    $current_template = get_block_templates(array('slug__in' => array($template_slug)));
    if (!empty($current_template)) {
        $template_blocks = parse_blocks($current_template[0]->content);
        $post_content_block = wp_get_first_block($template_blocks, 'core/post-content');
        if (!empty($post_content_block['attrs'])) {
            return $post_content_block['attrs'];
        }
    }
    return array();
}