Make WordPress Core


Ignore:
Timestamp:
02/16/2024 12:53:16 PM (13 months ago)
Author:
gziolo
Message:

Editor: Merge uses_context defined by block bindings sources with block types

Adds logic that fixes the limitation for souces by allowing merging the uses_context defined by block bindings sources into supported block types. Each source defines the context it needs and it is added to the block types that are using the block bindings API.

Fixes #60525.
Props santosguillamot, gziolo, czapla, thekt12.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-block-type.php

    r57565 r57641  
    181181     * @var string[]
    182182     */
    183     public $uses_context = array();
     183    private $uses_context = array();
    184184
    185185    /**
     
    367367        }
    368368
     369        if ( 'uses_context' === $name ) {
     370            return $this->get_uses_context();
     371        }
     372
    369373        if ( ! in_array( $name, $this->deprecated_properties, true ) ) {
    370374            return;
     
    395399     */
    396400    public function __isset( $name ) {
    397         if ( 'variations' === $name ) {
     401        if ( in_array( $name, array( 'variations', 'uses_context' ), true ) ) {
    398402            return true;
    399403        }
     
    418422     */
    419423    public function __set( $name, $value ) {
    420         if ( 'variations' === $name ) {
    421             $this->variations = $value;
    422             return;
    423         }
    424 
    425424        if ( ! in_array( $name, $this->deprecated_properties, true ) ) {
    426425            $this->{$name} = $value;
     
    617616        return apply_filters( 'get_block_type_variations', $this->variations, $this );
    618617    }
     618
     619    /**
     620     * Get block uses context.
     621     *
     622     * @since 6.5.0
     623     *
     624     * @return array[]
     625     */
     626    public function get_uses_context() {
     627        /**
     628         * Filters the registered uses context for a block type.
     629         *
     630         * @since 6.5.0
     631         *
     632         * @param array         $uses_context Array of registered uses context for a block type.
     633         * @param WP_Block_Type $block_type   The full block type object.
     634         */
     635        return apply_filters( 'get_block_type_uses_context', $this->uses_context, $this );
     636    }
    619637}
Note: See TracChangeset for help on using the changeset viewer.