/admin/class-admin-user-profile.php

  1. <?php 
  2. /** 
  3. * @package WPSEO\Admin 
  4. * @since 1.8.0 
  5. */ 
  6.  
  7. /** 
  8. * Customizes user profile. 
  9. */ 
  10. class WPSEO_Admin_User_Profile { 
  11. /** 
  12. * Class constructor 
  13. */ 
  14. public function __construct() { 
  15. add_action( 'show_user_profile', array( $this, 'user_profile' ) ); 
  16. add_action( 'edit_user_profile', array( $this, 'user_profile' ) ); 
  17. add_action( 'personal_options_update', array( $this, 'process_user_option_update' ) ); 
  18. add_action( 'edit_user_profile_update', array( $this, 'process_user_option_update' ) ); 
  19.  
  20. add_action( 'update_user_meta', array( $this, 'clear_author_sitemap_cache' ), 10, 3 ); 
  21.  
  22. /** 
  23. * Clear author sitemap cache when settings are changed 
  24. * 
  25. * @since 3.1 
  26. * 
  27. * @param int $meta_id The ID of the meta option changed. 
  28. * @param int $object_id The ID of the user. 
  29. * @param string $meta_key The key of the meta field changed. 
  30. */ 
  31. public function clear_author_sitemap_cache( $meta_id, $object_id, $meta_key ) { 
  32. if ( '_yoast_wpseo_profile_updated' === $meta_key ) { 
  33. WPSEO_Sitemaps_Cache::clear( array( 'author' ) ); 
  34.  
  35. /** 
  36. * Filter POST variables. 
  37. * 
  38. * @param string $var_name Name of the variable to filter. 
  39. * 
  40. * @return mixed 
  41. */ 
  42. private function filter_input_post( $var_name ) { 
  43. $val = filter_input( INPUT_POST, $var_name ); 
  44. if ( $val ) { 
  45. return WPSEO_Utils::sanitize_text_field( $val ); 
  46. return ''; 
  47.  
  48. /** 
  49. * Updates the user metas that (might) have been set on the user profile page. 
  50. * 
  51. * @param int $user_id of the updated user. 
  52. */ 
  53. public function process_user_option_update( $user_id ) { 
  54. update_user_meta( $user_id, '_yoast_wpseo_profile_updated', time() ); 
  55.  
  56. $nonce_value = $this->filter_input_post( 'wpseo_nonce' ); 
  57.  
  58. if ( empty( $nonce_value ) ) { // Submit from alternate forms. 
  59. return; 
  60.  
  61. check_admin_referer( 'wpseo_user_profile_update', 'wpseo_nonce' ); 
  62.  
  63. update_user_meta( $user_id, 'wpseo_title', $this->filter_input_post( 'wpseo_author_title' ) ); 
  64. update_user_meta( $user_id, 'wpseo_metadesc', $this->filter_input_post( 'wpseo_author_metadesc' ) ); 
  65. update_user_meta( $user_id, 'wpseo_metakey', $this->filter_input_post( 'wpseo_author_metakey' ) ); 
  66. update_user_meta( $user_id, 'wpseo_excludeauthorsitemap', $this->filter_input_post( 'wpseo_author_exclude' ) ); 
  67. update_user_meta( $user_id, 'wpseo_content_analysis_disable', $this->filter_input_post( 'wpseo_content_analysis_disable' ) ); 
  68. update_user_meta( $user_id, 'wpseo_keyword_analysis_disable', $this->filter_input_post( 'wpseo_keyword_analysis_disable' ) ); 
  69.  
  70. /** 
  71. * Add the inputs needed for SEO values to the User Profile page 
  72. * 
  73. * @param WP_User $user User instance to output for. 
  74. */ 
  75. public function user_profile( $user ) { 
  76. $options = WPSEO_Options::get_option( 'wpseo' ); 
  77. $options_titles = WPSEO_Options::get_option( 'wpseo_titles' ); 
  78.  
  79. wp_nonce_field( 'wpseo_user_profile_update', 'wpseo_nonce' ); 
  80.  
  81. require_once( 'views/user-profile.php' ); 
.