PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.7.0
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.7.0
4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 340 releases
profile-builder / admin / admin-bar.php

admin-bar.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.7.0, at admin/admin-bar.php

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