PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 All 507 releases
jetpack / jetpack_vendor / automattic / jetpack-masterbar / src / profile-edit / profile-edit.php

profile-edit.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-beta, at jetpack_vendor/automattic/jetpack-masterbar/src/profile-edit/profile-edit.php

73 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WP-Admin Profile edit.
4 *
5 * @package automattic/jetpack-masterbar
6 */
7
8 namespace Automattic\Jetpack\Masterbar;
9
10 use Automattic\Jetpack\Connection\Manager as Connection_Manager;
11 use WP_User;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit( 0 );
15 }
16
17 /**
18 * Hides profile fields for WordPress.com connected users.
19 *
20 * @param WP_User $user The current WP_User object.
21 */
22 function jetpack_masterbar_hide_profile_fields( $user ) {
23 $connection_manager = new Connection_Manager( 'jetpack' );
24 if ( ! $connection_manager->is_user_connected( $user->ID ) ) {
25 // If this is a local user, show the default UX.
26 return;
27 }
28 $wp_kses_rule = array(
29 'a' => array(
30 'href' => array(),
31 'rel' => array(),
32 'target' => array(),
33 ),
34 );
35 // Since there is no hook for altering profile fields, we will use CSS and JS.
36 $name_info_wpcom_link_message = sprintf(
37 /* translators: 1 link */
38 __( 'WordPress.com users can change their profile’s basic details ( i.e., First Name, Last Name, Display Name, About ) in <a href="%1$s" target="_blank" rel="noopener noreferrer">WordPress.com Profile settings.</a>', 'jetpack-masterbar' ),
39 'https://wordpress.com/me'
40 );
41 $contact_info_wpcom_link_message = sprintf(
42 /* translators: 1 link */
43 __( 'WordPress.com users can change their profile’s email & website address in <a href="%1$s" target="_blank" rel="noopener noreferrer">WordPress.com Account settings.</a>', 'jetpack-masterbar' ),
44 'https://wordpress.com/me/account'
45 );
46 ?>
47 <script>
48 document.addEventListener( 'DOMContentLoaded', function() {
49 // Field to be hidden.
50 var fieldsToHide = '.user-first-name-wrap, .user-last-name-wrap, .user-nickname-wrap, .user-display-name-wrap, .user-email-wrap, .user-url-wrap, .user-description-wrap';
51 document.querySelectorAll( fieldsToHide ).forEach( element => element.classList.add( 'hidden' ) );
52
53 // Name Info.
54 var nameInfo = document.querySelector( '.user-first-name-wrap' ).closest( 'table' );
55 var nameInfoWpcomLink = document.createElement( 'div' );
56 nameInfoWpcomLink.className = 'notice inline notice-large notice-warning';
57 nameInfoWpcomLink.innerHTML = '<?php echo wp_kses( $name_info_wpcom_link_message, $wp_kses_rule ); ?>';
58 nameInfo.parentNode.insertBefore( nameInfoWpcomLink, nameInfo.nextSibling );
59
60 // Contact Info.
61 var contactInfo = document.querySelector( '.user-email-wrap' ).closest( 'table' );
62 var contactInfoWpcomLink = document.createElement( 'div' );
63 contactInfoWpcomLink.className = 'notice inline notice-large notice-warning';
64 contactInfoWpcomLink.innerHTML = '<?php echo wp_kses( $contact_info_wpcom_link_message, $wp_kses_rule ); ?>';
65 contactInfo.parentNode.insertBefore( contactInfoWpcomLink, contactInfo.nextSibling );
66 });
67
68 </script>
69 <?php
70 }
71
72 add_action( 'personal_options', __NAMESPACE__ . '\jetpack_masterbar_hide_profile_fields' );
73