| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package Adminimize |
| 4 | - * @subpackage Remove Admin Bar of > WP 3.3 Setup | |
| 4 | + * @subpackage Remove Admin Bar of WP 3.3 Setup | |
| 5 | 5 | * @author Frank Bültge |
| 6 | 6 | */ |
| 7 | 7 | if ( ! function_exists( 'add_action' ) ) { |
| 8 | 8 | echo "Hi there! I'm just a part of plugin, not much I can do when called directly."; |
| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | * Change the var of Admin Bar in WP 3.3 |
| 17 | 17 | * |
| 18 | 18 | * @param array $admin_bar_keys |
| 19 | 19 | */ |
| 20 | -function _mw_adminimize_customize_admin_bar( array $admin_bar_keys ) { | |
| 20 | +function _mw_adminimize_customize_admin_bar( $admin_bar_keys = array() ) { | |
| 21 | 21 | |
| 22 | 22 | if ( ! is_admin_bar_showing() ) { |
| 23 | 23 | return; |
| 24 | 24 | } |
| @@ -40,17 +40,18 @@ | ||
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Add Logout link to admin abr in wp 3.3 |
| 43 | 43 | * |
| 44 | - * @param $wp_admin_bar WP_Admin_Bar | |
| 44 | + * @param $wp_admin_bar | |
| 45 | 45 | */ |
| 46 | 46 | function _mw_adminimize_add_logout( $wp_admin_bar ) { |
| 47 | 47 | |
| 48 | 48 | $user_id = get_current_user_id(); |
| 49 | 49 | $_mw_adminimize_ui_redirect = (int) _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' ); |
| 50 | - $redirect = ''; | |
| 51 | 50 | if ( 1 === $_mw_adminimize_ui_redirect ) { |
| 52 | 51 | $redirect = '&redirect_to=' . get_option( 'siteurl' ); |
| 52 | + } else { | |
| 53 | + $redirect = ''; | |
| 53 | 54 | } |
| 54 | 55 | |
| 55 | 56 | if ( ! $user_id ) { |
| 56 | 57 | return; |
| @@ -65,32 +66,17 @@ | ||
| 65 | 66 | ) |
| 66 | 67 | ); |
| 67 | 68 | } |
| 68 | 69 | |
| 69 | -/** | |
| 70 | - * Add stylesheet for see the the admin bar item also on mobile. | |
| 71 | - */ | |
| 72 | -function _mw_adminimize_admin_bar_style() { | |
| 73 | - ?> | |
| 74 | - <style type="text/css"> | |
| 75 | - #wpadminbar #wp-admin-bar-mw-account { display: block; } | |
| 76 | - </style> | |
| 77 | - <?php | |
| 78 | -} | |
| 79 | - | |
| 80 | -/** | |
| 81 | - * Add Logout link include user info. | |
| 82 | - * | |
| 83 | - * @param $wp_admin_bar WP_Admin_Bar | |
| 84 | - */ | |
| 85 | 70 | function _mw_adminimize_add_user_logout( $wp_admin_bar ) { |
| 86 | 71 | |
| 87 | 72 | $user_id = get_current_user_id(); |
| 88 | 73 | $current_user = wp_get_current_user(); |
| 89 | 74 | $_mw_adminimize_ui_redirect = (int) _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' ); |
| 90 | - $redirect = ''; | |
| 91 | 75 | if ( 1 === $_mw_adminimize_ui_redirect ) { |
| 92 | 76 | $redirect = '&redirect_to=' . get_option( 'siteurl' ); |
| 77 | + } else { | |
| 78 | + $redirect = ''; | |
| 93 | 79 | } |
| 94 | 80 | |
| 95 | 81 | if ( ! $user_id ) { |
| 96 | 82 | return; |
| @@ -107,29 +93,15 @@ | ||
| 107 | 93 | ) |
| 108 | 94 | ); |
| 109 | 95 | } |
| 110 | 96 | |
| 111 | -/** | |
| 112 | - * Change logout, user info link in Admin bar. | |
| 113 | - * | |
| 114 | - * @return void | |
| 115 | - */ | |
| 116 | -function _mw_adminimize_set_logout_menu() { | |
| 97 | +function _mw_adminimize_set_menu_option_33() { | |
| 117 | 98 | |
| 118 | - if ( ! is_user_logged_in() ) { | |
| 119 | - return; | |
| 120 | - } | |
| 121 | - | |
| 122 | 99 | // exclude super admin |
| 123 | 100 | if ( _mw_adminimize_exclude_super_admin() ) { |
| 124 | - return; | |
| 101 | + return NULL; | |
| 125 | 102 | } |
| 126 | 103 | |
| 127 | - // Leave the settings screen from Adminimize to see all areas on settings. | |
| 128 | - if ( _mw_adminimize_exclude_settings_page() ) { | |
| 129 | - return; | |
| 130 | - } | |
| 131 | - | |
| 132 | 104 | $user_roles = _mw_adminimize_get_all_user_roles(); |
| 133 | 105 | |
| 134 | 106 | foreach ( $user_roles as $role ) { |
| 135 | 107 | $disabled_menu_[ $role ] = _mw_adminimize_get_option_value( |
| @@ -139,9 +111,9 @@ | ||
| 139 | 111 | 'mw_adminimize_disabled_submenu_' . $role . '_items' |
| 140 | 112 | ); |
| 141 | 113 | } |
| 142 | 114 | |
| 143 | - $_mw_adminimize_user_info = (int) _mw_adminimize_get_option_value( '_mw_adminimize_user_info' ); | |
| 115 | + $_mw_adminimize_user_info = (int) _mw_adminimize_get_option_value( '_mw_adminimize_user_info' ); | |
| 144 | 116 | // change user-info |
| 145 | 117 | switch ( $_mw_adminimize_user_info ) { |
| 146 | 118 | case 1: |
| 147 | 119 | add_action( 'wp_before_admin_bar_render', '_mw_adminimize_remove_my_account' ); |
| @@ -148,16 +120,12 @@ | ||
| 148 | 120 | break; |
| 149 | 121 | case 2: |
| 150 | 122 | add_action( 'wp_before_admin_bar_render', '_mw_adminimize_remove_my_account' ); |
| 151 | 123 | add_action( 'admin_bar_menu', '_mw_adminimize_add_logout', 0 ); |
| 152 | - add_action( 'wp_head', '_mw_adminimize_admin_bar_style' ); | |
| 153 | - add_action( 'admin_head', '_mw_adminimize_admin_bar_style' ); | |
| 154 | 124 | break; |
| 155 | 125 | case 3: |
| 156 | 126 | add_action( 'wp_before_admin_bar_render', '_mw_adminimize_remove_my_account' ); |
| 157 | 127 | add_action( 'admin_bar_menu', '_mw_adminimize_add_user_logout', 0 ); |
| 158 | - add_action( 'wp_head', '_mw_adminimize_admin_bar_style' ); | |
| 159 | - add_action( 'admin_head', '_mw_adminimize_admin_bar_style' ); | |
| 160 | 128 | break; |
| 161 | 129 | } |
| 162 | 130 | } |
| 163 | 131 | |
| @@ -162,96 +130,91 @@ | ||
| 162 | 130 | } |
| 163 | 131 | |
| 164 | 132 | /** |
| 165 | 133 | * Remove Admin Bar |
| 166 | - * | |
| 167 | - * @return void | |
| 168 | 134 | */ |
| 169 | 135 | function _mw_adminimize_remove_admin_bar() { |
| 170 | 136 | |
| 171 | - if ( ! is_user_logged_in() ) { | |
| 172 | - return; | |
| 173 | - } | |
| 174 | - | |
| 175 | 137 | // exclude super admin |
| 176 | 138 | if ( _mw_adminimize_exclude_super_admin() ) { |
| 177 | - return; | |
| 139 | + return NULL; | |
| 178 | 140 | } |
| 179 | 141 | |
| 180 | - // Leave the settings screen from Adminimize to see all areas on settings. | |
| 181 | - if ( _mw_adminimize_exclude_settings_page() ) { | |
| 182 | - return; | |
| 183 | - } | |
| 142 | + global $wp_version; | |
| 184 | 143 | |
| 185 | 144 | $user_roles = _mw_adminimize_get_all_user_roles(); |
| 186 | - $disabled_global_option_ = array(); | |
| 187 | 145 | |
| 188 | 146 | foreach ( $user_roles as $role ) { |
| 189 | - $disabled_global_option_[ $role ] = (array) _mw_adminimize_get_option_value( | |
| 147 | + $disabled_global_option_[ $role ] = _mw_adminimize_get_option_value( | |
| 190 | 148 | 'mw_adminimize_disabled_global_option_' . $role . '_items' |
| 191 | 149 | ); |
| 192 | 150 | } |
| 193 | 151 | |
| 194 | - $mw_global_options = array(); | |
| 195 | - $user = wp_get_current_user(); | |
| 196 | - | |
| 197 | 152 | foreach ( $user_roles as $role ) { |
| 198 | - | |
| 199 | - if ( in_array( $role, $user->roles, FALSE ) | |
| 200 | - && _mw_adminimize_current_user_has_role( $role ) | |
| 201 | - ) { | |
| 202 | - // Create array about all items with all affected roles, important for multiple roles. | |
| 203 | - foreach ( $disabled_global_option_[ $role ] as $global_item ) { | |
| 204 | - $mw_global_options[] = $global_item; | |
| 205 | - } | |
| 153 | + if ( ! isset( $disabled_global_option_[ $role ][ '0' ] ) ) { | |
| 154 | + $disabled_global_option_[ $role ][ '0' ] = ''; | |
| 206 | 155 | } |
| 207 | - | |
| 208 | 156 | } |
| 209 | 157 | |
| 210 | - // Support Multiple Roles for users. | |
| 211 | - if ( _mw_adminimize_get_option_value( 'mw_adminimize_multiple_roles' ) && 1 < count( $user->roles ) ) { | |
| 212 | - $mw_global_options = _mw_adminimize_get_duplicate( $mw_global_options ); | |
| 213 | - } | |
| 214 | - | |
| 215 | 158 | $remove_adminbar = FALSE; |
| 216 | - // Check for admin bar selector to set to remove the Admin Bar. | |
| 217 | - if ( _mw_adminimize_recursive_in_array( '.show-admin-bar', $mw_global_options ) ) { | |
| 218 | - $remove_adminbar = TRUE; | |
| 159 | + // new 1.7.8 | |
| 160 | + foreach ( $user_roles as $role ) { | |
| 161 | + $user = wp_get_current_user(); | |
| 162 | + if ( is_array( $user->roles ) && in_array( $role, $user->roles ) ) { | |
| 163 | + if ( _mw_adminimize_current_user_has_role( $role ) | |
| 164 | + && isset( $disabled_global_option_[ $role ] ) | |
| 165 | + && is_array( $disabled_global_option_[ $role ] ) | |
| 166 | + ) { | |
| 167 | + if ( _mw_adminimize_recursive_in_array( '.show-admin-bar', $disabled_global_option_[ $role ] ) ) { | |
| 168 | + $remove_adminbar = TRUE; | |
| 169 | + } | |
| 170 | + } | |
| 171 | + } | |
| 219 | 172 | } |
| 220 | 173 | |
| 221 | 174 | if ( $remove_adminbar ) { |
| 222 | - if ( ! is_admin_bar_showing() ) { | |
| 223 | - return; | |
| 224 | - } | |
| 175 | + // for deactivate admin bar in WP smaller WP 3.3 | |
| 176 | + if ( version_compare( $wp_version, '3.3alpha', '<=' ) ) { | |
| 177 | + add_filter( 'show_admin_bar', '__return_false' ); | |
| 178 | + wp_deregister_script( 'admin-bar' ); | |
| 179 | + wp_deregister_style( 'admin-bar' ); | |
| 180 | + remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); | |
| 181 | + remove_action( 'wp_head', '_admin_bar_bump_cb' ); | |
| 182 | + } else { | |
| 183 | + if ( ! is_admin_bar_showing() ) { | |
| 184 | + return FALSE; | |
| 185 | + } | |
| 225 | 186 | |
| 226 | - add_filter( 'show_admin_bar', '__return_false' ); | |
| 227 | - add_filter( 'wp_admin_bar_class', '__return_false' ); | |
| 228 | - add_filter( 'show_wp_pointer_admin_bar', '__return_false' ); | |
| 229 | - wp_deregister_script( 'admin-bar' ); | |
| 230 | - wp_deregister_style( 'admin-bar' ); | |
| 231 | - remove_action( 'init', '_wp_admin_bar_init' ); | |
| 232 | - remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); | |
| 233 | - remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 ); | |
| 187 | + add_filter( 'show_admin_bar', '__return_false' ); | |
| 188 | + add_filter( 'wp_admin_bar_class', '__return_false' ); | |
| 189 | + add_filter( 'show_wp_pointer_admin_bar', '__return_false' ); | |
| 190 | + wp_deregister_script( 'admin-bar' ); | |
| 191 | + wp_deregister_style( 'admin-bar' ); | |
| 192 | + remove_action( 'init', '_wp_admin_bar_init' ); | |
| 193 | + remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); | |
| 194 | + remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 ); | |
| 234 | 195 | |
| 235 | - // maybe also: 'wp_head' | |
| 236 | - foreach ( array( 'wp_head', 'admin_head' ) as $hook ) { | |
| 237 | - add_action( | |
| 238 | - $hook, | |
| 239 | - create_function( | |
| 240 | - '', | |
| 241 | - "echo '<style>body.admin-bar, body.admin-bar #wpcontent, body.admin-bar #adminmenu { | |
| 196 | + // maybe also: 'wp_head' | |
| 197 | + foreach ( array( 'wp_head', 'admin_head' ) as $hook ) { | |
| 198 | + add_action( | |
| 199 | + $hook, | |
| 200 | + create_function( | |
| 201 | + '', | |
| 202 | + "echo '<style>body.admin-bar, body.admin-bar #wpcontent, body.admin-bar #adminmenu { | |
| 242 | 203 | padding-top: 0 !important; |
| 243 | 204 | } |
| 244 | 205 | html.wp-toolbar { |
| 245 | 206 | padding-top: 0 !important; |
| 246 | 207 | }</style>';" |
| 247 | - ) | |
| 248 | - ); | |
| 249 | - } | |
| 208 | + ) | |
| 209 | + ); | |
| 210 | + } | |
| 250 | 211 | |
| 251 | - add_action( 'in_admin_header', '_mw_adminimize_restore_links' ); | |
| 212 | + add_action( 'in_admin_header', '_mw_adminimize_restore_links' ); | |
| 213 | + } // end else version 3.3 | |
| 214 | + } // end if $remove_adminbar TRUE | |
| 252 | 215 | |
| 253 | - } // end if $remove_adminbar TRUE | |
| 216 | + return NULL; | |
| 254 | 217 | } |
| 255 | 218 | |
| 256 | 219 | /** |
| 257 | 220 | * Add Site Link in Menu |
| @@ -295,12 +258,11 @@ | ||
| 295 | 258 | ) . '" target="_blank">' . get_bloginfo( 'name' ) . '</a>'; |
| 296 | 259 | ?> |
| 297 | 260 | <div id="mw_adminimize_login"> |
| 298 | 261 | <?php |
| 262 | + wp_get_current_user(); | |
| 299 | 263 | $current_user = wp_get_current_user(); |
| 300 | - if ( empty( $_mw_adminimize_user_info ) || 0 === $_mw_adminimize_user_info | |
| 301 | - || 3 === $_mw_adminimize_user_info | |
| 302 | - ) { | |
| 264 | + if ( empty( $_mw_adminimize_user_info ) || 0 === $_mw_adminimize_user_info || 3 === $_mw_adminimize_user_info ) { | |
| 303 | 265 | if ( ! ( $current_user instanceof WP_User ) ) { |
| 304 | 266 | return; |
| 305 | 267 | } |
| 306 | 268 | echo ' ' . $current_user->user_login . ' '; |
| @@ -317,20 +279,15 @@ | ||
| 317 | 279 | } |
| 318 | 280 | } |
| 319 | 281 | } |
| 320 | 282 | |
| 321 | - if ( empty( $_mw_adminimize_user_info ) || 0 === $_mw_adminimize_user_info | |
| 322 | - || 2 === $_mw_adminimize_user_info | |
| 323 | - || 3 === $_mw_adminimize_user_info | |
| 324 | - ) { | |
| 325 | - ?> | <?php echo '<a href="' . wp_logout_url() . '" title="' . esc_attr__( | |
| 283 | + if ( empty( $_mw_adminimize_user_info ) || 0 == $_mw_adminimize_user_info || 2 == $_mw_adminimize_user_info || 3 == $_mw_adminimize_user_info ) { | |
| 284 | + ?> | <?php echo '<a href="' . wp_logout_url() . '" title="' . esc_attr__( 'Log Out' ) . '">' . esc_attr__( | |
| 326 | 285 | 'Log Out' |
| 327 | - ) . '">' . esc_attr__( | |
| 328 | - 'Log Out' | |
| 329 | 286 | ) . '</a>'; |
| 330 | 287 | } |
| 331 | 288 | ?> |
| 332 | 289 | </div> |
| 333 | 290 | </div> |
| 334 | - <?php | |
| 291 | +<?php | |
| 335 | 292 | } |
| 336 | 293 | |