| 1 |
<?php |
| 2 |
/** |
| 3 |
* Fix integration issues with third-party blocks (e.g., WPForms). |
| 4 |
* |
| 5 |
* Adds missing attributes required by Gutenify for better block compatibility. |
| 6 |
* |
| 7 |
* @package gutenify |
| 8 |
* @subpackage Compatibility |
| 9 |
* @since 1.0.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace gutenify; |
| 13 |
|
| 14 |
defined( 'ABSPATH' ) || exit; |
| 15 |
|
| 16 |
/** |
| 17 |
* Class Fix_Third_Party_Block_Issues |
| 18 |
* |
| 19 |
* Ensures compatibility with WPForms Gutenberg block by adding required attributes. |
| 20 |
*/ |
| 21 |
class Fix_Third_Party_Block_Issues { |
| 22 |
|
| 23 |
/** |
| 24 |
* Attributes to inject into WPForms Gutenberg block. |
| 25 |
* |
| 26 |
* @var array |
| 27 |
*/ |
| 28 |
private static $attributes = array( |
| 29 |
// 'customCss' => array( |
| 30 |
// 'type' => 'string', |
| 31 |
// ), |
| 32 |
// 'blockClientId' => array( |
| 33 |
// 'type' => 'string', |
| 34 |
// ), |
| 35 |
'animationsSettings' => array( |
| 36 |
'type' => 'object', |
| 37 |
'default' => array( |
| 38 |
'duration' => 1000, |
| 39 |
), |
| 40 |
), |
| 41 |
); |
| 42 |
|
| 43 |
/** |
| 44 |
* Constructor: hooks into WPForms block attribute filter. |
| 45 |
*/ |
| 46 |
public function __construct() { |
| 47 |
add_filter( |
| 48 |
'wpforms_gutenberg_form_selector_attributes', |
| 49 |
array( __CLASS__, 'add_custom_block_attributes' ) |
| 50 |
); |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Adds missing attributes to the WPForms block if not already set. |
| 55 |
* |
| 56 |
* @param array $attrs Existing block attributes. |
| 57 |
* @return array Modified attributes. |
| 58 |
*/ |
| 59 |
public static function add_custom_block_attributes( $attrs ) { |
| 60 |
foreach ( self::$attributes as $key => $val ) { |
| 61 |
if ( ! isset( $attrs[ $key ] ) ) { |
| 62 |
$attrs[ $key ] = array( |
| 63 |
'type' => ! empty( $val['type'] ) ? $val['type'] : 'string', |
| 64 |
'default' => ! empty( $val['default'] ) ? $val['default'] : '', |
| 65 |
); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
return $attrs; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
// Initialize the class. |
| 74 |
new Fix_Third_Party_Block_Issues(); |
| 75 |
|