| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package Adminimize |
| 4 |
* @subpackage Remove Admin Bar of WP 3.3 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 |
// on init of WordPress |
| 13 |
add_action( 'init', '_mw_adminimize_remove_admin_bar', 0 ); |
| 14 |
|
| 15 |
/** |
| 16 |
* Change the var of Admin Bar in WP 3.3 |
| 17 |
* |
| 18 |
* @param array $admin_bar_keys |
| 19 |
*/ |
| 20 |
function _mw_adminimize_customize_admin_bar( $admin_bar_keys = array() ) { |
| 21 |
|
| 22 |
if ( ! is_admin_bar_showing() ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
global $wp_admin_bar; |
| 27 |
|
| 28 |
foreach ( $admin_bar_keys as $key ) { |
| 29 |
$wp_admin_bar->remove_menu( $key ); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
/* |
| 34 |
* Remove my account item in admin bar >3.3 |
| 35 |
*/ |
| 36 |
function _mw_adminimize_remove_my_account() { |
| 37 |
|
| 38 |
_mw_adminimize_customize_admin_bar( array( 'my-account' ) ); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Add Logout link to admin abr in wp 3.3 |
| 43 |
* |
| 44 |
* @param $wp_admin_bar |
| 45 |
*/ |
| 46 |
function _mw_adminimize_add_logout( $wp_admin_bar ) { |
| 47 |
|
| 48 |
$user_id = get_current_user_id(); |
| 49 |
$_mw_adminimize_ui_redirect = (int) _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' ); |
| 50 |
if ( 1 === $_mw_adminimize_ui_redirect ) { |
| 51 |
$redirect = '&redirect_to=' . get_option( 'siteurl' ); |
| 52 |
} else { |
| 53 |
$redirect = ''; |
| 54 |
} |
| 55 |
|
| 56 |
if ( ! $user_id ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
$wp_admin_bar->add_menu( |
| 61 |
array( |
| 62 |
'id' => 'mw-account', |
| 63 |
'parent' => 'top-secondary', |
| 64 |
'title' => esc_attr__( 'Log Out' ), |
| 65 |
'href' => wp_logout_url() . $redirect, |
| 66 |
) |
| 67 |
); |
| 68 |
} |
| 69 |
|
| 70 |
function _mw_adminimize_add_user_logout( $wp_admin_bar ) { |
| 71 |
|
| 72 |
$user_id = get_current_user_id(); |
| 73 |
$current_user = wp_get_current_user(); |
| 74 |
$_mw_adminimize_ui_redirect = (int) _mw_adminimize_get_option_value( '_mw_adminimize_ui_redirect' ); |
| 75 |
if ( 1 === $_mw_adminimize_ui_redirect ) { |
| 76 |
$redirect = '&redirect_to=' . get_option( 'siteurl' ); |
| 77 |
} else { |
| 78 |
$redirect = ''; |
| 79 |
} |
| 80 |
|
| 81 |
if ( ! $user_id ) { |
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
$user_info = $current_user->display_name; |
| 86 |
|
| 87 |
$wp_admin_bar->add_menu( |
| 88 |
array( |
| 89 |
'id' => 'mw-account', |
| 90 |
'parent' => 'top-secondary', |
| 91 |
'title' => $user_info . ' ' . esc_attr__( 'Log Out' ), |
| 92 |
'href' => wp_logout_url() . $redirect, |
| 93 |
) |
| 94 |
); |
| 95 |
} |
| 96 |
|
| 97 |
function _mw_adminimize_set_menu_option_33() { |
| 98 |
|
| 99 |
// exclude super admin |
| 100 |
if ( _mw_adminimize_exclude_super_admin() ) { |
| 101 |
return NULL; |
| 102 |
} |
| 103 |
|
| 104 |
$user_roles = _mw_adminimize_get_all_user_roles(); |
| 105 |
|
| 106 |
foreach ( $user_roles as $role ) { |
| 107 |
$disabled_menu_[ $role ] = _mw_adminimize_get_option_value( |
| 108 |
'mw_adminimize_disabled_menu_' . $role . '_items' |
| 109 |
); |
| 110 |
$disabled_submenu_[ $role ] = _mw_adminimize_get_option_value( |
| 111 |
'mw_adminimize_disabled_submenu_' . $role . '_items' |
| 112 |
); |
| 113 |
} |
| 114 |
|
| 115 |
$_mw_adminimize_user_info = (int) _mw_adminimize_get_option_value( '_mw_adminimize_user_info' ); |
| 116 |
// change user-info |
| 117 |
switch ( $_mw_adminimize_user_info ) { |
| 118 |
case 1: |
| 119 |
add_action( 'wp_before_admin_bar_render', '_mw_adminimize_remove_my_account' ); |
| 120 |
break; |
| 121 |
case 2: |
| 122 |
add_action( 'wp_before_admin_bar_render', '_mw_adminimize_remove_my_account' ); |
| 123 |
add_action( 'admin_bar_menu', '_mw_adminimize_add_logout', 0 ); |
| 124 |
break; |
| 125 |
case 3: |
| 126 |
add_action( 'wp_before_admin_bar_render', '_mw_adminimize_remove_my_account' ); |
| 127 |
add_action( 'admin_bar_menu', '_mw_adminimize_add_user_logout', 0 ); |
| 128 |
break; |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
/** |
| 133 |
* Remove Admin Bar |
| 134 |
*/ |
| 135 |
function _mw_adminimize_remove_admin_bar() { |
| 136 |
|
| 137 |
// exclude super admin |
| 138 |
if ( _mw_adminimize_exclude_super_admin() ) { |
| 139 |
return NULL; |
| 140 |
} |
| 141 |
|
| 142 |
global $wp_version; |
| 143 |
|
| 144 |
$user_roles = _mw_adminimize_get_all_user_roles(); |
| 145 |
|
| 146 |
foreach ( $user_roles as $role ) { |
| 147 |
$disabled_global_option_[ $role ] = _mw_adminimize_get_option_value( |
| 148 |
'mw_adminimize_disabled_global_option_' . $role . '_items' |
| 149 |
); |
| 150 |
} |
| 151 |
|
| 152 |
foreach ( $user_roles as $role ) { |
| 153 |
if ( ! isset( $disabled_global_option_[ $role ][ '0' ] ) ) { |
| 154 |
$disabled_global_option_[ $role ][ '0' ] = ''; |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
$remove_adminbar = FALSE; |
| 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 |
} |
| 172 |
} |
| 173 |
|
| 174 |
if ( $remove_adminbar ) { |
| 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 |
} |
| 186 |
|
| 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 ); |
| 195 |
|
| 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 { |
| 203 |
padding-top: 0 !important; |
| 204 |
} |
| 205 |
html.wp-toolbar { |
| 206 |
padding-top: 0 !important; |
| 207 |
}</style>';" |
| 208 |
) |
| 209 |
); |
| 210 |
} |
| 211 |
|
| 212 |
add_action( 'in_admin_header', '_mw_adminimize_restore_links' ); |
| 213 |
} // end else version 3.3 |
| 214 |
} // end if $remove_adminbar TRUE |
| 215 |
|
| 216 |
return NULL; |
| 217 |
} |
| 218 |
|
| 219 |
/** |
| 220 |
* Add Site Link in Menu |
| 221 |
*/ |
| 222 |
function _mw_adminimize_restore_links() { |
| 223 |
|
| 224 |
$_mw_adminimize_user_info = (int) _mw_adminimize_get_option_value( '_mw_adminimize_user_info' ); |
| 225 |
?> |
| 226 |
<style type="text/css"> |
| 227 |
#mw_adminimize_admin_bar { |
| 228 |
left: 0; |
| 229 |
right: 0; |
| 230 |
height: 33px; |
| 231 |
z-index: 999; |
| 232 |
border-bottom: 1px solid #dfdfdf; |
| 233 |
} |
| 234 |
|
| 235 |
#mw_adminimize_admin_bar #mw_title { |
| 236 |
font-family: Georgia, "Times New Roman", Times, serif; |
| 237 |
font-size: 16px; |
| 238 |
color: #464646; |
| 239 |
text-decoration: none; |
| 240 |
padding-top: 8px; |
| 241 |
display: block; |
| 242 |
float: left; |
| 243 |
} |
| 244 |
|
| 245 |
#mw_adminimize_admin_bar #mw_title:hover { |
| 246 |
text-decoration: underline; |
| 247 |
} |
| 248 |
|
| 249 |
#mw_adminimize_admin_bar #mw_adminimize_login { |
| 250 |
padding: 8px 15px 0 0; |
| 251 |
display: block; |
| 252 |
float: right; |
| 253 |
} |
| 254 |
</style> |
| 255 |
<div id="mw_adminimize_admin_bar"> |
| 256 |
<?php echo '<a id="mw_title" href="' . home_url() . '" title="' . esc_attr__( |
| 257 |
get_bloginfo( 'name' ) |
| 258 |
) . '" target="_blank">' . get_bloginfo( 'name' ) . '</a>'; |
| 259 |
?> |
| 260 |
<div id="mw_adminimize_login"> |
| 261 |
<?php |
| 262 |
wp_get_current_user(); |
| 263 |
$current_user = wp_get_current_user(); |
| 264 |
if ( empty( $_mw_adminimize_user_info ) || 0 === $_mw_adminimize_user_info || 3 === $_mw_adminimize_user_info ) { |
| 265 |
if ( ! ( $current_user instanceof WP_User ) ) { |
| 266 |
return; |
| 267 |
} |
| 268 |
echo ' ' . $current_user->user_login . ' '; |
| 269 |
|
| 270 |
if ( is_multisite() && is_super_admin() ) { |
| 271 |
if ( ! is_network_admin() ) { |
| 272 |
echo '| <a href="' . network_admin_url() . '" title="' . esc_attr__( |
| 273 |
'Network Admin' |
| 274 |
) . '">' . esc_attr__( 'Network Admin' ) . '</a>'; |
| 275 |
} else { |
| 276 |
echo '| <a href="' . get_dashboard_url( get_current_user_id() ) . '" title="' . esc_attr__( |
| 277 |
'Site Admin' |
| 278 |
) . '">' . esc_attr__( 'Site Admin' ) . '</a>'; |
| 279 |
} |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 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__( |
| 285 |
'Log Out' |
| 286 |
) . '</a>'; |
| 287 |
} |
| 288 |
?> |
| 289 |
</div> |
| 290 |
</div> |
| 291 |
<?php |
| 292 |
} |
| 293 |
|
| 294 |
|