From 61d99135f428520464ab65636f5b2574df95891a Mon Sep 17 00:00:00 2001 From: ashubawork Date: Wed, 29 Mar 2023 11:48:51 +0300 Subject: [PATCH 01/66] - 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/66] - 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/66] - 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/66] - 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/66] - 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/66] - 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/66] - 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/66] - 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/66] - 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/66] - 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 b60f2aced31d79093c11fb39523abd6fa44ce08e Mon Sep 17 00:00:00 2001 From: ashubawork Date: Fri, 7 Apr 2023 09:51:31 +0300 Subject: [PATCH 11/66] - add settings tab --- includes/admin/core/class-admin-settings.php | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index 176b29ba..e452c81a 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -64,6 +64,9 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { add_filter( 'um_settings_section_install_info__content', array( $this, 'settings_install_info_tab' ), 10, 2 ); + //custom content for licenses tab + add_filter( 'um_settings_section_override_templates__content', array( $this, 'settings_override_templates_tab' ), 10, 2 ); + add_filter( 'um_settings_structure', array( $this, 'sorting_licenses_options' ), 9999, 1 ); @@ -1839,6 +1842,14 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { ), ), ), + 'override_templates' => array( + 'title' => __( 'Override templates', 'ultimate-member' ), + 'fields' => array( + array( + 'type' => 'override_templates', + ), + ), + ), ) ); @@ -3008,6 +3019,21 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { } + public function settings_override_templates_tab( $html, $section_fields ) { + ob_start(); + ?> +

+ + + +

+ Date: Fri, 7 Apr 2023 11:33:22 +0300 Subject: [PATCH 12/66] - basic list of override templates --- includes/admin/core/class-admin-settings.php | 99 ++++++++++++++++++++ templates/message.php | 9 +- templates/profile.php | 6 +- templates/searchform.php | 8 +- 4 files changed, 117 insertions(+), 5 deletions(-) diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index e452c81a..c448377c 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -3020,6 +3020,46 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { public function settings_override_templates_tab( $html, $section_fields ) { + $outdated_files = array(); + $scan_files = $this->scan_template_files( um_path . '/templates/' ); + foreach ( $scan_files as $key => $file ) { + if ( ! str_contains( $file, 'email/' ) ) { + $located = apply_filters( 'um_located_template', $file, get_stylesheet_directory() . '/ultimate-member/' ); + if ( file_exists( $located ) ) { + $theme_file = $located; + } elseif ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/' . $file ) ) { + $theme_file = get_stylesheet_directory() . '/ultimate-member/templates/' . $file; + } else { + $theme_file = false; + } + if ( ! empty( $theme_file ) ) { + $core_file = $file; + + $core_version = $this->get_file_version( um_path . '/templates/' . $core_file ); + $theme_version = $this->get_file_version( $theme_file ); + + $status = esc_html__( 'Theme version up to date', 'ultimate-member' ); + $status_code = 1; + if ( version_compare( $theme_version, $core_version, '<' ) ) { + $status = esc_html__( 'Theme version is out of date', 'ultimate-member' ); + $status_code = 0; + } + if ( '' === $theme_version ) { + $status = esc_html__( 'Theme version is empty', 'ultimate-member' ); + $status_code = 0; + } + $outdated_files[] = array( + 'core_version' => $core_version, + 'theme_version' => $theme_version, + 'core_file' => stristr( um_path . 'templates/' . $core_file, 'wp-content' ), + 'theme_file' => stristr( $theme_file, 'wp-content' ), + 'status' => $status, + 'status_code' => $status_code, + ); + } + } + } + ob_start(); ?>

@@ -3034,6 +3074,65 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { } + /** + * Scan the template files. + * + * @param string $template_path Path to the template directory. + * @return array + */ + public static function scan_template_files( $template_path ) { + $files = @scandir( $template_path ); // @codingStandardsIgnoreLine. + $result = array(); + + if ( ! empty( $files ) ) { + + foreach ( $files as $key => $value ) { + + if ( ! in_array( $value, array( '.', '..' ), true ) ) { + + if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) { + $sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value ); + foreach ( $sub_files as $sub_file ) { + $result[] = $value . DIRECTORY_SEPARATOR . $sub_file; + } + } else { + $result[] = $value; + } + } + } + } + return $result; + } + + + public static function get_file_version( $file ) { + + // Avoid notices if file does not exist. + if ( ! file_exists( $file ) ) { + return ''; + } + + // We don't need to write to the file, so just open for reading. + $fp = fopen( $file, 'r' ); // @codingStandardsIgnoreLine. + + // Pull only the first 8kiB of the file in. + $file_data = fread( $fp, 8192 ); // @codingStandardsIgnoreLine. + + // PHP will close file handle, but we are good citizens. + fclose( $fp ); // @codingStandardsIgnoreLine. + + // Make sure we catch CR-only line endings. + $file_data = str_replace( "\r", "\n", $file_data ); + $version = ''; + + if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) { + $version = _cleanup_header_comment( $match[1] ); + } + + return $version; + } + + /** * @param $html * @param $section_fields diff --git a/templates/message.php b/templates/message.php index 58572f36..b2d6c5d4 100644 --- a/templates/message.php +++ b/templates/message.php @@ -1,4 +1,9 @@ - +

@@ -8,4 +13,4 @@ printf( __( '%s', 'ultimate-member' ), $this->custom_message ); ?>
- \ No newline at end of file + diff --git a/templates/profile.php b/templates/profile.php index 7ca2fb9e..6c85989c 100644 --- a/templates/profile.php +++ b/templates/profile.php @@ -1,4 +1,8 @@ - +
diff --git a/templates/searchform.php b/templates/searchform.php index 7761c452..0e08d9a7 100644 --- a/templates/searchform.php +++ b/templates/searchform.php @@ -1,4 +1,8 @@ - +
@@ -9,4 +13,4 @@
-
\ No newline at end of file + From 00dd3d6b9fbce758ffb6d21edd1b3079fd2d074d Mon Sep 17 00:00:00 2001 From: ashubawork Date: Fri, 7 Apr 2023 12:45:34 +0300 Subject: [PATCH 13/66] - list of templates --- .../admin/assets/css/um-admin-settings.css | 16 +- includes/admin/core/class-admin-settings.php | 29 +- .../version-template-list-table.php | 322 ++++++++++++++++++ 3 files changed, 351 insertions(+), 16 deletions(-) create mode 100644 includes/admin/core/list-tables/version-template-list-table.php diff --git a/includes/admin/assets/css/um-admin-settings.css b/includes/admin/assets/css/um-admin-settings.css index 0f8d78df..1e159673 100644 --- a/includes/admin/assets/css/um-admin-settings.css +++ b/includes/admin/assets/css/um-admin-settings.css @@ -46,6 +46,20 @@ text-align: center; } +.column-core_version { + width: 100px; + text-align: center; +} + +.column-theme_version { + width: 100px; + text-align: center; +} + +.column-status { + width: 260px; +} + th.column-email.column-primary { padding-left: 48px; } @@ -243,4 +257,4 @@ th.column-email.column-primary { .um_setting_ajax_button_response.complete { color:darkgreen; font-style: italic; -} \ No newline at end of file +} diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index c448377c..441bdbcd 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -3020,14 +3020,23 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { public function settings_override_templates_tab( $html, $section_fields ) { + ?> +

+ + + +

+ scan_template_files( um_path . '/templates/' ); foreach ( $scan_files as $key => $file ) { if ( ! str_contains( $file, 'email/' ) ) { - $located = apply_filters( 'um_located_template', $file, get_stylesheet_directory() . '/ultimate-member/' ); - if ( file_exists( $located ) ) { - $theme_file = $located; - } elseif ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/' . $file ) ) { + if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/' . $file ) ) { $theme_file = get_stylesheet_directory() . '/ultimate-member/templates/' . $file; } else { $theme_file = false; @@ -3060,17 +3069,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { } } - ob_start(); - ?> -

- - - -

- __( 'item', 'ultimate-member' ), + 'plural' => __( 'items', 'ultimate-member' ), + 'ajax' => false, + ) + ); + + $this->no_items_message = $args['plural'] . ' ' . __( 'not found.', 'ultimate-member' ); + + parent::__construct( $args ); + } + + + /** + * @param callable $name + * @param array $arguments + * + * @return mixed + */ + public function __call( $name, $arguments ) { + return call_user_func_array( array( $this, $name ), $arguments ); + } + + + /** + * + */ + public function prepare_items() { + $columns = $this->get_columns(); + $hidden = array(); + $sortable = $this->get_sortable_columns(); + $this->_column_headers = array( $columns, $hidden, $sortable ); + } + + + /** + * @param object $item + * @param string $column_name + * + * @return string + */ + public function column_default( $item, $column_name ) { + if ( isset( $item[ $column_name ] ) ) { + return $item[ $column_name ]; + } else { + return ''; + } + } + + + /** + * + */ + public function no_items() { + echo $this->no_items_message; + } + + + /** + * @param array $args + * + * @return $this + */ + public function set_sortable_columns( $args = array() ) { + $return_args = array(); + foreach ( $args as $k=>$val ) { + if ( is_numeric( $k ) ) { + $return_args[ $val ] = array( $val, $val == $this->default_sorting_field ); + } elseif( is_string( $k ) ) { + $return_args[ $k ] = array( $val, $k == $this->default_sorting_field ); + } else { + continue; + } + } + $this->sortable_columns = $return_args; + return $this; + } + + + /** + * @return array + */ + public function get_sortable_columns() { + return $this->sortable_columns; + } + + + /** + * @param array $args + * + * @return $this + */ + public function set_columns( $args = array() ) { + if ( count( $this->bulk_actions ) ) { + $args = array_merge( array( 'cb' => '' ), $args ); + } + $this->columns = $args; + + return $this; + } + + + /** + * @return array + */ + public function get_columns() { + return $this->columns; + } + + + /** + * @param array $args + * + * @return $this + */ + public function set_actions( $args = array() ) { + $this->actions = $args; + return $this; + } + + + /** + * @return array + */ + public function get_actions() { + return $this->actions; + } + + + /** + * @param array $args + * + * @return $this + */ + public function set_bulk_actions( $args = array() ) { + $this->bulk_actions = $args; + return $this; + } + + + /** + * @return array + */ + public function get_bulk_actions() { + return $this->bulk_actions; + } + + + /** + * @param $item + * + * @return string + */ + public function column_template( $item ) { + $output = esc_html__( 'Core path - ', 'ultimate-member' ); + $output .= $item['core_file'] . '
'; + $output .= esc_html__( 'Theme path - ', 'ultimate-member' ); + $output .= $item['theme_file']; + + return $output; + } + + + /** + * @param $item + * + * @return string + */ + public function column_core_version( $item ) { + return $item['core_version']; + } + + + /** + * @param $item + * + * @return string + */ + public function column_theme_version( $item ) { + $theme_version = $item['theme_version'] ? $item['theme_version'] : '-'; + + return $theme_version; + } + + + /** + * @param $item + * + * @return string + */ + public function column_status( $item ) { + $icon = 1 === $item['status_code'] ? 'um-notification-is-active dashicons-yes' : 'dashicons-no-alt'; + $text = $item['status'] . ' '; + + return $text; + } + + + /** + * @param array $attr + */ + public function wpc_set_pagination_args( $attr = array() ) { + $this->set_pagination_args( $attr ); + } +} + +$ListTable = new UM_Versions_List_Table( + array( + 'singular' => __( 'Template', 'ultimate-member' ), + 'plural' => __( 'Templates', 'ultimate-member' ), + 'ajax' => false, + ) +); + +$per_page = 999; +$paged = $ListTable->get_pagenum(); + +/** + * UM hook + * + * @type filter + * @title um_versions_templates_columns + * @description Version Templates List Table columns + * @input_vars + * [{"var":"$columns","type":"array","desc":"Columns"}] + * @change_log + * ["Since: 2.0"] + * @usage add_filter( 'um_versions_templates_columns', 'function_name', 10, 1 ); + * @example + * + */ +$columns = apply_filters( + 'um_versions_templates_columns', + array( + 'template' => __( 'Template', 'ultimate-member' ), + 'core_version' => __( 'Core version', 'ultimate-member' ), + 'theme_version' => __( 'Theme version', 'ultimate-member' ), + 'status' => __( 'Status', 'ultimate-member' ), + ) +); + +$ListTable->set_columns( $columns ); + +$templates = UM()->admin_settings()->get_override_templates(); + +$ListTable->prepare_items(); +$ListTable->items = array_slice( $templates, ( $paged - 1 ) * $per_page, $per_page ); +$ListTable->wpc_set_pagination_args( + array( + 'total_items' => count( $templates ), + 'per_page' => $per_page, + ) +); ?> + +
+ + + + display(); ?> +
From 1a219ebb24326b25f1389833fe0d8341a900019b Mon Sep 17 00:00:00 2001 From: Nikita Sinelnikov Date: Fri, 7 Apr 2023 13:24:01 +0300 Subject: [PATCH 14/66] - fixed https://github.com/ultimatemember/woocommerce/issues/12 --- includes/admin/core/class-admin-settings.php | 2 +- ultimate-member.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index 176b29ba..d7beb454 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -440,7 +440,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { $duplicates = array(); $taxonomies_options = array(); $exclude_taxonomies = UM()->excluded_taxonomies(); - $all_taxonomies = get_taxonomies( array( 'public' => true ), 'objects' ); + $all_taxonomies = get_taxonomies( array( 'public' => true, 'show_ui' => true ), 'objects' ); foreach ( $all_taxonomies as $key => $taxonomy ) { if ( in_array( $key, $exclude_taxonomies, true ) ) { continue; diff --git a/ultimate-member.php b/ultimate-member.php index 28d9b9c7..233b610f 100644 --- a/ultimate-member.php +++ b/ultimate-member.php @@ -3,7 +3,7 @@ Plugin Name: Ultimate Member Plugin URI: http://ultimatemember.com/ Description: The easiest way to create powerful online communities and beautiful user profiles with WordPress -Version: 2.6.0 +Version: 2.6.1-alpha Author: Ultimate Member Author URI: http://ultimatemember.com/ Text Domain: ultimate-member From 42337c440ac1f71a53c53b5eaac6bc2e5aca0b89 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Mon, 10 Apr 2023 17:46:25 +0300 Subject: [PATCH 15/66] - check versions, add transient --- includes/admin/class-admin.php | 28 ++++++++++++ includes/admin/core/class-admin-notices.php | 27 +++++++++++ includes/admin/core/class-admin-settings.php | 45 ++++++++++++++++--- .../version-template-list-table.php | 2 +- 4 files changed, 96 insertions(+), 6 deletions(-) diff --git a/includes/admin/class-admin.php b/includes/admin/class-admin.php index c6cf0c80..626d35d4 100644 --- a/includes/admin/class-admin.php +++ b/includes/admin/class-admin.php @@ -80,6 +80,7 @@ if ( ! class_exists( 'um\admin\Admin' ) ) { add_action( 'um_admin_do_action__um_can_register_notice', array( &$this, 'um_hide_notice' ) ); add_action( 'um_admin_do_action__um_hide_exif_notice', array( &$this, 'um_hide_notice' ) ); add_action( 'um_admin_do_action__user_action', array( &$this, 'user_action' ) ); + add_action( 'um_admin_do_action__check_version', array( &$this, 'check_version' ) ); add_action( 'um_admin_do_action__install_core_pages', array( &$this, 'install_core_pages' ) ); @@ -1869,6 +1870,33 @@ if ( ! class_exists( 'um\admin\Admin' ) ) { } + public function check_version( $action ) { + $templates = UM()->admin_settings()->get_override_templates( true ); + $out_date = false; + + foreach ( $templates as $template ) { + if ( 0 === $template['status_code'] ) { + $out_date = true; + break; + } + } + + if ( false === $out_date ) { + delete_option( 'um_template_version' ); + } + + $url = add_query_arg( + array( + 'page' => 'um_options', + 'tab' => 'override_templates', + ), + admin_url( 'admin.php' ) + ); + wp_safe_redirect( $url ); + exit; + } + + /** * Add any custom links to plugin page * diff --git a/includes/admin/core/class-admin-notices.php b/includes/admin/core/class-admin-notices.php index 7b335fc5..34745cd8 100644 --- a/includes/admin/core/class-admin-notices.php +++ b/includes/admin/core/class-admin-notices.php @@ -52,6 +52,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) { $this->extensions_page(); + $this->template_version(); + // removed for now to avoid the bad reviews //$this->reviews_notice(); @@ -714,6 +716,31 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) { } + public function template_version() { + if ( true === (bool) get_option( 'um_template_version' ) ) { + $link = get_admin_url( null, 'admin.php?page=um_options&tab=override_templates' ); + ob_start(); + ?> + +

+ override templates status page and update templates', 'ultimate-member' ), $link ); ?> +

+ + admin()->notices()->add_notice( + 'um_private_content_notice', + array( + 'class' => 'error', + 'message' => $message, + 'dismissible' => false, + ), + 10 + ); + } + } + + function dismiss_notice() { UM()->admin()->check_ajax_nonce(); diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index 441bdbcd..e72982e2 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -64,7 +64,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { add_filter( 'um_settings_section_install_info__content', array( $this, 'settings_install_info_tab' ), 10, 2 ); - //custom content for licenses tab + //custom content for override templates tab + add_action( 'plugins_loaded', array( $this, 'um_check_template_version' ), 10 ); add_filter( 'um_settings_section_override_templates__content', array( $this, 'settings_override_templates_tab' ), 10, 2 ); @@ -3019,11 +3020,34 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { } + public function um_check_template_version() { + $um_check_version = get_transient( 'um_check_template_versions' ); + if ( false === $um_check_version ) { + $this->get_override_templates(); + } + } + + public function settings_override_templates_tab( $html, $section_fields ) { + $um_check_version = get_transient( 'um_check_template_versions' ); ?> +

+ '; + echo esc_html__('You could re-checked changes manually', 'ultimate-member'); + } + ?> +

- + + +

+

+ +

scan_template_files( um_path . '/templates/' ); + $out_date = false; + set_transient( 'um_check_template_versions', current_time('d/m/Y H:i' ), 12 * HOUR_IN_SECONDS ); foreach ( $scan_files as $key => $file ) { if ( ! str_contains( $file, 'email/' ) ) { if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/' . $file ) ) { @@ -3057,6 +3083,10 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { $status = esc_html__( 'Theme version is empty', 'ultimate-member' ); $status_code = 0; } + if ( 0 === $status_code ) { + $out_date = true; + update_option( 'um_template_version', 1 ); + } $outdated_files[] = array( 'core_version' => $core_version, 'theme_version' => $theme_version, @@ -3068,8 +3098,13 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { } } } - - return $outdated_files; + if ( false === $out_date ) { + delete_option( 'um_template_version' ); + } + update_option( 'um_template_statuses', $outdated_files ); + if ( true === $get_list ) { + return $outdated_files; + } } diff --git a/includes/admin/core/list-tables/version-template-list-table.php b/includes/admin/core/list-tables/version-template-list-table.php index 1eb41c65..dda0f3e8 100644 --- a/includes/admin/core/list-tables/version-template-list-table.php +++ b/includes/admin/core/list-tables/version-template-list-table.php @@ -303,7 +303,7 @@ $columns = apply_filters( $ListTable->set_columns( $columns ); -$templates = UM()->admin_settings()->get_override_templates(); +$templates = get_option( 'um_template_statuses' ) ? get_option( 'um_template_statuses' ) : array(); $ListTable->prepare_items(); $ListTable->items = array_slice( $templates, ( $paged - 1 ) * $per_page, $per_page ); From 879290aa908c1de45da189799326287cc83e95c6 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Tue, 11 Apr 2023 09:13:36 +0300 Subject: [PATCH 16/66] - add templates versions --- templates/account.php | 22 +++++++++++++--------- templates/gdpr-register.php | 8 ++++++-- templates/login-to-view.php | 8 ++++++-- templates/login.php | 8 ++++++-- templates/logout.php | 18 +++++++++++------- templates/members-grid.php | 6 +++++- templates/members-header.php | 8 ++++++-- templates/members-list.php | 6 +++++- templates/members-pagination.php | 8 ++++++-- templates/members.php | 6 +++++- templates/message.php | 3 +-- templates/modal/um_upload_single.php | 8 ++++++-- templates/modal/um_view_photo.php | 8 ++++++-- templates/password-change.php | 6 +++++- templates/password-reset.php | 6 +++++- templates/profile.php | 2 +- templates/profile/comments-single.php | 8 ++++++-- templates/profile/comments.php | 8 ++++++-- templates/profile/posts-single.php | 6 +++++- templates/profile/posts.php | 8 ++++++-- templates/register.php | 10 +++++++--- templates/restricted-blog.php | 3 +++ templates/restricted-taxonomy.php | 8 ++++++-- templates/searchform.php | 2 +- 24 files changed, 133 insertions(+), 51 deletions(-) diff --git a/templates/account.php b/templates/account.php index 143dc14d..f252d580 100644 --- a/templates/account.php +++ b/templates/account.php @@ -1,11 +1,15 @@ - +
- +
- +
- + \ No newline at end of file +
diff --git a/templates/gdpr-register.php b/templates/gdpr-register.php index 2b175fe1..11248b6b 100644 --- a/templates/gdpr-register.php +++ b/templates/gdpr-register.php @@ -1,4 +1,8 @@ - +
@@ -48,4 +52,4 @@
- \ No newline at end of file + diff --git a/templates/login-to-view.php b/templates/login-to-view.php index 432f1b82..ad253dad 100644 --- a/templates/login-to-view.php +++ b/templates/login-to-view.php @@ -1,7 +1,11 @@ - +
-
\ No newline at end of file + diff --git a/templates/login.php b/templates/login.php index a72c1620..a03f9e78 100644 --- a/templates/login.php +++ b/templates/login.php @@ -1,4 +1,8 @@ - +
@@ -137,4 +141,4 @@
- \ No newline at end of file + diff --git a/templates/logout.php b/templates/logout.php index 6239943f..f51bb105 100644 --- a/templates/logout.php +++ b/templates/logout.php @@ -1,4 +1,8 @@ - +
@@ -11,9 +15,9 @@
- +
- + */ do_action( 'um_logout_after_user_welcome', $args ); ?> - + - +
    - + */ do_action( 'um_logout_user_links', $args ); ?> - +
diff --git a/templates/members-grid.php b/templates/members-grid.php index 125e1564..8f55be79 100644 --- a/templates/members-grid.php +++ b/templates/members-grid.php @@ -1,4 +1,8 @@ - diff --git a/templates/members-header.php b/templates/members-header.php index a7b186ea..8e5506cb 100644 --- a/templates/members-header.php +++ b/templates/members-header.php @@ -1,4 +1,8 @@ - + \ No newline at end of file + diff --git a/templates/members-list.php b/templates/members-list.php index 09ab2d75..67541620 100644 --- a/templates/members-list.php +++ b/templates/members-list.php @@ -1,4 +1,8 @@ - diff --git a/templates/members-pagination.php b/templates/members-pagination.php index b719824c..217feebc 100644 --- a/templates/members-pagination.php +++ b/templates/members-pagination.php @@ -1,4 +1,8 @@ - + \ No newline at end of file + diff --git a/templates/members.php b/templates/members.php index 3a215ade..f1bdb161 100644 --- a/templates/members.php +++ b/templates/members.php @@ -1,4 +1,8 @@ -
diff --git a/templates/modal/um_upload_single.php b/templates/modal/um_upload_single.php index 5fe2bc35..8692c1e0 100644 --- a/templates/modal/um_upload_single.php +++ b/templates/modal/um_upload_single.php @@ -1,3 +1,7 @@ - + - \ No newline at end of file + diff --git a/templates/modal/um_view_photo.php b/templates/modal/um_view_photo.php index d24dbc23..ee373df1 100644 --- a/templates/modal/um_view_photo.php +++ b/templates/modal/um_view_photo.php @@ -1,4 +1,8 @@ - + -
\ No newline at end of file + diff --git a/templates/password-change.php b/templates/password-change.php index 414cb6e0..90e85034 100644 --- a/templates/password-change.php +++ b/templates/password-change.php @@ -1,4 +1,8 @@ - +
diff --git a/templates/password-reset.php b/templates/password-reset.php index 9b706317..62d222cb 100644 --- a/templates/password-reset.php +++ b/templates/password-reset.php @@ -1,4 +1,8 @@ - diff --git a/templates/profile.php b/templates/profile.php index 6c85989c..333359bd 100644 --- a/templates/profile.php +++ b/templates/profile.php @@ -1,6 +1,6 @@ diff --git a/templates/profile/comments-single.php b/templates/profile/comments-single.php index a2b0a395..31bf1ef5 100644 --- a/templates/profile/comments-single.php +++ b/templates/profile/comments-single.php @@ -1,4 +1,8 @@ -comment_post_ID ), $comment ); $link = apply_filters( 'um_user_profile_comment_url', get_permalink( $comment->comment_post_ID ), $comment ); ?> @@ -13,4 +17,4 @@ $link = apply_filters( 'um_user_profile_comment_url', get_permalink( $comment->c
%2$s','ultimate-member' ), $link, $comment_title ); ?>
-
\ No newline at end of file + diff --git a/templates/profile/comments.php b/templates/profile/comments.php index 4b8b3aaa..d73d5366 100644 --- a/templates/profile/comments.php +++ b/templates/profile/comments.php @@ -1,4 +1,8 @@ - +
-
\ No newline at end of file + diff --git a/templates/restricted-blog.php b/templates/restricted-blog.php index 5f682323..afa1c9b4 100644 --- a/templates/restricted-blog.php +++ b/templates/restricted-blog.php @@ -1,4 +1,7 @@ @@ -51,4 +55,4 @@ get_header(); ?> - From 871c0412b4918087fd392a974c984d7e530c0485 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Tue, 11 Apr 2023 16:25:25 +0300 Subject: [PATCH 17/66] - add comments to templates --- includes/admin/class-admin.php | 5 +++++ includes/admin/core/class-admin-notices.php | 8 +++++++- includes/admin/core/class-admin-settings.php | 18 ++++++++++++++++- templates/account.php | 14 ++++++++++++- templates/gdpr-register.php | 10 ++++++++++ templates/login-to-view.php | 12 ++++++++++- templates/login.php | 14 ++++++++++++- templates/logout.php | 14 ++++++++++++- templates/members-grid.php | 21 +++++++++++++++++++- templates/members-header.php | 10 +++++++++- templates/members-list.php | 17 ++++++++++++++++ templates/members-pagination.php | 10 +++++++++- templates/members.php | 12 ++++++++++- templates/message.php | 13 +++++++++++- templates/modal/um_upload_single.php | 8 +++++++- templates/modal/um_view_photo.php | 8 +++++++- templates/password-change.php | 15 +++++++++++++- templates/password-reset.php | 10 ++++++++++ templates/profile.php | 14 ++++++++++++- templates/profile/comments-single.php | 12 ++++++++++- templates/profile/comments.php | 14 ++++++++++++- templates/profile/posts-single.php | 12 ++++++++++- templates/profile/posts.php | 13 +++++++++++- templates/register.php | 14 ++++++++++++- templates/restricted-blog.php | 6 ++++++ templates/restricted-taxonomy.php | 10 +++++++++- templates/searchform.php | 14 ++++++++++++- ultimate-member.php | 2 +- 28 files changed, 307 insertions(+), 23 deletions(-) diff --git a/includes/admin/class-admin.php b/includes/admin/class-admin.php index 626d35d4..5db21566 100644 --- a/includes/admin/class-admin.php +++ b/includes/admin/class-admin.php @@ -1870,6 +1870,11 @@ if ( ! class_exists( 'um\admin\Admin' ) ) { } + /** + * Manual check templates versions + * + * @param $action + */ public function check_version( $action ) { $templates = UM()->admin_settings()->get_override_templates( true ); $out_date = false; diff --git a/includes/admin/core/class-admin-notices.php b/includes/admin/core/class-admin-notices.php index 34745cd8..dd4277d3 100644 --- a/includes/admin/core/class-admin-notices.php +++ b/includes/admin/core/class-admin-notices.php @@ -716,6 +716,9 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) { } + /** + * Check Templates Versions notice + */ public function template_version() { if ( true === (bool) get_option( 'um_template_version' ) ) { $link = get_admin_url( null, 'admin.php?page=um_options&tab=override_templates' ); @@ -723,7 +726,10 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) { ?>

- override templates status page and update templates', 'ultimate-member' ), $link ); ?> + override templates status page and update templates', 'ultimate-member' ), $link ), UM()->get_allowed_html( 'admin_notice' ) ); + ?>

@@ -3055,11 +3061,16 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { } + /** + * @param $get_list boolean + * + * @return array + */ public function get_override_templates( $get_list = false ) { $outdated_files = array(); $scan_files = $this->scan_template_files( um_path . '/templates/' ); $out_date = false; - set_transient( 'um_check_template_versions', current_time('d/m/Y H:i' ), 12 * HOUR_IN_SECONDS ); + set_transient( 'um_check_template_versions', current_time( 'd/m/Y H:i' ), 12 * HOUR_IN_SECONDS ); foreach ( $scan_files as $key => $file ) { if ( ! str_contains( $file, 'email/' ) ) { if ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/' . $file ) ) { @@ -3139,6 +3150,11 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { } + /** + * @param $file string + * + * @return string + */ public static function get_file_version( $file ) { // Avoid notices if file does not exist. diff --git a/templates/account.php b/templates/account.php index f252d580..48e77697 100644 --- a/templates/account.php +++ b/templates/account.php @@ -1,8 +1,20 @@ +if ( ! defined( 'ABSPATH' ) ) { + exit; +} ?>
diff --git a/templates/gdpr-register.php b/templates/gdpr-register.php index 11248b6b..aab7f89e 100644 --- a/templates/gdpr-register.php +++ b/templates/gdpr-register.php @@ -1,6 +1,16 @@ diff --git a/templates/login-to-view.php b/templates/login-to-view.php index ad253dad..2d335469 100644 --- a/templates/login-to-view.php +++ b/templates/login-to-view.php @@ -1,8 +1,18 @@ +if ( ! defined( 'ABSPATH' ) ) { + exit; +} ?>
diff --git a/templates/login.php b/templates/login.php index a03f9e78..74d6a293 100644 --- a/templates/login.php +++ b/templates/login.php @@ -1,8 +1,20 @@ +if ( ! defined( 'ABSPATH' ) ) { + exit; +} ?>
diff --git a/templates/logout.php b/templates/logout.php index f51bb105..df1eda6a 100644 --- a/templates/logout.php +++ b/templates/logout.php @@ -1,8 +1,20 @@ +if ( ! defined( 'ABSPATH' ) ) { + exit; +} ?>
diff --git a/templates/members-grid.php b/templates/members-grid.php index 8f55be79..f2eb27e3 100644 --- a/templates/members-grid.php +++ b/templates/members-grid.php @@ -1,8 +1,27 @@ diff --git a/templates/members-header.php b/templates/members-header.php index 8e5506cb..e83c40f1 100644 --- a/templates/members-header.php +++ b/templates/members-header.php @@ -1,8 +1,16 @@ +if ( ! defined( 'ABSPATH' ) ) { + exit; +} ?>