class-admin-menu.php
9.82 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<?php
namespace um\admin\core;
use \RecursiveDirectoryIterator;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'um\admin\core\Admin_Menu' ) ) {
/**
* Class Admin_Menu
* @package um\admin\core
*/
class Admin_Menu {
/**
* @var string
*/
var $pagehook;
var $slug = 'ultimatemember';
/**
* Admin_Menu constructor.
*/
function __construct() {
add_action( 'admin_menu', array( &$this, 'primary_admin_menu' ), 0 );
add_action( 'admin_menu', array( &$this, 'secondary_menu_items' ), 1000 );
add_action( 'admin_menu', array( &$this, 'extension_menu' ), 9999 );
add_action( 'admin_head', array( $this, 'menu_order_count' ) );
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 1000 );
}
/**
* Change the admin footer text on UM admin pages
*
* @param $footer_text
*
* @return string
*/
public function admin_footer_text( $footer_text ) {
$current_screen = get_current_screen();
// Add the dashboard pages
$um_pages[] = 'toplevel_page_ultimatemember';
$um_pages[] = 'ultimate-member_page_um_options';
$um_pages[] = 'edit-um_form';
$um_pages[] = 'edit-um_role';
$um_pages[] = 'edit-um_directory';
$um_pages[] = 'ultimate-member_page_ultimatemember-extensions';
if ( isset( $current_screen->id ) && in_array( $current_screen->id, $um_pages ) ) {
// Change the footer text
if ( ! get_option( 'um_admin_footer_text_rated' ) ) {
ob_start(); ?>
<a href="https://wordpress.org/support/plugin/ultimate-member/reviews/?filter=5" target="_blank" class="um-admin-rating-link" data-rated="<?php esc_attr_e( 'Thanks :)', 'ultimate-member' ) ?>">
★★★★★
</a>
<?php $link = ob_get_clean();
ob_start();
// translators: %s: Review link.
echo wp_kses( sprintf( __( 'If you like Ultimate Member please consider leaving a %s review. It will help us to grow the plugin and make it more popular. Thank you.', 'ultimate-member' ), $link ), UM()->get_allowed_html( 'admin_notice' ) );
?>
<script type="text/javascript">
jQuery( 'a.um-admin-rating-link' ).click(function() {
jQuery.ajax({
url: wp.ajax.settings.url,
type: 'post',
data: {
action: 'um_rated',
nonce: um_admin_scripts.nonce
},
success: function(){
}
});
jQuery(this).parent().text( jQuery( this ).data( 'rated' ) );
});
</script>
<?php $footer_text = ob_get_clean();
}
}
return $footer_text;
}
/**
* When user clicks the review link in backend
*/
function ultimatemember_rated() {
UM()->admin()->check_ajax_nonce();
if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( __( 'Please login as administrator', 'ultimate-member' ) );
}
update_option( 'um_admin_footer_text_rated', 1 );
wp_send_json_success();
}
/**
* Manage order of admin menu items
*/
public function menu_order_count() {
global $menu, $submenu;
if ( ! current_user_can( 'list_users' ) ) {
return;
}
$count = UM()->query()->get_pending_users_count();
if ( is_array( $menu ) ) {
foreach ( $menu as $key => $menu_item ) {
if ( 0 === strpos( $menu_item[0], _x( 'Users', 'Admin menu name' ) ) ) {
$menu[ $key ][0] .= ' <span class="update-plugins count-' . $count . '"><span class="processing-count">' . $count . '</span></span>';
}
}
}
if ( is_array( $submenu ) && isset( $submenu['users.php'] ) ) {
foreach ( $submenu['users.php'] as $key => $menu_item ) {
if ( 0 === strpos( $menu_item[0], _x( 'All Users', 'Admin menu name' ) ) ) {
$submenu['users.php'][ $key ][0] .= ' <span class="update-plugins count-' .$count . '"><span class="processing-count">' . $count . '</span></span>';
}
}
}
}
/**
* Setup admin menu
*/
function primary_admin_menu() {
$this->pagehook = add_menu_page( __( 'Ultimate Member', 'ultimate-member' ), __( 'Ultimate Member', 'ultimate-member' ), 'manage_options', $this->slug, array( &$this, 'admin_page' ), 'dashicons-admin-users', '42.78578');
add_action( 'load-' . $this->pagehook, array( &$this, 'on_load_page' ) );
add_submenu_page( $this->slug, __( 'Dashboard', 'ultimate-member' ), __( 'Dashboard', 'ultimate-member' ), 'manage_options', $this->slug, array( &$this, 'admin_page' ) );
}
/**
* Secondary admin menu (after settings)
*/
function secondary_menu_items() {
add_submenu_page( $this->slug, __( 'Forms', 'ultimate-member' ), __( 'Forms', 'ultimate-member' ), 'manage_options', 'edit.php?post_type=um_form', '' );
add_submenu_page( $this->slug, __( 'User Roles', 'ultimate-member' ), __( 'User Roles', 'ultimate-member' ), 'manage_options', 'um_roles', array( &$this, 'um_roles_pages' ) );
if ( UM()->options()->get( 'members_page' ) ) {
add_submenu_page( $this->slug, __( 'Member Directories', 'ultimate-member' ), __( 'Member Directories', 'ultimate-member' ), 'manage_options', 'edit.php?post_type=um_directory', '' );
}
/**
* UM hook
*
* @type action
* @title um_extend_admin_menu
* @description Extend UM menu
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_extend_admin_menu', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_extend_admin_menu', 'my_extend_admin_menu', 10 );
* function my_extend_admin_menu() {
* // your code here
* }
* ?>
*/
do_action( 'um_extend_admin_menu' );
}
/**
* Role page menu callback
*/
function um_roles_pages() {
if ( empty( $_GET['tab'] ) ) {
include_once um_path . 'includes/admin/core/list-tables/roles-list-table.php';
} elseif ( 'add' === sanitize_key( $_GET['tab'] ) || 'edit' === sanitize_key( $_GET['tab'] ) ) {
include_once um_path . 'includes/admin/templates/role/role-edit.php';
} else {
um_js_redirect( add_query_arg( array( 'page' => 'um_roles' ), get_admin_url( 'admin.php' ) ) );
}
}
/**
* Extension menu
*/
function extension_menu() {
add_submenu_page( $this->slug, __( 'Extensions', 'ultimate-member' ), '<span style="color: #00B9EB">' .__( 'Extensions', 'ultimate-member' ) . '</span>', 'manage_options', $this->slug . '-extensions', array( &$this, 'admin_page' ) );
}
/**
* Load metabox stuff
*/
function on_load_page() {
wp_enqueue_script( 'common' );
wp_enqueue_script( 'wp-lists' );
wp_enqueue_script( 'postbox' );
/** custom metaboxes for dashboard defined here **/
add_meta_box( 'um-metaboxes-contentbox-1', __( 'Users Overview', 'ultimate-member' ), array( &$this, 'users_overview' ), $this->pagehook, 'core', 'core' );
add_meta_box( 'um-metaboxes-sidebox-1', __( 'Purge Temp Files', 'ultimate-member' ), array( &$this, 'purge_temp' ), $this->pagehook, 'side', 'core' );
add_meta_box( 'um-metaboxes-sidebox-2', __( 'User Cache', 'ultimate-member' ), array( &$this, 'user_cache' ), $this->pagehook, 'side', 'core' );
//If there are active and licensed extensions - show metabox for upgrade it
$exts = UM()->plugin_updater()->get_active_plugins();
if ( 0 < count( $exts ) ) {
add_meta_box( 'um-metaboxes-sidebox-3', __( 'Upgrade\'s Manual Request', 'ultimate-member' ), array( &$this, 'upgrade_request' ), $this->pagehook, 'side', 'core' );
}
}
/**
*
*/
function users_overview() {
include_once UM()->admin()->templates_path . 'dashboard/users.php';
}
/**
*
*/
function purge_temp() {
include_once UM()->admin()->templates_path . 'dashboard/purge.php';
}
/**
*
*/
function upgrade_request() {
include_once UM()->admin()->templates_path . 'dashboard/upgrade-request.php';
}
/**
*
*/
function user_cache() {
include_once UM()->admin()->templates_path . 'dashboard/cache.php';
}
/**
* Get a directory size
*
* @param $directory
*
* @return float|int
*/
function dir_size( $directory ) {
if ( $directory == 'temp' ) {
$directory = UM()->files()->upload_temp;
$size = 0;
foreach( new \RecursiveIteratorIterator( new \RecursiveDirectoryIterator( $directory ) ) as $file ) {
$filename = $file->getFilename();
if ( $filename == '.' || $filename == '..' ) {
continue;
}
$size += $file->getSize();
}
return round ( $size / 1048576, 2);
}
return 0;
}
/**
* Which admin page to show?
*/
function admin_page() {
$page = ! empty( $_REQUEST['page'] ) ? sanitize_key( $_REQUEST['page'] ) : '';
if ( $page == 'ultimatemember' ) { ?>
<div id="um-metaboxes-general" class="wrap">
<h1>Ultimate Member <sup><?php echo ultimatemember_version; ?></sup></h1>
<?php wp_nonce_field( 'um-metaboxes-general' ); ?>
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
<?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
<input type="hidden" name="action" value="save_um_metaboxes_general" />
<div id="dashboard-widgets-wrap">
<div id="dashboard-widgets" class="metabox-holder um-metabox-holder">
<div id="postbox-container-1" class="postbox-container"><?php do_meta_boxes( $this->pagehook, 'core', null ); ?></div>
<div id="postbox-container-2" class="postbox-container"><?php do_meta_boxes( $this->pagehook, 'normal', null ); ?></div>
<div id="postbox-container-3" class="postbox-container"><?php do_meta_boxes( $this->pagehook, 'side', null ); ?></div>
</div>
</div>
</div>
<div class="um-admin-clear"></div>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready( function($) {
// postboxes setup
postboxes.add_postbox_toggles('<?php echo esc_js( $this->pagehook ); ?>');
});
//]]>
</script>
<?php } elseif ( $page == 'ultimatemember-extensions' ) {
include_once UM()->admin()->templates_path . 'extensions.php';
}
}
}
}