repository = $repository; $this->builder = $builder; } /** * Initializes the integration. * * This is the place to register hooks and filters. * * @return void */ public function register_hooks() { \add_action( 'update_option_wpseo_titles', [ $this, 'check_option' ], 10, 2 ); } /** * Checks if the date archive indexable needs to be rebuild based on option values. * * @param array $old_value The old value of the option. * @param array $new_value The new value of the option. * * @return void */ public function check_option( $old_value, $new_value ) { $relevant_keys = [ 'title-archive-wpseo', 'breadcrumbs-archiveprefix', 'metadesc-archive-wpseo', 'noindex-archive-wpseo' ]; foreach ( $relevant_keys as $key ) { // If both values aren't set they haven't changed. if ( ! isset( $old_value[ $key ] ) && ! isset( $new_value[ $key ] ) ) { continue; } // If the value was set but now isn't, is set but wasn't or is not the same it has changed. if ( ! isset( $old_value[ $key ] ) || ! isset( $new_value[ $key ] ) || $old_value[ $key ] !== $new_value[ $key ] ) { $this->build_indexable(); return; } } } /** * Saves the date archive. * * @return void */ public function build_indexable() { $indexable = $this->repository->find_for_date_archive( false ); $this->builder->build_for_date_archive( $indexable ); } }