post_indexation = $post_indexation; $this->term_indexation = $term_indexation; $this->post_type_archive_indexation = $post_type_archive_indexation; $this->general_indexation = $general_indexation; $this->complete_indexation_action = $complete_indexation_action; $this->post_link_indexing_action = $post_link_indexing_action; $this->term_link_indexing_action = $term_link_indexing_action; $this->indexing_helper = $indexing_helper; } /** * Register hooks. */ public function register_hooks() { \add_action( 'admin_init', [ $this, 'register_shutdown_indexing' ], 10 ); } /** * Enqueues the required scripts. * * @return void */ public function register_shutdown_indexing() { if ( $this->should_index_on_shutdown( $this->get_shutdown_limit() ) ) { \register_shutdown_function( [ $this, 'index' ] ); } } /** * Run a single indexing pass of each indexing action. Intended for use as a shutdown function. * * @return void */ public function index() { $this->post_indexation->index(); $this->term_indexation->index(); $this->general_indexation->index(); $this->post_type_archive_indexation->index(); $this->post_link_indexing_action->index(); $this->term_link_indexing_action->index(); $this->complete_indexation_action->complete(); } /** * Retrieves the shutdown limit. This limit is the amount of indexables that is generated in the background. * * @return int The shutdown limit. */ protected function get_shutdown_limit() { /** * Filter 'wpseo_shutdown_indexation_limit' - Allow filtering the number of objects that can be indexed during shutdown. * * @api int The maximum number of objects indexed. */ return \apply_filters( 'wpseo_shutdown_indexation_limit', 25 ); } /** * Determine whether background indexation should be performed. * * @param int $shutdown_limit The shutdown limit used to determine whether indexation should be run. * * @return bool Should background indexation be performed. */ public function should_index_on_shutdown( $shutdown_limit ) { $total = $this->indexing_helper->get_limited_filtered_unindexed_count( $shutdown_limit ); return ( $total > 0 && $total < $shutdown_limit ); } }