wp/wp-includes/class-wp-block-type.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    13  * @since 5.0.0
    13  * @since 5.0.0
    14  *
    14  *
    15  * @see register_block_type()
    15  * @see register_block_type()
    16  */
    16  */
    17 class WP_Block_Type {
    17 class WP_Block_Type {
       
    18 
    18 	/**
    19 	/**
    19 	 * Block type key.
    20 	 * Block type key.
    20 	 *
    21 	 *
    21 	 * @since 5.0.0
    22 	 * @since 5.0.0
    22 	 * @var string
    23 	 * @var string
    23 	 */
    24 	 */
    24 	public $name;
    25 	public $name;
    25 
    26 
    26 	/**
    27 	/**
       
    28 	 * @since 5.5.0
       
    29 	 * @var string
       
    30 	 */
       
    31 	public $title = '';
       
    32 
       
    33 	/**
       
    34 	 * @since 5.5.0
       
    35 	 * @var string|null
       
    36 	 */
       
    37 	public $category = null;
       
    38 
       
    39 	/**
       
    40 	 * @since 5.5.0
       
    41 	 * @var array|null
       
    42 	 */
       
    43 	public $parent = null;
       
    44 
       
    45 	/**
       
    46 	 * @since 5.5.0
       
    47 	 * @var string|null
       
    48 	 */
       
    49 	public $icon = null;
       
    50 
       
    51 	/**
       
    52 	 * @since 5.5.0
       
    53 	 * @var string
       
    54 	 */
       
    55 	public $description = '';
       
    56 
       
    57 	/**
       
    58 	 * @since 5.5.0
       
    59 	 * @var array
       
    60 	 */
       
    61 	public $keywords = array();
       
    62 
       
    63 	/**
       
    64 	 * @since 5.5.0
       
    65 	 * @var string|null
       
    66 	 */
       
    67 	public $textdomain = null;
       
    68 
       
    69 	/**
       
    70 	 * @since 5.5.0
       
    71 	 * @var array
       
    72 	 */
       
    73 	public $styles = array();
       
    74 
       
    75 	/**
       
    76 	 * @since 5.5.0
       
    77 	 * @var array|null
       
    78 	 */
       
    79 	public $supports = null;
       
    80 
       
    81 	/**
       
    82 	 * @since 5.5.0
       
    83 	 * @var array|null
       
    84 	 */
       
    85 	public $example = null;
       
    86 
       
    87 	/**
    27 	 * Block type render callback.
    88 	 * Block type render callback.
    28 	 *
    89 	 *
    29 	 * @since 5.0.0
    90 	 * @since 5.0.0
    30 	 * @var callable
    91 	 * @var callable
    31 	 */
    92 	 */
    32 	public $render_callback;
    93 	public $render_callback = null;
    33 
    94 
    34 	/**
    95 	/**
    35 	 * Block type attributes property schemas.
    96 	 * Block type attributes property schemas.
    36 	 *
    97 	 *
    37 	 * @since 5.0.0
    98 	 * @since 5.0.0
       
    99 	 * @var array|null
       
   100 	 */
       
   101 	public $attributes = null;
       
   102 
       
   103 	/**
       
   104 	 * Context values inherited by blocks of this type.
       
   105 	 *
       
   106 	 * @since 5.5.0
    38 	 * @var array
   107 	 * @var array
    39 	 */
   108 	 */
    40 	public $attributes;
   109 	public $uses_context = array();
       
   110 
       
   111 	/**
       
   112 	 * Context provided by blocks of this type.
       
   113 	 *
       
   114 	 * @since 5.5.0
       
   115 	 * @var array|null
       
   116 	 */
       
   117 	public $provides_context = null;
    41 
   118 
    42 	/**
   119 	/**
    43 	 * Block type editor script handle.
   120 	 * Block type editor script handle.
    44 	 *
   121 	 *
    45 	 * @since 5.0.0
   122 	 * @since 5.0.0
    46 	 * @var string
   123 	 * @var string|null
    47 	 */
   124 	 */
    48 	public $editor_script;
   125 	public $editor_script = null;
    49 
   126 
    50 	/**
   127 	/**
    51 	 * Block type front end script handle.
   128 	 * Block type front end script handle.
    52 	 *
   129 	 *
    53 	 * @since 5.0.0
   130 	 * @since 5.0.0
    54 	 * @var string
   131 	 * @var string|null
    55 	 */
   132 	 */
    56 	public $script;
   133 	public $script = null;
    57 
   134 
    58 	/**
   135 	/**
    59 	 * Block type editor style handle.
   136 	 * Block type editor style handle.
    60 	 *
   137 	 *
    61 	 * @since 5.0.0
   138 	 * @since 5.0.0
    62 	 * @var string
   139 	 * @var string|null
    63 	 */
   140 	 */
    64 	public $editor_style;
   141 	public $editor_style = null;
    65 
   142 
    66 	/**
   143 	/**
    67 	 * Block type front end style handle.
   144 	 * Block type front end style handle.
    68 	 *
   145 	 *
    69 	 * @since 5.0.0
   146 	 * @since 5.0.0
    70 	 * @var string
   147 	 * @var string|null
    71 	 */
   148 	 */
    72 	public $style;
   149 	public $style = null;
    73 
   150 
    74 	/**
   151 	/**
    75 	 * Constructor.
   152 	 * Constructor.
    76 	 *
   153 	 *
    77 	 * Will populate object properties from the provided arguments.
   154 	 * Will populate object properties from the provided arguments.
   125 	 * Validates attributes against the current block schema, populating
   202 	 * Validates attributes against the current block schema, populating
   126 	 * defaulted and missing values.
   203 	 * defaulted and missing values.
   127 	 *
   204 	 *
   128 	 * @since 5.0.0
   205 	 * @since 5.0.0
   129 	 *
   206 	 *
   130 	 * @param  array $attributes Original block attributes.
   207 	 * @param array $attributes Original block attributes.
   131 	 * @return array             Prepared block attributes.
   208 	 * @return array Prepared block attributes.
   132 	 */
   209 	 */
   133 	public function prepare_attributes_for_render( $attributes ) {
   210 	public function prepare_attributes_for_render( $attributes ) {
   134 		// If there are no attribute definitions for the block type, skip
   211 		// If there are no attribute definitions for the block type, skip
   135 		// processing and return vebatim.
   212 		// processing and return vebatim.
   136 		if ( ! isset( $this->attributes ) ) {
   213 		if ( ! isset( $this->attributes ) ) {
   183 			)
   260 			)
   184 		);
   261 		);
   185 
   262 
   186 		$args['name'] = $this->name;
   263 		$args['name'] = $this->name;
   187 
   264 
       
   265 		/**
       
   266 		 * Filters the arguments for registering a block type.
       
   267 		 *
       
   268 		 * @since 5.5.0
       
   269 		 *
       
   270 		 * @param array  $args       Array of arguments for registering a block type.
       
   271 		 * @param string $block_type Block type name including namespace.
       
   272 		 */
       
   273 		$args = apply_filters( 'register_block_type_args', $args, $this->name );
       
   274 
   188 		foreach ( $args as $property_name => $property_value ) {
   275 		foreach ( $args as $property_name => $property_value ) {
   189 			$this->$property_name = $property_value;
   276 			$this->$property_name = $property_value;
   190 		}
   277 		}
   191 	}
   278 	}
   192 
   279 
   197 	 *
   284 	 *
   198 	 * @return array Array of attributes.
   285 	 * @return array Array of attributes.
   199 	 */
   286 	 */
   200 	public function get_attributes() {
   287 	public function get_attributes() {
   201 		return is_array( $this->attributes ) ?
   288 		return is_array( $this->attributes ) ?
   202 			array_merge(
   289 			$this->attributes :
   203 				$this->attributes,
   290 			array();
   204 				array(
       
   205 					'layout' => array(
       
   206 						'type' => 'string',
       
   207 					),
       
   208 				)
       
   209 			) :
       
   210 			array(
       
   211 				'layout' => array(
       
   212 					'type' => 'string',
       
   213 				),
       
   214 			);
       
   215 	}
   291 	}
   216 }
   292 }