PluginProbe
Adminimize / 1.9.1
Adminimize v1.9.1
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
← All changes | inc-setup/dashboard.php +36 -130 1.11.10 → 1.9.1 View file →
@@ -3,9 +3,8 @@
3 3 * @package Adminimize
4 4 * @subpackage Dashboard Setup
5 5 * @author Frank Bültge
6 6 */
7 -
8 7 if ( ! function_exists( 'add_action' ) ) {
9 8 echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
10 9 exit;
11 10 }
@@ -10,173 +9,80 @@
10 9 exit;
11 10 }
12 11
13 12 if ( ! is_admin() ) {
14 - return;
13 + return NULL;
15 14 }
16 15
17 -// If is AJAX Call.
18 -if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
19 - return;
20 -}
16 +// Return registered widgets; only on page index/dashboard :(
17 +add_action( 'wp_dashboard_setup', '_mw_adminimize_dashboard_setup', 99 );
21 18
22 -add_action( 'wp_dashboard_setup', '_mw_adminimize_update_dashboard_widgets', 9998 );
23 -/**
24 - * Write dashboard widgets in settings.
25 - *
26 - * @return bool
27 - */
28 -function _mw_adminimize_update_dashboard_widgets() {
19 +function _mw_adminimize_dashboard_setup() {
29 20
30 - // Only manage options users have the chance to update the settings.
31 - if ( ! current_user_can( 'manage_options' ) ) {
32 - return false;
33 - }
21 + $adminimizeoptions = _mw_adminimize_get_option_value();
34 22
35 - $adminimizeoptions = _mw_adminimize_get_option_value();
36 - $adminimizeoptions['mw_adminimize_dashboard_widgets'] = _mw_adminimize_get_dashboard_widgets();
23 + $widgets = _mw_adminimize_get_dashboard_widgets();
24 + $adminimizeoptions[ 'mw_adminimize_dashboard_widgets' ] = $widgets;
37 25
38 - return _mw_adminimize_update_option( $adminimizeoptions );
39 -}
26 + _mw_adminimize_update_option( $adminimizeoptions );
40 27
41 -// Return registered widgets; only on page index/dashboard :(
42 -add_action( 'wp_dashboard_setup', '_mw_adminimize_dashboard_setup', PHP_INT_MAX );
43 -/**
44 - * Set dashboard widget options.
45 - */
46 -function _mw_adminimize_dashboard_setup() {
47 -
48 28 // exclude super admin
49 29 if ( _mw_adminimize_exclude_super_admin() ) {
50 - return;
30 + return NULL;
51 31 }
52 32
53 - // Get all widgets.
54 - $widgets = _mw_adminimize_get_dashboard_widgets();
55 - $user_roles = _mw_adminimize_get_all_user_roles();
56 - $disabled_dashboard_option = array();
57 - $disabled_dashboard_option_ = array();
58 - $user = wp_get_current_user();
33 + $user_roles = _mw_adminimize_get_all_user_roles();
59 34
60 - // Get settings for each role.
61 35 foreach ( $user_roles as $role ) {
62 - $disabled_dashboard_option_[ $role ] = (array) _mw_adminimize_get_option_value(
36 + $disabled_dashboard_option_[ $role ] = _mw_adminimize_get_option_value(
63 37 'mw_adminimize_disabled_dashboard_option_' . $role . '_items'
64 38 );
65 39 }
66 40
67 41 foreach ( $user_roles as $role ) {
68 - if ( in_array( $role, $user->roles, false ) && _mw_adminimize_current_user_has_role( $role )
69 - ) {
70 - // Create array about all items with all affected roles, important for multiple roles.
71 - foreach ( (array) $disabled_dashboard_option_[ $role ] as $dashboard_item ) {
72 - $disabled_dashboard_option[] = $dashboard_item;
73 - }
42 + if ( ! isset( $disabled_dashboard_option_[ $role ][ '0' ] ) ) {
43 + $disabled_dashboard_option_[ $role ][ '0' ] = '';
74 44 }
75 45 }
76 46
77 - // Support Multiple Roles for users, if option is active.
78 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
79 - $disabled_dashboard_option = _mw_adminimize_get_duplicate( $disabled_dashboard_option );
80 - }
47 + foreach ( $user_roles as $role ) {
48 + $user = wp_get_current_user();
81 49
82 - // Remove the dashboards widgets for the current active role.
83 - foreach ( $disabled_dashboard_option as $widget ) {
84 - if ( isset( $widgets[ $widget ]['context'] ) ) {
85 - remove_meta_box( $widget, 'dashboard', $widgets[ $widget ]['context'] );
50 + if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) {
51 + if ( _mw_adminimize_current_user_has_role( $role ) && is_array( $disabled_dashboard_option_[ $role ] ) ) {
52 + foreach ( $disabled_dashboard_option_[ $role ] as $widget ) {
53 + if ( isset( $widgets[ $widget ][ 'context' ] ) ) {
54 + remove_meta_box( $widget, 'dashboard', $widgets[ $widget ][ 'context' ] );
55 + }
56 + }
57 + }
86 58 }
87 59 }
88 60
89 61 }
90 62
91 -add_action( 'admin_head-index.php', '_mw_adminimize_remove_custom_panels', 99 );
92 -/**
93 - * Add custom options to the head head to hide it via css.
94 - *
95 - * @since 2017-01-05
96 - */
97 -function _mw_adminimize_remove_custom_panels() {
98 -
99 - // exclude super admin
100 - if ( _mw_adminimize_exclude_super_admin() ) {
101 - return;
102 - }
103 -
104 - $options = _mw_adminimize_get_option_value( '_mw_adminimize_own_dashboard_values' );
105 -
106 - if ( empty( $options ) ) {
107 - return;
108 - }
109 -
110 - // Get current user data.
111 - $user = wp_get_current_user();
112 - if ( ! $user->roles ) {
113 - return;
114 - }
115 -
116 - // Get settings for the roles.
117 - $disabled_dashboard_option_ = array();
118 - foreach ( $user->roles as $role ) {
119 - $disabled_dashboard_option_[] = _mw_adminimize_get_option_value( 'mw_adminimize_disabled_dashboard_option_' . $role . '_items' );
120 - }
121 -
122 - // Support Multiple Roles for users.
123 - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) {
124 - $disabled_dashboard_option_ = _mw_adminimize_get_duplicate( $disabled_dashboard_option_ );
125 - }
126 -
127 - if ( empty( $disabled_dashboard_option_[0] ) ) {
128 - return;
129 - }
130 -
131 - $selectors = implode( ', ', $disabled_dashboard_option_[0] );
132 - echo '<!-- Set Adminimize dashboard options -->' . "\n";
133 - echo '<style type="text/css">' . esc_attr( $selectors ) . ' {display:none !important;}</style>' . "\n";
134 -}
135 -
136 -/**
137 - * Get all registered dashboard widgets.
138 - *
139 - * @return array
140 - */
141 63 function _mw_adminimize_get_dashboard_widgets() {
142 64
143 65 global $wp_meta_boxes;
144 66
145 67 $widgets = array();
146 - if ( ! isset( $wp_meta_boxes['dashboard'] ) ) {
147 - return $widgets;
148 - }
68 + if ( isset( $wp_meta_boxes[ 'dashboard' ] ) ) {
149 69
150 - foreach ( (array) $wp_meta_boxes['dashboard'] as $context => $datas ) {
151 - foreach ( (array) $datas as $priority => $data ) {
152 - foreach ( (array) $data as $widget => $value ) {
153 -
154 - $value['title'] = ($value['title'] == FALSE) ? [] : $value['title'];
155 -
156 - if ( ! is_array( $value ) ) {
157 - $value = [];
70 + foreach ( $wp_meta_boxes[ 'dashboard' ] as $context => $datas ) {
71 + foreach ( $datas as $priority => $data ) {
72 + foreach ( $data as $widget => $value ) {
73 + $widgets[ $widget ] = array(
74 + 'id' => $widget,
75 + 'title' => strip_tags(
76 + preg_replace( '/( |)<span.*span>/im', '', $value[ 'title' ] )
77 + ),
78 + 'context' => $context,
79 + 'priority' => $priority
80 + );
158 81 }
159 -
160 - if ( ! isset( $value['title'])) {
161 - $value['title'] = '';
162 - }
163 -
164 - // Some plugins create a title that contains an array, we create an empty string to prevent an error in strip_tags
165 - if ( is_array( $value['title'])) {
166 - $value['title'] = '';
167 - }
168 -
169 - $widgets[ $widget ] = array(
170 - 'id' => $widget,
171 - 'title' => strip_tags(
172 - preg_replace( '/( |)<span.*span>/im', '', $value['title'] )
173 - ),
174 - 'context' => $context,
175 - 'priority' => $priority,
176 - );
177 82 }
178 83 }
84 +
179 85 }
180 86
181 87 return $widgets;
182 88 }