WPSEO_Addon_Manager::convert_subscription_to_plugin()protectedYoast 1.0

Converts a subscription to plugin based format.

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

Хуков нет.

Возвращает

stdClass. The converted subscription.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->convert_subscription_to_plugin( $subscription, $yoast_free_data, $plugin_info, $plugin_file );
$subscription(stdClass) (обязательный)
The subscription to convert.
$yoast_free_data(stdClass|null)
The Yoast Free's data.
По умолчанию: null
$plugin_info(true|false)
Whether we're in the plugin information modal.
По умолчанию: false
$plugin_file(строка)
The plugin filename.
По умолчанию: ''

Код WPSEO_Addon_Manager::convert_subscription_to_plugin() Yoast 22.4

protected function convert_subscription_to_plugin( $subscription, $yoast_free_data = null, $plugin_info = false, $plugin_file = '' ) {
	$changelog = '';
	if ( isset( $subscription->product->changelog ) ) {
		// We need to replace h2's and h3's with h4's because the styling expects that.
		$changelog = str_replace( '</h2', '</h4', str_replace( '<h2', '<h4', $subscription->product->changelog ) );
		$changelog = str_replace( '</h3', '</h4', str_replace( '<h3', '<h4', $changelog ) );

	}

	// If we're running this because we want to just show the plugin info in the version details modal, we can fallback to the Yoast Free constants, since that modal will not be accessible anyway in the event that the new Free version increases those constants.
	$defaults = [
		// It can be expanded if we have the 'tested' and 'requires_php' data be returned from wp.org in the future.
		'requires'     => ( $plugin_info ) ? YOAST_SEO_WP_REQUIRED : null,
	];

	return (object) [
		'new_version'      => ( $subscription->product->version ?? '' ),
		'name'             => $subscription->product->name,
		'slug'             => $subscription->product->slug,
		'plugin'           => $plugin_file,
		'url'              => $subscription->product->store_url,
		'last_update'      => $subscription->product->last_updated,
		'homepage'         => $subscription->product->store_url,
		'download_link'    => $subscription->product->download,
		'package'          => $subscription->product->download,
		'sections'         => [
			'changelog' => $changelog,
			'support'   => $this->get_support_section(),
		],
		'icons'            => [
			'2x' => $this->get_icon( $subscription->product->slug ),
		],
		'update_supported' => true,
		'banners'          => $this->get_banners( $subscription->product->slug ),
		// If we have extracted Yoast Free's data before, use that. If not, resort to the defaults.
		'tested'           => YOAST_SEO_WP_TESTED,
		'requires'         => ( $yoast_free_data->requires ?? $defaults['requires'] ),
		'requires_php'     => YOAST_SEO_PHP_REQUIRED,
	];
}