get_block_file_template example

/** * Returns the given template * * @since 5.8.0 * * @param WP_REST_Request $request The request instance. * @return WP_REST_Response|WP_Error */
    public function get_item( $request ) {
        if ( isset( $request['source'] ) && 'theme' === $request['source'] ) {
            $template = get_block_file_template( $request['id']$this->post_type );
        } else {
            $template = get_block_template( $request['id']$this->post_type );
        }

        if ( ! $template ) {
            return new WP_Error( 'rest_template_not_found', __( 'No templates exist with that id.' ), array( 'status' => 404 ) );
        }

        return $this->prepare_item_for_response( $template$request );
    }

    
$template_query       = new WP_Query( $wp_query_args );
    $posts                = $template_query->posts;

    if ( count( $posts ) > 0 ) {
        $template = _build_block_template_result_from_post( $posts[0] );

        if ( ! is_wp_error( $template ) ) {
            return $template;
        }
    }

    $block_template = get_block_file_template( $id$template_type );

    /** * Filters the queried block template object after it's been fetched. * * @since 5.9.0 * * @param WP_Block_Template|null $block_template The found block template, or null if there isn't one. * @param string $id Template unique identifier (example: 'theme_slug//template_slug'). * @param array $template_type Template type: 'wp_template' or 'wp_template_part'. */
    return apply_filters( 'get_block_template', $block_template$id$template_type );
}
Home | Imprint | This part of the site doesn't use cookies.