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 ); } }