hooks = $hooks; } /** * Queues the block registration filter via the hook loader. * * @return void */ public function register(): void { $this->hooks->add_filter( 'register_block_type_args', array( $this, 'add_attribute' ) ); } /** * Adds the visibility attribute schema to a block type's arguments. * * No default is declared, so server-side an unconfigured block simply has no * `visibility` attribute and RenderService skips it. * * Accepts `mixed` because `register_block_type_args` is a public filter: * another plugin may hand it something that is not an array, and a * TypeError here would take down block registration. * * @param mixed $args Block type arguments. * @return mixed */ public function add_attribute( $args ) { if ( ! is_array( $args ) ) { return $args; } $attributes = isset( $args['attributes'] ) && is_array( $args['attributes'] ) ? $args['attributes'] : array(); if ( ! isset( $attributes[ RenderService::ATTRIBUTE_KEY ] ) ) { $attributes[ RenderService::ATTRIBUTE_KEY ] = array( 'type' => 'object' ); $args['attributes'] = $attributes; } return $args; } }