From 61d99135f428520464ab65636f5b2574df95891a Mon Sep 17 00:00:00 2001 From: ashubawork Date: Wed, 29 Mar 2023 11:48:51 +0300 Subject: [PATCH 01/25] - add member directory block --- includes/admin/core/class-admin-enqueue.php | 410 ++++++++++-------- .../blocks/um-member-directories/block.json | 15 + .../blocks/um-member-directories/src/index.js | 105 +++++ includes/class-init.php | 15 + includes/core/class-blocks.php | 69 +++ package.json | 17 +- 6 files changed, 451 insertions(+), 180 deletions(-) create mode 100644 includes/blocks/um-member-directories/block.json create mode 100644 includes/blocks/um-member-directories/src/index.js create mode 100644 includes/core/class-blocks.php diff --git a/includes/admin/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php index 659cfaa7..bf7b9b69 100644 --- a/includes/admin/core/class-admin-enqueue.php +++ b/includes/admin/core/class-admin-enqueue.php @@ -1,8 +1,9 @@ js_url = um_url . 'includes/admin/assets/js/'; + public function __construct() { + $this->js_url = um_url . 'includes/admin/assets/js/'; $this->css_url = um_url . 'includes/admin/assets/css/'; - $this->front_js_baseurl = um_url . 'assets/js/'; + $this->front_js_baseurl = um_url . 'assets/js/'; $this->front_css_baseurl = um_url . 'assets/css/'; $this->suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'UM_SCRIPT_DEBUG' ) ) ? '' : '.min'; @@ -73,7 +74,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { add_action( 'admin_head', array( &$this, 'admin_head' ), 9 ); - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); + add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); add_filter( 'enter_title_here', array( &$this, 'enter_title_here' ) ); @@ -89,20 +90,70 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { } else { add_filter( 'block_categories', array( &$this, 'blocks_category' ), 10, 2 ); } + add_action( 'enqueue_block_assets', array( &$this, 'block_editor' ), 11 ); } - function enqueue_role_wrapper() { - add_action( 'admin_enqueue_scripts', array( &$this, 'load_role_wrapper' ) ); + /** + * Enqueue Gutenberg Block Editor assets + */ + public function block_editor() { + wp_register_style( 'um_ui', um_url . '/assets/css/jquery-ui.css', array(), ultimatemember_version ); + wp_register_style( 'um_members', um_url . '/assets/css/um-members.css', array( 'um_ui' ), ultimatemember_version ); + if ( is_rtl() ) { + wp_register_style( 'um_members_rtl', um_url . '/assets/css/um-members-rtl.css', array( 'um_members' ), ultimatemember_version ); + } + wp_register_style( 'um_styles', um_url . '/assets/css/um-styles.css', array(), ultimatemember_version ); + + wp_register_script( 'um_datetime', um_url . 'assets/js/pickadate/picker.js', array( 'jquery' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime_date', um_url . 'assets/js/pickadate/picker.date.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime_time', um_url . 'assets/js/pickadate/picker.time.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); + wp_register_script( 'um_conditional', um_url . 'assets/js/um-conditional' . $this->suffix . '.js', array( 'jquery', 'wp-hooks' ), ultimatemember_version, true ); + wp_register_script( 'um_scripts', um_url . 'assets/js/um-scripts' . $this->suffix . '.js', array( 'jquery', 'wp-util', 'um_conditional', 'um_datetime', 'um_datetime_date', 'um_datetime_time', 'select2' ), ultimatemember_version, true ); + $max_upload_size = wp_max_upload_size(); + if ( ! $max_upload_size ) { + $max_upload_size = 0; + } + + $localize_data = apply_filters( + 'um_enqueue_localize_data', + array( + 'max_upload_size' => $max_upload_size, + 'nonce' => wp_create_nonce( 'um-frontend-nonce' ), + ) + ); + wp_localize_script( 'um_scripts', 'um_scripts', $localize_data ); + + wp_register_script( 'um_dropdown', um_url . 'assets/js/dropdown' . $this->suffix . '.js', array( 'jquery' ), ultimatemember_version, true ); + wp_register_script( 'um_members', um_url . 'assets/js/um-members' . $this->suffix . '.js', array( 'jquery', 'wp-util', 'jquery-ui-slider', 'um_dropdown', 'wp-hooks', 'jquery-masonry', 'um_scripts' ), ultimatemember_version, true ); + + // render blocks + wp_enqueue_script( 'um_datetime' ); + wp_enqueue_script( 'um_datetime_date' ); + wp_enqueue_script( 'um_datetime_time' ); + wp_enqueue_script( 'um_conditional' ); + wp_enqueue_script( 'um_dropdown' ); + wp_enqueue_script( 'um_members' ); + wp_enqueue_style( 'um_members' ); + wp_enqueue_style( 'um_styles' ); + + $custom_css = '.um{opacity: 1;}'; + + wp_add_inline_style( 'um_styles', $custom_css ); + } + + + public function enqueue_role_wrapper() { + add_action( 'admin_enqueue_scripts', array( &$this, 'load_role_wrapper' ) ); } /** * */ - function enqueue_cpt_scripts() { - if ( ( isset( $_GET['post_type'] ) && 'um_form' === sanitize_key( $_GET['post_type'] ) ) || - ( isset( $_GET['post'] ) && 'um_form' === get_post_type( absint( $_GET['post'] ) ) ) ) { + public function enqueue_cpt_scripts() { + // phpcs:ignore WordPress.Security.NonceVerification + if ( ( isset( $_GET['post_type'] ) && 'um_form' === sanitize_key( $_GET['post_type'] ) ) || ( isset( $_GET['post'] ) && 'um_form' === get_post_type( absint( $_GET['post'] ) ) ) ) { $this->um_cpt_form_screen = true; add_action( 'admin_footer', array( $this, 'admin_footer_scripts' ), 20 ); } @@ -112,7 +163,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * */ - function enqueue_frontend_preview_assets() { + public function enqueue_frontend_preview_assets() { //scripts for FRONTEND PREVIEW if ( class_exists( 'WooCommerce' ) ) { wp_dequeue_style( 'select2' ); @@ -122,7 +173,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_deregister_script( 'select2' ); } - wp_register_script( 'select2', $this->front_js_baseurl . 'select2/select2.full' . $this->suffix . '.js', array( 'jquery', 'jquery-masonry' ), '4.0.13', true ); wp_register_script( 'um_jquery_form', $this->front_js_baseurl . 'um-jquery-form' . $this->suffix . '.js', array( 'jquery' ), ultimatemember_version, true ); wp_register_script( 'um_fileupload', $this->front_js_baseurl . 'um-fileupload.js', array( 'jquery' ), ultimatemember_version, true ); @@ -138,9 +188,9 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { $locale = get_locale(); if ( $locale ) { if ( file_exists( WP_LANG_DIR . '/plugins/ultimate-member/assets/js/pickadate/' . $locale . '.js' ) ) { - wp_register_script('um_datetime_locale', content_url() . '/languages/plugins/ultimate-member/assets/js/pickadate/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime_locale', content_url() . '/languages/plugins/ultimate-member/assets/js/pickadate/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); } elseif ( file_exists( um_path . 'assets/js/pickadate/translations/' . $locale . '.js' ) ) { - wp_register_script('um_datetime_locale', um_url . 'assets/js/pickadate/translations/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime_locale', um_url . 'assets/js/pickadate/translations/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); } } @@ -148,7 +198,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_script( 'um_responsive', $this->front_js_baseurl . 'um-responsive' . $this->suffix . '.js', array( 'um_scripts' ), ultimatemember_version, true ); wp_register_script( 'um_modal', $this->front_js_baseurl . 'um-modal' . $this->suffix . '.js', array( 'um_responsive' ), ultimatemember_version, true ); - wp_register_style( 'select2', $this->front_css_baseurl . 'select2/select2' . $this->suffix . '.css', array(), '4.0.13' ); wp_register_style( 'um_datetime', $this->front_css_baseurl . 'pickadate/default.css', array(), ultimatemember_version ); wp_register_style( 'um_datetime_date', $this->front_css_baseurl . 'pickadate/default.date.css', array( 'um_datetime' ), ultimatemember_version ); @@ -174,7 +223,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load js for Add/Edit User form */ - function load_role_wrapper() { + public function load_role_wrapper() { wp_register_script( 'um_admin_role_wrapper', $this->js_url . 'um-admin-role-wrapper.js', array( 'jquery' ), ultimatemember_version, true ); $localize_roles_data = get_option( 'um_roles', array() ); wp_localize_script( 'um_admin_role_wrapper', 'um_roles', (array) $localize_roles_data ); @@ -189,11 +238,11 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { * * @return string */ - function enter_title_here( $title ) { + public function enter_title_here( $title ) { $screen = get_current_screen(); - if ( 'um_directory' == $screen->post_type ) { + if ( 'um_directory' === $screen->post_type ) { $title = __( 'e.g. Member Directory', 'ultimate-member' ); - } elseif ( 'um_form' == $screen->post_type ) { + } elseif ( 'um_form' === $screen->post_type ) { $title = __( 'e.g. New Registration Form', 'ultimate-member' ); } return $title; @@ -203,7 +252,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Runs on admin head */ - function admin_head() { + public function admin_head() { if ( UM()->admin()->is_plugin_post_type() ) { ?> - css_url . 'um-admin-form.css', array(), ultimatemember_version ); wp_enqueue_style( 'um_admin_form' ); @@ -230,7 +280,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load Forms */ - function load_forms() { + public function load_forms() { if ( class_exists( 'WooCommerce' ) ) { wp_dequeue_style( 'select2' ); wp_deregister_style( 'select2' ); @@ -248,9 +298,20 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_script( 'um_admin_forms', $this->js_url . 'um-admin-forms.js', array( 'jquery', 'wp-i18n', 'select2' ), ultimatemember_version, true ); - wp_localize_script( 'um_admin_forms', 'um_forms_data', array( - 'successfully_redirect' => add_query_arg( array( 'page' => 'um_options', 'tab' => 'misc', 'msg' => 'updated' ), admin_url( 'admin.php' ) ), - ) ); + wp_localize_script( + 'um_admin_forms', + 'um_forms_data', + array( + 'successfully_redirect' => add_query_arg( + array( + 'page' => 'um_options', + 'tab' => 'misc', + 'msg' => 'updated', + ), + admin_url( 'admin.php' ) + ), + ) + ); wp_enqueue_script( 'um_admin_forms' ); } @@ -259,7 +320,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load dashboard */ - function load_dashboard() { + public function load_dashboard() { wp_register_style( 'um_admin_dashboard', $this->css_url . 'um-admin-dashboard.css', array(), ultimatemember_version ); wp_enqueue_style( 'um_admin_dashboard' ); } @@ -268,7 +329,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load settings */ - function load_settings() { + public function load_settings() { wp_register_style( 'um_admin_settings', $this->css_url . 'um-admin-settings.css', array(), ultimatemember_version ); wp_enqueue_style( 'um_admin_settings' ); @@ -280,7 +341,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load modal */ - function load_modal() { + public function load_modal() { wp_register_style( 'um_admin_modal', $this->css_url . 'um-admin-modal.css', array( 'wp-color-picker' ), ultimatemember_version ); wp_enqueue_style( 'um_admin_modal' ); @@ -292,8 +353,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Field Processing */ - function load_field() { - wp_register_script( 'um_admin_field', $this->js_url . 'um-admin-field.js', array('jquery', 'wp-util', 'wp-i18n'), ultimatemember_version, true ); + public function load_field() { + wp_register_script( 'um_admin_field', $this->js_url . 'um-admin-field.js', array( 'jquery', 'wp-util', 'wp-i18n' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_field' ); } @@ -301,8 +362,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load Builder */ - function load_builder() { - wp_register_script( 'um_admin_builder', $this->js_url . 'um-admin-builder.js', array('jquery', 'wp-util'), ultimatemember_version, true ); + public function load_builder() { + wp_register_script( 'um_admin_builder', $this->js_url . 'um-admin-builder.js', array( 'jquery', 'wp-util' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_builder' ); //hide footer text on add/edit UM Forms @@ -310,9 +371,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { //and WP calculate page height $hide_footer = false; global $pagenow, $post; - if ( ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) && - ( ( isset( $_GET['post_type'] ) && 'um_form' === sanitize_key( $_GET['post_type'] ) ) || - ( isset( $post->post_type ) && 'um_form' === $post->post_type ) ) ) { + // phpcs:ignore WordPress.Security.NonceVerification + if ( ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) && ( ( isset( $_GET['post_type'] ) && 'um_form' === sanitize_key( $_GET['post_type'] ) ) || ( isset( $post->post_type ) && 'um_form' === $post->post_type ) ) ) { $hide_footer = true; } @@ -321,7 +381,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { ); wp_localize_script( 'um_admin_builder', 'um_admin_builder_data', $localize_data ); - wp_register_script( 'um_admin_dragdrop', $this->js_url . 'um-admin-dragdrop.js', array('jquery', 'wp-util'), ultimatemember_version, true ); + wp_register_script( 'um_admin_dragdrop', $this->js_url . 'um-admin-dragdrop.js', array( 'jquery', 'wp-util' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_dragdrop' ); wp_register_style( 'um_admin_builder', $this->css_url . 'um-admin-builder.css', array(), ultimatemember_version ); @@ -332,7 +392,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load core WP styles/scripts */ - function load_core_wp() { + public function load_core_wp() { wp_enqueue_script( 'jquery-ui-draggable' ); wp_enqueue_script( 'jquery-ui-sortable' ); @@ -343,7 +403,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load Admin Styles */ - function load_css() { + public function load_css() { wp_register_style( 'um_admin_menu', $this->css_url . 'um-admin-menu.css', array(), ultimatemember_version ); wp_enqueue_style( 'um_admin_menu' ); @@ -358,7 +418,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load functions js */ - function load_functions() { + public function load_functions() { wp_register_script( 'um_scrollbar', um_url . 'assets/js/simplebar.js', array( 'jquery' ), ultimatemember_version, true ); wp_register_script( 'um_functions', um_url . 'assets/js/um-functions.js', array( 'jquery', 'jquery-masonry', 'wp-util', 'um_scrollbar' ), ultimatemember_version, true ); wp_enqueue_script( 'um_functions' ); @@ -368,7 +428,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load Fonticons */ - function load_fonticons() { + public function load_fonticons() { wp_register_style( 'um_fonticons_ii', um_url . 'assets/css/um-fonticons-ii.css', array(), ultimatemember_version ); wp_enqueue_style( 'um_fonticons_ii' ); @@ -380,8 +440,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load global css */ - function load_global_scripts() { - wp_register_script( 'um_admin_global', $this->js_url . 'um-admin-global.js', array('jquery'), ultimatemember_version, true ); + public function load_global_scripts() { + wp_register_script( 'um_admin_global', $this->js_url . 'um-admin-global.js', array( 'jquery' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_global' ); wp_register_style( 'um_admin_global', $this->css_url . 'um-admin-global.css', array(), ultimatemember_version ); @@ -392,7 +452,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load jQuery custom code */ - function load_custom_scripts() { + public function load_custom_scripts() { wp_register_script( 'um_datetime', $this->front_js_baseurl . 'pickadate/picker.js', array( 'jquery' ), ultimatemember_version, true ); wp_register_script( 'um_datetime_date', $this->front_js_baseurl . 'pickadate/picker.date.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); wp_register_script( 'um_datetime_time', $this->front_js_baseurl . 'pickadate/picker.time.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); @@ -401,9 +461,9 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { $locale = get_locale(); if ( $locale ) { if ( file_exists( WP_LANG_DIR . '/plugins/ultimate-member/assets/js/pickadate/' . $locale . '.js' ) ) { - wp_register_script('um_datetime_locale', content_url() . '/languages/plugins/ultimate-member/assets/js/pickadate/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime_locale', content_url() . '/languages/plugins/ultimate-member/assets/js/pickadate/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); } elseif ( file_exists( um_path . 'assets/js/pickadate/translations/' . $locale . '.js' ) ) { - wp_register_script('um_datetime_locale', um_url . 'assets/js/pickadate/translations/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); + wp_register_script( 'um_datetime_locale', um_url . 'assets/js/pickadate/translations/' . $locale . '.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); } } @@ -411,9 +471,10 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_style( 'um_datetime_date', $this->front_css_baseurl . 'pickadate/default.date.css', array( 'um_datetime' ), ultimatemember_version ); wp_register_style( 'um_datetime_time', $this->front_css_baseurl . 'pickadate/default.time.css', array( 'um_datetime' ), ultimatemember_version ); - wp_enqueue_style( 'um_datetime_date', 'um_datetime_time' ); + wp_enqueue_style( 'um_datetime_date' ); + wp_enqueue_style( 'um_datetime_time' ); - wp_register_script( 'um_admin_scripts', $this->js_url . 'um-admin-scripts.js', array('jquery','wp-util', 'wp-color-picker', 'um_datetime', 'um_datetime_date', 'um_datetime_time'/*, 'um_datetime_legacy'*/ ), ultimatemember_version, true ); + wp_register_script( 'um_admin_scripts', $this->js_url . 'um-admin-scripts.js', array( 'jquery', 'wp-util', 'wp-color-picker', 'um_datetime', 'um_datetime_date', 'um_datetime_time'/*, 'um_datetime_legacy'*/ ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_scripts' ); } @@ -421,8 +482,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load jQuery custom code */ - function load_nav_manus_scripts() { - wp_register_script( 'um_admin_nav_manus', $this->js_url . 'um-admin-nav-menu.js', array('jquery','wp-util'), ultimatemember_version, true ); + public function load_nav_manus_scripts() { + wp_register_script( 'um_admin_nav_manus', $this->js_url . 'um-admin-nav-menu.js', array( 'jquery', 'wp-util' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_nav_manus' ); } @@ -430,8 +491,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load AJAX */ - function load_ajax_js() { - wp_register_script( 'um_admin_ajax', $this->js_url . 'um-admin-ajax.js', array('jquery','wp-util'), ultimatemember_version, true ); + public function load_ajax_js() { + wp_register_script( 'um_admin_ajax', $this->js_url . 'um-admin-ajax.js', array( 'jquery', 'wp-util' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_ajax' ); } @@ -439,102 +500,102 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load Gutenberg scripts */ - function load_gutenberg_js() { - //disable Gutenberg scripts to avoid the conflicts - $disable_script = apply_filters( 'um_disable_blocks_script', false ); - if ( $disable_script ) { - return; - } - - $restricted_blocks = UM()->options()->get( 'restricted_blocks' ); - if ( empty( $restricted_blocks ) ) { - return; - } - - wp_register_script( 'um_block_js', $this->js_url . 'um-admin-blocks.js', array( 'wp-i18n', 'wp-blocks', 'wp-components', 'wp-hooks' ), ultimatemember_version, true ); - wp_set_script_translations( 'um_block_js', 'ultimate-member' ); - - $restrict_options = array(); - $roles = UM()->roles()->get_roles( false ); - if ( ! empty( $roles ) ) { - foreach ( $roles as $role_key => $title ) { - $restrict_options[] = array( - 'label' => $title, - 'value' => $role_key - ); - } - } - wp_localize_script( 'um_block_js', 'um_restrict_roles', $restrict_options ); - - wp_enqueue_script( 'um_block_js' ); - - do_action( 'um_load_gutenberg_js' ); - } +// public function load_gutenberg_js() { +// //disable Gutenberg scripts to avoid the conflicts +// $disable_script = apply_filters( 'um_disable_blocks_script', false ); +// if ( $disable_script ) { +// return; +// } +// +// $restricted_blocks = UM()->options()->get( 'restricted_blocks' ); +// if ( empty( $restricted_blocks ) ) { +// return; +// } +// +// wp_register_script( 'um_block_js', $this->js_url . 'um-admin-blocks.js', array( 'wp-i18n', 'wp-blocks', 'wp-components', 'wp-hooks' ), ultimatemember_version, true ); +// wp_set_script_translations( 'um_block_js', 'ultimate-member' ); +// +// $restrict_options = array(); +// $roles = UM()->roles()->get_roles( false ); +// if ( ! empty( $roles ) ) { +// foreach ( $roles as $role_key => $title ) { +// $restrict_options[] = array( +// 'label' => $title, +// 'value' => $role_key, +// ); +// } +// } +// wp_localize_script( 'um_block_js', 'um_restrict_roles', $restrict_options ); +// +// wp_enqueue_script( 'um_block_js' ); +// +// do_action( 'um_load_gutenberg_js' ); +// } /** * Load Gutenberg blocks js */ - function load_gutenberg_shortcode_blocks() { - if ( ! function_exists( 'register_block_type' ) ) { - // Gutenberg is not active. - return; - } - - //disable Gutenberg scripts to avoid the conflicts - $disable_script = apply_filters( 'um_disable_blocks_script', false ); - if ( $disable_script ) { - return; - } - - $enable_blocks = UM()->options()->get( 'enable_blocks' ); - if ( empty( $enable_blocks ) ) { - return; - } - - wp_register_script( 'um-blocks-shortcode-js', $this->js_url . 'um-admin-blocks-shortcode.js', array( 'wp-i18n', 'wp-blocks', 'wp-components', /*'rich-text'*/ ), ultimatemember_version, true ); - wp_set_script_translations( 'um-blocks-shortcode-js', 'ultimate-member' ); - wp_enqueue_script( 'um-blocks-shortcode-js' ); - - $account_settings = array( - 'password' => array( - 'label' => __( 'Password', 'ultimate-member' ), - 'enabled' => UM()->options()->get( 'account_tab_password' ), - ), - 'privacy' => array( - 'label' => __( 'Privacy', 'ultimate-member' ), - 'enabled' => UM()->options()->get( 'account_tab_privacy' ), - ), - 'notifications' => array( - 'label' => __( 'Notifications', 'ultimate-member' ), - 'enabled' => UM()->options()->get( 'account_tab_notifications' ), - ), - 'delete' => array( - 'label' => __( 'Delete', 'ultimate-member' ), - 'enabled' => UM()->options()->get( 'account_tab_delete' ), - ), - ); - wp_localize_script( 'um-blocks-shortcode-js', 'um_account_settings', $account_settings ); - - /** - * create gutenberg blocks - */ - register_block_type( 'um-block/um-forms', array( - 'editor_script' => 'um-blocks-shortcode-js', - ) ); - - register_block_type( 'um-block/um-member-directories', array( - 'editor_script' => 'um-blocks-shortcode-js', - ) ); - - register_block_type( 'um-block/um-password-reset', array( - 'editor_script' => 'um-blocks-shortcode-js', - ) ); - - register_block_type( 'um-block/um-account', array( - 'editor_script' => 'um-blocks-shortcode-js', - ) ); - } +// public function load_gutenberg_shortcode_blocks() { +// if ( ! function_exists( 'register_block_type' ) ) { +// // Gutenberg is not active. +// return; +// } +// +// //disable Gutenberg scripts to avoid the conflicts +// $disable_script = apply_filters( 'um_disable_blocks_script', false ); +// if ( $disable_script ) { +// return; +// } +// +// $enable_blocks = UM()->options()->get( 'enable_blocks' ); +// if ( empty( $enable_blocks ) ) { +// return; +// } +// +// wp_register_script( 'um-blocks-shortcode-js', $this->js_url . 'um-admin-blocks-shortcode.js', array( 'wp-i18n', 'wp-blocks', 'wp-components', /*'rich-text'*/ ), ultimatemember_version, true ); +// wp_set_script_translations( 'um-blocks-shortcode-js', 'ultimate-member' ); +// wp_enqueue_script( 'um-blocks-shortcode-js' ); +// +// $account_settings = array( +// 'password' => array( +// 'label' => __( 'Password', 'ultimate-member' ), +// 'enabled' => UM()->options()->get( 'account_tab_password' ), +// ), +// 'privacy' => array( +// 'label' => __( 'Privacy', 'ultimate-member' ), +// 'enabled' => UM()->options()->get( 'account_tab_privacy' ), +// ), +// 'notifications' => array( +// 'label' => __( 'Notifications', 'ultimate-member' ), +// 'enabled' => UM()->options()->get( 'account_tab_notifications' ), +// ), +// 'delete' => array( +// 'label' => __( 'Delete', 'ultimate-member' ), +// 'enabled' => UM()->options()->get( 'account_tab_delete' ), +// ), +// ); +// wp_localize_script( 'um-blocks-shortcode-js', 'um_account_settings', $account_settings ); +// +// /** +// * create gutenberg blocks +// */ +// register_block_type( 'um-block/um-forms', array( +// 'editor_script' => 'um-blocks-shortcode-js', +// ) ); +// +// register_block_type( 'um-block/um-member-directories', array( +// 'editor_script' => 'um-blocks-shortcode-js', +// ) ); +// +// register_block_type( 'um-block/um-password-reset', array( +// 'editor_script' => 'um-blocks-shortcode-js', +// ) ); +// +// register_block_type( 'um-block/um-account', array( +// 'editor_script' => 'um-blocks-shortcode-js', +// ) ); +// } /** @@ -545,27 +606,27 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { * * @return array */ - function blocks_category( $categories, $context ) { - $enable_blocks = UM()->options()->get( 'enable_blocks' ); - if ( empty( $enable_blocks ) ) { - return $categories; - } + public function blocks_category( $categories, $context ) { + $enable_blocks = UM()->options()->get( 'enable_blocks' ); + if ( empty( $enable_blocks ) ) { + return $categories; + } - return array_merge( - $categories, - array( - array( - 'slug' => 'um-blocks', - 'title' => __( 'Ultimate Member Blocks', 'ultimate-member' ), - ), - ) - ); - } + return array_merge( + $categories, + array( + array( + 'slug' => 'um-blocks', + 'title' => __( 'Ultimate Member Blocks', 'ultimate-member' ), + ), + ) + ); + } /** * Load localize scripts */ - function load_localize_scripts() { + public function load_localize_scripts() { /** * UM hook @@ -587,10 +648,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { * } * ?> */ - $localize_data = apply_filters( 'um_admin_enqueue_localize_data', array( - 'nonce' => wp_create_nonce( "um-admin-nonce" ) - ) - ); + $localize_data = apply_filters( 'um_admin_enqueue_localize_data', array( 'nonce' => wp_create_nonce( 'um-admin-nonce' ) ) ); wp_localize_script( 'um_admin_global', 'um_admin_scripts', $localize_data ); } @@ -599,7 +657,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Enqueue scripts and styles */ - function admin_enqueue_scripts() { + public function admin_enqueue_scripts() { if ( UM()->admin()->is_um_screen() ) { /*if ( get_post_type() != 'shop_order' ) { @@ -628,7 +686,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { $this->load_fonticons(); $this->load_localize_scripts(); - //scripts for frontend preview UM()->enqueue()->load_imagecrop(); UM()->enqueue()->load_css(); @@ -646,7 +703,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_style( 'um_admin_rtl', $this->css_url . 'um-admin-rtl.css', array(), ultimatemember_version ); wp_enqueue_style( 'um_admin_rtl' ); } - } else { $this->load_global_scripts(); @@ -658,8 +714,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { if ( version_compare( $wp_version, '5.0', '>=' ) ) { if ( isset( $current_screen ) && $current_screen->is_block_editor() ) { - $this->load_gutenberg_js(); - $this->load_gutenberg_shortcode_blocks(); +// $this->load_gutenberg_js(); +// $this->load_gutenberg_shortcode_blocks(); } } } @@ -668,7 +724,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Print editor scripts if they are not printed by default */ - function admin_footer_scripts() { + public function admin_footer_scripts() { /** * @var $class \_WP_Editors */ diff --git a/includes/blocks/um-member-directories/block.json b/includes/blocks/um-member-directories/block.json new file mode 100644 index 00000000..ddaabf37 --- /dev/null +++ b/includes/blocks/um-member-directories/block.json @@ -0,0 +1,15 @@ +{ + "apiVersion": 2, + "name": "um-block/um-member-directories", + "title": "Member Directory", + "description": "Choose display directory", + "icon": "groups", + "category": "um-blocks", + "attributes": { + "member_id": { + "type": "integer" + } + }, + "editorScript": "file:./build/index.js", + "textdomain": "ultimate-member" +} diff --git a/includes/blocks/um-member-directories/src/index.js b/includes/blocks/um-member-directories/src/index.js new file mode 100644 index 00000000..12ac4b6a --- /dev/null +++ b/includes/blocks/um-member-directories/src/index.js @@ -0,0 +1,105 @@ +import { useSelect } from '@wordpress/data'; +import { PanelBody, SelectControl, Spinner } from '@wordpress/components'; +import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; +import ServerSideRender from '@wordpress/server-side-render'; +import { registerBlockType } from "@wordpress/blocks"; + +registerBlockType('um-block/um-member-directories', { + edit: function (props) { + let { member_id, setAttributes } = props.attributes; + const blockProps = useBlockProps(); + const posts = useSelect((select) => { + return select('core').getEntityRecords('postType', 'um_directory', { + per_page: -1, + _fields: ['id', 'title'] + }); + }); + + if (!posts) { + return ( +

+ + {wp.i18n.__('Loading...', 'ultimate-member')} +

+ ); + } + + if (posts.length === 0) { + return 'No posts found.'; + } + + function get_option( posts ) { + var option = []; + + posts.map( function( post ) { + option.push( + { + label: post.title.rendered, + value: post.id + } + ); + }); + + return option; + } + + function umShortcode( value ) { + + var shortcode = ''; + + if (value !== undefined && value !== '') { + shortcode = '[ultimatemember form_id="' + value + '"]'; + } + + return shortcode; + } + + let posts_data = [{ id: '', title: '' }].concat(posts); + + let get_post = posts_data.map((post) => { + return { + label: post.title.rendered, + value: post.id + }; + }); + + return ( +
+ + + + { + props.setAttributes({ member_id: value }); + umShortcode(value); + }} + /> + + +
+ ); + + }, + save: function save(props) { + return null; + } +}); + +jQuery(window).on( 'load', function($) { + var observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + + jQuery(mutation.addedNodes).find('.um.um-directory').each(function() { + var directory = jQuery(this); + um_ajax_get_members( directory ); + }); + }); + }); + + observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true}); +}); diff --git a/includes/class-init.php b/includes/class-init.php index 1e64f3e3..daf946e0 100644 --- a/includes/class-init.php +++ b/includes/class-init.php @@ -602,6 +602,7 @@ if ( ! class_exists( 'UM' ) ) { $this->external_integrations(); $this->gdpr(); $this->member_directory(); + $this->blocks(); //if multisite networks active if ( is_multisite() ) { @@ -631,6 +632,20 @@ if ( ! class_exists( 'UM' ) ) { } + /** + * @since 2.6.1 + * + * @return um\core\Blocks() + */ + public function blocks() { + if ( empty( $this->classes['blocks'] ) ) { + $this->classes['blocks'] = new um\core\Blocks(); + } + + return $this->classes['blocks']; + } + + /** * Get extension API * diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php new file mode 100644 index 00000000..89131429 --- /dev/null +++ b/includes/core/class-blocks.php @@ -0,0 +1,69 @@ +options()->get( 'enable_blocks' ); + if ( empty( $enable_blocks ) ) { + return; + } + + $blocks = array( + 'um-block/um-member-directories' => array( + 'render_callback' => array( $this, 'um_member_directories_render' ), + 'attributes' => array( + 'member_id' => array( + 'type' => 'string', + ), + ), + ), + ); + + foreach ( $blocks as $k => $block_data ) { + $block_type = str_replace( 'um-block/', '', $k ); + register_block_type_from_metadata( um_path . 'includes/blocks/' . $block_type, $block_data ); + } + } + + + public function um_member_directories_render( $atts ) { + $shortcode = '[ultimatemember'; + + if ( isset( $atts['member_id'] ) && '' !== $atts['member_id'] ) { + $shortcode .= ' form_id="' . $atts['member_id'] . '"'; + } + + $shortcode .= ']'; + + return apply_shortcodes( $shortcode ); + } + } +} diff --git a/package.json b/package.json index faa58dc5..adaf09b0 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,10 @@ } ], "scripts": { - "postinstall": "node node_modules/bower/bin/bower install && grunt dev" + "postinstall": "node node_modules/bower/bin/bower install && grunt dev", + "build": "npm-run-all build:*", + "build:all-blocks": "npm-run-all --parallel build-block-*", + "build-block-um-member-directories": "cd includes/blocks/um-member-directories && wp-scripts build src/index.js" }, "engines": { "node": ">= 0.10.0" @@ -27,10 +30,18 @@ "gulp-cli": "^2.3.0", "gulp-concat": "2.6.1", "gulp-rename": "^2.0.0", - "gulp-sass": "^4.1.0", + "gulp-sass": "^5.1.0", "gulp-uglify": "^3.0.2", - "gulp-clean-css": "^4.3.0" + "gulp-clean-css": "^4.3.0", + "npm-run-all": "^4.1.5", + "@wordpress/block-editor": "^11.5.0", + "@wordpress/blocks": "^12.5.0", + "@wordpress/components": "^23.5.0", + "@wordpress/i18n": "^4.28.0", + "@wordpress/scripts": "^25.5.1", + "@wordpress/server-side-render": "^4.5.0" }, "dependencies": { + "react": "^18.2.0" } } From a08ed9b6c1510ebbfadc51e9818d472ac5e7e145 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Wed, 29 Mar 2023 14:38:11 +0300 Subject: [PATCH 02/25] - reset password block --- .../assets/js/um-admin-blocks-shortcode.js | 172 +----------------- includes/blocks/um-forms/block.json | 15 ++ includes/blocks/um-forms/src/index.js | 105 +++++++++++ includes/blocks/um-password-reset/block.json | 10 + .../blocks/um-password-reset/src/index.js | 19 ++ includes/core/class-blocks.php | 31 ++++ includes/core/class-shortcodes.php | 32 ++-- package.json | 4 +- 8 files changed, 200 insertions(+), 188 deletions(-) create mode 100644 includes/blocks/um-forms/block.json create mode 100644 includes/blocks/um-forms/src/index.js create mode 100644 includes/blocks/um-password-reset/block.json create mode 100644 includes/blocks/um-password-reset/src/index.js diff --git a/includes/admin/assets/js/um-admin-blocks-shortcode.js b/includes/admin/assets/js/um-admin-blocks-shortcode.js index 88038cf3..0ad57c4b 100644 --- a/includes/admin/assets/js/um-admin-blocks-shortcode.js +++ b/includes/admin/assets/js/um-admin-blocks-shortcode.js @@ -128,176 +128,6 @@ wp.blocks.registerBlockType( 'um-block/um-forms', { }); -//-------------------------------------\\ -//-- Um Member Directories shortcode --\\ -//-------------------------------------\\ - -wp.blocks.registerBlockType( 'um-block/um-member-directories', { - title: wp.i18n.__( 'Member Directory', 'ultimate-member' ), - description: wp.i18n.__( 'Choose display directory', 'ultimate-member' ), - icon: 'groups', - category: 'um-blocks', - attributes: { - content: { - source: 'html', - selector: 'p' - }, - member_id: { - type: 'select' - } - }, - - edit: wp.data.withSelect( function( select ) { - return { - posts: select( 'core' ).getEntityRecords( 'postType', 'um_directory', { - per_page: -1 - }) - }; - } )( function( props ) { - var posts = props.posts, - className = props.className, - attributes = props.attributes, - setAttributes = props.setAttributes, - member_id = props.attributes.member_id, - content = props.attributes.content; - - function get_option( posts ) { - var option = []; - - posts.map( function( post ) { - option.push( - { - label: post.title.rendered, - value: post.id - } - ); - }); - - return option; - } - - function umShortcode( value ) { - - var shortcode = ''; - - if ( value !== undefined ) { - shortcode = '[ultimatemember form_id="' + value + '"]'; - } - - return shortcode; - } - - if ( ! posts ) { - return wp.element.createElement( - 'p', - { - className: className - }, - wp.element.createElement( - wp.components.Spinner, - null - ), - wp.i18n.__( 'Loading Forms', 'ultimate-member' ) - ); - } - - if ( 0 === posts.length ) { - return wp.element.createElement( - 'p', - null, - wp.i18n.__( 'No Posts', 'ultimate-member' ) - ); - } - - if ( member_id === undefined ) { - props.setAttributes({ member_id: posts[0]['id'] }); - var shortcode = umShortcode(posts[0]['id']); - props.setAttributes( { content: shortcode } ); - } - - var get_post = get_option( posts ); - - return wp.element.createElement( - 'div', - { - className: className - }, - wp.element.createElement( - wp.components.SelectControl, - { - label: wp.i18n.__( 'Select Directories', 'ultimate-member' ), - className: 'um_select_directory', - type: 'number', - value: member_id, - options: get_post, - onChange: function onChange( value ) { - props.setAttributes({ member_id: value }); - var shortcode = umShortcode(value); - props.setAttributes( { content: shortcode } ); - } - } - ) - ); - } // end withSelect - ), // end edit - - save: function save( props ) { - - return wp.element.createElement( - wp.editor.RichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } - -}); - -//-------------------------------------\\ -//--------- Um password reset ---------\\ -//-------------------------------------\\ -wp.blocks.registerBlockType( 'um-block/um-password-reset', { - title: wp.i18n.__( 'Password Reset', 'ultimate-member' ), - description: wp.i18n.__( 'Displaying the password reset form', 'ultimate-member' ), - icon: 'unlock', - category: 'um-blocks', - attributes: { - content: { - source: 'html', - selector: 'p' - } - }, - - edit: function( props ) { - var content = props.attributes.content; - props.setAttributes({ content: '[ultimatemember_password]' }); - - return [ - wp.element.createElement( - "div", - { - className: "um-password-reset-wrapper" - }, - wp.i18n.__( 'Password Reset', 'ultimate-member' ) - ) - ] - }, - - save: function( props ) { - - return wp.element.createElement( - wp.editor.RichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } -}); - //-------------------------------------\\ //------------ Um Account -------------\\ //-------------------------------------\\ @@ -402,4 +232,4 @@ wp.blocks.registerBlockType( 'um-block/um-account', { } ); } -}); \ No newline at end of file +}); diff --git a/includes/blocks/um-forms/block.json b/includes/blocks/um-forms/block.json new file mode 100644 index 00000000..563f7399 --- /dev/null +++ b/includes/blocks/um-forms/block.json @@ -0,0 +1,15 @@ +{ + "apiVersion": 2, + "name": "um-block/um-forms", + "title": "Form", + "description": "Choose display form", + "icon": "forms", + "category": "um-blocks", + "attributes": { + "form_id": { + "type": "integer" + } + }, + "editorScript": "file:./build/index.js", + "textdomain": "ultimate-member" +} diff --git a/includes/blocks/um-forms/src/index.js b/includes/blocks/um-forms/src/index.js new file mode 100644 index 00000000..227d98ea --- /dev/null +++ b/includes/blocks/um-forms/src/index.js @@ -0,0 +1,105 @@ +import { useSelect } from '@wordpress/data'; +import { PanelBody, SelectControl, Spinner } from '@wordpress/components'; +import { InspectorControls, useBlockProps } from '@wordpress/block-editor'; +import ServerSideRender from '@wordpress/server-side-render'; +import { registerBlockType } from "@wordpress/blocks"; + +registerBlockType('um-block/um-forms', { + edit: function (props) { + let { form_id, setAttributes } = props.attributes; + const blockProps = useBlockProps(); + const posts = useSelect((select) => { + return select('core').getEntityRecords('postType', 'um_form', { + per_page: -1, + _fields: ['id', 'title'] + }); + }); + + if (!posts) { + return ( +

+ + {wp.i18n.__('Loading...', 'ultimate-member')} +

+ ); + } + + if (posts.length === 0) { + return 'No forms found.'; + } + + function get_option( posts ) { + var option = []; + + posts.map( function( post ) { + option.push( + { + label: post.title.rendered, + value: post.id + } + ); + }); + + return option; + } + + function umShortcode( value ) { + + var shortcode = ''; + + if (value !== undefined && value !== '') { + shortcode = '[ultimatemember form_id="' + value + '"]'; + } + + return shortcode; + } + + let posts_data = [{ id: '', title: '' }].concat(posts); + + let get_post = posts_data.map((post) => { + return { + label: post.title.rendered, + value: post.id + }; + }); + + return ( +
+ + + + { + props.setAttributes({ form_id: value }); + umShortcode(value); + }} + /> + + +
+ ); + + }, + save: function save(props) { + return null; + } +}); + +// jQuery(window).on( 'load', function($) { +// var observer = new MutationObserver(function(mutations) { +// mutations.forEach(function(mutation) { +// +// jQuery(mutation.addedNodes).find('.um.um-directory').each(function() { +// var directory = jQuery(this); +// um_ajax_get_members( directory ); +// }); +// }); +// }); +// +// observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true}); +// }); diff --git a/includes/blocks/um-password-reset/block.json b/includes/blocks/um-password-reset/block.json new file mode 100644 index 00000000..f73a45ee --- /dev/null +++ b/includes/blocks/um-password-reset/block.json @@ -0,0 +1,10 @@ +{ + "apiVersion": 2, + "name": "um-block/um-password-reset", + "title": "Password Reset", + "description": "Displaying the password reset form", + "icon": "unlock", + "category": "um-blocks", + "editorScript": "file:./build/index.js", + "textdomain": "ultimate-member" +} diff --git a/includes/blocks/um-password-reset/src/index.js b/includes/blocks/um-password-reset/src/index.js new file mode 100644 index 00000000..56ab795b --- /dev/null +++ b/includes/blocks/um-password-reset/src/index.js @@ -0,0 +1,19 @@ +import { registerBlockType } from '@wordpress/blocks'; +import ServerSideRender from '@wordpress/server-side-render'; +import { useBlockProps } from '@wordpress/block-editor'; + +registerBlockType('um-block/um-password-reset', { + edit: function (props) { + const blockProps = useBlockProps(); + + return ( +
+ +
+ ); + + }, + save: function save(props) { + return null; + } +}); diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php index 89131429..86975428 100644 --- a/includes/core/class-blocks.php +++ b/includes/core/class-blocks.php @@ -45,6 +45,17 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { ), ), ), + 'um-block/um-forms' => array( + 'render_callback' => array( $this, 'um_forms_render' ), + 'attributes' => array( + 'form_id' => array( + 'type' => 'string', + ), + ), + ), + 'um-block/um-password-reset' => array( + 'render_callback' => array( $this, 'um_password_reset_render' ), + ), ); foreach ( $blocks as $k => $block_data ) { @@ -65,5 +76,25 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { return apply_shortcodes( $shortcode ); } + + + public function um_forms_render( $atts ) { + $shortcode = '[ultimatemember'; + + if ( isset( $atts['form_id'] ) && '' !== $atts['form_id'] ) { + $shortcode .= ' form_id="' . $atts['form_id'] . '"'; + } + + $shortcode .= ']'; + + return apply_shortcodes( $shortcode ); + } + + + public function um_password_reset_render() { + $shortcode = '[ultimatemember_password]'; + + return apply_shortcodes( $shortcode ); + } } } diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index cd7fa823..5cb06727 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -430,11 +430,11 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { $args = ! empty( $args ) ? $args : array(); $default_login = $wpdb->get_var( - "SELECT pm.post_id - FROM {$wpdb->postmeta} pm + "SELECT pm.post_id + FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' ) - WHERE pm.meta_key = '_um_mode' AND - pm.meta_value = 'login' AND + WHERE pm.meta_key = '_um_mode' AND + pm.meta_value = 'login' AND pm2.meta_value = '1'" ); @@ -463,11 +463,11 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { $args = ! empty( $args ) ? $args : array(); $default_register = $wpdb->get_var( - "SELECT pm.post_id - FROM {$wpdb->postmeta} pm + "SELECT pm.post_id + FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' ) - WHERE pm.meta_key = '_um_mode' AND - pm.meta_value = 'register' AND + WHERE pm.meta_key = '_um_mode' AND + pm.meta_value = 'register' AND pm2.meta_value = '1'" ); @@ -496,11 +496,11 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { $args = ! empty( $args ) ? $args : array(); $default_profile = $wpdb->get_var( - "SELECT pm.post_id - FROM {$wpdb->postmeta} pm + "SELECT pm.post_id + FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' ) - WHERE pm.meta_key = '_um_mode' AND - pm.meta_value = 'profile' AND + WHERE pm.meta_key = '_um_mode' AND + pm.meta_value = 'profile' AND pm2.meta_value = '1'" ); @@ -530,11 +530,11 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { $args = ! empty( $args ) ? $args : array(); $default_directory = $wpdb->get_var( - "SELECT pm.post_id - FROM {$wpdb->postmeta} pm + "SELECT pm.post_id + FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->postmeta} pm2 ON( pm.post_id = pm2.post_id AND pm2.meta_key = '_um_is_default' ) - WHERE pm.meta_key = '_um_mode' AND - pm.meta_value = 'directory' AND + WHERE pm.meta_key = '_um_mode' AND + pm.meta_value = 'directory' AND pm2.meta_value = '1'" ); diff --git a/package.json b/package.json index adaf09b0..4f093087 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,9 @@ "postinstall": "node node_modules/bower/bin/bower install && grunt dev", "build": "npm-run-all build:*", "build:all-blocks": "npm-run-all --parallel build-block-*", - "build-block-um-member-directories": "cd includes/blocks/um-member-directories && wp-scripts build src/index.js" + "build-block-um-member-directories": "cd includes/blocks/um-member-directories && wp-scripts build src/index.js", + "build-block-um-forms": "cd includes/blocks/um-forms && wp-scripts build src/index.js", + "build-block-um-password-reset": "cd includes/blocks/um-password-reset && wp-scripts build src/index.js" }, "engines": { "node": ">= 0.10.0" From c9dedf6d91ae91f7b3e3a9967d86c5a055256e53 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Wed, 29 Mar 2023 17:42:53 +0300 Subject: [PATCH 03/25] - add account block --- assets/js/um-blocks.js | 0 includes/admin/core/class-admin-enqueue.php | 58 +++++++++++++- includes/blocks/um-account/block.json | 15 ++++ includes/blocks/um-account/src/index.js | 88 +++++++++++++++++++++ includes/core/class-blocks.php | 21 +++++ package.json | 3 +- 6 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 assets/js/um-blocks.js create mode 100644 includes/blocks/um-account/block.json create mode 100644 includes/blocks/um-account/src/index.js diff --git a/assets/js/um-blocks.js b/assets/js/um-blocks.js new file mode 100644 index 00000000..e69de29b diff --git a/includes/admin/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php index bf7b9b69..c173d1f3 100644 --- a/includes/admin/core/class-admin-enqueue.php +++ b/includes/admin/core/class-admin-enqueue.php @@ -104,6 +104,46 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_style( 'um_members_rtl', um_url . '/assets/css/um-members-rtl.css', array( 'um_members' ), ultimatemember_version ); } wp_register_style( 'um_styles', um_url . '/assets/css/um-styles.css', array(), ultimatemember_version ); + wp_register_style( 'um_profile', um_url . '/assets/css/um-profile.css', array(), ultimatemember_version ); + wp_register_style( 'um_crop', um_url . '/assets/css/um-crop.css', array(), ultimatemember_version ); + wp_register_style( 'um_responsive', um_url . '/assets/css/um-responsive.css', array( 'um_profile', 'um_crop' ), ultimatemember_version ); + wp_register_style( 'um_account', um_url . '/assets/css/um-account.css', array(), ultimatemember_version ); + + wp_register_script( 'um_admin_blocks_shortcodes', um_url . 'assets/js/um-blocks' . $this->suffix . '.js', array( 'wp-i18n', 'wp-blocks', 'wp-components' ), ultimatemember_version, true ); + wp_set_script_translations( 'jb_admin_blocks_shortcodes', 'ultimate-member' ); + + if ( ! empty( UM()->account()->get_tab_fields( 'notifications', array() ) ) ) { + $notifications_enabled = 1; + } else { + $notifications_enabled = 0; + } + + $um_account_settings = array( + 'general' => array( + 'label' => __( 'General', 'ultimate-member' ), + 'enabled' => 1, + ), + 'password' => array( + 'label' => __( 'Password', 'ultimate-member' ), + 'enabled' => UM()->options()->get( 'account_tab_password' ), + ), + 'privacy' => array( + 'label' => __( 'Privacy', 'ultimate-member' ), + 'enabled' => UM()->options()->get( 'account_tab_privacy' ), + ), + 'notifications' => array( + 'label' => __( 'Notifications', 'ultimate-member' ), + 'enabled' => $notifications_enabled, + ), + 'delete' => array( + 'label' => __( 'Delete', 'ultimate-member' ), + 'enabled' => UM()->options()->get( 'account_tab_delete' ), + ), + ); + $um_account_settings = apply_filters( 'um_extend_account_settings', $um_account_settings ); + wp_localize_script( 'um_admin_blocks_shortcodes', 'um_account_settings', $um_account_settings ); + + wp_enqueue_script( 'um_admin_blocks_shortcodes' ); wp_register_script( 'um_datetime', um_url . 'assets/js/pickadate/picker.js', array( 'jquery' ), ultimatemember_version, true ); wp_register_script( 'um_datetime_date', um_url . 'assets/js/pickadate/picker.date.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); @@ -127,6 +167,12 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_script( 'um_dropdown', um_url . 'assets/js/dropdown' . $this->suffix . '.js', array( 'jquery' ), ultimatemember_version, true ); wp_register_script( 'um_members', um_url . 'assets/js/um-members' . $this->suffix . '.js', array( 'jquery', 'wp-util', 'jquery-ui-slider', 'um_dropdown', 'wp-hooks', 'jquery-masonry', 'um_scripts' ), ultimatemember_version, true ); + wp_register_script( 'um_account', um_url . 'assets/js/um-account' . $this->suffix . '.js', array( 'jquery', 'wp-hooks' ), ultimatemember_version, true ); + wp_register_script( 'um_scrollbar', um_url . 'assets/js/simplebar' . $this->suffix . '.js', array( 'jquery' ), ultimatemember_version, true ); + wp_register_script( 'um_crop', um_url . 'assets/js/um-crop' . $this->suffix . '.js', array( 'jquery' ), ultimatemember_version, true ); + wp_register_script( 'um_functions', um_url . 'assets/js/um-functions' . $this->suffix . '.js', array( 'jquery', 'jquery-masonry', 'wp-util', 'um_scrollbar' ), ultimatemember_version, true ); + wp_register_script( 'um_responsive', um_url . 'assets/js/um-responsive' . $this->suffix . '.js', array( 'jquery', 'um_functions', 'um_crop' ), ultimatemember_version, true ); + // render blocks wp_enqueue_script( 'um_datetime' ); wp_enqueue_script( 'um_datetime_date' ); @@ -134,10 +180,20 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_enqueue_script( 'um_conditional' ); wp_enqueue_script( 'um_dropdown' ); wp_enqueue_script( 'um_members' ); + wp_enqueue_script( 'um_account' ); + wp_enqueue_script( 'um_scrollbar' ); + wp_enqueue_script( 'um_crop' ); + wp_enqueue_script( 'um_functions' ); + wp_enqueue_script( 'um_responsive' ); + wp_enqueue_style( 'um_members' ); wp_enqueue_style( 'um_styles' ); + wp_enqueue_style( 'um_profile' ); + wp_enqueue_style( 'um_crop' ); + wp_enqueue_style( 'um_responsive' ); + wp_enqueue_style( 'um_account' ); - $custom_css = '.um{opacity: 1;}'; + $custom_css = '.um{opacity: 1;}.um_request_name {display: none !important;}'; wp_add_inline_style( 'um_styles', $custom_css ); } diff --git a/includes/blocks/um-account/block.json b/includes/blocks/um-account/block.json new file mode 100644 index 00000000..2085aec7 --- /dev/null +++ b/includes/blocks/um-account/block.json @@ -0,0 +1,15 @@ +{ + "apiVersion": 2, + "name": "um-block/um-account", + "title": "Account", + "description": "Displaying the account page of the current user", + "icon": "id", + "category": "um-blocks", + "attributes": { + "tab": { + "type": "string" + } + }, + "editorScript": "file:./build/index.js", + "textdomain": "ultimate-member" +} diff --git a/includes/blocks/um-account/src/index.js b/includes/blocks/um-account/src/index.js new file mode 100644 index 00000000..530cd789 --- /dev/null +++ b/includes/blocks/um-account/src/index.js @@ -0,0 +1,88 @@ +import { registerBlockType } from '@wordpress/blocks'; +import ServerSideRender from '@wordpress/server-side-render'; +import {InspectorControls, useBlockProps} from '@wordpress/block-editor'; +import {PanelBody, SelectControl} from "@wordpress/components"; + +registerBlockType('um-block/um-account', { + edit: function (props) { + let { tab, setAttributes } = props.attributes; + const blockProps = useBlockProps(); + + function get_options() { + var option = []; + + option.push( { label: wp.i18n.__( 'All', 'ultimate-member' ), value: 'all' } ); + + for ( var key in um_account_settings ) { + if ( um_account_settings.hasOwnProperty( key ) && um_account_settings[ key ]['enabled'] ) { + option.push( + { + label: um_account_settings[ key ]['label'], + value: key + } + ) + } + } + + return option; + } + + function umShortcode( value ) { + + var shortcode = '[ultimatemember_account'; + + if ( value !== 'all' ) { + shortcode = shortcode + ' tab="' + value + '"'; + } + + shortcode = shortcode + ']'; + + props.setAttributes({ content: shortcode }); + } + + return ( +
+ + + + { + props.setAttributes({ tab: value }); + umShortcode(value); + }} + /> + + +
+ ); + + }, + save: function save(props) { + return null; + } +}); + +jQuery(window).on( 'load', function($) { + var observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + + jQuery(mutation.addedNodes).find('.um.um-account').each(function() { + var current_tab = jQuery(this).find('.um-account-main').attr('data-current_tab'); + + if ( current_tab ) { + jQuery(this).find('.um-account-tab[data-tab="'+current_tab+'"]').show(); + jQuery(this).find('.um-account-tab:not(:visible)').find( 'input, select, textarea' ).not( ':disabled' ).addClass('um_account_inactive').prop( 'disabled', true ).attr( 'disabled', true ); + um_responsive(); + um_modal_responsive(); + } + }); + }); + }); + + observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true}); +}); diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php index 86975428..625272fd 100644 --- a/includes/core/class-blocks.php +++ b/includes/core/class-blocks.php @@ -56,6 +56,14 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { 'um-block/um-password-reset' => array( 'render_callback' => array( $this, 'um_password_reset_render' ), ), + 'um-block/um-account' => array( + 'render_callback' => array( $this, 'um_account_render' ), + 'attributes' => array( + 'tab' => array( + 'type' => 'string', + ), + ), + ), ); foreach ( $blocks as $k => $block_data ) { @@ -96,5 +104,18 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { return apply_shortcodes( $shortcode ); } + + + public function um_account_render( $atts ) { + $shortcode = '[ultimatemember_account'; + + if ( isset( $atts['tab'] ) && 'all' !== $atts['tab'] ) { + $shortcode .= ' tab="' . $atts['tab'] . '"'; + } + + $shortcode .= ']'; + + return apply_shortcodes( $shortcode ); + } } } diff --git a/package.json b/package.json index 4f093087..ce1525b8 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "build:all-blocks": "npm-run-all --parallel build-block-*", "build-block-um-member-directories": "cd includes/blocks/um-member-directories && wp-scripts build src/index.js", "build-block-um-forms": "cd includes/blocks/um-forms && wp-scripts build src/index.js", - "build-block-um-password-reset": "cd includes/blocks/um-password-reset && wp-scripts build src/index.js" + "build-block-um-password-reset": "cd includes/blocks/um-password-reset && wp-scripts build src/index.js", + "build-block-um-account": "cd includes/blocks/um-account && wp-scripts build src/index.js" }, "engines": { "node": ">= 0.10.0" From 8a2932dc1179259f03775a543ef0fe429feac444 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Thu, 30 Mar 2023 14:03:36 +0300 Subject: [PATCH 04/25] - remove old blocks script --- .../assets/js/um-admin-blocks-shortcode.js | 107 --------------- includes/admin/core/class-admin-enqueue.php | 126 +++++------------- 2 files changed, 30 insertions(+), 203 deletions(-) diff --git a/includes/admin/assets/js/um-admin-blocks-shortcode.js b/includes/admin/assets/js/um-admin-blocks-shortcode.js index 0ad57c4b..08b90fc4 100644 --- a/includes/admin/assets/js/um-admin-blocks-shortcode.js +++ b/includes/admin/assets/js/um-admin-blocks-shortcode.js @@ -126,110 +126,3 @@ wp.blocks.registerBlockType( 'um-block/um-forms', { } }); - - -//-------------------------------------\\ -//------------ Um Account -------------\\ -//-------------------------------------\\ -wp.blocks.registerBlockType( 'um-block/um-account', { - title: wp.i18n.__( 'Account', 'ultimate-member' ), - description: wp.i18n.__( 'Displaying the account page of the current user', 'ultimate-member' ), - icon: 'id', - category: 'um-blocks', - attributes: { - content: { - source: 'html', - selector: 'p' - }, - tab: { - type: 'select' - } - }, - - edit: function( props ) { - var content = props.attributes.content, - tab = props.attributes.tab; - - function get_options() { - var option = []; - - option.push( { label: wp.i18n.__( 'All', 'ultimate-member' ), value: 'all' } ); - - for ( var key in um_account_settings ) { - if ( um_account_settings.hasOwnProperty( key ) && um_account_settings[ key ]['enabled'] ) { - option.push( - { - label: um_account_settings[ key ]['label'], - value: key - } - ) - } - } - - return option; - } - - function umShortcode( value ) { - - var shortcode = '[ultimatemember_account'; - - if ( value !== 'all' ) { - shortcode = shortcode + ' tab="' + value + '"'; - } - - shortcode = shortcode + ']'; - - props.setAttributes({ content: shortcode }); - } - - if ( content === undefined ) { - props.setAttributes({ content: '[ultimatemember_account]' }); - } - - return [ - wp.element.createElement( - "div", - { - className: 'um-account-wrapper' - }, - wp.i18n.__( 'Account', 'ultimate-member' ) - ), - wp.element.createElement( - wp.blockEditor.InspectorControls, - {}, - wp.element.createElement( - wp.components.PanelBody, - { - title: wp.i18n.__( 'Account Tab', 'ultimate-member' ) - }, - wp.element.createElement( - wp.components.SelectControl, - { - label: wp.i18n.__( 'Select Tab', 'ultimate-member' ), - className: "um_select_account_tab", - type: 'number', - value: props.attributes.tab, - options: get_options(), - onChange: function onChange( value ) { - props.setAttributes({ tab: value }); - umShortcode( value ); - } - } - ) - ) - ) - ] - }, - - save: function( props ) { - - return wp.element.createElement( - wp.editor.RichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } -}); diff --git a/includes/admin/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php index c173d1f3..65e7badc 100644 --- a/includes/admin/core/class-admin-enqueue.php +++ b/includes/admin/core/class-admin-enqueue.php @@ -556,102 +556,37 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { /** * Load Gutenberg scripts */ -// public function load_gutenberg_js() { -// //disable Gutenberg scripts to avoid the conflicts -// $disable_script = apply_filters( 'um_disable_blocks_script', false ); -// if ( $disable_script ) { -// return; -// } -// -// $restricted_blocks = UM()->options()->get( 'restricted_blocks' ); -// if ( empty( $restricted_blocks ) ) { -// return; -// } -// -// wp_register_script( 'um_block_js', $this->js_url . 'um-admin-blocks.js', array( 'wp-i18n', 'wp-blocks', 'wp-components', 'wp-hooks' ), ultimatemember_version, true ); -// wp_set_script_translations( 'um_block_js', 'ultimate-member' ); -// -// $restrict_options = array(); -// $roles = UM()->roles()->get_roles( false ); -// if ( ! empty( $roles ) ) { -// foreach ( $roles as $role_key => $title ) { -// $restrict_options[] = array( -// 'label' => $title, -// 'value' => $role_key, -// ); -// } -// } -// wp_localize_script( 'um_block_js', 'um_restrict_roles', $restrict_options ); -// -// wp_enqueue_script( 'um_block_js' ); -// -// do_action( 'um_load_gutenberg_js' ); -// } + public function load_gutenberg_js() { + //disable Gutenberg scripts to avoid the conflicts + $disable_script = apply_filters( 'um_disable_blocks_script', false ); + if ( $disable_script ) { + return; + } + $restricted_blocks = UM()->options()->get( 'restricted_blocks' ); + if ( empty( $restricted_blocks ) ) { + return; + } - /** - * Load Gutenberg blocks js - */ -// public function load_gutenberg_shortcode_blocks() { -// if ( ! function_exists( 'register_block_type' ) ) { -// // Gutenberg is not active. -// return; -// } -// -// //disable Gutenberg scripts to avoid the conflicts -// $disable_script = apply_filters( 'um_disable_blocks_script', false ); -// if ( $disable_script ) { -// return; -// } -// -// $enable_blocks = UM()->options()->get( 'enable_blocks' ); -// if ( empty( $enable_blocks ) ) { -// return; -// } -// -// wp_register_script( 'um-blocks-shortcode-js', $this->js_url . 'um-admin-blocks-shortcode.js', array( 'wp-i18n', 'wp-blocks', 'wp-components', /*'rich-text'*/ ), ultimatemember_version, true ); -// wp_set_script_translations( 'um-blocks-shortcode-js', 'ultimate-member' ); -// wp_enqueue_script( 'um-blocks-shortcode-js' ); -// -// $account_settings = array( -// 'password' => array( -// 'label' => __( 'Password', 'ultimate-member' ), -// 'enabled' => UM()->options()->get( 'account_tab_password' ), -// ), -// 'privacy' => array( -// 'label' => __( 'Privacy', 'ultimate-member' ), -// 'enabled' => UM()->options()->get( 'account_tab_privacy' ), -// ), -// 'notifications' => array( -// 'label' => __( 'Notifications', 'ultimate-member' ), -// 'enabled' => UM()->options()->get( 'account_tab_notifications' ), -// ), -// 'delete' => array( -// 'label' => __( 'Delete', 'ultimate-member' ), -// 'enabled' => UM()->options()->get( 'account_tab_delete' ), -// ), -// ); -// wp_localize_script( 'um-blocks-shortcode-js', 'um_account_settings', $account_settings ); -// -// /** -// * create gutenberg blocks -// */ -// register_block_type( 'um-block/um-forms', array( -// 'editor_script' => 'um-blocks-shortcode-js', -// ) ); -// -// register_block_type( 'um-block/um-member-directories', array( -// 'editor_script' => 'um-blocks-shortcode-js', -// ) ); -// -// register_block_type( 'um-block/um-password-reset', array( -// 'editor_script' => 'um-blocks-shortcode-js', -// ) ); -// -// register_block_type( 'um-block/um-account', array( -// 'editor_script' => 'um-blocks-shortcode-js', -// ) ); -// } + wp_register_script( 'um_block_js', $this->js_url . 'um-admin-blocks.js', array( 'wp-i18n', 'wp-blocks', 'wp-components', 'wp-hooks' ), ultimatemember_version, true ); + wp_set_script_translations( 'um_block_js', 'ultimate-member' ); + + $restrict_options = array(); + $roles = UM()->roles()->get_roles( false ); + if ( ! empty( $roles ) ) { + foreach ( $roles as $role_key => $title ) { + $restrict_options[] = array( + 'label' => $title, + 'value' => $role_key, + ); + } + } + wp_localize_script( 'um_block_js', 'um_restrict_roles', $restrict_options ); + + wp_enqueue_script( 'um_block_js' ); + + do_action( 'um_load_gutenberg_js' ); + } /** @@ -770,8 +705,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { if ( version_compare( $wp_version, '5.0', '>=' ) ) { if ( isset( $current_screen ) && $current_screen->is_block_editor() ) { -// $this->load_gutenberg_js(); -// $this->load_gutenberg_shortcode_blocks(); + $this->load_gutenberg_js(); } } } From e2e7765600a0da1fad808e1cd9fad9d85345c624 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Thu, 30 Mar 2023 14:10:31 +0300 Subject: [PATCH 05/25] - remove wrong code --- .../assets/js/um-admin-blocks-shortcode.js | 128 ------------------ includes/blocks/um-forms/src/index.js | 14 -- 2 files changed, 142 deletions(-) delete mode 100644 includes/admin/assets/js/um-admin-blocks-shortcode.js diff --git a/includes/admin/assets/js/um-admin-blocks-shortcode.js b/includes/admin/assets/js/um-admin-blocks-shortcode.js deleted file mode 100644 index 08b90fc4..00000000 --- a/includes/admin/assets/js/um-admin-blocks-shortcode.js +++ /dev/null @@ -1,128 +0,0 @@ -//-------------------------------------\\ -//--------- Um Forms shortcode --------\\ -//-------------------------------------\\ - -wp.blocks.registerBlockType( 'um-block/um-forms', { - title: wp.i18n.__( 'Form', 'ultimate-member' ), - description: wp.i18n.__( 'Choose display form', 'ultimate-member' ), - icon: 'forms', - category: 'um-blocks', - attributes: { - content: { - source: 'html', - selector: 'p' - }, - form_id: { - type: 'select' - } - }, - - edit: wp.data.withSelect( function( select ) { - return { - posts: select( 'core' ).getEntityRecords( 'postType', 'um_form', { - per_page: -1 - }) - }; - } )( function( props ) { - var posts = props.posts, - className = props.className, - attributes = props.attributes, - setAttributes = props.setAttributes, - form_id = props.attributes.form_id, - content = props.attributes.content; - - function get_option( posts ) { - - var option = []; - - posts.map( function( post ) { - option.push( - { - label: post.title.rendered, - value: post.id - } - ); - }); - - return option; - } - - function umShortcode( value ) { - - var shortcode = ''; - - if ( value !== undefined ) { - shortcode = '[ultimatemember form_id="' + value + '"]'; - } - - return shortcode; - } - - - if ( ! posts ) { - return wp.element.createElement( - 'p', - { - className: className - }, - wp.element.createElement( - wp.components.Spinner, - null - ), - wp.i18n.__( 'Loading Forms', 'ultimate-member' ) - ); - } - - if ( 0 === posts.length ) { - return wp.element.createElement( - 'p', - null, - wp.i18n.__( 'No Posts', 'ultimate-member' ) - ); - } - - if ( form_id === undefined ) { - props.setAttributes({ form_id: posts[0]['id'] }); - var shortcode = umShortcode( posts[0]['id'] ); - props.setAttributes( { content: shortcode } ); - } - - var get_post = get_option( posts ); - - return wp.element.createElement( - 'div', - { - className: className - }, - wp.element.createElement( - wp.components.SelectControl, - { - label: wp.i18n.__( 'Select Forms', 'ultimate-member' ), - className: 'um_select_forms', - type: 'number', - value: form_id, - options: get_post, - onChange: function onChange( value ) { - props.setAttributes({ form_id: value }); - var shortcode = umShortcode( value ); - props.setAttributes( { content: shortcode } ); - } - } - ) - ); - } // end withSelect - ), // end edit - - save: function save( props ) { - - return wp.element.createElement( - wp.editor.RichText.Content, - { - tagName: 'p', - className: props.className, - value: props.attributes.content - } - ); - } - -}); diff --git a/includes/blocks/um-forms/src/index.js b/includes/blocks/um-forms/src/index.js index 227d98ea..27cc2418 100644 --- a/includes/blocks/um-forms/src/index.js +++ b/includes/blocks/um-forms/src/index.js @@ -89,17 +89,3 @@ registerBlockType('um-block/um-forms', { return null; } }); - -// jQuery(window).on( 'load', function($) { -// var observer = new MutationObserver(function(mutations) { -// mutations.forEach(function(mutation) { -// -// jQuery(mutation.addedNodes).find('.um.um-directory').each(function() { -// var directory = jQuery(this); -// um_ajax_get_members( directory ); -// }); -// }); -// }); -// -// observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true}); -// }); From 7712a8c139a4861f95085a9c2b632526a12559a2 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Thu, 30 Mar 2023 15:45:34 +0300 Subject: [PATCH 06/25] - disable all inputs --- assets/js/um-blocks.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/assets/js/um-blocks.js b/assets/js/um-blocks.js index e69de29b..f6da25c9 100644 --- a/assets/js/um-blocks.js +++ b/assets/js/um-blocks.js @@ -0,0 +1,25 @@ +jQuery(window).on( 'load', function($) { + var observer = new MutationObserver(function(mutations) { + mutations.forEach(function(mutation) { + jQuery(mutation.addedNodes).find('.um.um-directory').each(function() { + jQuery('.um-directory input, .um-directory select, .um-directory button').attr('disabled', 'disabled'); + jQuery('.um-directory a').attr('href', ''); + }); + jQuery(mutation.addedNodes).find('.um.um-profile').each(function() { + jQuery('.um-profile input, .um-profile select, .um-profile button').attr('disabled', 'disabled'); + jQuery('.um-profile a').attr('href', ''); + }); + jQuery(mutation.addedNodes).find('.um.um-account').each(function() { + jQuery('.um-account input, .um-account select, .um-account button').attr('disabled', 'disabled'); + jQuery('.um-account a').attr('href', ''); + }); + jQuery(mutation.addedNodes).find('.um.um-password').each(function() { + jQuery('.um-password input, .um-password select, .um-password button').attr('disabled', 'disabled'); + jQuery('.um-password a').attr('href', ''); + }); + }); + }); + + observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true}); + +}); From a8d3c01e1ff0fc5ad2d4a66e0e1e47a85a82eae5 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Mon, 3 Apr 2023 11:55:40 +0300 Subject: [PATCH 07/25] - fix restrictions for module --- includes/admin/assets/js/um-admin-blocks.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/admin/assets/js/um-admin-blocks.js b/includes/admin/assets/js/um-admin-blocks.js index f6161b61..30007284 100644 --- a/includes/admin/assets/js/um-admin-blocks.js +++ b/includes/admin/assets/js/um-admin-blocks.js @@ -20,6 +20,7 @@ var um_block_restriction = wp.compose.createHigherOrderComponent( function( Bloc um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields_default', um_condition_fields ); return function( props ) { + let initialIsRestrict = props.attributes.um_is_restrict !== undefined ? props.attributes.um_is_restrict : false; if ( props.attributes.um_is_restrict !== true ) { um_condition_fields['um_who_access'] = 'um_block_settings_hide'; @@ -72,7 +73,7 @@ var um_block_restriction = wp.compose.createHigherOrderComponent( function( Bloc wp.components.ToggleControl, { label: wp.i18n.__( 'Restrict access?', 'ultimate-member' ), - checked: props.attributes.um_is_restrict, + checked: initialIsRestrict, onChange: function onChange( value ) { props.setAttributes({ um_is_restrict: value }); if ( value === false ) { From 9e0baf676f85bafc69498da93ed2414830e3d376 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Tue, 4 Apr 2023 17:40:15 +0300 Subject: [PATCH 08/25] - fix restrictions for not UM and JB blokcs --- includes/admin/assets/js/um-admin-blocks.js | 56 ++++++++++----------- includes/core/class-blocks.php | 34 ++++++++++++- 2 files changed, 61 insertions(+), 29 deletions(-) diff --git a/includes/admin/assets/js/um-admin-blocks.js b/includes/admin/assets/js/um-admin-blocks.js index 30007284..d7b16826 100644 --- a/includes/admin/assets/js/um-admin-blocks.js +++ b/includes/admin/assets/js/um-admin-blocks.js @@ -199,25 +199,25 @@ wp.hooks.addFilter( 'editor.BlockEdit', 'um-block/um_block_restriction', um_bloc * * @type {{um_is_restrict: {type: string}, um_who_access: {type: string}, um_message_type: {type: string}, um_message_content: {type: string}}} */ -var um_block_restrict_settings = { - um_is_restrict: { - type: "boolean" - }, - um_who_access: { - type: "select" - }, - um_roles_access: { - type: "select" - }, - um_message_type: { - type: "select" - }, - um_message_content: { - type: "string" - } -}; - -um_block_restrict_settings = wp.hooks.applyFilters( 'um_admin_blocks_restrict_settings', um_block_restrict_settings ); +// var um_block_restrict_settings = { +// um_is_restrict: { +// type: "boolean" +// }, +// um_who_access: { +// type: "select" +// }, +// um_roles_access: { +// type: "select" +// }, +// um_message_type: { +// type: "select" +// }, +// um_message_content: { +// type: "string" +// } +// }; +// +// um_block_restrict_settings = wp.hooks.applyFilters( 'um_admin_blocks_restrict_settings', um_block_restrict_settings ); /** @@ -225,12 +225,12 @@ um_block_restrict_settings = wp.hooks.applyFilters( 'um_admin_blocks_restrict_se * @param settings * @returns {*} */ -function um_add_block_attributes( settings ) { - var _lodash = lodash, - assign = _lodash.assign; - - settings.attributes = assign( settings.attributes, um_block_restrict_settings ); - return settings; -} - -wp.hooks.addFilter( 'blocks.registerBlockType', 'um-block/um_add_block_attributes', um_add_block_attributes ); +// function um_add_block_attributes( settings ) { +// var _lodash = lodash, +// assign = _lodash.assign; +// +// settings.attributes = assign( settings.attributes, um_block_restrict_settings ); +// return settings; +// } +// +// wp.hooks.addFilter( 'blocks.registerBlockType', 'um-block/um_add_block_attributes', um_add_block_attributes ); diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php index 625272fd..1522fbcd 100644 --- a/includes/core/class-blocks.php +++ b/includes/core/class-blocks.php @@ -20,7 +20,39 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { * Access constructor. */ public function __construct() { - add_action( 'init', array( &$this, 'block_editor_render' ), 11 ); + add_action( 'init', array( &$this, 'block_editor_render' ), 10 ); + add_filter( 'block_type_metadata', array( &$this, 'block_type_metadata' ), 11, 1 ); + } + + + public function block_type_metadata( $metadata ) { + if ( empty( $metadata['attributes']['um_is_restrict'] ) ) { + $metadata['attributes']['um_is_restrict'] = array( + 'type' => 'boolean', + ); + } + if ( empty( $metadata['attributes']['um_who_access'] ) ) { + $metadata['attributes']['um_who_access'] = array( + 'type' => 'string', + ); + } + if ( empty( $metadata['attributes']['um_roles_access'] ) ) { + $metadata['attributes']['um_roles_access'] = array( + 'type' => 'array', + ); + } + if ( empty( $metadata['attributes']['um_message_type'] ) ) { + $metadata['attributes']['um_message_type'] = array( + 'type' => 'string', + ); + } + if ( empty( $metadata['attributes']['um_message_content'] ) ) { + $metadata['attributes']['um_message_content'] = array( + 'type' => 'string', + ); + } + + return $metadata; } From 8cf8c6f25e8dd2bacc25866d23ef0d096d57b305 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Wed, 5 Apr 2023 20:17:29 +0300 Subject: [PATCH 09/25] - fix um restrictions blocks --- includes/admin/assets/js/um-admin-blocks.js | 367 +++++++++----------- includes/admin/core/class-admin-enqueue.php | 2 +- includes/core/class-blocks.php | 26 +- 3 files changed, 178 insertions(+), 217 deletions(-) diff --git a/includes/admin/assets/js/um-admin-blocks.js b/includes/admin/assets/js/um-admin-blocks.js index d7b16826..2f3ec381 100644 --- a/includes/admin/assets/js/um-admin-blocks.js +++ b/includes/admin/assets/js/um-admin-blocks.js @@ -1,7 +1,7 @@ 'use strict'; -var um_components = wp.components, - umSelectControl = um_components.SelectControl, +var um_components = wp.components, + umSelectControl = um_components.SelectControl, umTextareaControl = um_components.TextareaControl; @@ -9,228 +9,189 @@ function um_admin_blocks_custom_fields( um_condition_fields, props ) { return wp.hooks.applyFilters( 'um_admin_blocks_custom_fields', [], um_condition_fields, props ); } -var um_block_restriction = wp.compose.createHigherOrderComponent( function( BlockEdit ) { - var um_condition_fields = { - um_who_access: 'um_block_settings_hide', - um_roles_access: 'um_block_settings_hide', - um_message_type: 'um_block_settings_hide', - um_message_content: 'um_block_settings_hide' - }; +var um_block_restriction = wp.compose.createHigherOrderComponent( + function( BlockEdit ) { + var um_condition_fields = { + um_who_access: 'um_block_settings_hide', + um_roles_access: 'um_block_settings_hide', + um_message_type: 'um_block_settings_hide', + um_message_content: 'um_block_settings_hide' + }; - um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields_default', um_condition_fields ); + um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields_default', um_condition_fields ); - return function( props ) { - let initialIsRestrict = props.attributes.um_is_restrict !== undefined ? props.attributes.um_is_restrict : false; + return function( props ) { + let initialIsRestrict = props.attributes.um_is_restrict !== undefined ? props.attributes.um_is_restrict : false; - if ( props.attributes.um_is_restrict !== true ) { - um_condition_fields['um_who_access'] = 'um_block_settings_hide'; - um_condition_fields['um_roles_access'] = 'um_block_settings_hide'; - um_condition_fields['um_message_type'] = 'um_block_settings_hide'; - um_condition_fields['um_message_content'] = 'um_block_settings_hide'; - } else { - um_condition_fields['um_who_access'] = ''; - - if ( parseInt( props.attributes.um_who_access ) === 0 || typeof props.attributes.um_who_access === 'undefined' ) { - um_condition_fields['um_roles_access'] = 'um_block_settings_hide'; - um_condition_fields['um_message_type'] = 'um_block_settings_hide'; + if ( props.attributes.um_is_restrict !== true ) { + um_condition_fields['um_who_access'] = 'um_block_settings_hide'; + um_condition_fields['um_roles_access'] = 'um_block_settings_hide'; + um_condition_fields['um_message_type'] = 'um_block_settings_hide'; um_condition_fields['um_message_content'] = 'um_block_settings_hide'; - } else if ( parseInt( props.attributes.um_who_access ) === 1 ) { - um_condition_fields['um_roles_access'] = ''; - um_condition_fields['um_message_type'] = ''; - - if ( parseInt( props.attributes.um_message_type ) === 2 ) { - um_condition_fields['um_message_content'] = ''; - } else { - um_condition_fields['um_message_content'] = 'um_block_settings_hide'; - } } else { - um_condition_fields['um_message_type'] = ''; + um_condition_fields['um_who_access'] = ''; - if ( parseInt( props.attributes.um_message_type ) === 2 ) { - um_condition_fields['um_message_content'] = ''; - } else { + if ( parseInt( props.attributes.um_who_access ) === 0 || typeof props.attributes.um_who_access === 'undefined' ) { + um_condition_fields['um_roles_access'] = 'um_block_settings_hide'; + um_condition_fields['um_message_type'] = 'um_block_settings_hide'; um_condition_fields['um_message_content'] = 'um_block_settings_hide'; + } else if ( parseInt( props.attributes.um_who_access ) === 1 ) { + um_condition_fields['um_roles_access'] = ''; + um_condition_fields['um_message_type'] = ''; + + if ( parseInt( props.attributes.um_message_type ) === 2 ) { + um_condition_fields['um_message_content'] = ''; + } else { + um_condition_fields['um_message_content'] = 'um_block_settings_hide'; + } + } else { + um_condition_fields['um_message_type'] = ''; + + if ( parseInt( props.attributes.um_message_type ) === 2 ) { + um_condition_fields['um_message_content'] = ''; + } else { + um_condition_fields['um_message_content'] = 'um_block_settings_hide'; + } } } - } - um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields', um_condition_fields, props ); + um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields', um_condition_fields, props ); - return wp.element.createElement( - wp.element.Fragment, - {}, - wp.element.createElement( BlockEdit, props ), - wp.element.createElement( - wp.blockEditor.InspectorControls, + return wp.element.createElement( + wp.element.Fragment, {}, + wp.element.createElement( BlockEdit, props ), wp.element.createElement( - wp.components.PanelBody, - { - title: wp.i18n.__( 'Ultimate Member: Content Restriction', 'ultimate-member' ), - className: 'um_block_settings' - }, + wp.blockEditor.InspectorControls, + {}, wp.element.createElement( - wp.components.ToggleControl, + wp.components.PanelBody, { - label: wp.i18n.__( 'Restrict access?', 'ultimate-member' ), - checked: initialIsRestrict, - onChange: function onChange( value ) { - props.setAttributes({ um_is_restrict: value }); - if ( value === false ) { - um_condition_fields['um_who_access'] = 'um_block_settings_hide'; - um_condition_fields['um_roles_access'] = 'um_block_settings_hide'; - um_condition_fields['um_message_type'] = 'um_block_settings_hide'; - um_condition_fields['um_message_content'] = 'um_block_settings_hide'; - } else { - um_condition_fields['um_who_access'] = ''; - } + title: wp.i18n.__( 'Ultimate Member: Content Restriction', 'ultimate-member' ), + className: 'um_block_settings' + }, + wp.element.createElement( + wp.components.ToggleControl, + { + label: wp.i18n.__( 'Restrict access?', 'ultimate-member' ), + checked: initialIsRestrict, + onChange: function onChange( value ) { + props.setAttributes( { um_is_restrict: value } ); + if ( value === false ) { + um_condition_fields['um_who_access'] = 'um_block_settings_hide'; + um_condition_fields['um_roles_access'] = 'um_block_settings_hide'; + um_condition_fields['um_message_type'] = 'um_block_settings_hide'; + um_condition_fields['um_message_content'] = 'um_block_settings_hide'; + } else { + um_condition_fields['um_who_access'] = ''; + } - um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields_on_change', um_condition_fields, 'um_is_restrict', value ); + um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields_on_change', um_condition_fields, 'um_is_restrict', value ); + } } - } - ), - wp.element.createElement( - umSelectControl, - { - type: 'number', - className: um_condition_fields['um_who_access'], - label: wp.i18n.__( 'Who can access this block?', 'ultimate-member' ), - value: props.attributes.um_who_access, - options: [ - { - label: wp.i18n.__( 'Everyone', 'ultimate-member' ), - value: 0 - }, - { - label: wp.i18n.__( 'Logged in users', 'ultimate-member' ), - value: 1 - }, - { - label: wp.i18n.__( 'Logged out users', 'ultimate-member' ), - value: 2 - } - ], - onChange: function onChange( value ) { - props.setAttributes({ um_who_access: value }); - if ( parseInt( value ) === 0 ) { - um_condition_fields['um_message_type'] = 'um_block_settings_hide'; - um_condition_fields['um_message_content'] = 'um_block_settings_hide'; - um_condition_fields['um_roles_access'] = 'um_block_settings_hide'; - } else if ( parseInt( value ) === 1 ) { - um_condition_fields['um_message_type'] = ''; - um_condition_fields['um_roles_access'] = ''; - } else { - um_condition_fields['um_message_type'] = ''; - um_condition_fields['um_roles_access'] = 'um_block_settings_hide'; - } + ), + wp.element.createElement( + umSelectControl, + { + type: 'number', + className: um_condition_fields['um_who_access'], + label: wp.i18n.__( 'Who can access this block?', 'ultimate-member' ), + value: props.attributes.um_who_access, + options: [ + { + label: wp.i18n.__( 'Everyone', 'ultimate-member' ), + value: 0 + }, + { + label: wp.i18n.__( 'Logged in users', 'ultimate-member' ), + value: 1 + }, + { + label: wp.i18n.__( 'Logged out users', 'ultimate-member' ), + value: 2 + } + ], + onChange: function onChange( value ) { + props.setAttributes( { um_who_access: value } ); + if ( parseInt( value ) === 0 ) { + um_condition_fields['um_message_type'] = 'um_block_settings_hide'; + um_condition_fields['um_message_content'] = 'um_block_settings_hide'; + um_condition_fields['um_roles_access'] = 'um_block_settings_hide'; + } else if ( parseInt( value ) === 1 ) { + um_condition_fields['um_message_type'] = ''; + um_condition_fields['um_roles_access'] = ''; + } else { + um_condition_fields['um_message_type'] = ''; + um_condition_fields['um_roles_access'] = 'um_block_settings_hide'; + } - um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields_on_change', um_condition_fields, 'um_who_access', value ); - } - } - ), - wp.element.createElement( - umSelectControl, - { - multiple: true, - className: um_condition_fields['um_roles_access'], - label: wp.i18n.__( 'What roles can access this block?', 'ultimate-member' ), - value: props.attributes.um_roles_access, - options: um_restrict_roles, - onChange: function onChange( value ) { - props.setAttributes({ um_roles_access: value }); - } - } - ), - wp.element.createElement( - umSelectControl, - { - type: 'number', - className: um_condition_fields['um_message_type'], - label: wp.i18n.__( 'Restriction action', 'ultimate-member' ), - value: props.attributes.um_message_type, - options: [ - { - label: wp.i18n.__( 'Hide block', 'ultimate-member' ), - value: 0 - }, - { - label: wp.i18n.__( 'Show global default message', 'ultimate-member' ), - value: 1 - }, - { - label: wp.i18n.__( 'Show custom message', 'ultimate-member' ), - value: 2 - } - ], - onChange: function onChange( value ) { - props.setAttributes({ um_message_type: value }); - if ( parseInt( value ) === 2 ) { - um_condition_fields['um_message_content'] = ''; - } else { - um_condition_fields['um_message_content'] = 'um_block_settings_hide'; + um_condition_fields = wp.hooks.applyFilters( 'um_admin_blocks_condition_fields_on_change', um_condition_fields, 'um_who_access', value ); } } - } - ), - wp.element.createElement( - umTextareaControl, - { - type: 'number', - className: um_condition_fields['um_message_content'], - label: wp.i18n.__( 'Custom restricted access message', 'ultimate-member' ), - value: props.attributes.um_message_content, - onChange: function onChange( value ) { - props.setAttributes({ um_message_content: value }); + ), + wp.element.createElement( + umSelectControl, + { + multiple: true, + className: um_condition_fields['um_roles_access'], + label: wp.i18n.__( 'What roles can access this block?', 'ultimate-member' ), + value: props.attributes.um_roles_access, + options: um_restrict_roles, + onChange: function onChange( value ) { + props.setAttributes( { um_roles_access: value } ); + } } - } - ), - um_admin_blocks_custom_fields( um_condition_fields, props ) + ), + wp.element.createElement( + umSelectControl, + { + type: 'number', + className: um_condition_fields['um_message_type'], + label: wp.i18n.__( 'Restriction action', 'ultimate-member' ), + value: props.attributes.um_message_type, + options: [ + { + label: wp.i18n.__( 'Hide block', 'ultimate-member' ), + value: 0 + }, + { + label: wp.i18n.__( 'Show global default message', 'ultimate-member' ), + value: 1 + }, + { + label: wp.i18n.__( 'Show custom message', 'ultimate-member' ), + value: 2 + } + ], + onChange: function onChange( value ) { + props.setAttributes( { um_message_type: value } ); + if ( parseInt( value ) === 2 ) { + um_condition_fields['um_message_content'] = ''; + } else { + um_condition_fields['um_message_content'] = 'um_block_settings_hide'; + } + } + } + ), + wp.element.createElement( + umTextareaControl, + { + type: 'number', + className: um_condition_fields['um_message_content'], + label: wp.i18n.__( 'Custom restricted access message', 'ultimate-member' ), + value: props.attributes.um_message_content, + onChange: function onChange( value ) { + props.setAttributes( { um_message_content: value } ); + } + } + ), + um_admin_blocks_custom_fields( um_condition_fields, props ) + ) ) - ) - ); - }; -}, 'um_block_restriction' ); + ); + }; + }, + 'um_block_restriction' +); wp.hooks.addFilter( 'editor.BlockEdit', 'um-block/um_block_restriction', um_block_restriction ); - - -/** - * Save Attributes - * - * @type {{um_is_restrict: {type: string}, um_who_access: {type: string}, um_message_type: {type: string}, um_message_content: {type: string}}} - */ -// var um_block_restrict_settings = { -// um_is_restrict: { -// type: "boolean" -// }, -// um_who_access: { -// type: "select" -// }, -// um_roles_access: { -// type: "select" -// }, -// um_message_type: { -// type: "select" -// }, -// um_message_content: { -// type: "string" -// } -// }; -// -// um_block_restrict_settings = wp.hooks.applyFilters( 'um_admin_blocks_restrict_settings', um_block_restrict_settings ); - - -/** - * - * @param settings - * @returns {*} - */ -// function um_add_block_attributes( settings ) { -// var _lodash = lodash, -// assign = _lodash.assign; -// -// settings.attributes = assign( settings.attributes, um_block_restrict_settings ); -// return settings; -// } -// -// wp.hooks.addFilter( 'blocks.registerBlockType', 'um-block/um_add_block_attributes', um_add_block_attributes ); diff --git a/includes/admin/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php index 65e7badc..75ed7b5d 100644 --- a/includes/admin/core/class-admin-enqueue.php +++ b/includes/admin/core/class-admin-enqueue.php @@ -572,7 +572,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_set_script_translations( 'um_block_js', 'ultimate-member' ); $restrict_options = array(); - $roles = UM()->roles()->get_roles( false ); + $roles = UM()->roles()->get_roles( false ); if ( ! empty( $roles ) ) { foreach ( $roles as $role_key => $title ) { $restrict_options[] = array( diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php index 1522fbcd..201b2bb8 100644 --- a/includes/core/class-blocks.php +++ b/includes/core/class-blocks.php @@ -21,38 +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', array( &$this, 'block_type_metadata' ), 11, 1 ); + add_filter( 'block_type_metadata_settings', array( &$this, 'block_type_metadata_settings' ), 10, 2 ); } - public function block_type_metadata( $metadata ) { - if ( empty( $metadata['attributes']['um_is_restrict'] ) ) { - $metadata['attributes']['um_is_restrict'] = array( + 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( $metadata['attributes']['um_who_access'] ) ) { - $metadata['attributes']['um_who_access'] = array( + if ( empty( $settings['attributes']['um_who_access'] ) ) { + $settings['attributes']['um_who_access'] = array( 'type' => 'string', ); } - if ( empty( $metadata['attributes']['um_roles_access'] ) ) { - $metadata['attributes']['um_roles_access'] = array( + if ( empty( $settings['attributes']['um_roles_access'] ) ) { + $settings['attributes']['um_roles_access'] = array( 'type' => 'array', ); } - if ( empty( $metadata['attributes']['um_message_type'] ) ) { - $metadata['attributes']['um_message_type'] = array( + if ( empty( $settings['attributes']['um_message_type'] ) ) { + $settings['attributes']['um_message_type'] = array( 'type' => 'string', ); } - if ( empty( $metadata['attributes']['um_message_content'] ) ) { - $metadata['attributes']['um_message_content'] = array( + if ( empty( $settings['attributes']['um_message_content'] ) ) { + $settings['attributes']['um_message_content'] = array( 'type' => 'string', ); } - return $metadata; + return $settings; } From 27b8b7de7d24a348c4434d9dd74152601b6037e0 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Thu, 6 Apr 2023 09:36:01 +0300 Subject: [PATCH 10/25] - upload builded scripts --- .gitignore | 2 -- includes/blocks/um-account/build/index.asset.php | 1 + includes/blocks/um-account/build/index.js | 1 + includes/blocks/um-forms/build/index.asset.php | 1 + includes/blocks/um-forms/build/index.js | 1 + includes/blocks/um-member-directories/build/index.asset.php | 1 + includes/blocks/um-member-directories/build/index.js | 1 + includes/blocks/um-password-reset/build/index.asset.php | 1 + includes/blocks/um-password-reset/build/index.js | 1 + 9 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 includes/blocks/um-account/build/index.asset.php create mode 100644 includes/blocks/um-account/build/index.js create mode 100644 includes/blocks/um-forms/build/index.asset.php create mode 100644 includes/blocks/um-forms/build/index.js create mode 100644 includes/blocks/um-member-directories/build/index.asset.php create mode 100644 includes/blocks/um-member-directories/build/index.js create mode 100644 includes/blocks/um-password-reset/build/index.asset.php create mode 100644 includes/blocks/um-password-reset/build/index.js diff --git a/.gitignore b/.gitignore index 706e5908..a7597b20 100644 --- a/.gitignore +++ b/.gitignore @@ -47,7 +47,6 @@ local.properties [Dd]ebug/ [Rr]elease/ x64/ -build/ [Bb]in/ [Oo]bj/ @@ -195,7 +194,6 @@ $RECYCLE.BIN/ *.egg *.egg-info dist/ -build/ eggs/ parts/ var/ diff --git a/includes/blocks/um-account/build/index.asset.php b/includes/blocks/um-account/build/index.asset.php new file mode 100644 index 00000000..cf48a0d1 --- /dev/null +++ b/includes/blocks/um-account/build/index.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-server-side-render'), 'version' => '98a99fd44cd9deb95734'); diff --git a/includes/blocks/um-account/build/index.js b/includes/blocks/um-account/build/index.js new file mode 100644 index 00000000..d8d1e5fe --- /dev/null +++ b/includes/blocks/um-account/build/index.js @@ -0,0 +1 @@ +(()=>{"use strict";var t={n:e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return t.d(n,{a:n}),n},d:(e,n)=>{for(var a in n)t.o(n,a)&&!t.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:n[a]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const e=window.wp.element,n=window.wp.blocks,a=window.wp.serverSideRender;var o=t.n(a);const u=window.wp.blockEditor,r=window.wp.components;(0,n.registerBlockType)("um-block/um-account",{edit:function(t){let{tab:n,setAttributes:a}=t.attributes;const c=(0,u.useBlockProps)();return(0,e.createElement)("div",c,(0,e.createElement)(o(),{block:"um-block/um-account",attributes:t.attributes}),(0,e.createElement)(u.InspectorControls,null,(0,e.createElement)(r.PanelBody,{title:wp.i18n.__("Account Tab","ultimate-member")},(0,e.createElement)(r.SelectControl,{label:wp.i18n.__("Select Tab","ultimate-member"),className:"um_select_account_tab",value:n,options:function(){var t=[];for(var e in t.push({label:wp.i18n.__("All","ultimate-member"),value:"all"}),um_account_settings)um_account_settings.hasOwnProperty(e)&&um_account_settings[e].enabled&&t.push({label:um_account_settings[e].label,value:e});return t}(),style:{height:"35px",lineHeight:"20px",padding:"0 7px"},onChange:e=>{t.setAttributes({tab:e}),function(e){var n="[ultimatemember_account";"all"!==e&&(n=n+' tab="'+e+'"'),n+="]",t.setAttributes({content:n})}(e)}}))))},save:function(t){return null}}),jQuery(window).on("load",(function(t){new MutationObserver((function(t){t.forEach((function(t){jQuery(t.addedNodes).find(".um.um-account").each((function(){var t=jQuery(this).find(".um-account-main").attr("data-current_tab");t&&(jQuery(this).find('.um-account-tab[data-tab="'+t+'"]').show(),jQuery(this).find(".um-account-tab:not(:visible)").find("input, select, textarea").not(":disabled").addClass("um_account_inactive").prop("disabled",!0).attr("disabled",!0),um_responsive(),um_modal_responsive())}))}))})).observe(document,{attributes:!1,childList:!0,characterData:!1,subtree:!0})}))})(); \ No newline at end of file diff --git a/includes/blocks/um-forms/build/index.asset.php b/includes/blocks/um-forms/build/index.asset.php new file mode 100644 index 00000000..6ef4166a --- /dev/null +++ b/includes/blocks/um-forms/build/index.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-server-side-render'), 'version' => '9dc130f3a0af7db5d679'); diff --git a/includes/blocks/um-forms/build/index.js b/includes/blocks/um-forms/build/index.js new file mode 100644 index 00000000..eaaac6a4 --- /dev/null +++ b/includes/blocks/um-forms/build/index.js @@ -0,0 +1 @@ +(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.element,r=window.wp.data,n=window.wp.components,l=window.wp.blockEditor,o=window.wp.serverSideRender;var i=e.n(o);(0,window.wp.blocks.registerBlockType)("um-block/um-forms",{edit:function(e){let{form_id:o,setAttributes:a}=e.attributes;const s=(0,l.useBlockProps)(),m=(0,r.useSelect)((e=>e("core").getEntityRecords("postType","um_form",{per_page:-1,_fields:["id","title"]})));if(!m)return(0,t.createElement)("p",null,(0,t.createElement)(n.Spinner,null),wp.i18n.__("Loading...","ultimate-member"));if(0===m.length)return"No forms found.";let c=[{id:"",title:""}].concat(m).map((e=>({label:e.title.rendered,value:e.id})));return(0,t.createElement)("div",s,(0,t.createElement)(i(),{block:"um-block/um-forms",attributes:e.attributes}),(0,t.createElement)(l.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:wp.i18n.__("Select Forms","ultimate-member")},(0,t.createElement)(n.SelectControl,{label:wp.i18n.__("Select Forms","ultimate-member"),className:"um_select_forms",value:o,options:c,style:{height:"35px",lineHeight:"20px",padding:"0 7px"},onChange:t=>{e.setAttributes({form_id:t})}}))))},save:function(e){return null}})})(); \ No newline at end of file diff --git a/includes/blocks/um-member-directories/build/index.asset.php b/includes/blocks/um-member-directories/build/index.asset.php new file mode 100644 index 00000000..8e85d2c6 --- /dev/null +++ b/includes/blocks/um-member-directories/build/index.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-server-side-render'), 'version' => '57ea4f619de4d752a4bb'); diff --git a/includes/blocks/um-member-directories/build/index.js b/includes/blocks/um-member-directories/build/index.js new file mode 100644 index 00000000..05bc85e3 --- /dev/null +++ b/includes/blocks/um-member-directories/build/index.js @@ -0,0 +1 @@ +(()=>{"use strict";var e={n:t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return e.d(r,{a:r}),r},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.element,r=window.wp.data,n=window.wp.components,i=window.wp.blockEditor,o=window.wp.serverSideRender;var l=e.n(o);(0,window.wp.blocks.registerBlockType)("um-block/um-member-directories",{edit:function(e){let{member_id:o,setAttributes:a}=e.attributes;const c=(0,i.useBlockProps)(),u=(0,r.useSelect)((e=>e("core").getEntityRecords("postType","um_directory",{per_page:-1,_fields:["id","title"]})));if(!u)return(0,t.createElement)("p",null,(0,t.createElement)(n.Spinner,null),wp.i18n.__("Loading...","ultimate-member"));if(0===u.length)return"No posts found.";let d=[{id:"",title:""}].concat(u).map((e=>({label:e.title.rendered,value:e.id})));return(0,t.createElement)("div",c,(0,t.createElement)(l(),{block:"um-block/um-member-directories",attributes:e.attributes}),(0,t.createElement)(i.InspectorControls,null,(0,t.createElement)(n.PanelBody,{title:wp.i18n.__("Select Directories","ultimate-member")},(0,t.createElement)(n.SelectControl,{label:wp.i18n.__("Select Directories","ultimate-member"),className:"um_select_directory",value:o,options:d,style:{height:"35px",lineHeight:"20px",padding:"0 7px"},onChange:t=>{e.setAttributes({member_id:t})}}))))},save:function(e){return null}}),jQuery(window).on("load",(function(e){new MutationObserver((function(e){e.forEach((function(e){jQuery(e.addedNodes).find(".um.um-directory").each((function(){var e=jQuery(this);um_ajax_get_members(e)}))}))})).observe(document,{attributes:!1,childList:!0,characterData:!1,subtree:!0})}))})(); \ No newline at end of file diff --git a/includes/blocks/um-password-reset/build/index.asset.php b/includes/blocks/um-password-reset/build/index.asset.php new file mode 100644 index 00000000..75ba44e5 --- /dev/null +++ b/includes/blocks/um-password-reset/build/index.asset.php @@ -0,0 +1 @@ + array('wp-block-editor', 'wp-blocks', 'wp-element', 'wp-server-side-render'), 'version' => '95e8fe2695e681505871'); diff --git a/includes/blocks/um-password-reset/build/index.js b/includes/blocks/um-password-reset/build/index.js new file mode 100644 index 00000000..5f96959e --- /dev/null +++ b/includes/blocks/um-password-reset/build/index.js @@ -0,0 +1 @@ +(()=>{"use strict";var e={n:r=>{var o=r&&r.__esModule?()=>r.default:()=>r;return e.d(o,{a:o}),o},d:(r,o)=>{for(var t in o)e.o(o,t)&&!e.o(r,t)&&Object.defineProperty(r,t,{enumerable:!0,get:o[t]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r)};const r=window.wp.element,o=window.wp.blocks,t=window.wp.serverSideRender;var n=e.n(t);const s=window.wp.blockEditor;(0,o.registerBlockType)("um-block/um-password-reset",{edit:function(e){const o=(0,s.useBlockProps)();return(0,r.createElement)("div",o,(0,r.createElement)(n(),{block:"um-block/um-password-reset"}))},save:function(e){return null}})})(); \ No newline at end of file From a4e5eab8b5908aabefe56d8d0b1dcfb63e60e04c Mon Sep 17 00:00:00 2001 From: ashubawork Date: Wed, 12 Apr 2023 10:13:32 +0300 Subject: [PATCH 11/25] - fix widget screen CSS for blocks --- includes/admin/core/class-admin-enqueue.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/admin/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php index 75ed7b5d..686847fe 100644 --- a/includes/admin/core/class-admin-enqueue.php +++ b/includes/admin/core/class-admin-enqueue.php @@ -108,6 +108,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_style( 'um_crop', um_url . '/assets/css/um-crop.css', array(), ultimatemember_version ); wp_register_style( 'um_responsive', um_url . '/assets/css/um-responsive.css', array( 'um_profile', 'um_crop' ), ultimatemember_version ); wp_register_style( 'um_account', um_url . '/assets/css/um-account.css', array(), ultimatemember_version ); + wp_register_style( 'um_default_css', um_url . '/assets/css/um-old-default.css', array(), ultimatemember_version ); + wp_register_style( 'um_fonticons_fa', um_url . '/assets/css/um-fonticons-fa.css', array(), ultimatemember_version ); wp_register_script( 'um_admin_blocks_shortcodes', um_url . 'assets/js/um-blocks' . $this->suffix . '.js', array( 'wp-i18n', 'wp-blocks', 'wp-components' ), ultimatemember_version, true ); wp_set_script_translations( 'jb_admin_blocks_shortcodes', 'ultimate-member' ); @@ -174,6 +176,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_script( 'um_responsive', um_url . 'assets/js/um-responsive' . $this->suffix . '.js', array( 'jquery', 'um_functions', 'um_crop' ), ultimatemember_version, true ); // render blocks + wp_enqueue_style( 'um_default_css' ); + wp_enqueue_style( 'um_fonticons_fa' ); wp_enqueue_script( 'um_datetime' ); wp_enqueue_script( 'um_datetime_date' ); wp_enqueue_script( 'um_datetime_time' ); From cf40103e4154fe256fe1210f6597df2a32f0a536 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Wed, 12 Apr 2023 10:23:12 +0300 Subject: [PATCH 12/25] - fix error in member directory block --- templates/members.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/members.php b/templates/members.php index 3a215ade..0e86d394 100644 --- a/templates/members.php +++ b/templates/members.php @@ -208,10 +208,13 @@ if ( ( ( $search && $show_search ) || ( $filters && $show_filters && count( $sea } } } -} ?> +} + +$postid = ! empty( $post->ID ) ? $post->ID : ''; +?>
From 33c6968055e2181973fc91cf48df07e7f0600883 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Fri, 21 Apr 2023 12:09:28 +0300 Subject: [PATCH 13/25] - fix enqueue js/css for blocks --- assets/js/um-blocks.js | 54 +++++++++++++++++++++ includes/admin/core/class-admin-enqueue.php | 29 ++++++----- 2 files changed, 71 insertions(+), 12 deletions(-) diff --git a/assets/js/um-blocks.js b/assets/js/um-blocks.js index f6da25c9..2b258d3b 100644 --- a/assets/js/um-blocks.js +++ b/assets/js/um-blocks.js @@ -4,6 +4,46 @@ jQuery(window).on( 'load', function($) { jQuery(mutation.addedNodes).find('.um.um-directory').each(function() { jQuery('.um-directory input, .um-directory select, .um-directory button').attr('disabled', 'disabled'); jQuery('.um-directory a').attr('href', ''); + + if ( typeof( jQuery.fn.select2 ) === 'function' ) { + jQuery(".um-s1").each( function( e ) { + var obj = jQuery(this); + obj.select2({ + allowClear: true, + dropdownParent: obj.parent() + }).on( 'change', unselectEmptyOption ); + } ); + + jQuery(".um-s2").each( function( e ) { + var obj = jQuery(this); + + // fix https://github.com/ultimatemember/ultimatemember/issues/941 + // using .um-custom-shortcode-tab class as temporarily solution + var atts = {}; + if ( obj.parents('.um-custom-shortcode-tab').length ) { + atts = { + allowClear: false + }; + } else { + atts = { + allowClear: false, + minimumResultsForSearch: 10, + dropdownParent: obj.parent() + }; + } + obj.select2( atts ).on( 'change', unselectEmptyOption ); + } ); + + jQuery(".um-s3").each( function( e ) { + var obj = jQuery(this); + + obj.select2({ + allowClear: false, + minimumResultsForSearch: -1, + dropdownParent: obj.parent() + }).on( 'change', unselectEmptyOption ); + } ); + } }); jQuery(mutation.addedNodes).find('.um.um-profile').each(function() { jQuery('.um-profile input, .um-profile select, .um-profile button').attr('disabled', 'disabled'); @@ -23,3 +63,17 @@ jQuery(window).on( 'load', function($) { observer.observe(document, {attributes: false, childList: true, characterData: false, subtree:true}); }); + +function unselectEmptyOption( e ) { + var $element = jQuery( e.currentTarget ); + var $selected = $element.find(':selected'); + + if ( $selected.length > 1 ) { + $selected.each( function ( i, option ) { + if ( option.value === '' ) { + option.selected = false; + $element.trigger( 'change' ); + } + }); + } +}`` diff --git a/includes/admin/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php index 686847fe..b3f5669a 100644 --- a/includes/admin/core/class-admin-enqueue.php +++ b/includes/admin/core/class-admin-enqueue.php @@ -98,18 +98,20 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { * Enqueue Gutenberg Block Editor assets */ public function block_editor() { - wp_register_style( 'um_ui', um_url . '/assets/css/jquery-ui.css', array(), ultimatemember_version ); - wp_register_style( 'um_members', um_url . '/assets/css/um-members.css', array( 'um_ui' ), ultimatemember_version ); + wp_register_style( 'um_ui', um_url . 'assets/css/jquery-ui.css', array(), ultimatemember_version ); + wp_register_style( 'um_members', um_url . 'assets/css/um-members.css', array( 'um_ui' ), ultimatemember_version ); if ( is_rtl() ) { - wp_register_style( 'um_members_rtl', um_url . '/assets/css/um-members-rtl.css', array( 'um_members' ), ultimatemember_version ); + wp_register_style( 'um_members_rtl', um_url . 'assets/css/um-members-rtl.css', array( 'um_members' ), ultimatemember_version ); } - wp_register_style( 'um_styles', um_url . '/assets/css/um-styles.css', array(), ultimatemember_version ); - wp_register_style( 'um_profile', um_url . '/assets/css/um-profile.css', array(), ultimatemember_version ); - wp_register_style( 'um_crop', um_url . '/assets/css/um-crop.css', array(), ultimatemember_version ); - wp_register_style( 'um_responsive', um_url . '/assets/css/um-responsive.css', array( 'um_profile', 'um_crop' ), ultimatemember_version ); - wp_register_style( 'um_account', um_url . '/assets/css/um-account.css', array(), ultimatemember_version ); - wp_register_style( 'um_default_css', um_url . '/assets/css/um-old-default.css', array(), ultimatemember_version ); - wp_register_style( 'um_fonticons_fa', um_url . '/assets/css/um-fonticons-fa.css', array(), ultimatemember_version ); + wp_register_style( 'um_styles', um_url . 'assets/css/um-styles.css', array(), ultimatemember_version ); + wp_register_style( 'um_profile', um_url . 'assets/css/um-profile.css', array(), ultimatemember_version ); + wp_register_style( 'um_crop', um_url . 'assets/css/um-crop.css', array(), ultimatemember_version ); + wp_register_style( 'um_responsive', um_url . 'assets/css/um-responsive.css', array( 'um_profile', 'um_crop' ), ultimatemember_version ); + wp_register_style( 'um_account', um_url . 'assets/css/um-account.css', array(), ultimatemember_version ); + wp_register_style( 'um_default_css', um_url . 'assets/css/um-old-default.css', array(), ultimatemember_version ); + wp_register_style( 'um_fonticons_fa', um_url . 'assets/css/um-fonticons-fa.css', array(), ultimatemember_version ); + wp_register_style( 'select2', um_url . 'assets/css/select2/select2' . $this->suffix . '.css', array(), ultimatemember_version ); + wp_register_style( 'um_fonticons_ii', um_url . 'assets/css/um-fonticons-ii.css', array(), ultimatemember_version ); wp_register_script( 'um_admin_blocks_shortcodes', um_url . 'assets/js/um-blocks' . $this->suffix . '.js', array( 'wp-i18n', 'wp-blocks', 'wp-components' ), ultimatemember_version, true ); wp_set_script_translations( 'jb_admin_blocks_shortcodes', 'ultimate-member' ); @@ -147,6 +149,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_enqueue_script( 'um_admin_blocks_shortcodes' ); + wp_register_script( 'select2', um_url . 'assets/js/select2/select2.full' . $this->suffix . '.js', array( 'jquery', 'jquery-masonry' ), ultimatemember_version, true ); wp_register_script( 'um_datetime', um_url . 'assets/js/pickadate/picker.js', array( 'jquery' ), ultimatemember_version, true ); wp_register_script( 'um_datetime_date', um_url . 'assets/js/pickadate/picker.date.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); wp_register_script( 'um_datetime_time', um_url . 'assets/js/pickadate/picker.time.js', array( 'jquery', 'um_datetime' ), ultimatemember_version, true ); @@ -176,8 +179,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_script( 'um_responsive', um_url . 'assets/js/um-responsive' . $this->suffix . '.js', array( 'jquery', 'um_functions', 'um_crop' ), ultimatemember_version, true ); // render blocks - wp_enqueue_style( 'um_default_css' ); - wp_enqueue_style( 'um_fonticons_fa' ); wp_enqueue_script( 'um_datetime' ); wp_enqueue_script( 'um_datetime_date' ); wp_enqueue_script( 'um_datetime_time' ); @@ -190,6 +191,10 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_enqueue_script( 'um_functions' ); wp_enqueue_script( 'um_responsive' ); + wp_enqueue_style( 'um_fonticons_ii' ); + wp_enqueue_style( 'select2' ); + wp_enqueue_style( 'um_default_css' ); + wp_enqueue_style( 'um_fonticons_fa' ); wp_enqueue_style( 'um_members' ); wp_enqueue_style( 'um_styles' ); wp_enqueue_style( 'um_profile' ); From bcadcfc7bdc5621e27f660131fe371cee6b520a4 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Tue, 25 Apr 2023 11:18:22 +0300 Subject: [PATCH 14/25] - fix profile form for guests --- includes/core/class-blocks.php | 2 +- includes/core/class-shortcodes.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php index 201b2bb8..0ca6c7ab 100644 --- a/includes/core/class-blocks.php +++ b/includes/core/class-blocks.php @@ -119,7 +119,7 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { public function um_forms_render( $atts ) { - $shortcode = '[ultimatemember'; + $shortcode = '[ultimatemember widget="1"'; if ( isset( $atts['form_id'] ) && '' !== $atts['form_id'] ) { $shortcode .= ' form_id="' . $atts['form_id'] . '"'; diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index 5cb06727..cbf6983e 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -691,6 +691,10 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { } } + if ( ! is_user_logged_in() && isset( $args['widget'] ) && 1 === (int) $args['widget'] && 'profile' === $mode ) { + return; + } + // for profiles only if ( $mode == 'profile' && um_profile_id() ) { From 5c40cf7b0815877ff3cb99bd58eb1e8e12bf56b5 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Thu, 27 Apr 2023 12:51:57 +0300 Subject: [PATCH 15/25] - fix wrong user id in account block --- includes/core/class-account.php | 12 ++++++ includes/core/class-blocks.php | 2 +- includes/core/class-fields.php | 6 ++- includes/core/um-actions-account.php | 60 ++++++++++++++-------------- 4 files changed, 48 insertions(+), 32 deletions(-) diff --git a/includes/core/class-account.php b/includes/core/class-account.php index 95caa02c..a190b3c5 100644 --- a/includes/core/class-account.php +++ b/includes/core/class-account.php @@ -626,6 +626,9 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { + if ( 1 === (int) $shortcode_args['widget'] ) { + $data['widget'] = 1; + } $output .= UM()->fields()->edit_field( $key, $data ); } break; @@ -666,6 +669,9 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { + if ( 1 === (int) $shortcode_args['widget'] ) { + $data['widget'] = 1; + } $output .= UM()->fields()->edit_field( $key, $data ); } @@ -720,6 +726,9 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { + if ( 1 === (int) $shortcode_args['widget'] ) { + $data['widget'] = 1; + } $output .= UM()->fields()->edit_field( $key, $data ); } @@ -758,6 +767,9 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { + if ( 1 === (int) $shortcode_args['widget'] ) { + $data['widget'] = 1; + } $output .= UM()->fields()->edit_field( $key, $data ); } diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php index 0ca6c7ab..2720f033 100644 --- a/includes/core/class-blocks.php +++ b/includes/core/class-blocks.php @@ -139,7 +139,7 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { public function um_account_render( $atts ) { - $shortcode = '[ultimatemember_account'; + $shortcode = '[ultimatemember_account widget="1"'; if ( isset( $atts['tab'] ) && 'all' !== $atts['tab'] ) { $shortcode .= ' tab="' . $atts['tab'] . '"'; diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 01f51ada..313c1fca 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -2076,7 +2076,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) { function edit_field( $key, $data, $rule = false, $args = array() ) { global $_um_profile_id; - $output = ''; + if ( 1 === (int) $data['widget'] ) { + $_um_profile_id = get_current_user_id(); + } + + $output = ''; $disabled = ''; if ( empty( $_um_profile_id ) ) { $_um_profile_id = um_user( 'ID' ); diff --git a/includes/core/um-actions-account.php b/includes/core/um-actions-account.php index 84e099fd..44ef426d 100644 --- a/includes/core/um-actions-account.php +++ b/includes/core/um-actions-account.php @@ -593,20 +593,20 @@ function um_after_account_privacy( $args ) {
get_row( - "SELECT ID - FROM $wpdb->posts - WHERE post_author = $user_id AND - post_type = 'user_request' AND - post_name = 'export_personal_data' AND - post_status = 'request-completed' - ORDER BY ID DESC + "SELECT ID + FROM $wpdb->posts + WHERE post_author = $user_id AND + post_type = 'user_request' AND + post_name = 'export_personal_data' AND + post_status = 'request-completed' + ORDER BY ID DESC LIMIT 1", ARRAY_A ); if ( ! empty( $completed ) ) { - + $exports_url = wp_privacy_exports_url(); - + echo '

' . esc_html__( 'You could download your previous data:', 'ultimate-member' ) . '

'; echo '' . esc_html__( 'Download Personal Data', 'ultimate-member' ) . ''; echo '

' . esc_html__( 'You could send a new request for an export of personal your data.', 'ultimate-member' ) . '

'; @@ -614,13 +614,13 @@ function um_after_account_privacy( $args ) { } $pending = $wpdb->get_row( - "SELECT ID, post_status - FROM $wpdb->posts - WHERE post_author = $user_id AND - post_type = 'user_request' AND - post_name = 'export_personal_data' AND - post_status != 'request-completed' - ORDER BY ID DESC + "SELECT ID, post_status + FROM $wpdb->posts + WHERE post_author = $user_id AND + post_type = 'user_request' AND + post_name = 'export_personal_data' AND + post_status != 'request-completed' + ORDER BY ID DESC LIMIT 1", ARRAY_A ); @@ -670,13 +670,13 @@ function um_after_account_privacy( $args ) { get_row( - "SELECT ID - FROM $wpdb->posts - WHERE post_author = $user_id AND - post_type = 'user_request' AND - post_name = 'remove_personal_data' AND - post_status = 'request-completed' - ORDER BY ID DESC + "SELECT ID + FROM $wpdb->posts + WHERE post_author = $user_id AND + post_type = 'user_request' AND + post_name = 'remove_personal_data' AND + post_status = 'request-completed' + ORDER BY ID DESC LIMIT 1", ARRAY_A ); @@ -688,13 +688,13 @@ function um_after_account_privacy( $args ) { } $pending = $wpdb->get_row( - "SELECT ID, post_status - FROM $wpdb->posts - WHERE post_author = $user_id AND - post_type = 'user_request' AND - post_name = 'remove_personal_data' AND - post_status != 'request-completed' - ORDER BY ID DESC + "SELECT ID, post_status + FROM $wpdb->posts + WHERE post_author = $user_id AND + post_type = 'user_request' AND + post_name = 'remove_personal_data' AND + post_status != 'request-completed' + ORDER BY ID DESC LIMIT 1", ARRAY_A ); From a366a3733fb2e89d53cff728af848b0423e49d02 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Thu, 27 Apr 2023 14:34:13 +0300 Subject: [PATCH 16/25] - fix sanitize restriction message --- includes/core/class-access.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/core/class-access.php b/includes/core/class-access.php index 9e445ac5..3955da75 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -1196,7 +1196,7 @@ if ( ! class_exists( 'um\core\Access' ) ) { if ( $block['attrs']['um_message_type'] == '1' ) { $block_content = $default_message; } elseif ( $block['attrs']['um_message_type'] == '2' ) { - $block_content = $block['attrs']['um_message_content']; + $block_content = sanitize_textarea_field( $block['attrs']['um_message_content'] ); } } } else { From 81eddaa7ea827d8e8ffac61c69bd5d0fb9177231 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Mon, 1 May 2023 10:42:37 +0300 Subject: [PATCH 17/25] - fix checking attr widget --- includes/core/class-account.php | 8 ++++---- includes/core/class-fields.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/core/class-account.php b/includes/core/class-account.php index a190b3c5..29d6abf5 100644 --- a/includes/core/class-account.php +++ b/includes/core/class-account.php @@ -626,7 +626,7 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { - if ( 1 === (int) $shortcode_args['widget'] ) { + if ( isset( $shortcode_args['widget'] ) && 1 === (int) $shortcode_args['widget'] ) { $data['widget'] = 1; } $output .= UM()->fields()->edit_field( $key, $data ); @@ -669,7 +669,7 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { - if ( 1 === (int) $shortcode_args['widget'] ) { + if ( isset( $shortcode_args['widget'] ) && 1 === (int) $shortcode_args['widget'] ) { $data['widget'] = 1; } $output .= UM()->fields()->edit_field( $key, $data ); @@ -726,7 +726,7 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { - if ( 1 === (int) $shortcode_args['widget'] ) { + if ( isset( $shortcode_args['widget'] ) && 1 === (int) $shortcode_args['widget'] ) { $data['widget'] = 1; } $output .= UM()->fields()->edit_field( $key, $data ); @@ -767,7 +767,7 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { - if ( 1 === (int) $shortcode_args['widget'] ) { + if ( isset( $shortcode_args['widget'] ) && 1 === (int) $shortcode_args['widget'] ) { $data['widget'] = 1; } $output .= UM()->fields()->edit_field( $key, $data ); diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 313c1fca..e4ec89cd 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -2076,7 +2076,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { function edit_field( $key, $data, $rule = false, $args = array() ) { global $_um_profile_id; - if ( 1 === (int) $data['widget'] ) { + if ( isset( $data['widget'] ) && 1 === (int) $data['widget'] ) { $_um_profile_id = get_current_user_id(); } From bbc62dca09c481c89c90c4c884e2e46b7affce9c Mon Sep 17 00:00:00 2001 From: ashubawork Date: Mon, 1 May 2023 15:28:39 +0300 Subject: [PATCH 18/25] - fix sanitize restriction message --- includes/core/class-access.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/includes/core/class-access.php b/includes/core/class-access.php index 3955da75..660c291b 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -1220,7 +1220,13 @@ if ( ! class_exists( 'um\core\Access' ) ) { if ( $block['attrs']['um_message_type'] == '1' ) { $block_content = $default_message; } elseif ( $block['attrs']['um_message_type'] == '2' ) { - $block_content = $block['attrs']['um_message_content']; + $block_content = sanitize_textarea_field( $block['attrs']['um_message_content'] ); + + + + + + } } } @@ -1234,7 +1240,7 @@ if ( ! class_exists( 'um\core\Access' ) ) { if ( $block['attrs']['um_message_type'] == '1' ) { $block_content = $default_message; } elseif ( $block['attrs']['um_message_type'] == '2' ) { - $block_content = $block['attrs']['um_message_content']; + $block_content = sanitize_textarea_field( $block['attrs']['um_message_content'] ); } } } From fa88bb5f4c9a32d0272c9697e9fe2e652315c1aa Mon Sep 17 00:00:00 2001 From: ashubawork Date: Mon, 1 May 2023 16:03:45 +0300 Subject: [PATCH 19/25] - fix wrong code --- includes/core/class-access.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/includes/core/class-access.php b/includes/core/class-access.php index 660c291b..ac36a846 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -1221,12 +1221,6 @@ if ( ! class_exists( 'um\core\Access' ) ) { $block_content = $default_message; } elseif ( $block['attrs']['um_message_type'] == '2' ) { $block_content = sanitize_textarea_field( $block['attrs']['um_message_content'] ); - - - - - - } } } From f71a508284ef4d57c2bbfeedd4b86172db6c4b6d Mon Sep 17 00:00:00 2001 From: ashubawork Date: Tue, 2 May 2023 14:25:32 +0300 Subject: [PATCH 20/25] - fix um_message_content if not isset --- includes/core/class-access.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/core/class-access.php b/includes/core/class-access.php index ac36a846..67372e11 100644 --- a/includes/core/class-access.php +++ b/includes/core/class-access.php @@ -1196,7 +1196,7 @@ if ( ! class_exists( 'um\core\Access' ) ) { if ( $block['attrs']['um_message_type'] == '1' ) { $block_content = $default_message; } elseif ( $block['attrs']['um_message_type'] == '2' ) { - $block_content = sanitize_textarea_field( $block['attrs']['um_message_content'] ); + $block_content = isset( $block['attrs']['um_message_content'] ) ? sanitize_textarea_field( $block['attrs']['um_message_content'] ) : ''; } } } else { @@ -1220,7 +1220,7 @@ if ( ! class_exists( 'um\core\Access' ) ) { if ( $block['attrs']['um_message_type'] == '1' ) { $block_content = $default_message; } elseif ( $block['attrs']['um_message_type'] == '2' ) { - $block_content = sanitize_textarea_field( $block['attrs']['um_message_content'] ); + $block_content = isset( $block['attrs']['um_message_content'] ) ? sanitize_textarea_field( $block['attrs']['um_message_content'] ) : ''; } } } @@ -1234,7 +1234,7 @@ if ( ! class_exists( 'um\core\Access' ) ) { if ( $block['attrs']['um_message_type'] == '1' ) { $block_content = $default_message; } elseif ( $block['attrs']['um_message_type'] == '2' ) { - $block_content = sanitize_textarea_field( $block['attrs']['um_message_content'] ); + $block_content = isset( $block['attrs']['um_message_content'] ) ? sanitize_textarea_field( $block['attrs']['um_message_content'] ) : ''; } } } From 7b1dbe6bd19f8e22f98b2500b2bc3ac10448f116 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Wed, 3 May 2023 11:53:50 +0300 Subject: [PATCH 21/25] - fix form suffix for blocks in widget --- includes/core/class-fields.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index e4ec89cd..64bbd8e2 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -2073,11 +2073,14 @@ if ( ! class_exists( 'um\core\Fields' ) ) { * @return string|null * @throws \Exception */ - function edit_field( $key, $data, $rule = false, $args = array() ) { + public function edit_field( $key, $data, $rule = false, $args = array() ) { global $_um_profile_id; if ( isset( $data['widget'] ) && 1 === (int) $data['widget'] ) { $_um_profile_id = get_current_user_id(); + $form_suffix = ''; + } else { + $form_suffix = UM()->form()->form_suffix; } $output = ''; @@ -2348,7 +2351,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $field_name = $key . UM()->form()->form_suffix; + $field_name = $key . $form_suffix; $field_value = htmlspecialchars( $this->field_value( $key, $default, $data ) ); $output .= ' @@ -2385,7 +2388,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $field_name = $key . UM()->form()->form_suffix; + $field_name = $key . $form_suffix; $field_value = htmlspecialchars( $this->field_value( $key, $default, $data ) ); $output .= ' @@ -2422,7 +2425,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $field_name = $key . UM()->form()->form_suffix; + $field_name = $key . $form_suffix; $field_value = htmlspecialchars( $this->field_value( $key, $default, $data ) ); $output .= ' @@ -2467,7 +2470,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $number_limit .= ' max="' . esc_attr( $max ) . '" '; } - $output .= ' + $output .= ' '; @@ -2503,7 +2506,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $output .= ' + $output .= ' '; @@ -2535,7 +2538,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $output .= ' + $output .= ' '; @@ -2571,7 +2574,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $name = $key . UM()->form()->form_suffix; + $name = $key . $form_suffix; if ( $this->set_mode == 'password' && um_is_core_page( 'password-reset' ) ) { $name = $key; } @@ -2609,7 +2612,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $name = $key . UM()->form()->form_suffix; + $name = $key . $form_suffix; if ( $this->set_mode == 'password' && um_is_core_page( 'password-reset' ) ) { $name = $key; } @@ -2659,7 +2662,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $output .= ' + $output .= ' '; @@ -2702,7 +2705,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $value = date( 'Y/m/d', $unixtimestamp ); } - $output .= ' + $output .= ' '; @@ -2732,7 +2735,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } - $output .= ' + $output .= ' '; @@ -2873,7 +2876,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } else { $field_value = $this->field_value( $key, $default, $data ); } - $output .= ''; + $output .= ''; if ( isset( $data['label'] ) ) { $output .= $this->field_label( $label, $key, $data ); } @@ -2958,7 +2961,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { /* Single File Upload */ case 'file': $output .= '
get_atts( $key, $classes, $conditional, $data ) . ' data-mode="' . esc_attr( $this->set_mode ) . '" data-upload-label="' . ( ! empty( $data['button_text'] ) ? esc_attr( $data['button_text'] ) : esc_attr__( 'Upload', 'ultimate-member' ) ) . '">'; - $output .= ''; + $output .= ''; if ( isset( $data['label'] ) ) { $output .= $this->field_label( $label, $key, $data ); } From 35f9aac031a231595a03928c3b37a6d5b14be0b6 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Mon, 8 May 2023 19:50:01 +0300 Subject: [PATCH 22/25] - not show account and profile on profile and account pages --- includes/core/class-account.php | 16 ++++++++-------- includes/core/class-blocks.php | 13 +++++++++++-- includes/core/class-fields.php | 2 +- includes/core/class-shortcodes.php | 4 ---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/includes/core/class-account.php b/includes/core/class-account.php index 29d6abf5..446a5cb2 100644 --- a/includes/core/class-account.php +++ b/includes/core/class-account.php @@ -626,8 +626,8 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { - if ( isset( $shortcode_args['widget'] ) && 1 === (int) $shortcode_args['widget'] ) { - $data['widget'] = 1; + if ( isset( $shortcode_args['is_block'] ) && 1 === (int) $shortcode_args['is_block'] ) { + $data['is_block'] = 1; } $output .= UM()->fields()->edit_field( $key, $data ); } @@ -669,8 +669,8 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { - if ( isset( $shortcode_args['widget'] ) && 1 === (int) $shortcode_args['widget'] ) { - $data['widget'] = 1; + if ( isset( $shortcode_args['is_block'] ) && 1 === (int) $shortcode_args['is_block'] ) { + $data['is_block'] = 1; } $output .= UM()->fields()->edit_field( $key, $data ); } @@ -726,8 +726,8 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { - if ( isset( $shortcode_args['widget'] ) && 1 === (int) $shortcode_args['widget'] ) { - $data['widget'] = 1; + if ( isset( $shortcode_args['is_block'] ) && 1 === (int) $shortcode_args['is_block'] ) { + $data['is_block'] = 1; } $output .= UM()->fields()->edit_field( $key, $data ); } @@ -767,8 +767,8 @@ if ( ! class_exists( 'um\core\Account' ) ) { $this->init_displayed_fields( $fields, $id ); foreach ( $fields as $key => $data ) { - if ( isset( $shortcode_args['widget'] ) && 1 === (int) $shortcode_args['widget'] ) { - $data['widget'] = 1; + if ( isset( $shortcode_args['is_block'] ) && 1 === (int) $shortcode_args['is_block'] ) { + $data['is_block'] = 1; } $output .= UM()->fields()->edit_field( $key, $data ); } diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php index 2720f033..3bbe6048 100644 --- a/includes/core/class-blocks.php +++ b/includes/core/class-blocks.php @@ -119,7 +119,13 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { public function um_forms_render( $atts ) { - $shortcode = '[ultimatemember widget="1"'; + 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' ) ) ) { + return ''; + } + } + $shortcode = '[ultimatemember'; if ( isset( $atts['form_id'] ) && '' !== $atts['form_id'] ) { $shortcode .= ' form_id="' . $atts['form_id'] . '"'; @@ -139,7 +145,10 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { public function um_account_render( $atts ) { - $shortcode = '[ultimatemember_account widget="1"'; + if ( um_is_core_page( 'account' ) || um_is_core_page( 'user' ) ) { + return ''; + } + $shortcode = '[ultimatemember_account is_block="1"'; if ( isset( $atts['tab'] ) && 'all' !== $atts['tab'] ) { $shortcode .= ' tab="' . $atts['tab'] . '"'; diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 64bbd8e2..d88721b9 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -2076,7 +2076,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { public function edit_field( $key, $data, $rule = false, $args = array() ) { global $_um_profile_id; - if ( isset( $data['widget'] ) && 1 === (int) $data['widget'] ) { + if ( isset( $data['is_block'] ) && 1 === (int) $data['is_block'] ) { $_um_profile_id = get_current_user_id(); $form_suffix = ''; } else { diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index cbf6983e..5cb06727 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -691,10 +691,6 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { } } - if ( ! is_user_logged_in() && isset( $args['widget'] ) && 1 === (int) $args['widget'] && 'profile' === $mode ) { - return; - } - // for profiles only if ( $mode == 'profile' && um_profile_id() ) { From 2c222e34b8d573f6dccdeefea513e314c0419d40 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Mon, 8 May 2023 21:28:22 +0300 Subject: [PATCH 23/25] - remove wrong code --- includes/core/class-fields.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index d88721b9..2e45d570 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -2077,8 +2077,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { global $_um_profile_id; if ( isset( $data['is_block'] ) && 1 === (int) $data['is_block'] ) { - $_um_profile_id = get_current_user_id(); - $form_suffix = ''; + $form_suffix = ''; } else { $form_suffix = UM()->form()->form_suffix; } From 0c7bfbf9d707cf9261267fcbb8d49feeca0ab28e Mon Sep 17 00:00:00 2001 From: ashubawork Date: Tue, 9 May 2023 13:30:39 +0300 Subject: [PATCH 24/25] - fix profile block for guests --- includes/core/class-blocks.php | 2 +- includes/core/class-shortcodes.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/core/class-blocks.php b/includes/core/class-blocks.php index 3bbe6048..583743fb 100644 --- a/includes/core/class-blocks.php +++ b/includes/core/class-blocks.php @@ -125,7 +125,7 @@ if ( ! class_exists( 'um\core\Blocks' ) ) { return ''; } } - $shortcode = '[ultimatemember'; + $shortcode = '[ultimatemember is_block="1"'; if ( isset( $atts['form_id'] ) && '' !== $atts['form_id'] ) { $shortcode .= ' form_id="' . $atts['form_id'] . '"'; diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index 5cb06727..6492314b 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -691,6 +691,10 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { } } + if ( ! is_user_logged_in() && isset( $args['is_block'] ) && 1 === (int) $args['is_block'] && 'profile' === $mode ) { + return; + } + // for profiles only if ( $mode == 'profile' && um_profile_id() ) { From 7cfa39f8935afb15885a697873d46e93362fa21e Mon Sep 17 00:00:00 2001 From: ashubawork Date: Tue, 9 May 2023 15:42:15 +0300 Subject: [PATCH 25/25] - fix register block fields for guests --- includes/core/class-fields.php | 3 +++ templates/register.php | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 2e45d570..b83d5af7 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -2087,6 +2087,9 @@ if ( ! class_exists( 'um\core\Fields' ) ) { if ( empty( $_um_profile_id ) ) { $_um_profile_id = um_user( 'ID' ); } + if ( ! is_user_logged_in() ) { + $_um_profile_id = 0; + } // get whole field data if ( isset( $data ) && is_array( $data ) ) { diff --git a/templates/register.php b/templates/register.php index c0c445b3..ed559be4 100644 --- a/templates/register.php +++ b/templates/register.php @@ -136,9 +136,9 @@ if ( ! is_user_logged_in() ) { * ?> */ do_action( 'um_after_form', $args ); ?> - +
- \ No newline at end of file +