Yoast\WP\SEO\Helpers

Social_Profiles_Helper::set_organization_social_profiles()publicYoast 1.0

Stores the values for the organization'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_organization_social_profiles( $social_profiles );
$social_profiles(массив) (обязательный)
An array with the social profiles values to be saved in the db.

Код Social_Profiles_Helper::set_organization_social_profiles() Yoast 24.4

public function set_organization_social_profiles( $social_profiles ) {
	$failures                           = [];
	$organization_social_profile_fields = $this->get_organization_social_profile_fields();

	// First validate all social profiles, before even attempting to save them.
	foreach ( $organization_social_profile_fields as $field_name => $validation_method ) {
		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 ] );

		$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( $organization_social_profile_fields ) as $field_name ) {
		if ( ! isset( $social_profiles[ $field_name ] ) ) {
			// Just skip social profiles that were not passed.
			continue;
		}

		// Remove empty strings in Other Social URLs.
		if ( $field_name === 'other_social_urls' ) {
			$other_social_urls = \array_filter(
				$social_profiles[ $field_name ],
				static function ( $other_social_url ) {
					return $other_social_url !== '';
				}
			);

			$social_profiles[ $field_name ] = \array_values( $other_social_urls );
		}

		$result = $this->options_helper->set( $field_name, $social_profiles[ $field_name ] );
		if ( ! $result ) {
			/**
			 * The value for Twitter might have been sanitised from URL to username.
			 * If so, $result will be false. We should check if the option value is part of the received value.
			 */
			if ( $field_name === 'twitter_site' ) {
				$current_option = $this->options_helper->get( $field_name );
				if ( ! \strpos( $social_profiles[ $field_name ], 'twitter.com/' . $current_option ) && ! \strpos( $social_profiles[ $field_name ], 'x.com/' . $current_option ) ) {
					$failures[] = $field_name;
				}
			}
			else {
				$failures[] = $field_name;
			}
		}
	}

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

	return [];
}