Yoast\WP\SEO\Abilities\Application
Author_Schema_Updater::update
Updates the author schema settings of a user in the input and returns the new state of all of them.
Only fields present in the input are changed (patch semantics), so an input without fields only reads the settings. Settings that cannot be applied or saved are reported in a warning, while the other settings are still saved.
Метод класса: Author_Schema_Updater{}
Хуков нет.
Возвращает
array<string, mixed>|WP_Error. The new author schema settings, plus a warning when some could not be changed, or an error when the user does not exist.
Использование
$Author_Schema_Updater = new Author_Schema_Updater(); $Author_Schema_Updater->update( $user_id, $input );
- $user_id(int) (обязательный)
- The ID of the user.
- $input(array<string, mixed>) (обязательный)
- The author schema settings to change, keyed by field name.
Код Author_Schema_Updater::update() Author Schema Updater::update Yoast 28.9
public function update( int $user_id, array $input ) {
if ( \get_userdata( $user_id ) === false ) {
return new WP_Error(
'yoast_seo_user_not_found',
\__( 'No user exists with the given ID.', 'wordpress-seo' ),
[ 'status' => 404 ],
);
}
$fields = $this->field_map->get_fields();
$update = $this->update_fields( $fields, $this->field_map->get_validators(), $input, [ 'user_id' => $user_id ] );
if ( $update['saved_any'] ) {
// Like saving the user profile page does, so the author sitemap gets the right last modified date.
$this->user_helper->update_meta( $user_id, '_yoast_wpseo_profile_updated', \time() );
}
$result = \array_merge( [ 'user_id' => $user_id ], $this->get_settings( $user_id, $fields ) );
if ( $update['warning'] !== null ) {
$result['warning'] = $update['warning'];
}
return $result;
}