The conditionals.
*/
public static function get_conditionals() {
return [
Admin_Conditional::class,
User_Can_Edit_Users_Conditional::class,
User_Edit_Conditional::class,
];
}
/**
* Registers action hook.
*
* @return void
*/
public function register_hooks(): void {
\add_action( 'show_user_profile', [ $this, 'user_profile' ] );
\add_action( 'edit_user_profile', [ $this, 'user_profile' ] );
\add_action( 'personal_options_update', [ $this, 'process_user_option_update' ] );
\add_action( 'edit_user_profile_update', [ $this, 'process_user_option_update' ] );
}
/**
* Updates the user metas that (might) have been set on the user profile page.
*
* @param int $user_id User ID of the updated user.
*
* @return void
*/
public function process_user_option_update( $user_id ) {
\update_user_meta( $user_id, '_yoast_wpseo_profile_updated', \time() );
if ( ! \check_admin_referer( 'wpseo_user_profile_update', 'wpseo_nonce' ) ) {
return;
}
foreach ( $this->custom_meta_collector->get_custom_meta() as $meta ) {
if ( ! $meta->is_setting_enabled() ) {
continue;
}
$meta_field_id = $meta->get_field_id();
$user_input_to_store = isset( $_POST[ $meta_field_id ] ) ? \sanitize_text_field( \wp_unslash( $_POST[ $meta_field_id ] ) ) : '';
if ( $meta->is_empty_allowed() || $user_input_to_store !== '' ) {
\update_user_meta( $user_id, $meta->get_key(), $user_input_to_store );
continue;
}
\delete_user_meta( $user_id, $meta->get_key() );
}
}
/**
* Adds the inputs needed for SEO values to the User Profile page.
*
* @param WP_User $user User instance to output for.
*
* @return void
*/
public function user_profile( $user ) {
\wp_nonce_field( 'wpseo_user_profile_update', 'wpseo_nonce' );
/* translators: %1$s expands to Yoast SEO */
$yoast_user_settings_header = \sprintf( \__( '%1$s settings', 'wordpress-seo' ), 'Yoast SEO' );
echo '
' . \esc_html( $yoast_user_settings_header ) . '
';
foreach ( $this->custom_meta_collector->get_sorted_custom_meta() as $meta ) {
if ( ! $meta->is_setting_enabled() ) {
continue;
}
$meta->render_field( $user->ID );
}
\do_action( 'wpseo_render_user_profile', $user );
echo '';
}
}