| 1 |
<?php |
| 2 |
/** |
| 3 |
* Function that creates the "Show/Hide the Admin Bar on the Front-End" submenu page |
| 4 |
* |
| 5 |
* @since v.2.0 |
| 6 |
* |
| 7 |
* @return void |
| 8 |
*/ |
| 9 |
function wppb_show_hide_admin_bar_submenu_page() { |
| 10 |
add_submenu_page( 'profile-builder', __( 'Show/Hide the Admin Bar on the Front-End', 'profilebuilder' ), __( 'Admin Bar Settings', 'profilebuilder' ), 'manage_options', 'profile-builder-admin-bar-settings', 'wppb_show_hide_admin_bar_content' ); |
| 11 |
} |
| 12 |
add_action( 'admin_menu', 'wppb_show_hide_admin_bar_submenu_page', 4 ); |
| 13 |
|
| 14 |
|
| 15 |
function wppb_generate_admin_bar_default_values( $roles ){ |
| 16 |
$wppb_display_admin_settings = get_option( 'wppb_display_admin_settings', 'not_found' ); |
| 17 |
|
| 18 |
if ( $wppb_display_admin_settings == 'not_found' ){ |
| 19 |
if( !empty( $roles ) ){ |
| 20 |
$admin_settings = array(); |
| 21 |
foreach ( $roles as $role ){ |
| 22 |
if( !empty( $role['name'] ) ) |
| 23 |
$admin_settings[$role['name']] = 'default'; |
| 24 |
} |
| 25 |
|
| 26 |
update_option( 'wppb_display_admin_settings', $admin_settings ); |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
/** |
| 33 |
* Function that adds content to the "Show/Hide the Admin Bar on the Front-End" submenu page |
| 34 |
* |
| 35 |
* @since v.2.0 |
| 36 |
* |
| 37 |
* @return string |
| 38 |
*/ |
| 39 |
function wppb_show_hide_admin_bar_content() { |
| 40 |
global $wp_roles; |
| 41 |
|
| 42 |
wppb_generate_admin_bar_default_values( $wp_roles ); |
| 43 |
?> |
| 44 |
|
| 45 |
<div class="wrap wppb-wrap wppb-admin-bar"> |
| 46 |
|
| 47 |
<h2><?php _e( 'Admin Bar Settings', 'profilebuilder' );?></h2> |
| 48 |
<p><?php _e( 'Choose which user roles view the admin bar in the front-end of the website.', 'profilebuilder' ); ?> |
| 49 |
<form method="post" action="options.php#show-hide-admin-bar"> |
| 50 |
<?php |
| 51 |
$admin_bar_settings = get_option( 'wppb_display_admin_settings' ); |
| 52 |
settings_fields( 'wppb_display_admin_settings' ); |
| 53 |
?> |
| 54 |
<table class="widefat"> |
| 55 |
<thead> |
| 56 |
<tr> |
| 57 |
<th class="row-title" scope="col"><?php _e('User-Role', 'profilebuilder');?></th> |
| 58 |
<th scope="col"><?php _e('Visibility', 'profilebuilder');?></th> |
| 59 |
</tr> |
| 60 |
</thead> |
| 61 |
<tbody> |
| 62 |
<?php |
| 63 |
$alt_i = 0; |
| 64 |
foreach ( $wp_roles->roles as $role ) { |
| 65 |
$alt_i++; |
| 66 |
$key = $role['name']; |
| 67 |
$setting_exists = !empty( $admin_bar_settings[$key] ); |
| 68 |
$alt_class = ( ( $alt_i%2 == 0 ) ? ' class="alternate"' : '' ); |
| 69 |
|
| 70 |
echo'<tr'.$alt_class.'> |
| 71 |
<td>'.translate_user_role($key).'</td> |
| 72 |
<td> |
| 73 |
<span><input id="rd'.$key.'" type="radio" name="wppb_display_admin_settings['.$key.']" value="default"'.( ( !$setting_exists || $admin_bar_settings[$key] == 'default' ) ? ' checked' : '' ).'/><label for="rd'.$key.'">'.__( 'Default', 'profilebuilder' ).'</label></span> |
| 74 |
<span><input id="rs'.$key.'" type="radio" name="wppb_display_admin_settings['.$key.']" value="show"'.( ( $setting_exists && $admin_bar_settings[$key] == 'show') ? ' checked' : '' ).'/><label for="rs'.$key.'">'.__( 'Show', 'profilebuilder' ).'</label></span> |
| 75 |
<span><input id="rh'.$key.'" type="radio" name="wppb_display_admin_settings['.$key.']" value="hide"'.( ( $setting_exists && $admin_bar_settings[$key] == 'hide') ? ' checked' : '' ).'/><label for="rh'.$key.'">'.__( 'Hide', 'profilebuilder' ).'</label></span> |
| 76 |
</td> |
| 77 |
</tr>'; |
| 78 |
} |
| 79 |
?> |
| 80 |
|
| 81 |
</table> |
| 82 |
|
| 83 |
<div id="wppb_submit_button_div"> |
| 84 |
<input type="hidden" name="action" value="update" /> |
| 85 |
<p class="submit"> |
| 86 |
<input type="submit" class="button-primary" value="<?php _e( 'Save Changes' ) ?>" /> |
| 87 |
</p> |
| 88 |
</div> |
| 89 |
|
| 90 |
</form> |
| 91 |
|
| 92 |
</div> |
| 93 |
<?php |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Function that changes the username on the top right menu (admin bar) |
| 98 |
* |
| 99 |
* @since v.2.0 |
| 100 |
* |
| 101 |
* @return string |
| 102 |
*/ |
| 103 |
function wppb_replace_username_on_admin_bar( $wp_admin_bar ) { |
| 104 |
$wppb_general_settings = get_option( 'wppb_general_settings' ); |
| 105 |
|
| 106 |
if ( isset( $wppb_general_settings['loginWith'] ) && ( $wppb_general_settings['loginWith'] == 'email' ) ){ |
| 107 |
$current_user = wp_get_current_user(); |
| 108 |
|
| 109 |
$my_account_main = $wp_admin_bar->get_node( 'my-account' ); |
| 110 |
$new_title1 = str_replace( $current_user->display_name, $current_user->user_email, $my_account_main->title ); |
| 111 |
$wp_admin_bar->add_node( array( 'id' => 'my-account', 'title' => $new_title1 ) ); |
| 112 |
|
| 113 |
$my_account_sub = $wp_admin_bar->get_node( 'user-info' ); |
| 114 |
$wp_admin_bar->add_node( array( 'parent' => 'user-actions', 'id' => 'user-info', 'title' => get_avatar( $current_user->ID, 64 )."<span class='display-name'>{$current_user->user_email}</span>", 'href' => get_edit_profile_url( $current_user->ID ), 'meta' => array( 'tabindex' => -1 ) ) ); |
| 115 |
} |
| 116 |
|
| 117 |
return $wp_admin_bar; |
| 118 |
} |
| 119 |
add_filter( 'admin_bar_menu', 'wppb_replace_username_on_admin_bar', 25 ); |