From c2757d824b859e775ccd88b764101346587be488 Mon Sep 17 00:00:00 2001 From: Mykyta Synelnikov Date: Mon, 26 Jun 2023 17:04:58 +0300 Subject: [PATCH] - review `ajax_muted_action()`; --- includes/core/class-form.php | 50 ++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/includes/core/class-form.php b/includes/core/class-form.php index e6007bcd..fbbbeed0 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -63,7 +63,6 @@ if ( ! class_exists( 'um\core\Form' ) ) { add_action( 'init', array( &$this, 'field_declare' ), 10 ); } - /** * */ @@ -71,41 +70,36 @@ if ( ! class_exists( 'um\core\Form' ) ) { UM()->check_ajax_nonce(); // phpcs:disable WordPress.Security.NonceVerification + if ( ! isset( $_REQUEST['hook'] ) ) { + die( esc_html__( 'Invalid hook', 'ultimate-member' ) ); + } + if ( isset( $_REQUEST['user_id'] ) ) { $user_id = absint( $_REQUEST['user_id'] ); } - - if ( isset( $_REQUEST['hook'] ) ) { - $hook = sanitize_key( $_REQUEST['hook'] ); + if ( ! isset( $user_id ) || ! UM()->roles()->um_current_user_can( 'edit', $user_id ) ) { + die( esc_html__( 'You can not edit this user.', 'ultimate-member' ) ); } - if ( ! UM()->roles()->um_current_user_can( 'edit', $user_id ) ) { - die( esc_html__( 'You can not edit this user', 'ultimate-member' ) ); - } - - switch ( $hook ) { - default: - /** - * Fires on AJAX muted action. - * - * @since 2.0 - * @hook um_run_ajax_function__{$hook} - * - * @param {array} $request Request. - * - * @example Make any custom action on AJAX muted action. - * function my_run_ajax_function( $request ) { - * // your code here - * } - * add_action( 'um_run_ajax_function__{$hook}', 'my_run_ajax_function', 10, 1 ); - */ - do_action( "um_run_ajax_function__{$hook}", $_REQUEST ); - break; - } + $hook = sanitize_key( $_REQUEST['hook'] ); + /** + * Fires on AJAX muted action. + * + * @since 1.3.x + * @hook um_run_ajax_function__{$hook} + * + * @param {array} $request Request. + * + * @example Make any custom action on AJAX muted action. + * function my_run_ajax_function( $request ) { + * // your code here + * } + * add_action( 'um_run_ajax_function__{$hook}', 'my_run_ajax_function', 10, 1 ); + */ + do_action( "um_run_ajax_function__{$hook}", $_REQUEST ); // phpcs:enable WordPress.Security.NonceVerification } - /** * */