mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
512dc53a18
* updated filters by status, avoid slow queries for getting users count; * updated bulk-actions for changing statuses (moved to WP native dropdown) * separate handlers for changing user statuses on wp-admin and frontend (partially implemented); * created class UM()->common()->users() to handle user statuses in more clear format; * deprecated old hooks and old functions
162 lines
4.4 KiB
PHP
162 lines
4.4 KiB
PHP
<?php if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* Processes the requests of UM actions
|
|
*
|
|
*/
|
|
function um_action_request_process() {
|
|
if ( is_admin() ) {
|
|
return;
|
|
}
|
|
|
|
if ( ! is_user_logged_in() ) {
|
|
return;
|
|
}
|
|
|
|
if ( ! isset( $_REQUEST['um_action'] ) ) {
|
|
return;
|
|
}
|
|
|
|
$action = sanitize_key( $_REQUEST['um_action'] );
|
|
|
|
$uid = 0;
|
|
if ( isset( $_REQUEST['uid'] ) ) {
|
|
$uid = absint( $_REQUEST['uid'] );
|
|
}
|
|
|
|
if ( ! empty( $uid ) && ! UM()->user()->user_exists_by_id( $uid ) ) {
|
|
return;
|
|
}
|
|
|
|
if ( ! empty( $uid ) && is_super_admin( $uid ) ) {
|
|
wp_die( esc_html__( 'Super administrators can not be modified.', 'ultimate-member' ) );
|
|
}
|
|
|
|
$role = get_role( UM()->roles()->get_priority_user_role( get_current_user_id() ) );
|
|
$can_edit_users = current_user_can( 'edit_users' ) && $role->has_cap( 'edit_users' );
|
|
|
|
switch ( $action ) {
|
|
default:
|
|
/**
|
|
* UM hook
|
|
*
|
|
* @type action
|
|
* @title um_action_user_request_hook
|
|
* @description Integration for user actions
|
|
* @input_vars
|
|
* [{"var":"$action","type":"string","desc":"Action for user"},
|
|
* {"var":"$user_id","type":"int","desc":"User ID"}]
|
|
* @change_log
|
|
* ["Since: 2.0"]
|
|
* @usage add_action( 'um_action_user_request_hook', 'function_name', 10, 2 );
|
|
* @example
|
|
* <?php
|
|
* add_action( 'um_action_user_request_hook', 'my_action_user_request', 10, 2 );
|
|
* function my_action_user_request( $action, $user_id ) {
|
|
* // your code here
|
|
* }
|
|
* ?>
|
|
*/
|
|
do_action( 'um_action_user_request_hook', $action, $uid );
|
|
break;
|
|
|
|
case 'edit':
|
|
UM()->fields()->editing = true;
|
|
if ( ! um_is_myprofile() ) {
|
|
if ( ! UM()->roles()->um_current_user_can( 'edit', um_profile_id() ) ) {
|
|
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
|
|
}
|
|
} else {
|
|
if ( ! um_can_edit_my_profile() ) {
|
|
$url = um_edit_my_profile_cancel_uri();
|
|
exit( wp_redirect( $url ) );
|
|
}
|
|
}
|
|
break;
|
|
|
|
case 'um_switch_user':
|
|
if ( ! current_user_can( 'manage_options' ) ) {
|
|
return;
|
|
}
|
|
UM()->user()->auto_login( $uid );
|
|
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
|
|
break;
|
|
|
|
case 'um_reject_membership':
|
|
if ( ! $can_edit_users ) {
|
|
wp_die( esc_html__( 'You do not have permission to make this action.', 'ultimate-member' ) );
|
|
}
|
|
|
|
um_fetch_user( $uid );
|
|
UM()->common()->users()->reject( $uid );
|
|
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
|
|
break;
|
|
|
|
case 'um_approve_membership':
|
|
if ( ! $can_edit_users ) {
|
|
wp_die( esc_html__( 'You do not have permission to make this action.', 'ultimate-member' ) );
|
|
}
|
|
|
|
um_fetch_user( $uid );
|
|
|
|
UM()->common()->users()->approve( $uid );
|
|
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
|
|
break;
|
|
|
|
case 'um_reactivate':
|
|
if ( ! $can_edit_users ) {
|
|
wp_die( esc_html__( 'You do not have permission to make this action.', 'ultimate-member' ) );
|
|
}
|
|
|
|
um_fetch_user( $uid );
|
|
|
|
UM()->common()->users()->reactivate( $uid );
|
|
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
|
|
break;
|
|
|
|
case 'um_put_as_pending':
|
|
if ( ! $can_edit_users ) {
|
|
wp_die( esc_html__( 'You do not have permission to make this action.', 'ultimate-member' ) );
|
|
}
|
|
|
|
um_fetch_user( $uid );
|
|
UM()->common()->users()->set_as_pending( $uid );
|
|
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
|
|
break;
|
|
|
|
case 'um_resend_activation':
|
|
if ( ! $can_edit_users ) {
|
|
wp_die( esc_html__( 'You do not have permission to make this action.', 'ultimate-member' ) );
|
|
}
|
|
|
|
um_fetch_user( $uid );
|
|
UM()->common()->users()->send_activation( $uid );
|
|
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
|
|
break;
|
|
|
|
case 'um_deactivate':
|
|
if ( ! $can_edit_users ) {
|
|
wp_die( esc_html__( 'You do not have permission to make this action.', 'ultimate-member' ) );
|
|
}
|
|
|
|
um_fetch_user( $uid );
|
|
UM()->common()->users()->deactivate( $uid );
|
|
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
|
|
break;
|
|
|
|
case 'um_delete':
|
|
if ( ! UM()->roles()->um_current_user_can( 'delete', $uid ) ) {
|
|
wp_die( esc_html__( 'You do not have permission to delete this user.', 'ultimate-member' ) );
|
|
}
|
|
|
|
um_fetch_user( $uid );
|
|
UM()->user()->delete();
|
|
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
|
|
break;
|
|
|
|
}
|
|
}
|
|
add_action( 'template_redirect', 'um_action_request_process', 10000 );
|