options_helper = $options_helper; } /** * Registers action hook to maybe save an option. * * @return void */ public function register_hooks(): void { \add_action( 'wpseo_indexables_unindexed_calculated', [ $this, 'maybe_set_indexables_unindexed_calculated', ], 10, 2 ); } /** * Saves a timestamp option when there are no unindexed indexables. * * @param string $indexable_name The name of the indexable that is being checked. * @param int $count The amount of missing indexables. * * @return void */ public function maybe_set_indexables_unindexed_calculated( string $indexable_name, int $count ): void { if ( $count === 0 ) { $no_index = $this->options_helper->get( 'last_known_no_unindexed', [] ); $no_index[ $indexable_name ] = \time(); \remove_action( 'update_option_wpseo', [ 'WPSEO_Utils', 'clear_cache' ] ); $this->options_helper->set( 'last_known_no_unindexed', $no_index ); \add_action( 'update_option_wpseo', [ 'WPSEO_Utils', 'clear_cache' ] ); } } }