PluginProbe
Gutenify – Visual Site Builder Blocks & Starter Templates / trunk
Gutenify – Visual Site Builder Blocks & Starter Templates vtrunk
1.9.0 1.8.0 1.7.0 1.6.6 1.6.5 1.6.4 trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 All 74 releases
gutenify / core / inc / blocks / class-extend-attributes.php

class-extend-attributes.php in Gutenify – Visual Site Builder Blocks & Starter Templates trunk, at core/inc/blocks/class-extend-attributes.php

84 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Extend_Attributes
4 *
5 * Extends block metadata to include custom attributes for the plugin.
6 * Adds 'customCss', 'blockClientId', and plugin-specific styles attributes to all blocks.
7 *
8 * @package gutenify
9 */
10
11 namespace gutenify;
12
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * Class Extend_Attributes
17 *
18 * Adds additional attributes to block metadata for enhanced customization.
19 */
20 class Extend_Attributes {
21
22 /**
23 * Register the extend_attributes method on the 'block_type_metadata' action.
24 */
25 public function __construct() {
26 add_action( 'block_type_metadata', array( $this, 'extend_attributes' ), 1 );
27 }
28
29 /**
30 * Extend block attributes if not already set.
31 *
32 * Adds:
33 * - 'customCss': For custom CSS input.
34 * - 'blockClientId': For storing the block's unique client ID.
35 * - '<plugin>Styles': For plugin-specific styles.
36 *
37 * @param array $metadata Block metadata array.
38 * @return array Modified block metadata.
39 */
40 public function extend_attributes( $metadata ) {
41 $constants = Helpers::plugin_constants();
42 $plugin_main_camel_case_name = $constants['plugin_main_camel_case_name'];
43
44 // Add customCss attribute if not present.
45 if ( ! isset( $metadata['attributes']['customCss'] ) ) {
46 $metadata['attributes']['customCss'] = array(
47 'type' => 'string',
48 'default' => '',
49 );
50 }
51
52 // Add blockClientId attribute if not present.
53 if ( ! isset( $metadata['attributes']['blockClientId'] ) ) {
54 $metadata['attributes']['blockClientId'] = array(
55 'type' => 'string',
56 'default' => '',
57 );
58 }
59
60 // Add plugin-specific styles attribute if not present.
61 if ( ! isset( $metadata['attributes'][ $plugin_main_camel_case_name . 'Styles' ] ) ) {
62 $metadata['attributes'][ $plugin_main_camel_case_name . 'Styles' ] = array(
63 'type' => 'string',
64 'default' => '',
65 );
66 }
67
68 // Add animation settings attribute if not present.
69 if ( ! isset( $metadata['attributes']['animationsSettings'] ) ) {
70 $metadata['attributes']['animationsSettings'] = array(
71 'type' => 'object',
72 'default' => array(
73 'duration' => 1000,
74 ),
75 );
76 }
77
78 return $metadata;
79 }
80 }
81
82 // Initialize the attribute extender.
83 new Extend_Attributes();
84