mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-20 15:13:55 +09:00
* Admin Users bulk-actions
* Admin single user actions * Frontend single user action
This commit is contained in:
@@ -2589,21 +2589,18 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
return $pagination_data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function build_user_actions_list( $user_id ) {
|
||||
|
||||
private function build_user_actions_list( $user_id ) {
|
||||
$actions = array();
|
||||
if ( ! is_user_logged_in() ) {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
if ( get_current_user_id() != $user_id ) {
|
||||
|
||||
if ( get_current_user_id() !== $user_id ) {
|
||||
if ( UM()->roles()->um_current_user_can( 'edit', $user_id ) ) {
|
||||
$actions['um-editprofile'] = array(
|
||||
'title' => esc_html__( 'Edit Profile', 'ultimate-member' ),
|
||||
@@ -2611,31 +2608,17 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_admin_user_actions_hook
|
||||
* @description Extend admin actions for each user
|
||||
* @input_vars
|
||||
* [{"var":"$actions","type":"array","desc":"Actions for user"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_admin_user_actions_hook', 'function_name', 10, 1 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_admin_user_actions_hook', 'my_admin_user_actions', 10, 1 );
|
||||
* function my_admin_user_actions( $actions ) {
|
||||
* // your code here
|
||||
* return $actions;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$admin_actions = apply_filters( 'um_admin_user_actions_hook', array(), $user_id );
|
||||
$admin_actions = UM()->frontend()->users()->get_actions_list( $user_id );
|
||||
if ( ! empty( $admin_actions ) ) {
|
||||
foreach ( $admin_actions as $id => $arr ) {
|
||||
$url = add_query_arg( array( 'um_action' => $id, 'uid' => $user_id ), um_get_core_page( 'user' ) );
|
||||
$url = add_query_arg(
|
||||
array(
|
||||
'um_action' => $id,
|
||||
'uid' => $user_id,
|
||||
'nonce' => wp_create_nonce( $id . $user_id ),
|
||||
),
|
||||
um_user_profile_url( $user_id )
|
||||
);
|
||||
|
||||
$actions[ $id ] = array(
|
||||
'title' => esc_html( $arr['label'] ),
|
||||
@@ -2645,9 +2628,7 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
}
|
||||
|
||||
$actions = apply_filters( 'um_member_directory_users_card_actions', $actions, $user_id );
|
||||
|
||||
} else {
|
||||
|
||||
if ( empty( UM()->user()->cannot_edit ) ) {
|
||||
$actions['um-editprofile'] = array(
|
||||
'title' => esc_html__( 'Edit Profile', 'ultimate-member' ),
|
||||
@@ -2671,15 +2652,13 @@ if ( ! class_exists( 'um\core\Member_Directory' ) ) {
|
||||
return $actions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $user_id
|
||||
* @param array $directory_data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function build_user_card_data( $user_id, $directory_data ) {
|
||||
|
||||
public function build_user_card_data( $user_id, $directory_data ) {
|
||||
um_fetch_user( $user_id );
|
||||
|
||||
$dropdown_actions = $this->build_user_actions_list( $user_id );
|
||||
|
||||
@@ -234,8 +234,8 @@ if ( ! class_exists( 'um\core\Rewrite' ) ) {
|
||||
$user_id = $this->get_user_id_by_user_login_slug();
|
||||
}
|
||||
|
||||
if ( 'user_id' === $permalink_base ) {
|
||||
$user_id = UM()->user()->user_exists_by_id( um_queried_user() );
|
||||
if ( 'user_id' === $permalink_base && UM()->common()->users()::user_exists( um_queried_user() ) ) {
|
||||
$user_id = um_queried_user();
|
||||
}
|
||||
|
||||
if ( 'hash' === $permalink_base ) {
|
||||
|
||||
@@ -1725,28 +1725,7 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
function get_admin_actions() {
|
||||
$items = array();
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_admin_user_actions_hook
|
||||
* @description Extend admin actions for each user
|
||||
* @input_vars
|
||||
* [{"var":"$actions","type":"array","desc":"Actions for user"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_admin_user_actions_hook', 'function_name', 10, 1 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_admin_user_actions_hook', 'my_admin_user_actions', 10, 1 );
|
||||
* function my_admin_user_actions( $actions ) {
|
||||
* // your code here
|
||||
* return $actions;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$actions = apply_filters( 'um_admin_user_actions_hook', array(), um_profile_id() );
|
||||
$actions = UM()->frontend()->users()->get_actions_list( um_profile_id() );
|
||||
if ( empty( $actions ) ) {
|
||||
return $items;
|
||||
}
|
||||
@@ -1756,10 +1735,9 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
array(
|
||||
'um_action' => $id,
|
||||
'uid' => um_profile_id(),
|
||||
'nonce' => wp_create_nonce( $id . um_profile_id() ),
|
||||
)
|
||||
);
|
||||
/*$url = add_query_arg( 'um_action', $id );
|
||||
$url = add_query_arg( 'uid', um_profile_id(), $url );*/
|
||||
$items[] = '<a href="' . esc_url( $url ) . '" class="real_url ' . esc_attr( $id ) . '-item">' . esc_html( $arr['label'] ) . '</a>';
|
||||
}
|
||||
return $items;
|
||||
@@ -2111,32 +2089,15 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
/**
|
||||
* This method checks if a user exists or not in your site based on the user ID.
|
||||
*
|
||||
* @usage <?php UM()->user()->user_exists_by_id( $user_id ); ?>
|
||||
* @deprecated 2.8.7
|
||||
*
|
||||
* @param int $user_id A user ID must be passed to check if the user exists
|
||||
*
|
||||
* @return bool|int
|
||||
*
|
||||
* @example Basic Usage
|
||||
|
||||
<?php
|
||||
|
||||
$boolean = UM()->user()->user_exists_by_id( 15 );
|
||||
if ( $boolean ) {
|
||||
// That user exists
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
*
|
||||
*/
|
||||
public function user_exists_by_id( $user_id ) {
|
||||
$aux = get_userdata( absint( $user_id ) );
|
||||
if ( $aux == false ) {
|
||||
return false;
|
||||
} else {
|
||||
return $user_id;
|
||||
}
|
||||
_deprecated_function( __METHOD__, '2.8.7', 'UM()->common()->users()::user_exists' );
|
||||
return UM()->common()->users()::user_exists( $user_id ) ? $user_id : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
<?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 );
|
||||
@@ -3,61 +3,6 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main admin user actions.
|
||||
*
|
||||
* @param array $actions
|
||||
* @param int $user_id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function um_admin_user_actions_hook( $actions, $user_id ) {
|
||||
um_fetch_user( $user_id );
|
||||
|
||||
$role = get_role( UM()->roles()->get_priority_user_role( get_current_user_id() ) );
|
||||
|
||||
$can_edit_users = null !== $role && current_user_can( 'edit_users' ) && $role->has_cap( 'edit_users' );
|
||||
if ( $can_edit_users ) {
|
||||
$account_status = um_user( 'account_status' );
|
||||
|
||||
if ( 'awaiting_admin_review' === $account_status ) {
|
||||
$actions['um_approve_membership'] = array( 'label' => __( 'Approve Membership', 'ultimate-member' ) );
|
||||
$actions['um_reject_membership'] = array( 'label' => __( 'Reject Membership', 'ultimate-member' ) );
|
||||
}
|
||||
|
||||
if ( 'rejected' === $account_status ) {
|
||||
$actions['um_approve_membership'] = array( 'label' => __( 'Approve Membership', 'ultimate-member' ) );
|
||||
}
|
||||
|
||||
if ( 'approved' === $account_status ) {
|
||||
$actions['um_put_as_pending'] = array( 'label' => __( 'Put as Pending Review', 'ultimate-member' ) );
|
||||
}
|
||||
|
||||
if ( 'awaiting_email_confirmation' === $account_status ) {
|
||||
$actions['um_resend_activation'] = array( 'label' => __( 'Resend Activation Email', 'ultimate-member' ) );
|
||||
}
|
||||
|
||||
if ( 'inactive' !== $account_status ) {
|
||||
$actions['um_deactivate'] = array( 'label' => __( 'Deactivate this account', 'ultimate-member' ) );
|
||||
}
|
||||
|
||||
if ( 'inactive' === $account_status ) {
|
||||
$actions['um_reactivate'] = array( 'label' => __( 'Reactivate this account', 'ultimate-member' ) );
|
||||
}
|
||||
}
|
||||
|
||||
if ( UM()->roles()->um_current_user_can( 'delete', $user_id ) ) {
|
||||
$actions['um_delete'] = array( 'label' => __( 'Delete this user', 'ultimate-member' ) );
|
||||
}
|
||||
|
||||
if ( current_user_can( 'manage_options' ) && ! is_super_admin( $user_id ) ) {
|
||||
$actions['um_switch_user'] = array( 'label' => __( 'Login as this user', 'ultimate-member' ) );
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
add_filter( 'um_admin_user_actions_hook', 'um_admin_user_actions_hook', 10, 2 );
|
||||
|
||||
/**
|
||||
* Filter user basename.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user