Automattic\WooCommerce\Internal\Admin\BlockTemplateRegistry

BlockTemplatesController{}WC 1.0

Block template controller.

Хуков нет.

Использование

$BlockTemplatesController = new BlockTemplatesController();
// use class methods

Методы

  1. ERROR: no method name found on line ``
  2. ERROR: no method name found on line ``
  3. ERROR: no method name found on line ``
  4. ERROR: no method name found on line ``
  5. ERROR: no method name found on line ``
  6. ERROR: no method name found on line ``
  7. ERROR: no method name found on line ``
  8. ERROR: no method name found on line ``
  9. ERROR: no method name found on line ``
  10. ERROR: no method name found on line ``
  11. ERROR: no method name found on line ``
  12. ERROR: no method name found on line ``
  13. public init( $block_template_registry, $template_transformer )
  14. ERROR: no method name found on line ``
  15. ERROR: no method name found on line ``
  16. ERROR: no method name found on line ``
  17. public register_templates()
  18. ERROR: no method name found on line ``
  19. ERROR: no method name found on line ``
  20. ERROR: no method name found on line ``
  21. ERROR: no method name found on line ``
  22. ERROR: no method name found on line ``
  23. ERROR: no method name found on line ``
  24. ERROR: no method name found on line ``

Код BlockTemplatesController{} WC 8.1.1

class BlockTemplatesController {

    /**
     * Block template registry
     *
     * @var BlockTemplateRegistry
     */
    private $block_template_registry;

    /**
     * Block template transformer.
     *
     * @var TemplateTransformer
     */
    private $template_transformer;

    /**
     * Init.
     */
    public function init( $block_template_registry, $template_transformer ) {
        $this->block_template_registry = $block_template_registry;
        $this->template_transformer    = $template_transformer;
        add_action( 'rest_api_init', array( $this, 'register_templates' ) );
    }

    /**
     * Register templates in the blocks endpoint.
     */
    public function register_templates() {
        $templates = $this->block_template_registry->get_all_registered();

        foreach ( $templates as $template ) {
            add_filter( 'pre_get_block_templates', function( $query_result, $query, $template_type ) use( $template ) {
                if ( ! isset( $query['area'] ) || $query['area'] !== $template->get_area() ) {
                    return $query_result;
                }

                $wp_block_template = $this->template_transformer->transform( $template );
                $query_result[]    = $wp_block_template;
        
                return $query_result;
            }, 10, 3 );
        }
    }

}