diff --git a/assets/js/admin/block-restrictions.js b/assets/js/admin/block-restrictions.js index 2f3ec381..04067f60 100644 --- a/assets/js/admin/block-restrictions.js +++ b/assets/js/admin/block-restrictions.js @@ -8,6 +8,40 @@ var um_components = wp.components, function um_admin_blocks_custom_fields( um_condition_fields, props ) { return wp.hooks.applyFilters( 'um_admin_blocks_custom_fields', [], um_condition_fields, props ); } +function um_add_restriction_attributes( settings, name ) { + // add attributes for all blocks + const restrictionAttributes = { + um_is_restrict: { + type: 'boolean', + default: false, + }, + um_who_access: { + type: 'string', + default: '0', + }, + um_roles_access: { + type: 'array', + default: [], + }, + um_message_type: { + type: 'string', + default: '0', + }, + um_message_content: { + type: 'string', + default: '', + }, + }; + + settings.attributes = Object.assign( settings.attributes, restrictionAttributes ); + return settings; +} + +wp.hooks.addFilter( + 'blocks.registerBlockType', + 'um-block/add-restriction-attributes', + um_add_restriction_attributes +); var um_block_restriction = wp.compose.createHigherOrderComponent( function( BlockEdit ) { diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php index 25b2cf9d..0b2fa4df 100644 --- a/includes/core/class-blocks.php +++ b/includes/core/class-blocks.php @@ -37,27 +37,33 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { if ( empty( $settings['attributes']['um_is_restrict'] ) ) { $settings['attributes']['um_is_restrict'] = array( - 'type' => 'boolean', + 'type' => 'boolean', + 'default' => false, ); } if ( empty( $settings['attributes']['um_who_access'] ) ) { $settings['attributes']['um_who_access'] = array( - 'type' => 'string', + 'type' => 'string', + 'default' => 0, ); } if ( empty( $settings['attributes']['um_roles_access'] ) ) { $settings['attributes']['um_roles_access'] = array( - 'type' => 'array', + 'type' => 'array', + 'default' => array(), + 'items' => array( 'type' => 'string' ), ); } if ( empty( $settings['attributes']['um_message_type'] ) ) { $settings['attributes']['um_message_type'] = array( - 'type' => 'string', + 'type' => 'string', + 'default' => 0, ); } if ( empty( $settings['attributes']['um_message_content'] ) ) { $settings['attributes']['um_message_content'] = array( - 'type' => 'string', + 'type' => 'string', + 'default' => '', ); }