From e2d890f99d1f04f2ff36bd99d38d2f205a1f0a50 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Thu, 8 Jun 2023 11:33:01 +0300 Subject: [PATCH 1/3] - fix ACF and UM blocks conflict --- includes/core/class-blocks.php | 53 ++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php index 583743fb..a24f30d5 100644 --- a/includes/core/class-blocks.php +++ b/includes/core/class-blocks.php @@ -21,35 +21,38 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { */ public function __construct() { add_action( 'init', array( &$this, 'block_editor_render' ), 10 ); - add_filter( 'block_type_metadata_settings', array( &$this, 'block_type_metadata_settings' ), 10, 2 ); + add_filter( 'block_type_metadata_settings', array( &$this, 'block_type_metadata_settings' ), 100, 2 ); } public function block_type_metadata_settings( $settings, $args ) { - if ( empty( $settings['attributes']['um_is_restrict'] ) ) { - $settings['attributes']['um_is_restrict'] = array( - 'type' => 'boolean', - ); - } - if ( empty( $settings['attributes']['um_who_access'] ) ) { - $settings['attributes']['um_who_access'] = array( - 'type' => 'string', - ); - } - if ( empty( $settings['attributes']['um_roles_access'] ) ) { - $settings['attributes']['um_roles_access'] = array( - 'type' => 'array', - ); - } - if ( empty( $settings['attributes']['um_message_type'] ) ) { - $settings['attributes']['um_message_type'] = array( - 'type' => 'string', - ); - } - if ( empty( $settings['attributes']['um_message_content'] ) ) { - $settings['attributes']['um_message_content'] = array( - 'type' => 'string', - ); + $restricted_blocks = UM()->options()->get( 'restricted_blocks' ); + if ( ! empty( $restricted_blocks ) ) { + if ( empty( $settings['attributes']['um_is_restrict'] ) ) { + $settings['attributes']['um_is_restrict'] = array( + 'type' => 'boolean', + ); + } + if ( empty( $settings['attributes']['um_who_access'] ) ) { + $settings['attributes']['um_who_access'] = array( + 'type' => 'string', + ); + } + if ( empty( $settings['attributes']['um_roles_access'] ) ) { + $settings['attributes']['um_roles_access'] = array( + 'type' => 'array', + ); + } + if ( empty( $settings['attributes']['um_message_type'] ) ) { + $settings['attributes']['um_message_type'] = array( + 'type' => 'string', + ); + } + if ( empty( $settings['attributes']['um_message_content'] ) ) { + $settings['attributes']['um_message_content'] = array( + 'type' => 'string', + ); + } } return $settings; From 03593d5be90ccda031f9878600fc839fde6fc36a Mon Sep 17 00:00:00 2001 From: Mykyta Synelnikov Date: Thu, 8 Jun 2023 12:22:11 +0300 Subject: [PATCH 2/3] - code review, added comments; --- includes/core/class-blocks.php | 63 +++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php index a24f30d5..dee42818 100644 --- a/includes/core/class-blocks.php +++ b/includes/core/class-blocks.php @@ -24,35 +24,44 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { add_filter( 'block_type_metadata_settings', array( &$this, 'block_type_metadata_settings' ), 100, 2 ); } - + /** + * Add attribute types if restricted blocks is active. + * + * @param array $settings Array of determined settings for registering a block type. + * @param array $args Metadata provided for registering a block type. + * + * @return array + */ public function block_type_metadata_settings( $settings, $args ) { $restricted_blocks = UM()->options()->get( 'restricted_blocks' ); - if ( ! empty( $restricted_blocks ) ) { - if ( empty( $settings['attributes']['um_is_restrict'] ) ) { - $settings['attributes']['um_is_restrict'] = array( - 'type' => 'boolean', - ); - } - if ( empty( $settings['attributes']['um_who_access'] ) ) { - $settings['attributes']['um_who_access'] = array( - 'type' => 'string', - ); - } - if ( empty( $settings['attributes']['um_roles_access'] ) ) { - $settings['attributes']['um_roles_access'] = array( - 'type' => 'array', - ); - } - if ( empty( $settings['attributes']['um_message_type'] ) ) { - $settings['attributes']['um_message_type'] = array( - 'type' => 'string', - ); - } - if ( empty( $settings['attributes']['um_message_content'] ) ) { - $settings['attributes']['um_message_content'] = array( - 'type' => 'string', - ); - } + if ( empty( $restricted_blocks ) ) { + return $settings; + } + + if ( empty( $settings['attributes']['um_is_restrict'] ) ) { + $settings['attributes']['um_is_restrict'] = array( + 'type' => 'boolean', + ); + } + if ( empty( $settings['attributes']['um_who_access'] ) ) { + $settings['attributes']['um_who_access'] = array( + 'type' => 'string', + ); + } + if ( empty( $settings['attributes']['um_roles_access'] ) ) { + $settings['attributes']['um_roles_access'] = array( + 'type' => 'array', + ); + } + if ( empty( $settings['attributes']['um_message_type'] ) ) { + $settings['attributes']['um_message_type'] = array( + 'type' => 'string', + ); + } + if ( empty( $settings['attributes']['um_message_content'] ) ) { + $settings['attributes']['um_message_content'] = array( + 'type' => 'string', + ); } return $settings; From 14b9cbc11bd5832bc0fd0a9f194293e696218c6a Mon Sep 17 00:00:00 2001 From: Mykyta Synelnikov Date: Thu, 8 Jun 2023 13:15:12 +0300 Subject: [PATCH 3/3] - code review, added comments; --- includes/admin/core/class-admin-enqueue.php | 2 +- includes/core/class-blocks.php | 82 ++++++++++++++++----- 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/includes/admin/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php index a46b67b8..d77e4c76 100644 --- a/includes/admin/core/class-admin-enqueue.php +++ b/includes/admin/core/class-admin-enqueue.php @@ -566,7 +566,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { * Load Gutenberg scripts */ public function load_gutenberg_js() { - //disable Gutenberg scripts to avoid the conflicts + /** This filter is documented in includes/core/class-blocks.php */ $disable_script = apply_filters( 'um_disable_blocks_script', false ); if ( $disable_script ) { return; diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php index dee42818..b1bbed6a 100644 --- a/includes/core/class-blocks.php +++ b/includes/core/class-blocks.php @@ -1,27 +1,24 @@ array( - 'render_callback' => array( $this, 'um_member_directories_render' ), + 'render_callback' => array( $this, 'member_directories_render' ), 'attributes' => array( 'member_id' => array( 'type' => 'string', @@ -90,7 +102,7 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { ), ), 'um-block/um-forms' => array( - 'render_callback' => array( $this, 'um_forms_render' ), + 'render_callback' => array( $this, 'forms_render' ), 'attributes' => array( 'form_id' => array( 'type' => 'string', @@ -98,10 +110,10 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { ), ), 'um-block/um-password-reset' => array( - 'render_callback' => array( $this, 'um_password_reset_render' ), + 'render_callback' => array( $this, 'password_reset_render' ), ), 'um-block/um-account' => array( - 'render_callback' => array( $this, 'um_account_render' ), + 'render_callback' => array( $this, 'account_render' ), 'attributes' => array( 'tab' => array( 'type' => 'string', @@ -116,8 +128,16 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { } } - - public function um_member_directories_render( $atts ) { + /** + * Renders member directory block. + * + * @param array $atts Block attributes. + * + * @return string + * + * @uses apply_shortcodes() + */ + public function member_directories_render( $atts ) { $shortcode = '[ultimatemember'; if ( isset( $atts['member_id'] ) && '' !== $atts['member_id'] ) { @@ -129,8 +149,16 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { return apply_shortcodes( $shortcode ); } - - public function um_forms_render( $atts ) { + /** + * Renders UM Form block. + * + * @param array $atts Block attributes. + * + * @return string + * + * @uses apply_shortcodes() + */ + public function forms_render( $atts ) { if ( isset( $atts['form_id'] ) && '' !== $atts['form_id'] ) { $mode = get_post_meta( $atts['form_id'], '_um_mode', true ); if ( 'profile' === $mode && ( um_is_core_page( 'account' ) || um_is_core_page( 'user' ) ) ) { @@ -148,15 +176,29 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { return apply_shortcodes( $shortcode ); } - - public function um_password_reset_render() { + /** + * Renders UM Reset Password form block. + * + * @return string + * + * @uses apply_shortcodes() + */ + public function password_reset_render() { $shortcode = '[ultimatemember_password]'; return apply_shortcodes( $shortcode ); } - - public function um_account_render( $atts ) { + /** + * Renders UM Account block. + * + * @param array $atts Block attributes. + * + * @return string + * + * @uses apply_shortcodes() + */ + public function account_render( $atts ) { if ( um_is_core_page( 'account' ) || um_is_core_page( 'user' ) ) { return ''; }