From 9cc48e0a8c11e9547697e6a866b0a91d2ca75807 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Thu, 22 Jun 2023 14:40:44 +0300 Subject: [PATCH] - fix load() --- includes/core/class-query.php | 1 + includes/core/class-shortcodes.php | 174 +++++++++++++---------------- 2 files changed, 76 insertions(+), 99 deletions(-) diff --git a/includes/core/class-query.php b/includes/core/class-query.php index 2519011c..c5583e5c 100644 --- a/includes/core/class-query.php +++ b/includes/core/class-query.php @@ -42,6 +42,7 @@ if ( ! class_exists( 'um\core\Query' ) ) { UM()->check_ajax_nonce(); // phpcs:disable WordPress.Security.NonceVerification + $hook = ''; if ( isset( $_REQUEST['hook'] ) ) { $hook = $_REQUEST['hook']; } diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php index e300d2e2..e736922c 100644 --- a/includes/core/class-shortcodes.php +++ b/includes/core/class-shortcodes.php @@ -602,9 +602,9 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { * * @return string */ - function load( $args ) { + public function load( $args ) { $defaults = array(); - $args = wp_parse_args( $args, $defaults ); + $args = wp_parse_args( $args, $defaults ); // when to not continue $this->form_id = isset( $args['form_id'] ) ? $args['form_id'] : null; @@ -613,36 +613,32 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { } $this->form_status = get_post_status( $this->form_id ); - if ( $this->form_status != 'publish' ) { + if ( 'publish' !== $this->form_status ) { return; } // get data into one global array $post_data = UM()->query()->post_data( $this->form_id ); - $args = array_merge( $args, $post_data ); + $args = array_merge( $args, $post_data ); ob_start(); /** - * UM hook + * Filters change arguments on load shortcode * - * @type filter - * @title um_pre_args_setup - * @description Change arguments on load shortcode - * @input_vars - * [{"var":"$post_data","type":"string","desc":"$_POST data"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * Change arguments on load shortcode. * function my_pre_args_setup( $post_data ) { * // your code here * return $post_data; * } - * ?> + * add_filter( 'um_pre_args_setup', 'my_pre_args_setup', 10, 1 ); */ $args = apply_filters( 'um_pre_args_setup', $args ); @@ -650,7 +646,7 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { $args['template'] = ''; } - if ( isset( $post_data['template'] ) && $post_data['template'] != $args['template'] ) { + if ( isset( $post_data['template'] ) && $post_data['template'] !== $args['template'] ) { $args['template'] = $post_data['template']; } @@ -662,7 +658,7 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { $post_data['template'] = $post_data['mode']; } - if ( 'directory' == $args['mode'] ) { + if ( 'directory' === $args['mode'] ) { wp_enqueue_script( 'um_members' ); if ( is_rtl() ) { wp_enqueue_style( 'um_members_rtl' ); @@ -671,7 +667,7 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { } } - if ( 'directory' != $args['mode'] ) { + if ( 'directory' !== $args['mode'] ) { $args = array_merge( $post_data, $args ); if ( empty( $args['use_custom_settings'] ) ) { @@ -683,39 +679,35 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { // filter for arguments /** - * UM hook + * Filters change arguments on load shortcode * - * @type filter - * @title um_shortcode_args_filter - * @description Change arguments on load shortcode - * @input_vars - * [{"var":"$args","type":"string","desc":"Shortcode arguments"}] - * @change_log - * ["Since: 2.0"] - * @usage - * - * @example - * Change arguments on load shortcode. * function my_shortcode_args( $args ) { * // your code here * return $args; * } - * ?> + * add_filter( 'um_shortcode_args_filter', 'my_shortcode_args', 10, 1 ); */ $args = apply_filters( 'um_shortcode_args_filter', $args ); - /** - * @var string $mode - */ - extract( $args, EXTR_SKIP ); + if ( ! array_key_exists( 'mode', $args ) || ! array_key_exists( 'template', $args ) ) { + return; + } + $mode = $args['mode']; //not display on admin preview - if ( empty( $_POST['act_id'] ) || sanitize_key( $_POST['act_id'] ) !== 'um_admin_preview_form' ) { + if ( empty( $_POST['act_id'] ) || 'um_admin_preview_form' !== sanitize_key( $_POST['act_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification $enable_loggedin_registration = apply_filters( 'um_registration_for_loggedin_users', false, $args ); - if ( 'register' == $mode && is_user_logged_in() && ! $enable_loggedin_registration ) { + if ( 'register' === $mode && is_user_logged_in() && ! $enable_loggedin_registration ) { ob_get_clean(); return __( 'You are already registered', 'ultimate-member' ); } @@ -726,7 +718,7 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { } // for profiles only - if ( $mode == 'profile' && um_profile_id() ) { + if ( 'profile' === $mode && um_profile_id() ) { //set requested user if it's not setup from permalinks (for not profile page in edit mode) if ( ! um_get_requested_user() ) { @@ -756,7 +748,7 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { } $this->profile_role = $args['role']; - } elseif ( $this->profile_role != $args['role'] ) { + } elseif ( $this->profile_role !== $args['role'] ) { ob_get_clean(); return ''; } @@ -765,90 +757,74 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) { } /** - * UM hook + * Fires pre-load form shortcode. * - * @type action - * @title um_pre_{$mode}_shortcode - * @description Action pre-load form shortcode - * @input_vars - * [{"var":"$args","type":"array","desc":"Form shortcode pre-loading"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_pre_{$mode}_shortcode', 'function_name', 10, 1 ); - * @example - * Make any custom action on pre-load form shortcode. * function my_pre_shortcode( $args ) { * // your code here * } - * ?> + * add_action( 'um_pre_{$mode}_shortcode', 'my_pre_shortcode', 10, 1 ); */ do_action( "um_pre_{$mode}_shortcode", $args ); + /** - * UM hook + * Fires pre-load form shortcode. * - * @type action - * @title um_before_form_is_loaded - * @description Action pre-load form shortcode - * @input_vars - * [{"var":"$args","type":"array","desc":"Form shortcode pre-loading"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_before_form_is_loaded', 'function_name', 10, 1 ); - * @example - * Make any custom action on pre-load form shortcode. + * function my_pre_shortcode( $args ) { + * // your code here + * } * add_action( 'um_before_form_is_loaded', 'my_pre_shortcode', 10, 1 ); - * function my_pre_shortcode( $args ) { - * // your code here - * } - * ?> */ - do_action( "um_before_form_is_loaded", $args ); + do_action( 'um_before_form_is_loaded', $args ); + /** - * UM hook + * Fires pre-load form shortcode. * - * @type action - * @title um_before_{$mode}_form_is_loaded - * @description Action pre-load form shortcode - * @input_vars - * [{"var":"$args","type":"array","desc":"Form shortcode pre-loading"}] - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_before_{$mode}_form_is_loaded', 'function_name', 10, 1 ); - * @example - * Make any custom action on pre-load form shortcode. * function my_pre_shortcode( $args ) { * // your code here * } - * ?> + * add_action( 'um_before_{$mode}_form_is_loaded', 'my_pre_shortcode', 10, 1 ); */ do_action( "um_before_{$mode}_form_is_loaded", $args ); - $this->template_load( $template, $args ); + $this->template_load( $args['template'], $args ); $this->dynamic_css( $args ); - if ( um_get_requested_user() || $mode == 'logout' ) { + if ( um_get_requested_user() || 'logout' === $mode ) { um_reset_user(); } /** - * UM hook + * Fires after load shortcode content. * - * @type action - * @title um_after_everything_output - * @description Action after load shortcode content - * @change_log - * ["Since: 2.0"] - * @usage add_action( 'um_after_everything_output', 'function_name', 10 ); - * @example - * Make any custom action after load shortcode content. + * function my_pre_shortcode() { * // your code here * } - * ?> + * add_action( 'um_after_everything_output', 'my_pre_shortcode', 10 ); */ do_action( 'um_after_everything_output' );