PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.3
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / admin / class-admin-user-profile.php

class-admin-user-profile.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.3, at admin/class-admin-user-profile.php

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