Yoast\WP\SEO\Alerts\User_Interface\Default_SEO_Data

Default_SEO_Data_Cron_Callback_Integration{}Yoast 1.0└─ Integration_Interface

Cron Callback integration. This handles the actual process of detecting default SEO data in recent posts and updating the relevant options.

Хуков нет.

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

$Default_SEO_Data_Cron_Callback_Integration = new Default_SEO_Data_Cron_Callback_Integration();
// use class methods

Методы

  1. public __construct(
  2. public detect_default_seo_data_in_recent()
  3. public register_hooks()

Код Default_SEO_Data_Cron_Callback_Integration{} Yoast 27.7

class Default_SEO_Data_Cron_Callback_Integration implements Integration_Interface {

	use No_Conditionals;

	/**
	 * The options helper.
	 *
	 * @var Options_Helper
	 */
	private $options_helper;

	/**
	 * The scheduler.
	 *
	 * @var Default_SEO_Data_Cron_Scheduler
	 */
	private $scheduler;

	/**
	 * The indexable repository.
	 *
	 * @var Indexable_Repository
	 */
	private $indexable_repository;

	/**
	 * Constructor.
	 *
	 * @param Options_Helper                  $options_helper       The options helper.
	 * @param Default_SEO_Data_Cron_Scheduler $scheduler            The scheduler.
	 * @param Indexable_Repository            $indexable_repository The indexable repository.
	 */
	public function __construct(
		Options_Helper $options_helper,
		Default_SEO_Data_Cron_Scheduler $scheduler,
		Indexable_Repository $indexable_repository
	) {
		$this->options_helper       = $options_helper;
		$this->scheduler            = $scheduler;
		$this->indexable_repository = $indexable_repository;
	}

	/**
	 * Registers the hooks.
	 *
	 * @return void
	 */
	public function register_hooks() {
		\add_action(
			Default_SEO_Data_Cron_Scheduler::CRON_HOOK,
			[
				$this,
				'detect_default_seo_data_in_recent',
			],
		);
	}

	/**
	 * Detects default SEO data in recent posts and updates the relevant options.
	 *
	 * @return void
	 */
	public function detect_default_seo_data_in_recent(): void {
		if ( ! \wp_doing_cron() ) {
			return;
		}

		$recent_posts = $this->indexable_repository->get_recently_modified_posts( 'post', 5, false );

		$recent_default_seo_title     = [];
		$recent_default_seo_meta_desc = [];
		foreach ( $recent_posts as $post ) {
			if ( $post->title === null ) {
				$recent_default_seo_title[] = $post->object_id;
			}

			if ( $post->description === null ) {
				$recent_default_seo_meta_desc[] = $post->object_id;
			}
		}

		$this->options_helper->set( 'default_seo_title', $recent_default_seo_title );
		$this->options_helper->set( 'default_seo_meta_desc', $recent_default_seo_meta_desc );
	}
}