Yoast\WP\SEO\Actions\Importing\Aioseo

Aioseo_Posts_Importing_Action::social_image_url_import()publicYoast 1.0

Imports the og and twitter image url.

{} Это метод класса: Aioseo_Posts_Importing_Action{}

Хуков нет.

Возвращает

true|false|null. The url of the social image we're importing, null if there's none.

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

$Aioseo_Posts_Importing_Action = new Aioseo_Posts_Importing_Action();
$Aioseo_Posts_Importing_Action->social_image_url_import( $aioseo_social_image_settings, $aioseo_key, $mapping, $indexable );
$aioseo_social_image_settings(true|false) (обязательный)
AIOSEO's set of social image settings for the post.
$aioseo_key(строка) (обязательный)
The AIOSEO key that contains the robot setting we're working with.
$mapping(массив) (обязательный)
The mapping of the setting we're working with.
$indexable(Indexable) (обязательный)
The Yoast indexable we're importing into.

Код Aioseo_Posts_Importing_Action::social_image_url_import() Yoast 19.2

public function social_image_url_import( $aioseo_social_image_settings, $aioseo_key, $mapping, $indexable ) {
	if ( $mapping['social_setting_prefix_aioseo'] === 'twitter_' && $aioseo_social_image_settings['twitter_use_og'] ) {
		$mapping['social_setting_prefix_aioseo'] = 'og_';
	}

	$social_setting = \rtrim( $mapping['social_setting_prefix_aioseo'], '_' );

	$image_type = $aioseo_social_image_settings[ $mapping['social_setting_prefix_aioseo'] . 'image_type' ];

	if ( $image_type === 'default' ) {
		$image_type = $this->social_images_provider->get_default_social_image_source( $social_setting );
	}

	switch ( $image_type ) {
		case 'attach':
			$image_url = $this->social_images_provider->get_first_attached_image( $indexable->object_id );
			break;
		case 'auto':
			if ( $this->social_images_provider->get_featured_image( $indexable->object_id ) ) {
				// If there's a featured image, lets not import it, as our indexable calculation has already set that as active social image. That way we achieve dynamicality.
				return null;
			}
			$image_url = $this->social_images_provider->get_auto_image( $indexable->object_id );
			break;
		case 'content':
			$image_url = $this->social_images_provider->get_first_image_in_content( $indexable->object_id );
			break;
		case 'custom_image':
			$image_url = $aioseo_social_image_settings[ $mapping['social_setting_prefix_aioseo'] . 'image_custom_url' ];
			break;
		case 'featured':
			return null; // Our auto-calculation when the indexable was built/updated has taken care of it, so it's not needed to transfer any data now.
		case 'author':
			return null;
		case 'custom':
			return null;
		case 'default':
			$image_url = $this->social_images_provider->get_default_custom_social_image( $social_setting );
			break;
		default:
			$image_url = $aioseo_social_image_settings[ $mapping['social_setting_prefix_aioseo'] . 'image_url' ];
			break;
	}

	if ( empty( $image_url ) ) {
		$image_url = $this->social_images_provider->get_default_custom_social_image( $social_setting );
	}

	if ( empty( $image_url ) ) {
		return null;
	}

	return $this->sanitization->sanitize_url( $image_url, null );
}