PluginProbe
Adminimize / 1.11.3
Adminimize v1.11.3
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.3, at inc-setup/dashboard.php

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