PluginProbe
Adminimize / 1.11.2
Adminimize v1.11.2
1.11.14 1.11.13 1.11.1 1.11.10 1.11.11 1.11.12 1.11.2 1.11.3 1.11.4 1.11.5 1.11.6 1.11.7 1.11.8 1.11.9 1.3 1.4.7 1.6 1.7.12 1.7.13 1.7.14 1.7.15 1.7.16 1.7.17 1.7.18 1.7.19 All 53 releases
adminimize / inc-setup / dashboard.php

dashboard.php in Adminimize 1.11.2, at inc-setup/dashboard.php

120 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Adminimize
4 * @subpackage Dashboard Setup
5 * @author Frank Bültge
6 */
7 if ( ! function_exists( 'add_action' ) ) {
8 echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
9 exit;
10 }
11
12 if ( ! is_admin() ) {
13 return;
14 }
15
16 // If is AJAX Call.
17 if ( defined('DOING_AJAX') && DOING_AJAX ) {
18 return;
19 }
20
21 add_action( 'wp_dashboard_setup', '_mw_adminimize_update_dashboard_widgets', 9998 );
22 /**
23 * Write dashboard widgets in settings.
24 *
25 * @return bool
26 */
27 function _mw_adminimize_update_dashboard_widgets() {
28
29 // Only manage options users have the chance to update the settings.
30 if ( ! current_user_can( 'manage_options' ) ) {
31 return FALSE;
32 }
33
34 $adminimizeoptions = _mw_adminimize_get_option_value();
35 $adminimizeoptions[ 'mw_adminimize_dashboard_widgets' ] = _mw_adminimize_get_dashboard_widgets();
36
37 return _mw_adminimize_update_option( $adminimizeoptions );
38 }
39
40 // Return registered widgets; only on page index/dashboard :(
41 add_action( 'wp_dashboard_setup', '_mw_adminimize_dashboard_setup', 9999 );
42 /**
43 * Set dashboard widget options.
44 */
45 function _mw_adminimize_dashboard_setup() {
46
47 // exclude super admin
48 if ( _mw_adminimize_exclude_super_admin() ) {
49 return;
50 }
51
52 $user_roles = _mw_adminimize_get_all_user_roles();
53
54 $disabled_dashboard_option_ = array();
55 foreach ( $user_roles as $role ) {
56 $disabled_dashboard_option_[ $role ] = _mw_adminimize_get_option_value(
57 'mw_adminimize_disabled_dashboard_option_' . $role . '_items'
58 );
59 }
60
61 foreach ( $user_roles as $role ) {
62 if ( ! isset( $disabled_dashboard_option_[ $role ][ '0' ] ) ) {
63 $disabled_dashboard_option_[ $role ][ '0' ] = '';
64 }
65 }
66
67 // Get all widgets.
68 $widgets = _mw_adminimize_get_dashboard_widgets();
69 // Get current user data.
70 $user = wp_get_current_user();
71 foreach ( $user_roles as $role ) {
72
73 if ( is_array( $user->roles )
74 && is_array( $disabled_dashboard_option_[ $role ] )
75 && in_array( $role, $user->roles )
76 && _mw_adminimize_current_user_has_role( $role )
77 ) {
78 foreach ( $disabled_dashboard_option_[ $role ] as $widget ) {
79 if ( isset( $widgets[ $widget ][ 'context' ] ) ) {
80 remove_meta_box( $widget, 'dashboard', $widgets[ $widget ][ 'context' ] );
81 }
82 }
83 }
84
85 }
86
87 }
88
89 /**
90 * Get all registered dashboard widgets.
91 *
92 * @return array
93 */
94 function _mw_adminimize_get_dashboard_widgets() {
95
96 global $wp_meta_boxes;
97
98 $widgets = array();
99 if ( ! isset( $wp_meta_boxes[ 'dashboard' ] ) ) {
100 return $widgets;
101 }
102
103 foreach ( $wp_meta_boxes[ 'dashboard' ] as $context => $datas ) {
104 foreach ( $datas as $priority => $data ) {
105 foreach ( $data as $widget => $value ) {
106 $widgets[ $widget ] = array(
107 'id' => $widget,
108 'title' => strip_tags(
109 preg_replace( '/( |)<span.*span>/im', '', $value[ 'title' ] )
110 ),
111 'context' => $context,
112 'priority' => $priority
113 );
114 }
115 }
116 }
117
118 return $widgets;
119 }
120