WPSEO_Admin_User_Profile

Customizes user profile.

Defined (1)

The class is defined in the following location(s).

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