class-admin-functions.php
2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace um\admin;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'um\admin\Admin_Functions' ) ) {
/**
* Class Admin_Functions
* @package um\admin\core
*/
class Admin_Functions {
/**
* Admin_Functions constructor.
*/
function __construct() {
}
/**
* Check wp-admin nonce
*
* @param bool $action
*/
function check_ajax_nonce( $action = false ) {
$nonce = isset( $_REQUEST['nonce'] ) ? sanitize_text_field( $_REQUEST['nonce'] ) : '';
$action = empty( $action ) ? 'um-admin-nonce' : $action;
if ( ! wp_verify_nonce( $nonce, $action ) ) {
wp_send_json_error( esc_js( __( 'Wrong Nonce', 'ultimate-member' ) ) );
}
}
/**
* Boolean check if we're viewing UM backend
*
* @return bool
*/
function is_um_screen() {
global $current_screen;
$is_um_screen = false;
if ( ! empty( $current_screen ) ) {
$screen_id = $current_screen->id;
if ( strstr( $screen_id, 'ultimatemember' ) ||
strstr( $screen_id, 'um_' ) ||
strstr( $screen_id, 'user' ) ||
strstr( $screen_id, 'profile' ) ||
$screen_id == 'nav-menus' ) {
$is_um_screen = true;
}
}
if ( $this->is_plugin_post_type() ) {
$is_um_screen = true;
}
if ( $this->is_restricted_entity() ) {
$is_um_screen = true;
}
return apply_filters( 'um_is_ultimatememeber_admin_screen', $is_um_screen );
}
/**
* Check if current page load UM post type
*
* @return bool
*/
function is_plugin_post_type() {
$cpt = UM()->cpt_list();
if ( isset( $_REQUEST['post_type'] ) ) {
$post_type = sanitize_key( $_REQUEST['post_type'] );
if ( in_array( $post_type, $cpt ) ) {
return true;
}
} elseif ( isset( $_REQUEST['action'] ) && sanitize_key( $_REQUEST['action'] ) == 'edit' ) {
$post_type = get_post_type();
if ( in_array( $post_type, $cpt ) ) {
return true;
}
}
return false;
}
/**
* If page now show content with restricted post/taxonomy
*
* @return bool
*/
function is_restricted_entity() {
$restricted_posts = UM()->options()->get( 'restricted_access_post_metabox' );
$restricted_taxonomies = UM()->options()->get( 'restricted_access_taxonomy_metabox' );
global $typenow, $taxnow;
if ( ! empty( $typenow ) && ! empty( $restricted_posts[ $typenow ] ) ) {
return true;
}
if ( ! empty( $taxnow ) && ! empty( $restricted_taxonomies[ $taxnow ] ) ) {
return true;
}
return false;
}
}
}