PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.8.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.8.3
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.8.3, at admin/admin-bar.php

132 lines 5.3 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>
49 <?php esc_html_e( 'Admin Bar Settings', 'profile-builder' );?>
50 <a href="https://www.cozmoslabs.com/docs/profile-builder-2/admin-bar-settings/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>
51 </h2>
52
53 <?php settings_errors(); ?>
54
55 <?php wppb_generate_settings_tabs() ?>
56
57 <p class="description"><?php esc_html_e( 'Choose which user roles view the admin bar in the front-end of the website.', 'profile-builder' ); ?>
58 <form method="post" action="options.php#show-hide-admin-bar">
59 <?php
60 $admin_bar_settings = get_option( 'wppb_display_admin_settings' );
61 settings_fields( 'wppb_display_admin_settings' );
62 ?>
63 <table class="widefat">
64 <thead>
65 <tr>
66 <th class="row-title" scope="col"><?php esc_html_e('User-Role', 'profile-builder');?></th>
67 <th scope="col"><?php esc_html_e('Visibility', 'profile-builder');?></th>
68 </tr>
69 </thead>
70 <tbody>
71 <?php
72 $alt_i = 0;
73 foreach ( $wp_roles->roles as $role ) {
74 $alt_i++;
75 $key = $role['name'];
76 $setting_exists = !empty( $admin_bar_settings[$key] );
77 $alt_class = ( ( $alt_i%2 == 0 ) ? ' class="alternate"' : '' );
78
79 echo'<tr'.esc_attr( $alt_class ).'>
80 <td>'. esc_html( translate_user_role($key) ).'</td>
81 <td>
82 <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>
83 <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>
84 <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>
85 </td>
86 </tr>';
87 }
88 ?>
89
90 </table>
91
92 <div id="wppb_submit_button_div">
93 <input type="hidden" name="action" value="update" />
94 <p class="submit">
95 <input type="submit" class="button-primary" value="<?php esc_html_e( 'Save Changes', 'profile-builder' ) ?>" />
96 </p>
97 </div>
98
99 </form>
100
101 </div>
102 <?php
103 }
104
105 /**
106 * Function that changes the username on the top right menu (admin bar)
107 *
108 * @since v.2.0
109 *
110 * @return string
111 */
112 function wppb_replace_username_on_admin_bar( $wp_admin_bar ) {
113 $wppb_general_settings = get_option( 'wppb_general_settings' );
114
115 if ( isset( $wppb_general_settings['loginWith'] ) && ( $wppb_general_settings['loginWith'] == 'email' ) ){
116 $current_user = wp_get_current_user();
117
118 if ( $current_user->ID != 0 ) {
119 if( $current_user->display_name === $current_user->user_login ) {
120 $my_account_main = $wp_admin_bar->get_node('my-account');
121 $new_title1 = str_replace($current_user->display_name, $current_user->user_email, $my_account_main->title);
122 $wp_admin_bar->add_node(array('id' => 'my-account', 'title' => $new_title1));
123
124 $my_account_sub = $wp_admin_bar->get_node('user-info');
125 $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)));
126 }
127 }
128 }
129
130 return $wp_admin_bar;
131 }
132 add_filter( 'admin_bar_menu', 'wppb_replace_username_on_admin_bar', 25 );