';
return $output;
}
-
/**
- *
+ * Admin Builder silent AJAX handler for actions with fields.
*/
- function do_ajax_action() {
+ public function do_ajax_action() {
UM()->admin()->check_ajax_nonce();
+ // phpcs:disable WordPress.Security.NonceVerification
if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
- wp_send_json_error( __( 'Please login as administrator', 'ultimate-member' ) );
+ wp_send_json_error( __( 'Please login as administrator.', 'ultimate-member' ) );
}
- /**
- * @var $in_row
- * @var $in_sub_row
- * @var $in_column
- * @var $in_group
- * @var $act_id
- * @var $arg1
- * @var $arg2
- */
- extract( $_POST );
-
- $output = null;
-
- $position = array();
- if ( ! empty( $in_column ) ) {
- $position['in_row'] = '_um_row_' . ( (int) $in_row + 1 );
- $position['in_sub_row'] = $in_sub_row;
- $position['in_column'] = $in_column;
- $position['in_group'] = $in_group;
+ if ( ! isset( $_POST['act_id'] ) ) {
+ wp_send_json_error( __( 'Invalid action.', 'ultimate-member' ) );
}
- switch ( $act_id ) {
+ $in_row = isset( $_POST['in_row'] ) ? absint( $_POST['in_row'] ) : 0;
+ $position = array(
+ 'in_row' => '_um_row_' . ( $in_row + 1 ),
+ 'in_sub_row' => isset( $_POST['in_sub_row'] ) ? absint( $_POST['in_sub_row'] ) : '',
+ 'in_column' => isset( $_POST['in_column'] ) ? absint( $_POST['in_column'] ) : '',
+ 'in_group' => isset( $_POST['in_group'] ) ? absint( $_POST['in_group'] ) : '',
+ );
+ switch ( sanitize_key( $_POST['act_id'] ) ) {
case 'um_admin_duplicate_field':
- $this->duplicate_field( $arg1, $arg2 );
+ // arg1 is a field metakey(id)
+ // arg2 is a form ID.
+ $this->duplicate_field( sanitize_text_field( $_POST['arg1'] ), absint( $_POST['arg2'] ) );
break;
-
case 'um_admin_remove_field_global':
- $this->delete_field_from_db( $arg1 );
+ // arg1 is a field metakey(id)
+ $this->delete_field_from_db( sanitize_text_field( $_POST['arg1'] ) );
break;
-
case 'um_admin_remove_field':
- $this->delete_field_from_form( $arg1, $arg2 );
+ // arg1 is a field metakey(id)
+ // arg2 is a form ID.
+ $this->delete_field_from_form( sanitize_text_field( $_POST['arg1'] ), absint( $_POST['arg2'] ) );
break;
-
case 'um_admin_add_field_from_predefined':
- $this->add_field_from_predefined( $arg1, $arg2, $position );
+ // arg1 is a field metakey(id)
+ // arg2 is a form ID.
+ $this->add_field_from_predefined( sanitize_text_field( $_POST['arg1'] ), absint( $_POST['arg2'] ), $position );
break;
-
case 'um_admin_add_field_from_list':
- $this->add_field_from_list( $arg1, $arg2, $position );
+ // arg1 is a field metakey(id)
+ // arg2 is a form ID.
+ $this->add_field_from_list( sanitize_text_field( $_POST['arg1'] ), absint( $_POST['arg2'] ), $position );
break;
-
}
-
- if ( is_array( $output ) ) {
- print_r( $output );
- } else {
- echo $output;
- }
- die;
-
+ // phpcs:enable WordPress.Security.NonceVerification
+ wp_send_json_success();
}
-
-
/**
* Get rendered field attributes
*
diff --git a/includes/core/class-files.php b/includes/core/class-files.php
index 8a702456..834db12d 100644
--- a/includes/core/class-files.php
+++ b/includes/core/class-files.php
@@ -1,12 +1,12 @@
check_ajax_nonce();
-
- /**
- * @var $key
- * @var $src
- * @var $coord
- * @var $user_id
- */
- extract( $_REQUEST );
-
- if ( ! isset( $src ) || ! isset( $coord ) ) {
+ // phpcs:disable WordPress.Security.NonceVerification -- verified by the `check_ajax_nonce()`
+ if ( ! isset( $_REQUEST['src'], $_REQUEST['coord'], $_REQUEST['key'] ) ) {
wp_send_json_error( esc_js( __( 'Invalid parameters', 'ultimate-member' ) ) );
}
- $coord_n = substr_count( $coord, "," );
- if ( $coord_n != 3 ) {
+ $coord_n = substr_count( $_REQUEST['coord'], ',' );
+ if ( 3 !== $coord_n ) {
wp_send_json_error( esc_js( __( 'Invalid coordinates', 'ultimate-member' ) ) );
}
+ $key = sanitize_text_field( $_REQUEST['key'] );
+ $coord = sanitize_text_field( $_REQUEST['coord'] );
$user_id = empty( $_REQUEST['user_id'] ) ? get_current_user_id() : absint( $_REQUEST['user_id'] );
UM()->fields()->set_id = isset( $_POST['set_id'] ) ? absint( $_POST['set_id'] ) : null;
UM()->fields()->set_mode = isset( $_POST['set_mode'] ) ? sanitize_text_field( $_POST['set_mode'] ) : null;
- if ( UM()->fields()->set_mode != 'register' && ! UM()->roles()->um_current_user_can( 'edit', $user_id ) ) {
+ if ( 'register' !== UM()->fields()->set_mode && ! UM()->roles()->um_current_user_can( 'edit', $user_id ) ) {
$ret['error'] = esc_js( __( 'You have no permission to edit this user', 'ultimate-member' ) );
wp_send_json_error( $ret );
}
- $src = esc_url_raw( $src );
-
+ $src = esc_url_raw( $_REQUEST['src'] );
$image_path = um_is_file_owner( $src, $user_id, true );
if ( ! $image_path ) {
wp_send_json_error( esc_js( __( 'Invalid file ownership', 'ultimate-member' ) ) );
}
UM()->uploader()->replace_upload_dir = true;
- $output = UM()->uploader()->resize_image( $image_path, $src, sanitize_text_field( $key ), $user_id, sanitize_text_field( $coord ) );
+
+ $output = UM()->uploader()->resize_image( $image_path, $src, $key, $user_id, $coord );
+
UM()->uploader()->replace_upload_dir = false;
delete_option( "um_cache_userdata_{$user_id}" );
-
+ // phpcs:enable WordPress.Security.NonceVerification -- verified by the `check_ajax_nonce()`
wp_send_json_success( $output );
}
-
/**
* Image upload by AJAX
*
diff --git a/includes/core/class-form.php b/includes/core/class-form.php
index 626047f1..76ce15f8 100644
--- a/includes/core/class-form.php
+++ b/includes/core/class-form.php
@@ -63,58 +63,43 @@ if ( ! class_exists( 'um\core\Form' ) ) {
add_action( 'init', array( &$this, 'field_declare' ), 10 );
}
-
/**
*
*/
public function ajax_muted_action() {
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( $user_id ) || ! UM()->roles()->um_current_user_can( 'edit', $user_id ) ) {
+ die( esc_html__( 'You can not edit this user.', 'ultimate-member' ) );
+ }
+
+ $hook = sanitize_key( $_REQUEST['hook'] );
/**
- * @var $user_id
- * @var $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 );
*/
- extract( $_REQUEST );
-
- if ( isset( $user_id ) ) {
- $user_id = absint( $user_id );
- }
-
- if ( isset( $hook ) ) {
- $hook = sanitize_key( $hook );
- }
-
- if ( ! UM()->roles()->um_current_user_can( 'edit', $user_id ) ) {
- die( esc_html__( 'You can not edit this user', 'ultimate-member' ) );
- }
-
- switch ( $hook ) {
- default:
- /**
- * UM hook
- *
- * @type action
- * @title um_run_ajax_function__{$hook}
- * @description Action on AJAX muted action
- * @input_vars
- * [{"var":"$request","type":"int","desc":"Request"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_run_ajax_function__{$hook}', 'function_name', 10, 1 );
- * @example
- *
- */
- do_action( "um_run_ajax_function__{$hook}", $_REQUEST );
- break;
- }
+ do_action( "um_run_ajax_function__{$hook}", $_REQUEST );
+ // phpcs:enable WordPress.Security.NonceVerification
}
-
/**
*
*/
@@ -608,11 +593,9 @@ if ( ! class_exists( 'um\core\Form' ) ) {
* ?>
*/
do_action( "um_submit_form_{$this->post_form['mode']}", $this->post_form );
-
}
}
-
/**
* Beautify form data
*
diff --git a/includes/core/class-password.php b/includes/core/class-password.php
index df8c3c2e..a839458e 100644
--- a/includes/core/class-password.php
+++ b/includes/core/class-password.php
@@ -33,7 +33,6 @@ if ( ! class_exists( 'um\core\Password' ) ) {
add_action( 'um_change_password_process_hook', array( &$this, 'um_change_password_process_hook' ) );
}
-
/**
* Get Reset URL
*
@@ -109,7 +108,6 @@ if ( ! class_exists( 'um\core\Password' ) ) {
return $classes;
}
-
/**
* Shortcode
*
@@ -117,44 +115,41 @@ if ( ! class_exists( 'um\core\Password' ) ) {
*
* @return string
*/
- function ultimatemember_password( $args = array() ) {
- ob_start();
-
- $defaults = array(
- 'template' => 'password-reset',
- 'mode' => 'password',
- 'form_id' => 'um_password_id',
- 'max_width' => '450px',
- 'align' => 'center',
+ public function ultimatemember_password( $args = array() ) {
+ /** There is possible to use 'shortcode_atts_ultimatemember_password' filter for getting customized $atts. This filter is documented in wp-includes/shortcodes.php "shortcode_atts_{$shortcode}" */
+ $args = shortcode_atts(
+ array(
+ 'template' => 'password-reset',
+ 'mode' => 'password',
+ 'form_id' => 'um_password_id',
+ 'max_width' => '450px',
+ 'align' => 'center',
+ ),
+ $args,
+ 'ultimatemember_password'
);
- $args = wp_parse_args( $args, $defaults );
if ( empty( $args['use_custom_settings'] ) ) {
$args = array_merge( $args, UM()->shortcodes()->get_css_args( $args ) );
} else {
$args = array_merge( UM()->shortcodes()->get_css_args( $args ), $args );
}
-
/**
- * UM hook
+ * Filters extend Reset Password Arguments
*
- * @type filter
- * @title um_reset_password_shortcode_args_filter
- * @description Extend Reset Password Arguments
- * @input_vars
- * [{"var":"$args","type":"array","desc":"Shortcode arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- * Extend Reset Password Arguments.
* function my_reset_password_shortcode_args( $args ) {
* // your code here
* return $args;
* }
- * ?>
+ * add_filter( 'um_reset_password_shortcode_args_filter', 'my_reset_password_shortcode_args', 10, 1 );
*/
$args = apply_filters( 'um_reset_password_shortcode_args_filter', $args );
@@ -162,7 +157,7 @@ if ( ! class_exists( 'um\core\Password' ) ) {
// then COOKIE are valid then get data from them and populate hidden fields for the password reset form
$args['template'] = 'password-change';
$args['rp_key'] = '';
- $rp_cookie = 'wp-resetpass-' . COOKIEHASH;
+ $rp_cookie = 'wp-resetpass-' . COOKIEHASH;
if ( isset( $_COOKIE[ $rp_cookie ] ) && 0 < strpos( $_COOKIE[ $rp_cookie ], ':' ) ) {
list( $rp_login, $rp_key ) = explode( ':', wp_unslash( $_COOKIE[ $rp_cookie ] ), 2 );
@@ -171,86 +166,30 @@ if ( ! class_exists( 'um\core\Password' ) ) {
}
}
- UM()->fields()->set_id = 'um_password_id';
+ if ( empty( $args['mode'] ) || empty( $args['template'] ) ) {
+ return '';
+ }
- /**
- * @var $mode
- * @var $template
- */
- extract( $args, EXTR_SKIP );
+ UM()->fields()->set_id = $args['form_id'];
- /**
- * UM hook
- *
- * @type action
- * @title um_pre_{$mode}_shortcode
- * @description Action pre-load password 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
- *
- */
- do_action( "um_pre_{$mode}_shortcode", $args );
- /**
- * UM hook
- *
- * @type action
- * @title um_before_form_is_loaded
- * @description Action pre-load password 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
- *
- */
- do_action( "um_before_form_is_loaded", $args );
- /**
- * UM hook
- *
- * @type action
- * @title um_before_{$mode}_form_is_loaded
- * @description Action pre-load password 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
- *
- */
- do_action( "um_before_{$mode}_form_is_loaded", $args );
+ ob_start();
- UM()->shortcodes()->template_load( $template, $args );
+ /** This filter is documented in includes/core/class-shortcodes.php */
+ do_action( "um_pre_{$args['mode']}_shortcode", $args );
+ /** This filter is documented in includes/core/class-shortcodes.php */
+ do_action( 'um_before_form_is_loaded', $args );
+ /** This filter is documented in includes/core/class-shortcodes.php */
+ do_action( "um_before_{$args['mode']}_form_is_loaded", $args );
+
+ UM()->shortcodes()->template_load( $args['template'], $args );
if ( ! is_admin() && ! defined( 'DOING_AJAX' ) ) {
UM()->shortcodes()->dynamic_css( $args );
}
- $output = ob_get_clean();
- return $output;
+ return ob_get_clean();
}
-
/**
* Check if a legitimate password reset request is in action
*
diff --git a/includes/core/class-query.php b/includes/core/class-query.php
index 80b72e42..2a4fbe49 100644
--- a/includes/core/class-query.php
+++ b/includes/core/class-query.php
@@ -1,87 +1,78 @@
check_ajax_nonce();
- /**
- * @var $hook
- * @var $args
- */
- extract( $_REQUEST );
+ // phpcs:disable WordPress.Security.NonceVerification
+ if ( ! isset( $_REQUEST['hook'] ) ) {
+ wp_send_json_error( __( 'Invalid hook.', 'ultimate-member' ) );
+ }
+ $hook = sanitize_key( $_REQUEST['hook'] );
+
+ $args = ! empty( $_REQUEST['args'] ) ? $_REQUEST['args'] : array();
+ // phpcs:enable WordPress.Security.NonceVerification
ob_start();
/**
- * UM hook
+ * Fires on posts loading by AJAX in User Profile tabs.
*
- * @type action
- * @title um_ajax_load_posts__{$hook}
- * @description Action on posts loading by AJAX
- * @input_vars
- * [{"var":"$args","type":"array","desc":"Query arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_ajax_load_posts__{$hook}', 'function_name', 10, 1 );
- * @example
- * Make any custom action on when posts loading by AJAX in User Profile.
* function my_ajax_load_posts( $args ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_ajax_load_posts__{$hook}', 'my_ajax_load_posts', 10, 1 );
*/
do_action( "um_ajax_load_posts__{$hook}", $args );
$output = ob_get_clean();
-
+ // @todo: investigate using WP_KSES
die( $output );
}
-
/**
* Get wp pages
*
* @return array|string
*/
- function wp_pages() {
+ public function wp_pages() {
global $wpdb;
if( isset( $this->wp_pages ) && ! empty( $this->wp_pages ) ){
@@ -114,13 +105,12 @@ if ( ! class_exists( 'um\core\Query' ) ) {
return $array;
}
-
/**
* Get all forms
*
* @return mixed
*/
- function forms() {
+ public function forms() {
$results = array();
$args = array(
@@ -137,65 +127,55 @@ if ( ! class_exists( 'um\core\Query' ) ) {
return $results;
}
-
/**
* Do custom queries
*
- * @param $args
+ * @param array $args
*
* @return array|bool|int|\WP_Query
*/
- function make( $args ) {
-
+ public function make( $args ) {
$defaults = array(
- 'post_type' => 'post',
- 'post_status' => array('publish')
+ 'post_type' => 'post',
+ 'post_status' => array( 'publish' ),
);
- $args = wp_parse_args( $args, $defaults );
+ $args = wp_parse_args( $args, $defaults );
- if ( isset( $args['post__in'] ) && empty( $args['post__in'] ) )
+ if ( isset( $args['post__in'] ) && empty( $args['post__in'] ) ) {
return false;
+ }
- extract( $args );
-
- if ( $post_type == 'comment' ) { // comments
-
+ if ( 'comment' === $args['post_type'] ) {
+ // Comments query.
unset( $args['post_type'] );
-
/**
- * UM hook
+ * Filters excluded comment types.
*
- * @type filter
- * @title um_excluded_comment_types
- * @description Extend excluded comment types
- * @input_vars
- * [{"var":"$types","type":"array","desc":"Comment Types"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- * Extend excluded comment types.
+ * function my_excluded_comment_types( $types ) {
* // your code here
* return $types;
* }
- * ?>
+ * add_filter( 'um_excluded_comment_types', 'my_excluded_comment_types' );
*/
- $args['type__not_in'] = apply_filters( 'um_excluded_comment_types', array('') );
+ $args['type__not_in'] = apply_filters( 'um_excluded_comment_types', array( '' ) );
- $comments = get_comments($args);
- return $comments;
-
- } else {
- $custom_posts = new \WP_Query();
- $args['post_status'] = is_array( $args['post_status'] ) ? $args['post_status'] : explode( ',', $args['post_status'] );
-
- $custom_posts->query( $args );
-
- return $custom_posts;
+ return get_comments( $args );
}
+
+ $custom_posts = new \WP_Query();
+ $args['post_status'] = is_array( $args['post_status'] ) ? $args['post_status'] : explode( ',', $args['post_status'] );
+
+ $custom_posts->query( $args );
+
+ return $custom_posts;
}
@@ -206,7 +186,7 @@ if ( ! class_exists( 'um\core\Query' ) ) {
*
* @return array
*/
- function get_recent_users($number = 5){
+ function get_recent_users( $number = 5 ) {
$args = array( 'fields' => 'ID', 'number' => $number, 'orderby' => 'user_registered', 'order' => 'desc' );
$users = new \WP_User_Query( $args );
diff --git a/includes/core/class-roles-capabilities.php b/includes/core/class-roles-capabilities.php
index 9b60c143..6e0cb8a9 100644
--- a/includes/core/class-roles-capabilities.php
+++ b/includes/core/class-roles-capabilities.php
@@ -592,19 +592,24 @@ if ( ! class_exists( 'um\core\Roles_Capabilities' ) ) {
/**
- * Get role data
+ * Get role data.
+ *
+ * @param int $role_id Role ID.
*
- * @param int $roleID Role ID
* @return array
*/
- function role_data( $roleID ) {
- if ( strpos( $roleID, 'um_' ) === 0 ) {
- $roleID = substr( $roleID, 3 );
- $role_data = get_option( "um_role_{$roleID}_meta", array() );
+ public function role_data( $role_id ) {
+ if ( empty( $role_id ) ) {
+ return array();
+ }
+
+ if ( strpos( $role_id, 'um_' ) === 0 ) {
+ $role_id = substr( $role_id, 3 );
+ $role_data = get_option( "um_role_{$role_id}_meta", array() );
}
if ( empty( $role_data ) ) {
- $role_data = get_option( "um_role_{$roleID}_meta", array() );
+ $role_data = get_option( "um_role_{$role_id}_meta", array() );
}
if ( ! $role_data ) {
@@ -612,21 +617,36 @@ if ( ! class_exists( 'um\core\Roles_Capabilities' ) ) {
}
$temp = array();
- foreach ( $role_data as $key=>$value ) {
+ foreach ( $role_data as $key => $value ) {
if ( strpos( $key, '_um_' ) === 0 ) {
- $key = preg_replace('/_um_/', '', $key, 1);
+ $key = preg_replace( '/_um_/', '', $key, 1 );
}
-
- //$key = str_replace( '_um_', '', $key, $count );
$temp[ $key ] = $value;
}
-
- $temp = apply_filters( 'um_change_role_data', $temp, $roleID );
-
- return $temp;
+ /**
+ * Filters the Ultimate Member related user role data.
+ *
+ * @since 2.0
+ * @hook um_change_role_data
+ *
+ * @param {array} $role_data Role data.
+ * @param {string} $role_id Role ID.
+ *
+ * @return {array} Role data.
+ *
+ * @example
Set {some_capability_key} capability for subscriber user role.
+ * function my_change_role_data( $role_data, $role_id ) {
+ * // your code here
+ * if ( 'subscriber' === $role_id ) {
+ * $role_data['{some_capability_key}'] = true;
+ * }
+ * return $role_data;
+ * }
+ * add_filter( 'um_change_role_data', 'my_change_role_data', 10, 2 );
+ */
+ return apply_filters( 'um_change_role_data', $temp, $role_id );
}
-
/**
* Query for UM roles
*
diff --git a/includes/core/class-shortcodes.php b/includes/core/class-shortcodes.php
index e300d2e2..f1b6bb78 100644
--- a/includes/core/class-shortcodes.php
+++ b/includes/core/class-shortcodes.php
@@ -297,16 +297,23 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
if ( isset( $this->set_args ) && is_array( $this->set_args ) ) {
$args = $this->set_args;
- unset( $args['file'] );
- unset( $args['theme_file'] );
- unset( $args['tpl'] );
+ unset( $args['file'], $args['theme_file'], $args['tpl'] );
$args = apply_filters( 'um_template_load_args', $args, $tpl );
- extract( $args );
+ /*
+ * This use of extract() cannot be removed. There are many possible ways that
+ * templates could depend on variables that it creates existing, and no way to
+ * detect and deprecate it.
+ *
+ * Passing the EXTR_SKIP flag is the safest option, ensuring globals and
+ * function variables cannot be overwritten.
+ */
+ // phpcs:ignore WordPress.PHP.DontExtract.extract_extract
+ extract( $args, EXTR_SKIP );
}
- $file = um_path . "templates/{$tpl}.php";
+ $file = UM_PATH . "templates/{$tpl}.php";
$theme_file = get_stylesheet_directory() . "/ultimate-member/templates/{$tpl}.php";
if ( file_exists( $theme_file ) ) {
$file = $theme_file;
@@ -582,7 +589,6 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
}
}
-
/**
* Shortcode
*
@@ -590,11 +596,10 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
*
* @return string
*/
- function ultimatemember( $args = array() ) {
+ public function ultimatemember( $args = array() ) {
return $this->load( $args );
}
-
/**
* Load a module with global function
*
@@ -602,47 +607,43 @@ 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;
- if ( ! $this->form_id ) {
- return;
+ // When to not continue.
+ if ( ! array_key_exists( 'form_id', $args ) ) {
+ return '';
}
+ $this->form_id = $args['form_id'];
$this->form_status = get_post_status( $this->form_id );
- if ( $this->form_status != 'publish' ) {
- return;
+ 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 arguments for loading Ultimate Member shortcodes.
*
- * @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( $args ) {
* // your code here
- * return $post_data;
+ * return $args;
* }
- * ?>
+ * add_filter( 'um_pre_args_setup', 'my_pre_args_setup' );
*/
$args = apply_filters( 'um_pre_args_setup', $args );
@@ -650,7 +651,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 +663,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 +672,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'] ) ) {
@@ -680,254 +681,255 @@ if ( ! class_exists( 'um\core\Shortcodes' ) ) {
$args = array_merge( $this->get_css_args( $args ), $args );
}
}
- // 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' );
*/
$args = apply_filters( 'um_shortcode_args_filter', $args );
- /**
- * @var string $mode
- */
- extract( $args, EXTR_SKIP );
-
- //not display on admin preview
- if ( empty( $_POST['act_id'] ) || sanitize_key( $_POST['act_id'] ) !== 'um_admin_preview_form' ) {
+ if ( ! array_key_exists( 'mode', $args ) || ! array_key_exists( 'template', $args ) ) {
+ ob_get_clean();
+ return '';
+ }
+ $mode = $args['mode'];
+ // Not display on admin preview.
+ if ( empty( $_POST['act_id'] ) || 'um_admin_preview_form' !== sanitize_key( $_POST['act_id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
+ /**
+ * Filters the ability to show registration form for the logged-in users.
+ * Set it to true for displaying registration form for the logged-in users.
+ *
+ * @since 2.1.20
+ * @hook um_registration_for_loggedin_users
+ *
+ * @param {bool} $show Show registration form for the logged-in users. By default, it's false
+ * @param {array} $args Shortcode arguments.
+ *
+ * @return {bool} Show registration form for the logged-in users.
+ *
+ * @example
Show registration form for the logged-in users for all UM registration forms on your website.
+ * add_filter( 'um_registration_for_loggedin_users', '__return_true' );
+ */
$enable_loggedin_registration = apply_filters( 'um_registration_for_loggedin_users', false, $args );
- if ( 'register' == $mode && is_user_logged_in() && ! $enable_loggedin_registration ) {
+ if ( ! $enable_loggedin_registration && 'register' === $mode && is_user_logged_in() ) {
ob_get_clean();
- return __( 'You are already registered', 'ultimate-member' );
+ return __( 'You are already registered.', 'ultimate-member' );
}
}
- if ( ! is_user_logged_in() && isset( $args['is_block'] ) && 1 === (int) $args['is_block'] && 'profile' === $mode ) {
- return;
+ if ( isset( $args['is_block'] ) && 1 === (int) $args['is_block'] && 'profile' === $mode && ! is_user_logged_in() ) {
+ ob_get_clean();
+ return '';
}
- // for profiles only
- if ( $mode == 'profile' && um_profile_id() ) {
-
- //set requested user if it's not setup from permalinks (for not profile page in edit mode)
+ // For profiles only.
+ 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() ) {
um_set_requested_user( um_profile_id() );
}
- if ( ! empty( $args['use_custom_settings'] ) ) { // Option "Apply custom settings to this form"
- if ( ! empty( $args['role'] ) ) { // Option "Make this profile form role-specific"
+ if ( ! empty( $args['use_custom_settings'] ) && ! empty( $args['role'] ) ) {
+ // Option "Apply custom settings to this form". Option "Make this profile form role-specific".
+ // Show the first Profile Form with role selected, don't show profile forms below the page with other role-specific setting.
+ if ( empty( $this->profile_role ) ) {
+ $current_user_roles = UM()->roles()->get_all_user_roles( um_profile_id() );
- // show the first Profile Form with role selected, don't show profile forms below the page with other role-specific setting
- if ( empty( $this->profile_role ) ) {
- $current_user_roles = UM()->roles()->get_all_user_roles( um_profile_id() );
-
- if ( empty( $current_user_roles ) ) {
- ob_get_clean();
- return '';
- } elseif ( is_array( $args['role'] ) ) {
- if ( ! count( array_intersect( $args['role'], $current_user_roles ) ) ) {
- ob_get_clean();
- return '';
- }
- } else {
- if ( ! in_array( $args['role'], $current_user_roles ) ) {
- ob_get_clean();
- return '';
- }
- }
-
- $this->profile_role = $args['role'];
- } elseif ( $this->profile_role != $args['role'] ) {
+ if ( empty( $current_user_roles ) ) {
ob_get_clean();
return '';
}
+ if ( is_array( $args['role'] ) ) {
+ if ( ! count( array_intersect( $args['role'], $current_user_roles ) ) ) {
+ ob_get_clean();
+ return '';
+ }
+ } elseif ( ! in_array( $args['role'], $current_user_roles, true ) ) {
+ ob_get_clean();
+ return '';
+ }
+
+ $this->profile_role = $args['role'];
+ } elseif ( $this->profile_role !== $args['role'] ) {
+ ob_get_clean();
+ return '';
}
}
}
/**
- * UM hook
+ * Fires before loading 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 before loading a registration form shortcode.
+ * function my_pre_register_shortcode( $args ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_pre_register_shortcode', 'my_pre_register_shortcode' );
+ * @example
Make any custom action before loading a login form shortcode.
+ * function my_pre_login_shortcode( $args ) {
+ * // your code here
+ * }
+ * add_action( 'um_pre_login_shortcode', 'my_pre_login_shortcode' );
+ * @example
Make any custom action before loading a password reset form shortcode.
+ * function my_pre_password_shortcode( $args ) {
+ * // your code here
+ * }
+ * add_action( 'um_pre_password_shortcode', 'my_pre_password_shortcode' );
+ * @example
Make any custom action before loading a profile form shortcode.
+ * function my_pre_profile_shortcode( $args ) {
+ * // your code here
+ * }
+ * add_action( 'um_pre_profile_shortcode', 'my_pre_profile_shortcode' );
+ * @example
Make any custom action before loading an account form shortcode.
+ * function my_pre_account_shortcode( $args ) {
+ * // your code here
+ * }
+ * add_action( 'um_pre_account_shortcode', 'my_pre_account_shortcode' );
*/
do_action( "um_pre_{$mode}_shortcode", $args );
/**
- * UM hook
+ * Fires before loading 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 before loading UM 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 before loading a 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
- *
+ * @since 1.3.x
+ * @todo Deprecate since 2.7.0. Use `um_pre_{$mode}_shortcode` or `um_before_form_is_loaded` instead.
+ * @hook um_before_{$mode}_form_is_loaded
+ *
+ * @param {array} $args Form shortcode arguments.
*/
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 ( 'logout' === $mode || um_get_requested_user() ) {
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' );
- $output = ob_get_clean();
- return $output;
+ return ob_get_clean();
}
-
/**
* Get dynamic CSS args
*
* @param $args
* @return array
*/
- function get_css_args( $args ) {
+ public function get_css_args( $args ) {
$arr = um_styling_defaults( $args['mode'] );
- $arr = array_merge( $arr, array( 'form_id' => $args['form_id'], 'mode' => $args['mode'] ) );
+ $arr = array_merge(
+ $arr,
+ array(
+ 'form_id' => $args['form_id'],
+ 'mode' => $args['mode'],
+ )
+ );
return $arr;
}
-
/**
- * Load dynamic css
+ * Load dynamic CSS.
*
* @param array $args
*
* @return string
*/
- function dynamic_css( $args = array() ) {
+ public function dynamic_css( $args = array() ) {
/**
- * UM hook
+ * Filters for disable global dynamic CSS. It's false by default, set it to true to disable.
*
- * @type filter
- * @title um_disable_dynamic_global_css
- * @description Turn on for disable global dynamic CSS for fix the issue #306
- * @input_vars
- * [{"var":"$disable","type":"bool","desc":"Disable global CSS"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- *
+ * @since 2.0
+ * @hook um_disable_dynamic_global_css
+ *
+ * @param {bool} $disable Disable global CSS.
+ *
+ * @return {bool} Disable global CSS.
+ *
+ * @example
Turn off enqueue of global dynamic CSS.
+ * add_filter( 'um_disable_dynamic_global_css', '__return_true' );
*/
$disable_css = apply_filters( 'um_disable_dynamic_global_css', false );
- if ( $disable_css )
+ if ( $disable_css ) {
return '';
+ }
- /**
- * @var $mode
- */
- extract( $args );
+ if ( empty( $args['form_id'] ) ) {
+ return '';
+ }
- include_once um_path . 'assets/dynamic_css/dynamic_global.php';
+ include_once UM_PATH . 'assets/dynamic_css/dynamic-global.php';
- if ( isset( $mode ) && in_array( $mode, array( 'profile', 'directory' ) ) ) {
- $file = um_path . 'assets/dynamic_css/dynamic_' . $mode . '.php';
+ if ( array_key_exists( 'mode', $args ) && in_array( $args['mode'], array( 'profile', 'directory' ), true ) ) {
+ $file = UM_PATH . 'assets/dynamic_css/dynamic-' . $args['mode'] . '.php';
- if ( file_exists( $file ) )
+ if ( file_exists( $file ) ) {
include_once $file;
+ }
}
return '';
}
-
/**
* Loads a template file
*
* @param $template
* @param array $args
*/
- function template_load( $template, $args = array() ) {
+ public function template_load( $template, $args = array() ) {
if ( is_array( $args ) ) {
$this->set_args = $args;
}
diff --git a/includes/core/rest/class-api-v1.php b/includes/core/rest/class-api-v1.php
index e7de1394..a3aee5c2 100644
--- a/includes/core/rest/class-api-v1.php
+++ b/includes/core/rest/class-api-v1.php
@@ -1,9 +1,9 @@
invalid_auth();
}
}
-
}
}
-
/**
* Retrieve the user ID based on the public key provided
*
@@ -116,10 +111,10 @@ if ( ! class_exists( 'um\core\rest\API_v1' ) ) {
if ( false === $user ) {
$user = $wpdb->get_var( $wpdb->prepare(
- "SELECT user_id
- FROM $wpdb->usermeta
- WHERE meta_key = 'um_user_public_key' AND
- meta_value = %s
+ "SELECT user_id
+ FROM $wpdb->usermeta
+ WHERE meta_key = 'um_user_public_key' AND
+ meta_value = %s
LIMIT 1",
$key
) );
@@ -134,106 +129,82 @@ if ( ! class_exists( 'um\core\rest\API_v1' ) ) {
return false;
}
-
/**
- * Process Get users API Request
+ * Process Get users API Request.
*
- * @param $args
+ * @param array $args
*
* @return array
*/
public function get_users( $args ) {
- /**
- * @var int $number
- * @var string $orderby
- * @var string $order
- * @var string $include
- * @var string $exclude
- */
- extract( $args );
-
$response = array();
- if ( ! $number ) {
- $number = 10;
- }
+ $number = array_key_exists( 'number', $args ) && is_numeric( $args['number'] ) ? absint( $args['number'] ) : 10;
+ $orderby = array_key_exists( 'orderby', $args ) ? sanitize_key( $args['orderby'] ) : 'user_registered';
+ $order = array_key_exists( 'order', $args ) ? sanitize_key( $args['order'] ) : 'desc';
- if ( ! $orderby ) {
- $orderby = 'user_registered';
- }
+ $loop_a = array(
+ 'number' => $number,
+ 'orderby' => $orderby,
+ 'order' => $order,
+ );
- if ( ! $order ) {
- $order = 'desc';
- }
-
- $loop_a = array( 'number' => $number, 'orderby' => $orderby, 'order' => $order );
-
- if ( $include ) {
- $include = explode(',', $include );
+ if ( array_key_exists( 'include', $args ) ) {
+ $include = explode( ',', sanitize_text_field( $args['include'] ) );
$loop_a['include'] = $include;
}
- if ( $exclude ) {
- $exclude = explode(',', $exclude );
+ if ( array_key_exists( 'exclude', $args ) ) {
+ $exclude = explode( ',', sanitize_text_field( $args['exclude'] ) );
$loop_a['exclude'] = $exclude;
}
$loop = get_users( $loop_a );
foreach ( $loop as $user ) {
-
- unset( $user->data->user_status );
- unset( $user->data->user_activation_key );
- unset( $user->data->user_pass );
+ unset( $user->data->user_status, $user->data->user_activation_key, $user->data->user_pass );
um_fetch_user( $user->ID );
foreach ( $user as $key => $val ) {
- if ( $key != 'data' ) {
+ if ( 'data' !== $key ) {
continue;
}
- $key = 'profile';
- $val->roles = $user->roles;
- $val->first_name = um_user('first_name');
- $val->last_name = um_user('last_name');
- $val->account_status = um_user('account_status');
- $val->profile_pic_original = um_get_user_avatar_url('', 'original');
- $val->profile_pic_normal = um_get_user_avatar_url('', 200);
- $val->profile_pic_small = um_get_user_avatar_url('', 40);
- $val->cover_photo = $this->getsrc( um_user('cover_photo', 1000) );
+ $val->roles = $user->roles;
+ $val->first_name = um_user( 'first_name' );
+ $val->last_name = um_user( 'last_name' );
+ $val->account_status = um_user( 'account_status' );
+ $val->profile_pic_original = um_get_user_avatar_url( '', 'original' );
+ $val->profile_pic_normal = um_get_user_avatar_url( '', 200 );
+ $val->profile_pic_small = um_get_user_avatar_url( '', 40 );
+ $val->cover_photo = $this->getsrc( um_user( 'cover_photo', 1000 ) );
/**
- * UM hook
+ * Filters the output data for Rest API userdata call.
*
- * @type filter
- * @title um_rest_userdata
- * @description Change output data for Rest API userdata call
- * @input_vars
- * [{"var":"$value","type":"array","desc":"Output Data"},
- * {"var":"$user_id","type":"string","desc":"User ID"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- * Force change the output data for Rest API userdata call.
+ * function my_custom_um_rest_userdata( $value, $user_id ) {
* // your code here
- * return $value;
+ * return $response;
* }
- * ?>
+ * add_filter( 'um_rest_userdata', 'my_custom_um_rest_userdata', 10, 2 );
*/
- $val = apply_filters( 'um_rest_userdata', $val, $user->ID );
- $response[ $user->ID ] = $val;
+ $response[ $user->ID ] = apply_filters( 'um_rest_userdata', $val, $user->ID );
}
}
return $response;
}
-
/**
* Update user API query
*
@@ -242,26 +213,28 @@ if ( ! class_exists( 'um\core\rest\API_v1' ) ) {
* @return array
*/
public function update_user( $args ) {
- /**
- * @var int $id
- * @var string $data
- * @var string $value
- */
- extract( $args );
-
$response = array();
- $error = array();
+ $error = array();
- if ( ! $id ) {
+ if ( empty( $args['id'] ) ) {
$error['error'] = __( 'You must provide a user ID', 'ultimate-member' );
return $error;
}
- if ( ! $data ) {
+ if ( empty( $args['data'] ) ) {
$error['error'] = __( 'You need to provide data to update', 'ultimate-member' );
return $error;
}
+ if ( ! array_key_exists( 'value', $args ) ) {
+ $error['error'] = __( 'You need to provide value to update', 'ultimate-member' );
+ return $error;
+ }
+
+ $id = absint( $args['id'] );
+ $data = sanitize_text_field( $args['data'] );
+ $value = sanitize_text_field( $args['value'] );
+
um_fetch_user( $id );
switch ( $data ) {
@@ -271,35 +244,16 @@ if ( ! class_exists( 'um\core\rest\API_v1' ) ) {
break;
case 'role':
$wp_user_object = new \WP_User( $id );
- $old_roles = $wp_user_object->roles;
+ $old_roles = $wp_user_object->roles;
$wp_user_object->set_role( $value );
- /**
- * UM hook
- *
- * @type action
- * @title um_after_member_role_upgrade
- * @description Action after user role was changed
- * @input_vars
- * [{"var":"$new_roles","type":"array","desc":"New User Roles"},
- * {"var":"$old_roles","type":"array","desc":"Old roles"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_after_member_role_upgrade', 'function_name', 10, 2 );
- * @example
- *
- */
+ /** This action is documented in includes/core/class-user.php */
do_action( 'um_after_member_role_upgrade', array( $value ), $old_roles, $id );
$response['success'] = __( 'User role has been changed.', 'ultimate-member' );
break;
default:
- update_user_meta( $id, $data, esc_attr( $value ) );
+ update_user_meta( $id, $data, $value );
$response['success'] = __( 'User meta has been changed.', 'ultimate-member' );
break;
}
@@ -307,7 +261,6 @@ if ( ! class_exists( 'um\core\rest\API_v1' ) ) {
return $response;
}
-
/**
* Process delete user via API
*
@@ -316,19 +269,16 @@ if ( ! class_exists( 'um\core\rest\API_v1' ) ) {
* @return array
*/
public function delete_user( $args ) {
- /**
- * @var int $id
- */
- extract( $args );
-
$response = array();
- $error = array();
+ $error = array();
- if ( ! isset( $id ) ) {
+ if ( empty( $args['id'] ) ) {
$error['error'] = __( 'You must provide a user ID', 'ultimate-member' );
return $error;
}
+ $id = absint( $args['id'] );
+
$user = get_userdata( $id );
if ( ! $user ) {
$error['error'] = __( 'Invalid user specified', 'ultimate-member' );
@@ -343,7 +293,6 @@ if ( ! class_exists( 'um\core\rest\API_v1' ) ) {
return $response;
}
-
/**
* Process Get user API Request
*
@@ -352,145 +301,101 @@ if ( ! class_exists( 'um\core\rest\API_v1' ) ) {
* @return array|mixed
*/
public function get_auser( $args ) {
- /**
- * @var int $um_id
- * @var string $um_fields
- */
- extract( $args );
-
$response = array();
- $error = array();
+ $error = array();
- if ( ! isset( $id ) ) {
- $error['error'] = __('You must provide a user ID','ultimate-member');
+ if ( empty( $args['id'] ) ) {
+ $error['error'] = __( 'You must provide a user ID', 'ultimate-member' );
return $error;
}
+ $id = absint( $args['id'] );
$user = get_userdata( $id );
if ( ! $user ) {
- $error['error'] = __('Invalid user specified','ultimate-member');
+ $error['error'] = __( 'Invalid user specified', 'ultimate-member' );
return $error;
}
- unset( $user->data->user_status );
- unset( $user->data->user_activation_key );
- unset( $user->data->user_pass );
+ unset( $user->data->user_status, $user->data->user_activation_key, $user->data->user_pass );
um_fetch_user( $user->ID );
- if ( isset( $fields ) && $fields ) {
- $fields = explode(',', $fields );
- $response['ID'] = $user->ID;
+ if ( array_key_exists( 'fields', $args ) ) {
+ $fields = explode( ',', sanitize_text_field( $args['fields'] ) );
+ $response['ID'] = $user->ID;
$response['username'] = $user->user_login;
foreach ( $fields as $field ) {
switch ( $field ) {
-
default:
- $response[ $field ] = ( um_profile( $field ) ) ? um_profile( $field ) : '';
+ $profile_data = um_profile( $field );
+ $response[ $field ] = $profile_data ? $profile_data : '';
/**
- * UM hook
+ * Filters the output data for Rest API user authentication call.
*
- * @type filter
- * @title um_rest_get_auser
- * @description Change output data for Rest API user authentification call
- * @input_vars
- * [{"var":"$response","type":"array","desc":"Output Data"},
- * {"var":"$field","type":"string","desc":"Field Key"},
- * {"var":"$user_id","type":"int","desc":"User ID"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- * Force change the output data for Rest API user authentication call.
+ * function my_custom_um_rest_get_auser( $response, $field, $user_id ) {
* // your code here
* return $response;
* }
- * ?>
+ * add_filter( 'um_rest_get_auser', 'my_custom_um_rest_get_auser', 10, 3 );
*/
$response = apply_filters( 'um_rest_get_auser', $response, $field, $user->ID );
break;
-
case 'cover_photo':
- $response['cover_photo'] = $this->getsrc( um_user('cover_photo', 1000) );
+ $response['cover_photo'] = $this->getsrc( um_user( 'cover_photo', 1000 ) );
break;
-
case 'profile_pic':
- $response['profile_pic_original'] = um_get_user_avatar_url('', 'original');
- $response['profile_pic_normal'] = um_get_user_avatar_url('', 200);
- $response['profile_pic_small'] = um_get_user_avatar_url('', 40);
+ $response['profile_pic_original'] = um_get_user_avatar_url( '', 'original' );
+ $response['profile_pic_normal'] = um_get_user_avatar_url( '', 200 );
+ $response['profile_pic_small'] = um_get_user_avatar_url( '', 40 );
break;
-
case 'status':
- $response['status'] = um_user('account_status');
+ $response['status'] = um_user( 'account_status' );
break;
-
case 'role':
//get priority role here
$response['role'] = um_user( 'role' );
break;
-
case 'email':
case 'user_email':
- $response['email'] = um_user('user_email');
+ $response['email'] = um_user( 'user_email' );
break;
-
}
-
}
} else {
-
foreach ( $user as $key => $val ) {
- if ( $key != 'data' ) {
+ if ( 'data' !== $key ) {
continue;
}
- $key = 'profile';
- $val->roles = $user->roles;
- $val->first_name = um_user( 'first_name' );
- $val->last_name = um_user('last_name' );
- $val->account_status = um_user( 'account_status' );
+ $val->roles = $user->roles;
+ $val->first_name = um_user( 'first_name' );
+ $val->last_name = um_user( 'last_name' );
+ $val->account_status = um_user( 'account_status' );
$val->profile_pic_original = um_get_user_avatar_url( '', 'original' );
- $val->profile_pic_normal = um_get_user_avatar_url( '', 200 );
- $val->profile_pic_small = um_get_user_avatar_url( '', 40 );
- $val->cover_photo = $this->getsrc( um_user( 'cover_photo', 1000 ) );
+ $val->profile_pic_normal = um_get_user_avatar_url( '', 200 );
+ $val->profile_pic_small = um_get_user_avatar_url( '', 40 );
+ $val->cover_photo = $this->getsrc( um_user( 'cover_photo', 1000 ) );
- /**
- * UM hook
- *
- * @type filter
- * @title um_rest_userdata
- * @description Change output data for Rest API userdata call
- * @input_vars
- * [{"var":"$value","type":"array","desc":"Output Data"},
- * {"var":"$user_id","type":"string","desc":"User ID"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- *
- */
- $val = apply_filters( 'um_rest_userdata', $val, $user->ID );
- $response = $val;
+ /** This filter is documented in includes/core/rest/class-api-v1.php */
+ $response = apply_filters( 'um_rest_userdata', $val, $user->ID );
}
-
}
return $response;
}
-
/**
* Get source
*
@@ -499,13 +404,12 @@ if ( ! class_exists( 'um\core\rest\API_v1' ) ) {
* @return string
*/
public function getsrc( $image ) {
- if (preg_match('/
query_vars['format'] ) ? $wp_query->query_vars['format'] : 'json';
/**
- * UM hook
+ * Filters the REST API output format. JSON by default.
*
- * @type filter
- * @title um_api_output_format
- * @description UM Rest API output format
- * @input_vars
- * [{"var":"$format","type":"string","desc":"Format"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- * Changing the REST API output format.
+ * function my_custom_um_api_output_format( $format ) {
* // your code here
+ * $format = 'xml';
* return $format;
* }
- * ?>
+ * add_filter( 'um_api_output_format', 'my_custom_um_api_output_format' );
*/
return apply_filters( 'um_api_output_format', $format );
}
}
-}
\ No newline at end of file
+}
diff --git a/includes/core/rest/class-api-v2.php b/includes/core/rest/class-api-v2.php
index dcf875d5..3874b827 100644
--- a/includes/core/rest/class-api-v2.php
+++ b/includes/core/rest/class-api-v2.php
@@ -1,13 +1,12 @@
get_var( $wpdb->prepare(
- "SELECT user_id
- FROM $wpdb->usermeta
- WHERE meta_key = 'um_user_public_key' AND
- meta_value = %s
+ "SELECT user_id
+ FROM $wpdb->usermeta
+ WHERE meta_key = 'um_user_public_key' AND
+ meta_value = %s
LIMIT 1",
$key
) );
@@ -133,107 +128,65 @@ if ( ! class_exists( 'um\core\rest\API_v2' ) ) {
return false;
}
-
/**
* Process Get users API Request
*
- * @param $args
+ * @param array $args
*
* @return array
*/
public function get_users( $args ) {
- /**
- * @var int $um_number
- * @var string $um_orderby
- * @var string $um_order
- * @var string $um_include
- * @var string $um_exclude
- */
- extract( $args );
-
$response = array();
- if ( ! $um_number ) {
- $um_number = 10;
+ $number = array_key_exists( 'um_number', $args ) && is_numeric( $args['um_number'] ) ? absint( $args['um_number'] ) : 10;
+ $orderby = array_key_exists( 'um_orderby', $args ) ? sanitize_key( $args['um_orderby'] ) : 'user_registered';
+ $order = array_key_exists( 'um_order', $args ) ? sanitize_key( $args['um_order'] ) : 'desc';
+
+ $loop_a = array(
+ 'number' => $number,
+ 'orderby' => $orderby,
+ 'order' => $order,
+ );
+
+ if ( array_key_exists( 'um_include', $args ) ) {
+ $include = explode( ',', sanitize_text_field( $args['um_include'] ) );
+ $loop_a['include'] = $include;
}
- if ( ! $um_orderby ) {
- $um_orderby = 'user_registered';
- }
-
- if ( ! $um_order ) {
- $um_order = 'desc';
- }
-
- $loop_a = array( 'number' => $um_number, 'orderby' => $um_orderby, 'order' => $um_order );
-
- if ( $um_include ) {
- $um_include = explode(',', $um_include );
- $loop_a['include'] = $um_include;
- }
-
- if ( $um_exclude ) {
- $um_exclude = explode(',', $um_exclude );
- $loop_a['exclude'] = $um_exclude;
+ if ( array_key_exists( 'um_exclude', $args ) ) {
+ $exclude = explode( ',', sanitize_text_field( $args['um_exclude'] ) );
+ $loop_a['exclude'] = $exclude;
}
$loop = get_users( $loop_a );
foreach ( $loop as $user ) {
-
- unset( $user->data->user_status );
- unset( $user->data->user_activation_key );
- unset( $user->data->user_pass );
+ unset( $user->data->user_status, $user->data->user_activation_key, $user->data->user_pass );
um_fetch_user( $user->ID );
foreach ( $user as $key => $val ) {
- if ( $key != 'data' ) {
+ if ( 'data' !== $key ) {
continue;
}
- $key = 'profile';
- $val->roles = $user->roles;
- $val->first_name = um_user( 'first_name' );
- $val->last_name = um_user( 'last_name' );
- $val->account_status = um_user( 'account_status' );
+ $val->roles = $user->roles;
+ $val->first_name = um_user( 'first_name' );
+ $val->last_name = um_user( 'last_name' );
+ $val->account_status = um_user( 'account_status' );
$val->profile_pic_original = um_get_user_avatar_url( '', 'original' );
- $val->profile_pic_normal = um_get_user_avatar_url( '', 200 );
- $val->profile_pic_small = um_get_user_avatar_url( '', 40 );
- $val->cover_photo = $this->getsrc( um_user( 'cover_photo', 1000 ) );
+ $val->profile_pic_normal = um_get_user_avatar_url( '', 200 );
+ $val->profile_pic_small = um_get_user_avatar_url( '', 40 );
+ $val->cover_photo = $this->getsrc( um_user( 'cover_photo', 1000 ) );
- /**
- * UM hook
- *
- * @type filter
- * @title um_rest_userdata
- * @description Change output data for Rest API userdata call
- * @input_vars
- * [{"var":"$value","type":"array","desc":"Output Data"},
- * {"var":"$user_id","type":"string","desc":"User ID"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- *
- */
- $val = apply_filters( 'um_rest_userdata', $val, $user->ID );
-
- $response[ $user->ID ] = $val;
+ /** This filter is documented in includes/core/rest/class-api-v1.php */
+ $response[ $user->ID ] = apply_filters( 'um_rest_userdata', $val, $user->ID );
}
}
return $response;
}
-
/**
* Update user API query
*
@@ -242,64 +195,47 @@ if ( ! class_exists( 'um\core\rest\API_v2' ) ) {
* @return array
*/
public function update_user( $args ) {
- /**
- * @var int $um_id
- * @var string $um_data
- * @var string $um_value
- */
- extract( $args );
-
$response = array();
- $error = array();
+ $error = array();
- if ( ! $um_id ) {
+ if ( empty( $args['um_id'] ) ) {
$error['error'] = __( 'You must provide a user ID', 'ultimate-member' );
return $error;
}
- if ( ! $um_data ) {
+ if ( empty( $args['um_data'] ) ) {
$error['error'] = __( 'You need to provide data to update', 'ultimate-member' );
return $error;
}
- um_fetch_user( $um_id );
+ if ( ! array_key_exists( 'um_value', $args ) ) {
+ $error['error'] = __( 'You need to provide value to update', 'ultimate-member' );
+ return $error;
+ }
- switch ( $um_data ) {
+ $id = absint( $args['um_id'] );
+ $data = sanitize_text_field( $args['um_data'] );
+ $value = sanitize_text_field( $args['um_value'] );
+
+ um_fetch_user( $id );
+
+ switch ( $data ) {
case 'status':
- UM()->user()->set_status( $um_value );
+ UM()->user()->set_status( $value );
$response['success'] = __( 'User status has been changed.', 'ultimate-member' );
break;
case 'role':
- $wp_user_object = new \WP_User( $um_id );
- $old_roles = $wp_user_object->roles;
- $wp_user_object->set_role( $um_value );
+ $wp_user_object = new \WP_User( $id );
+ $old_roles = $wp_user_object->roles;
+ $wp_user_object->set_role( $value );
- /**
- * UM hook
- *
- * @type action
- * @title um_after_member_role_upgrade
- * @description Action after user role was changed
- * @input_vars
- * [{"var":"$new_roles","type":"array","desc":"New User Roles"},
- * {"var":"$old_roles","type":"array","desc":"Old roles"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_after_member_role_upgrade', 'function_name', 10, 2 );
- * @example
- *
- */
- do_action( 'um_after_member_role_upgrade', array( $um_value ), $old_roles, $um_id );
+ /** This action is documented in includes/core/class-user.php */
+ do_action( 'um_after_member_role_upgrade', array( $value ), $old_roles, $id );
$response['success'] = __( 'User role has been changed.', 'ultimate-member' );
break;
default:
- update_user_meta( $um_id, $um_data, esc_attr( $um_value ) );
+ update_user_meta( $id, $data, $value );
$response['success'] = __( 'User meta has been changed.', 'ultimate-member' );
break;
}
@@ -307,35 +243,31 @@ if ( ! class_exists( 'um\core\rest\API_v2' ) ) {
return $response;
}
-
/**
- * Process delete user via API
+ * Process delete user via API.
*
- * @param $args
+ * @param array $args
*
* @return array
*/
public function delete_user( $args ) {
- /**
- * @var int $um_id
- */
- extract( $args );
-
$response = array();
- $error = array();
+ $error = array();
- if ( ! isset( $um_id ) ) {
+ if ( empty( $args['um_id'] ) ) {
$error['error'] = __( 'You must provide a user ID', 'ultimate-member' );
return $error;
}
- $user = get_userdata( $um_id );
+ $id = absint( $args['um_id'] );
+
+ $user = get_userdata( $id );
if ( ! $user ) {
$error['error'] = __( 'Invalid user specified', 'ultimate-member' );
return $error;
}
- um_fetch_user( $um_id );
+ um_fetch_user( $id );
UM()->user()->delete();
$response['success'] = __( 'User has been successfully deleted.', 'ultimate-member' );
@@ -343,7 +275,6 @@ if ( ! class_exists( 'um\core\rest\API_v2' ) ) {
return $response;
}
-
/**
* Process Get user API Request
*
@@ -352,88 +283,54 @@ if ( ! class_exists( 'um\core\rest\API_v2' ) ) {
* @return array
*/
public function get_auser( $args ) {
- /**
- * @var int $um_id
- * @var string $um_fields
- */
- extract( $args );
-
$response = array();
- $error = array();
+ $error = array();
- if ( ! isset( $um_id ) ) {
+ if ( empty( $args['um_id'] ) ) {
$error['error'] = __( 'You must provide a user ID', 'ultimate-member' );
return $error;
}
- $user = get_userdata( $um_id );
+ $id = absint( $args['um_id'] );
+ $user = get_userdata( $id );
if ( ! $user ) {
- $error['error'] = __('Invalid user specified','ultimate-member');
+ $error['error'] = __( 'Invalid user specified', 'ultimate-member' );
return $error;
}
- unset( $user->data->user_status );
- unset( $user->data->user_activation_key );
- unset( $user->data->user_pass );
+ unset( $user->data->user_status, $user->data->user_activation_key, $user->data->user_pass );
um_fetch_user( $user->ID );
- if ( isset( $um_fields ) && $um_fields ) {
- $um_fields = explode(',', $um_fields );
- $response['ID'] = $user->ID;
+ if ( array_key_exists( 'um_fields', $args ) ) {
+ $fields = explode( ',', sanitize_text_field( $args['um_fields'] ) );
+ $response['ID'] = $user->ID;
$response['username'] = $user->user_login;
- foreach ( $um_fields as $field ) {
+ foreach ( $fields as $field ) {
switch ( $field ) {
-
default:
- $response[ $field ] = ( um_profile( $field ) ) ? um_profile( $field ) : '';
+ $profile_data = um_profile( $field );
+ $response[ $field ] = $profile_data ? $profile_data : '';
- /**
- * UM hook
- *
- * @type filter
- * @title um_rest_get_auser
- * @description Change output data for Rest API user authentification call
- * @input_vars
- * [{"var":"$response","type":"array","desc":"Output Data"},
- * {"var":"$field","type":"string","desc":"Field Key"},
- * {"var":"$user_id","type":"int","desc":"User ID"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- *
- */
+ /** This filter is documented in includes/core/rest/class-api-v1.php */
$response = apply_filters( 'um_rest_get_auser', $response, $field, $user->ID );
break;
-
case 'cover_photo':
$response['cover_photo'] = $this->getsrc( um_user( 'cover_photo', 1000 ) );
break;
-
case 'profile_pic':
$response['profile_pic_original'] = um_get_user_avatar_url( '', 'original' );
- $response['profile_pic_normal'] = um_get_user_avatar_url( '', 200 );
- $response['profile_pic_small'] = um_get_user_avatar_url( '', 40 );
+ $response['profile_pic_normal'] = um_get_user_avatar_url( '', 200 );
+ $response['profile_pic_small'] = um_get_user_avatar_url( '', 40 );
break;
-
case 'status':
$response['status'] = um_user( 'account_status' );
break;
-
case 'role':
//get priority role here
$response['role'] = um_user( 'role' );
break;
-
case 'email':
case 'user_email':
$response['email'] = um_user( 'user_email' );
@@ -441,55 +338,28 @@ if ( ! class_exists( 'um\core\rest\API_v2' ) ) {
}
}
} else {
-
foreach ( $user as $key => $val ) {
- if ( $key != 'data' ) {
+ if ( 'data' !== $key ) {
continue;
}
- if ( $key == 'data' ) {
- $key = 'profile';
- $val->roles = $user->roles;
- $val->first_name = um_user( 'first_name' );
- $val->last_name = um_user( 'last_name' );
- $val->account_status = um_user( 'account_status' );
- $val->profile_pic_original = um_get_user_avatar_url( '', 'original' );
- $val->profile_pic_normal = um_get_user_avatar_url( '', 200 );
- $val->profile_pic_small = um_get_user_avatar_url( '', 40 );
- $val->cover_photo = $this->getsrc( um_user( 'cover_photo', 1000 ) );
- /**
- * UM hook
- *
- * @type filter
- * @title um_rest_userdata
- * @description Change output data for Rest API userdata call
- * @input_vars
- * [{"var":"$value","type":"array","desc":"Output Data"},
- * {"var":"$user_id","type":"string","desc":"User ID"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- *
- */
- $val = apply_filters( 'um_rest_userdata', $val, $user->ID );
- }
- $response = $val;
+ $val->roles = $user->roles;
+ $val->first_name = um_user( 'first_name' );
+ $val->last_name = um_user( 'last_name' );
+ $val->account_status = um_user( 'account_status' );
+ $val->profile_pic_original = um_get_user_avatar_url( '', 'original' );
+ $val->profile_pic_normal = um_get_user_avatar_url( '', 200 );
+ $val->profile_pic_small = um_get_user_avatar_url( '', 40 );
+ $val->cover_photo = $this->getsrc( um_user( 'cover_photo', 1000 ) );
+
+ /** This filter is documented in includes/core/rest/class-api-v1.php */
+ $response = apply_filters( 'um_rest_userdata', $val, $user->ID );
}
-
}
return $response;
}
-
/**
* Get source
*
@@ -498,13 +368,12 @@ if ( ! class_exists( 'um\core\rest\API_v2' ) ) {
* @return string
*/
public function getsrc( $image ) {
- if (preg_match('/query_vars['um_format'] ) ? $wp_query->query_vars['um_format'] : 'json';
- /**
- * UM hook
- *
- * @type filter
- * @title um_api_output_format
- * @description UM Rest API output format
- * @input_vars
- * [{"var":"$format","type":"string","desc":"Format"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- *
- */
+ /** This filter is documented in includes/core/rest/class-api-v1.php */
return apply_filters( 'um_api_output_format', $format );
}
}
-}
\ No newline at end of file
+}
diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php
index 3c4eae9f..e8eea188 100644
--- a/includes/core/um-actions-form.php
+++ b/includes/core/um-actions-form.php
@@ -416,8 +416,8 @@ function um_check_conditions_on_submit( $condition, $fields, $args, $reset = fal
*/
function um_submit_form_errors_hook_( $args ) {
$form_id = $args['form_id'];
- $mode = $args['mode'];
- $fields = unserialize( $args['custom_fields'] );
+ $mode = $args['mode'];
+ $fields = unserialize( $args['custom_fields'] );
$um_profile_photo = um_profile('profile_photo');
if ( get_post_meta( $form_id, '_um_profile_photo_required', true ) && ( empty( $args['profile_photo'] ) && empty( $um_profile_photo ) ) ) {
@@ -425,12 +425,12 @@ function um_submit_form_errors_hook_( $args ) {
}
if ( ! empty( $fields ) ) {
-
- $can_edit = false;
- $current_user_roles = [];
+ $can_edit = false;
+ $current_user_roles = array();
if ( is_user_logged_in() ) {
-
- $can_edit = UM()->roles()->um_current_user_can( 'edit', $args['user_id'] );
+ if ( array_key_exists( 'user_id', $args ) ) {
+ $can_edit = UM()->roles()->um_current_user_can( 'edit', $args['user_id'] );
+ }
um_fetch_user( get_current_user_id() );
$current_user_roles = um_user( 'roles' );
@@ -439,7 +439,7 @@ function um_submit_form_errors_hook_( $args ) {
foreach ( $fields as $key => $array ) {
- if ( $mode == 'profile' ) {
+ if ( 'profile' === $mode ) {
$restricted_fields = UM()->fields()->get_restricted_fields_for_edit();
if ( is_array( $restricted_fields ) && in_array( $key, $restricted_fields ) ) {
continue;
@@ -447,7 +447,7 @@ function um_submit_form_errors_hook_( $args ) {
}
$can_view = true;
- if ( isset( $array['public'] ) && $mode != 'register' ) {
+ if ( isset( $array['public'] ) && 'register' !== $mode ) {
switch ( $array['public'] ) {
case '1': // Everyone
@@ -491,7 +491,6 @@ function um_submit_form_errors_hook_( $args ) {
continue;
}
-
/**
* UM hook
*
diff --git a/includes/core/um-actions-login.php b/includes/core/um-actions-login.php
index 3c4ae9b7..dbf019ea 100644
--- a/includes/core/um-actions-login.php
+++ b/includes/core/um-actions-login.php
@@ -1,5 +1,7 @@
-form()->add_error( 'username', __( 'Please enter your username or email', 'ultimate-member' ) );
}
@@ -190,101 +191,88 @@ function um_store_lastlogin_timestamp_( $login ) {
}
add_action( 'wp_login', 'um_store_lastlogin_timestamp_' );
-
/**
* Login user process
*
* @param array $args
*/
function um_user_login( $args ) {
- extract( $args );
+ // phpcs:disable WordPress.Security.NonceVerification -- already verified here
+ $rememberme = ( isset( $_REQUEST['rememberme'], $args['rememberme'] ) && 1 === (int) $args['rememberme'] ) ? 1 : 0;
- $rememberme = ( isset( $args['rememberme'] ) && 1 == $args['rememberme'] && isset( $_REQUEST['rememberme'] ) ) ? 1 : 0;
-
- if ( ( UM()->options()->get( 'deny_admin_frontend_login' ) && ! isset( $_GET['provider'] ) ) && strrpos( um_user('wp_roles' ), 'administrator' ) !== false ) {
+ // @todo check using the 'deny_admin_frontend_login' option
+ if ( false !== strrpos( um_user( 'wp_roles' ), 'administrator' ) && ( ! isset( $_GET['provider'] ) && UM()->options()->get( 'deny_admin_frontend_login' ) ) ) {
wp_die( esc_html__( 'This action has been prevented for security measures.', 'ultimate-member' ) );
}
UM()->user()->auto_login( um_user( 'ID' ), $rememberme );
/**
- * UM hook
+ * Fires after successful login and before user is redirected.
*
- * @type action
- * @title um_on_login_before_redirect
- * @description Hook that runs after successful login and before user is redirected
- * @input_vars
- * [{"var":"$user_id","type":"int","desc":"User ID"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_on_login_before_redirect', 'function_name', 10, 1 );
- * @example
- * Make any custom action after successful login and before user is redirected.
* function my_on_login_before_redirect( $user_id ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_on_login_before_redirect', 'my_on_login_before_redirect', 10, 1 );
*/
do_action( 'um_on_login_before_redirect', um_user( 'ID' ) );
- // Priority redirect
- if ( ! empty( $args['redirect_to'] ) ) {
- exit( wp_safe_redirect( $args['redirect_to'] ) );
+ // Priority redirect from $_GET attribute.
+ if ( ! empty( $args['redirect_to'] ) ) {
+ wp_safe_redirect( $args['redirect_to'] );
+ exit;
}
// Role redirect
$after_login = um_user( 'after_login' );
if ( empty( $after_login ) ) {
- exit( wp_redirect( um_user_profile_url() ) );
+ wp_safe_redirect( um_user_profile_url() );
+ exit;
}
switch ( $after_login ) {
-
case 'redirect_admin':
- exit( wp_redirect( admin_url() ) );
- break;
-
+ wp_safe_redirect( admin_url() );
+ exit;
case 'redirect_url':
/**
- * UM hook
+ * Filters change redirect URL after successful login.
*
- * @type filter
- * @title um_login_redirect_url
- * @description Change redirect URL after successful login
- * @input_vars
- * [{"var":"$url","type":"string","desc":"Redirect URL"},
- * {"var":"$id","type":"int","desc":"User ID"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- * Change redirect URL.
* function my_login_redirect_url( $url, $id ) {
* // your code here
* return $url;
* }
- * ?>
+ * add_filter( 'um_login_redirect_url', 'my_login_redirect_url', 10, 2 );
*/
$redirect_url = apply_filters( 'um_login_redirect_url', um_user( 'login_redirect_url' ), um_user( 'ID' ) );
- exit( wp_redirect( $redirect_url ) );
- break;
-
+ wp_safe_redirect( $redirect_url );
+ exit;
case 'refresh':
- exit( wp_redirect( UM()->permalinks()->get_current_url() ) );
- break;
-
+ wp_safe_redirect( UM()->permalinks()->get_current_url() );
+ exit;
case 'redirect_profile':
default:
- exit( wp_redirect( um_user_profile_url() ) );
- break;
-
+ wp_safe_redirect( um_user_profile_url() );
+ exit;
}
+ // phpcs:enable WordPress.Security.NonceVerification -- already verified here
}
-add_action( 'um_user_login', 'um_user_login', 10 );
-
+add_action( 'um_user_login', 'um_user_login' );
/**
* Form processing
diff --git a/includes/core/um-actions-misc.php b/includes/core/um-actions-misc.php
index faf1a977..0160e190 100644
--- a/includes/core/um-actions-misc.php
+++ b/includes/core/um-actions-misc.php
@@ -1,8 +1,8 @@
-form()->errors ) {
- switch ( sanitize_key( $_REQUEST['updated'] ) ) {
+ // Skip if there are errors while submission.
+ if ( UM()->form()->errors ) {
+ return;
+ }
+
+ // phpcs:disable WordPress.Security.NonceVerification -- used for echo and already verified here.
+ if ( ! empty( $_REQUEST['updated'] ) ) {
+ $updated = sanitize_key( $_REQUEST['updated'] );
+ switch ( $updated ) {
default:
/**
- * UM hook
+ * Filters a custom success message.
*
- * @type filter
- * @title um_custom_success_message_handler
- * @description Add custom success message
- * @input_vars
- * [{"var":"$success","type":"string","desc":"Message"},
- * {"var":"$updated","type":"array","desc":"Updated data"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- * It adds a custom message for `custom_key_on_profile` updated key.
+ * function my_custom_success_message( $success, $updated, $args ) {
+ * if ( 'custom_key_on_profile' === $updated ) {
+ * $success = 'Some custom message';
+ * }
* return $success;
* }
- * ?>
+ * add_filter( 'um_custom_success_message_handler', 'my_custom_success_message', 10, 3 );
*/
- $success = apply_filters( 'um_custom_success_message_handler', $success, sanitize_key( $_REQUEST['updated'] ) );
+ $success = apply_filters( 'um_custom_success_message_handler', $success, $updated, $args );
break;
-
case 'account':
$success = __( 'Your account was updated successfully.', 'ultimate-member' );
break;
-
case 'password_changed':
$success = __( 'You have successfully changed your password.', 'ultimate-member' );
break;
-
case 'account_active':
$success = __( 'Your account is now active! You can login.', 'ultimate-member' );
break;
-
}
}
- if ( ! empty( $_REQUEST['err'] ) && ! UM()->form()->errors ) {
- switch( sanitize_key( $_REQUEST['err'] ) ) {
-
+ if ( ! empty( $_REQUEST['err'] ) ) {
+ $request_error = sanitize_key( $_REQUEST['err'] );
+ switch ( $request_error ) {
default:
/**
- * UM hook
+ * Filters a custom error message.
*
- * @type filter
- * @title um_custom_error_message_handler
- * @description Add custom error message
- * @input_vars
- * [{"var":"$error","type":"string","desc":"Error message"},
- * {"var":"$request_error","type":"array","desc":"Error data"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- * It adds a custom error for `custom_key_on_profile` error key.
+ * function my_custom_error_message( $error, $request_error, $args ) {
+ * if ( 'custom_key_on_profile' === $request_error ) {
+ * $error = 'Some custom message';
+ * }
* return $error;
* }
- * ?>
+ * add_filter( 'um_custom_error_message_handler', 'my_custom_error_message', 10, 3 );
*/
- $err = apply_filters( 'um_custom_error_message_handler', $err, sanitize_key( $_REQUEST['err'] ) );
- if ( ! $err ) {
+ $err = apply_filters( 'um_custom_error_message_handler', $err, $request_error, $args );
+ if ( empty( $err ) ) {
$err = __( 'An error has been encountered', 'ultimate-member' );
}
break;
-
case 'registration_disabled':
$err = __( 'Registration is currently disabled', 'ultimate-member' );
break;
-
case 'blocked_email':
$err = __( 'This email address has been blocked.', 'ultimate-member' );
break;
-
case 'blocked_domain':
$err = __( 'We do not accept registrations from that domain.', 'ultimate-member' );
break;
-
case 'blocked_ip':
$err = __( 'Your IP address has been blocked.', 'ultimate-member' );
break;
-
case 'inactive':
$err = __( 'Your account has been disabled.', 'ultimate-member' );
break;
-
case 'awaiting_admin_review':
$err = __( 'Your account has not been approved yet.', 'ultimate-member' );
break;
-
case 'awaiting_email_confirmation':
$err = __( 'Your account is awaiting e-mail verification.', 'ultimate-member' );
break;
-
case 'rejected':
$err = __( 'Your membership request has been rejected.', 'ultimate-member' );
break;
-
case 'invalid_nonce':
$err = __( 'An error has been encountered. Probably page was cached. Please try again.', 'ultimate-member' );
break;
-
}
}
+ // phpcs:enable WordPress.Security.NonceVerification -- used for echo and already verified here.
+
+ add_filter( 'um_late_escaping_allowed_tags', 'um_form_notices_additional_tags', 10, 2 );
if ( ! empty( $err ) ) {
$output .= '' . $err . '
';
@@ -201,6 +194,24 @@ function um_add_update_notice( $args ) {
$output .= '' . $success . '
';
}
- echo $output;
+ echo wp_kses( $output, UM()->get_allowed_html( 'templates' ) );
+
+ remove_filter( 'um_late_escaping_allowed_tags', 'um_form_notices_additional_tags' );
}
add_action( 'um_before_form', 'um_add_update_notice', 500 );
+
+/**
+ * Extends allowed tags for displaying UM Form notices.
+ *
+ * @since 2.6.4
+ *
+ * @param array $allowed_html
+ * @param string $context
+ * @return array
+ */
+function um_form_notices_additional_tags( $allowed_html, $context ) {
+ if ( 'templates' === $context ) {
+ $allowed_html['i']['onclick'] = true;
+ }
+ return $allowed_html;
+}
diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php
index e7a6dd36..4a4b10d2 100644
--- a/includes/core/um-actions-profile.php
+++ b/includes/core/um-actions-profile.php
@@ -1,170 +1,169 @@
-options()->get( 'profile_tab_main' ) && ! isset( $_REQUEST['um_action'] ) ) {
+ // phpcs:ignore WordPress.Security.NonceVerification -- $_REQUEST is used for echo only
+ if ( ! isset( $_REQUEST['um_action'] ) && ! UM()->options()->get( 'profile_tab_main' ) ) {
return;
}
/**
- * UM hook
+ * Filters user's ability to view a profile
*
- * @type filter
- * @title um_profile_can_view_main
- * @description Check user can view profile
- * @input_vars
- * [{"var":"$view","type":"bool","desc":"Can view?"},
- * {"var":"$user_id","type":"int","desc":"User profile ID"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- * Make profile hidden.
+ * function my_profile_can_view_main( $can_view, $profile_id ) {
+ * $can_view = 1; // make profile hidden.
+ * return $can_view;
* }
- * ?>
+ * add_filter( 'um_profile_can_view_main', 'my_profile_can_view_main', 10, 2 );
*/
$can_view = apply_filters( 'um_profile_can_view_main', -1, um_profile_id() );
- if ( $can_view == -1 ) {
+ if ( -1 === (int) $can_view ) {
/**
- * UM hook
+ * Fires before UM Form content.
*
- * @type action
- * @title um_before_form
- * @description Some actions before profile form
- * @input_vars
- * [{"var":"$args","type":"array","desc":"Profile form shortcode arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_before_form', 'function_name', 10, 1 );
- * @example
- * Make any custom action before UM form.
* function my_before_form( $args ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_before_form', 'my_before_form' );
*/
do_action( 'um_before_form', $args );
-
/**
- * UM hook
+ * Fires before UM Form fields.
*
- * @type action
- * @title um_before_{$mode}_fields
- * @description Some actions before profile form fields
- * @input_vars
- * [{"var":"$args","type":"array","desc":"{Profile} form shortcode arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_before_{$mode}_fields', 'function_name', 10, 1 );
- * @example
- * Make any custom action before UM Profile form fields.
+ * function my_before_profile_fields( $args ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_before_profile_fields', 'my_before_profile_fields' );
+ * @example Make any custom action before UM Login form fields.
+ * function my_before_login_fields( $args ) {
+ * // your code here
+ * }
+ * add_action( 'um_before_login_fields', 'my_before_login_fields' );
+ * @example Make any custom action before UM Register form fields.
+ * function my_before_register_fields( $args ) {
+ * // your code here
+ * }
+ * add_action( 'um_before_register_fields', 'my_before_register_fields' );
*/
do_action( "um_before_{$mode}_fields", $args );
-
/**
- * UM hook
+ * Fires for rendering UM Form fields.
*
- * @type action
- * @title um_main_{$mode}_fields
- * @description Some actions before login form fields
- * @input_vars
- * [{"var":"$args","type":"array","desc":"Login form shortcode arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_before_{$mode}_fields', 'function_name', 10, 1 );
- * @example
- * Make any custom action when profile form fields are rendered.
+ * function my_main_profile_fields( $args ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_main_profile_fields', 'my_main_profile_fields' );
+ * @example Make any custom action when login form fields are rendered.
+ * function my_main_login_fields( $args ) {
+ * // your code here
+ * }
+ * add_action( 'um_main_login_fields', 'my_main_login_fields' );
+ * @example Make any custom action when register form fields are rendered.
+ * function my_main_register_fields( $args ) {
+ * // your code here
+ * }
+ * add_action( 'um_main_register_fields', 'my_main_register_fields' );
*/
do_action( "um_main_{$mode}_fields", $args );
-
/**
- * UM hook
+ * Fires after UM Form fields.
*
- * @type action
- * @title um_after_form_fields
- * @description Some actions after login form fields
- * @input_vars
- * [{"var":"$args","type":"array","desc":"Login form shortcode arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_after_form_fields', 'function_name', 10, 1 );
- * @example
- * Make any custom action after UM Form fields.
* function my_after_form_fields( $args ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_after_form_fields', 'my_after_form_fields' );
*/
do_action( 'um_after_form_fields', $args );
-
/**
- * UM hook
+ * Fires after UM Form fields.
*
- * @type action
- * @title um_after_{$mode}_fields
- * @description Some actions after profile form fields
- * @input_vars
- * [{"var":"$args","type":"array","desc":"Profile form shortcode arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_after_{$mode}_fields', 'function_name', 10, 1 );
- * @example
- * Make any custom action after profile form fields.
+ * function my_after_profile_fields( $args ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_after_profile_fields', 'my_after_profile_fields' );
+ * @example Make any custom action after login form fields.
+ * function my_after_login_fields( $args ) {
+ * // your code here
+ * }
+ * add_action( 'um_after_login_fields', 'my_after_login_fields' );
+ * @example Make any custom action after register form fields.
+ * function my_after_register_fields( $args ) {
+ * // your code here
+ * }
+ * add_action( 'um_after_register_fields', 'my_after_register_fields' );
*/
do_action( "um_after_{$mode}_fields", $args );
-
/**
- * UM hook
+ * Fires after UM Form content.
*
- * @type action
- * @title um_after_form
- * @description Some actions after profile form fields
- * @input_vars
- * [{"var":"$args","type":"array","desc":"Profile form shortcode arguments"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_after_form', 'function_name', 10, 1 );
- * @example
- * Make any custom action after UM Form content.
* function my_after_form( $args ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_after_form', 'my_after_form' );
*/
do_action( 'um_after_form', $args );
@@ -173,7 +172,7 @@ function um_profile_content_main( $args ) {
-
+
fields()->editing ) {
- if ( um_get_requested_user() ) {
- if ( ! UM()->roles()->um_current_user_can( 'edit', um_get_requested_user() ) ) {
- um_redirect_home( um_get_requested_user(), um_is_myprofile() );
- }
- um_fetch_user( um_get_requested_user() );
+ if ( UM()->fields()->editing ) {
+ if ( um_get_requested_user() ) {
+ if ( ! UM()->roles()->um_current_user_can( 'edit', um_get_requested_user() ) ) {
+ um_redirect_home( um_get_requested_user(), um_is_myprofile() );
}
+ um_fetch_user( um_get_requested_user() );
+ }
+ } else {
+ UM()->fields()->viewing = 1;
+
+ if ( um_get_requested_user() ) {
+ if ( ! um_is_myprofile() && ! um_can_view_profile( um_get_requested_user() ) ) {
+ um_redirect_home( um_get_requested_user(), um_is_myprofile() );
+ }
+
+ if ( ! UM()->roles()->um_current_user_can( 'edit', um_get_requested_user() ) ) {
+ UM()->user()->cannot_edit = 1;
+ }
+
+ um_fetch_user( um_get_requested_user() );
} else {
- UM()->fields()->viewing = 1;
+ if ( ! is_user_logged_in() ) {
+ um_redirect_home( um_get_requested_user(), um_is_myprofile() );
+ }
- if ( um_get_requested_user() ) {
- if ( ! um_can_view_profile( um_get_requested_user() ) && ! um_is_myprofile() ) {
- um_redirect_home( um_get_requested_user(), um_is_myprofile() );
- }
-
- if ( ! UM()->roles()->um_current_user_can( 'edit', um_get_requested_user() ) ) {
- UM()->user()->cannot_edit = 1;
- }
-
- um_fetch_user( um_get_requested_user() );
- } else {
- if ( ! is_user_logged_in() ) {
- um_redirect_home( um_get_requested_user(), um_is_myprofile() );
- }
-
- if ( ! um_user( 'can_edit_profile' ) ) {
- UM()->user()->cannot_edit = 1;
- }
+ if ( ! um_user( 'can_edit_profile' ) ) {
+ UM()->user()->cannot_edit = 1;
}
}
}
}
add_action( 'um_pre_profile_shortcode', 'um_pre_profile_shortcode' );
-
/**
* Display the edit profile icon
*
diff --git a/includes/core/um-actions-register.php b/includes/core/um-actions-register.php
index 0d79bbcd..3bf016ce 100644
--- a/includes/core/um-actions-register.php
+++ b/includes/core/um-actions-register.php
@@ -1,11 +1,13 @@
-user()->pending();
}
-add_action('um_post_registration_pending_hook', 'um_post_registration_pending_hook', 10, 2);
-
+add_action( 'um_post_registration_pending_hook', 'um_post_registration_pending_hook', 10, 2 );
/**
* After insert a new user
@@ -118,7 +117,6 @@ function um_after_insert_user( $user_id, $args ) {
}
add_action( 'um_user_register', 'um_after_insert_user', 1, 2 );
-
/**
* Send notification about registration
*
@@ -131,7 +129,7 @@ function um_send_registration_notification( $user_id, $args ) {
$emails = um_multi_admin_email();
if ( ! empty( $emails ) ) {
foreach ( $emails as $email ) {
- if ( um_user( 'account_status' ) != 'pending' ) {
+ if ( 'pending' !== um_user( 'account_status' ) ) {
UM()->mail()->send( $email, 'notification_new_user', array( 'admin' => true ) );
} else {
UM()->mail()->send( $email, 'notification_review', array( 'admin' => true ) );
@@ -141,7 +139,6 @@ function um_send_registration_notification( $user_id, $args ) {
}
add_action( 'um_registration_complete', 'um_send_registration_notification', 10, 2 );
-
/**
* Check user status and redirect it after registration
*
@@ -270,7 +267,6 @@ function um_check_user_status( $user_id, $args ) {
}
add_action( 'um_registration_complete', 'um_check_user_status', 100, 2 );
-
function um_submit_form_errors_hook__registration( $args ) {
// Check for "\" in password.
if ( array_key_exists( 'user_password', $args ) && false !== strpos( wp_unslash( trim( $args['user_password'] ) ), '\\' ) ) {
@@ -280,68 +276,66 @@ function um_submit_form_errors_hook__registration( $args ) {
add_action( 'um_submit_form_errors_hook__registration', 'um_submit_form_errors_hook__registration', 10, 1 );
/**
- * Registration form submit handler
+ * Registration form submit handler.
*
- * @param $args
- * @return bool|int|WP_Error
+ * @param array $args
*/
function um_submit_form_register( $args ) {
if ( isset( UM()->form()->errors ) ) {
- return false;
+ return;
}
/**
- * UM hook
+ * Filters user data submitted by a registration form.
*
- * @type filter
- * @title um_add_user_frontend_submitted
- * @description Extend user data on registration form submit
- * @input_vars
- * [{"var":"$submitted","type":"array","desc":"Registration data"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- * Extends registration data.
* function my_add_user_frontend_submitted( $submitted ) {
* // your code here
* return $submitted;
* }
- * ?>
+ * add_filter( 'um_add_user_frontend_submitted', 'my_add_user_frontend_submitted' );
*/
$args = apply_filters( 'um_add_user_frontend_submitted', $args );
- extract( $args );
-
- if ( ! empty( $username ) && empty( $user_login ) ) {
- $user_login = $username;
+ if ( ! empty( $args['user_login'] ) ) {
+ $user_login = $args['user_login'];
+ }
+ if ( ! empty( $args['username'] ) && empty( $args['user_login'] ) ) {
+ $user_login = $args['username'];
}
- if ( ! empty( $first_name ) && ! empty( $last_name ) && empty( $user_login ) ) {
+ if ( ! empty( $args['first_name'] ) && ! empty( $args['last_name'] ) && empty( $user_login ) ) {
switch ( UM()->options()->get( 'permalink_base' ) ) {
case 'name':
- $user_login = str_replace( " ", ".", $first_name . " " . $last_name );
+ $user_login = str_replace( ' ', '.', $args['first_name'] . ' ' . $args['last_name'] );
break;
case 'name_dash':
- $user_login = str_replace( " ", "-", $first_name . " " . $last_name );
+ $user_login = str_replace( ' ', '-', $args['first_name'] . ' ' . $args['last_name'] );
break;
case 'name_plus':
- $user_login = str_replace( " ", "+", $first_name . " " . $last_name );
+ $user_login = str_replace( ' ', '+', $args['first_name'] . ' ' . $args['last_name'] );
break;
default:
- $user_login = str_replace( " ", "", $first_name . " " . $last_name );
+ $user_login = str_replace( ' ', '', $args['first_name'] . ' ' . $args['last_name'] );
break;
}
$user_login = sanitize_user( strtolower( remove_accents( $user_login ) ), true );
if ( ! empty( $user_login ) ) {
- $count = 1;
+ $count = 1;
$temp_user_login = $user_login;
while ( username_exists( $temp_user_login ) ) {
$temp_user_login = $user_login . $count;
@@ -351,56 +345,57 @@ function um_submit_form_register( $args ) {
}
}
- if ( empty( $user_login ) && ! empty( $user_email ) ) {
- $user_login = $user_email;
+ if ( empty( $user_login ) && ! empty( $args['user_email'] ) ) {
+ $user_login = $args['user_email'];
}
- $unique_userID = uniqid();
+ $unique_user_id = uniqid();
// see dbDelta and WP native DB structure user_login varchar(60)
- if ( empty( $user_login ) || mb_strlen( $user_login ) > 60 && ! is_email( $user_login ) ) {
- $user_login = 'user' . $unique_userID;
+ if ( empty( $user_login ) || ( mb_strlen( $user_login ) > 60 && ! is_email( $user_login ) ) ) {
+ $user_login = 'user' . $unique_user_id;
while ( username_exists( $user_login ) ) {
- $unique_userID = uniqid();
- $user_login = 'user' . $unique_userID;
+ $unique_user_id = uniqid();
+ $user_login = 'user' . $unique_user_id;
}
}
- if ( isset( $username ) && is_email( $username ) ) {
- $user_email = $username;
+ if ( isset( $args['username'] ) && is_email( $args['username'] ) ) {
+ $user_email = $args['username'];
+ } elseif ( ! empty( $args['user_email'] ) ) {
+ $user_email = $args['user_email'];
}
- if ( ! isset( $user_password ) ) {
+ if ( ! isset( $args['user_password'] ) ) {
$user_password = UM()->validation()->generate( 8 );
+ } else {
+ $user_password = $args['user_password'];
}
if ( empty( $user_email ) ) {
- $site_url = @$_SERVER['SERVER_NAME'];
- $user_email = 'nobody' . $unique_userID . '@' . $site_url;
+ $site_url = wp_parse_url( get_site_url(), PHP_URL_HOST );
+ $user_email = 'nobody' . $unique_user_id . '@' . $site_url;
while ( email_exists( $user_email ) ) {
- $unique_userID = uniqid();
- $user_email = 'nobody' . $unique_userID . '@' . $site_url;
+ $unique_user_id = uniqid();
+ $user_email = 'nobody' . $unique_user_id . '@' . $site_url;
}
+
/**
- * UM hook
+ * Filters change user default email if it's empty on registration.
*
- * @type filter
- * @title um_user_register_submitted__email
- * @description Change user default email if it's empty on registration
- * @input_vars
- * [{"var":"$user_email","type":"string","desc":"Default email"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- * Change user default email if it's empty on registration.
* function my_user_register_submitted__email( $user_email ) {
* // your code here
* return $user_email;
* }
- * ?>
+ * add_filter( 'um_user_register_submitted__email', 'my_user_register_submitted__email' );
*/
$user_email = apply_filters( 'um_user_register_submitted__email', $user_email );
}
@@ -417,10 +412,10 @@ function um_submit_form_register( $args ) {
$args['submitted'] = array_merge( $args['submitted'], $credentials );
- // set timestamp
- $timestamp = current_time( 'timestamp' );
+ // Set registration timestamp.
+ $timestamp = current_time( 'timestamp' ); // @todo Working on timestamps.
$args['submitted']['timestamp'] = $timestamp;
- $args['timestamp'] = $timestamp;
+ $args['timestamp'] = $timestamp;
$args = array_merge( $args, $credentials );
@@ -433,70 +428,58 @@ function um_submit_form_register( $args ) {
$exclude_roles = array_diff( array_keys( $wp_roles->roles ), UM()->roles()->get_editable_user_roles() );
//if role is properly set it
- if ( ! in_array( $args['role'], $exclude_roles ) ) {
+ if ( ! in_array( $args['role'], $exclude_roles, true ) ) {
$user_role = $args['role'];
}
}
/**
- * UM hook
+ * Filters change user role on registration process
*
- * @type filter
- * @title um_registration_user_role
- * @description Change user role on registration process
- * @input_vars
- * [{"var":"$role","type":"string","desc":"User role"},
- * {"var":"$submitted","type":"array","desc":"Registration data"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage
- *
- * @example
- * Change user role on registration process.
+ * function my_registration_user_role( $user_role, $args ) {
* // your code here
- * return $role;
+ * return $user_role;
* }
- * ?>
+ * add_filter( 'um_registration_user_role', 'my_registration_user_role', 10, 2 );
*/
$user_role = apply_filters( 'um_registration_user_role', $user_role, $args );
$userdata = array(
- 'user_login' => $user_login,
- 'user_pass' => $user_password,
- 'user_email' => $user_email,
- 'role' => $user_role,
+ 'user_login' => $user_login,
+ 'user_pass' => $user_password,
+ 'user_email' => $user_email,
+ 'role' => $user_role,
);
$user_id = wp_insert_user( $userdata );
/**
- * UM hook
+ * Fires after complete UM user registration.
*
- * @type action
- * @title um_user_register
- * @description After complete UM user registration.
- * @input_vars
- * [{"var":"$user_id","type":"int","desc":"User ID"},
- * {"var":"$args","type":"array","desc":"Form data"}]
- * @change_log
- * ["Since: 2.0"]
- * @usage add_action( 'um_user_register', 'function_name', 10, 2 );
- * @example
- * Make any custom action after complete UM user registration.
+ * function my_um_user_register( $user_id, $args ) {
* // your code here
* }
- * ?>
+ * add_action( 'um_user_register', 'my_um_user_register', 10, 2 );
*/
do_action( 'um_user_register', $user_id, $args );
-
- return $user_id;
}
-add_action( 'um_submit_form_register', 'um_submit_form_register', 10 );
-
+add_action( 'um_submit_form_register', 'um_submit_form_register' );
/**
* Show the submit button