Yoast\WP\SEO\Helpers

Social_Profiles_Helper::set_person_social_profiles()publicYoast 1.0

Stores the values for the person's social profiles.

Метод класса: Social_Profiles_Helper{}

Хуков нет.

Возвращает

Строку[]. An array of field names which failed to be saved in the db.

Использование

$Social_Profiles_Helper = new Social_Profiles_Helper();
$Social_Profiles_Helper->set_person_social_profiles( $person_id, $social_profiles );
$person_id(int) (обязательный)
The id of the person to edit.
$social_profiles(массив) (обязательный)
The array of the person's social profiles to be set.

Код Social_Profiles_Helper::set_person_social_profiles() Yoast 24.4

public function set_person_social_profiles( $person_id, $social_profiles ) {
	$failures                     = [];
	$person_social_profile_fields = $this->get_person_social_profile_fields();

	// First validate all social profiles, before even attempting to save them.
	foreach ( $person_social_profile_fields as $field_name => $validation_method ) {
		if ( ! isset( $social_profiles[ $field_name ] ) ) {
			// Just skip social profiles that were not passed.
			continue;
		}

		if ( $social_profiles[ $field_name ] === '' ) {
			continue;
		}

		$value_to_validate = $social_profiles[ $field_name ];
		$failures          = \array_merge( $failures, \call_user_func( [ $this, $validation_method ], $value_to_validate, $field_name ) );
	}

	if ( ! empty( $failures ) ) {
		return $failures;
	}

	// All social profiles look good, now let's try to save them.
	foreach ( \array_keys( $person_social_profile_fields ) as $field_name ) {
		if ( ! isset( $social_profiles[ $field_name ] ) ) {
			// Just skip social profiles that were not passed.
			continue;
		}
		$social_profiles[ $field_name ] = $this->sanitize_social_field( $social_profiles[ $field_name ] );
		\update_user_meta( $person_id, $field_name, $social_profiles[ $field_name ] );
	}

	return $failures;
}