- fix restrictions for all blocks

This commit is contained in:
ashubawork
2025-06-19 15:30:30 +03:00
parent 8f34bbb4fa
commit 45c8593157
2 changed files with 45 additions and 5 deletions
+34
View File
@@ -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 ) {
+11 -5
View File
@@ -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' => '',
);
}