Нет описания

profile-edit.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * WP-Admin Profile edit.
  4. *
  5. * @package Jetpack
  6. */
  7. use Automattic\Jetpack\Connection\Manager as Connection_Manager;
  8. /**
  9. * Hides profile fields for WordPress.com connected users.
  10. *
  11. * @param WP_User $user The current WP_User object.
  12. */
  13. function jetpack_masterbar_hide_profile_fields( $user ) {
  14. $connection_manager = new Connection_Manager( 'jetpack' );
  15. if ( ! $connection_manager->is_user_connected( $user->ID ) ) {
  16. // If this is a local user, show the default UX.
  17. return;
  18. }
  19. $wp_kses_rule = array(
  20. 'a' => array(
  21. 'href' => array(),
  22. 'rel' => array(),
  23. 'target' => array(),
  24. ),
  25. );
  26. // Since there is no hook for altering profile fields, we will use CSS and JS.
  27. $name_info_wpcom_link_message = sprintf(
  28. /* translators: 1 link */
  29. __( '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' ),
  30. 'https://wordpress.com/me'
  31. );
  32. $contact_info_wpcom_link_message = sprintf(
  33. /* translators: 1 link */
  34. __( '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' ),
  35. 'https://wordpress.com/me/account'
  36. );
  37. ?>
  38. <script>
  39. document.addEventListener( 'DOMContentLoaded', function() {
  40. // Field to be hidden.
  41. 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';
  42. document.querySelectorAll( fieldsToHide ).forEach( element => element.classList.add( 'hidden' ) );
  43. // Name Info.
  44. var nameInfo = document.querySelector( '.user-first-name-wrap' ).closest( 'table' );
  45. var nameInfoWpcomLink = document.createElement( 'div' );
  46. nameInfoWpcomLink.className = 'notice inline notice-large notice-warning';
  47. nameInfoWpcomLink.innerHTML = '<?php echo wp_kses( $name_info_wpcom_link_message, $wp_kses_rule ); ?>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
  48. nameInfo.parentNode.insertBefore( nameInfoWpcomLink, nameInfo.nextSibling );
  49. // Contact Info.
  50. var contactInfo = document.querySelector( '.user-email-wrap' ).closest( 'table' );
  51. var contactInfoWpcomLink = document.createElement( 'div' );
  52. contactInfoWpcomLink.className = 'notice inline notice-large notice-warning';
  53. contactInfoWpcomLink.innerHTML = '<?php echo wp_kses( $contact_info_wpcom_link_message, $wp_kses_rule ); ?>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
  54. contactInfo.parentNode.insertBefore( contactInfoWpcomLink, contactInfo.nextSibling );
  55. });
  56. </script>
  57. <?php
  58. }
  59. add_action( 'personal_options', 'jetpack_masterbar_hide_profile_fields' );