on, $term_indexation_action, $general_indexation_action, $post_type_archive_indexation_action, ]; } /** * Initializes the integration. * * This is the place to register hooks and filters. * * @return void */ public function register_hooks() { \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); \add_filter( 'wpseo_indexing_data', [ $this, 'adapt_indexing_data' ] ); \add_filter( 'wpseo_indexing_get_unindexed_count', [ $this, 'get_unindexed_count' ] ); \add_filter( 'wpseo_indexing_get_limited_unindexed_count', [ $this, 'get_limited_unindexed_count' ], 10, 2 ); \add_filter( 'wpseo_indexing_endpoints', [ $this, 'add_endpoints' ] ); } /** * Returns the conditionals based in which this loadable should be active. * * @return array */ public static function get_conditionals() { return [ Admin_Conditional::class, Migrations_Conditional::class, ]; } /** * Retrieves the endpoints to call. * * @param array $endpoints The endpoints to extend. * * @return array The endpoints. */ public function add_endpoints( $endpoints ) { $endpoints['get_content'] = Prominent_Words_Route::FULL_GET_CONTENT_ROUTE; $endpoints['complete_words'] = Prominent_Words_Route::FULL_COMPLETE_ROUTE; return $endpoints; } /** * Adapts the indexing data as sent to the JavaScript side of the * indexing process. * * Adds the appropriate prominent words endpoints and other settings. * * @param array $data The data to be adapted. * * @return array The adapted indexing data. */ public function adapt_indexing_data( $data ) { $site_locale = \get_locale(); $language = WPSEO_Language_Utils::get_language( $site_locale ); $data['locale'] = $site_locale; $data['language'] = $language; $data['morphologySupported'] = $this->language_helper->is_word_form_recognition_active( $language ); $per_indexable_limit = self::PER_INDEXABLE_LIMIT_NO_FUNCTION_WORD_SUPPORT; if ( $this->language_helper->has_function_word_support( $language ) ) { $per_indexable_limit = self::PER_INDEXABLE_LIMIT; } $data['prominentWords'] = [ 'endpoint' => Prominent_Words_Route::FULL_SAVE_ROUTE, 'perIndexableLimit' => $per_indexable_limit, ]; return $data; } /** * Enqueues the required scripts. * * @return void */ public function enqueue_scripts() { if ( ! isset( $_GET['page'] ) || ( $_GET['page'] !== 'wpseo_tools' && $_GET['page'] !== 'wpseo_workouts' && $_GET['page'] !== 'wpseo_dashboard' ) || ( $_GET['page'] === 'wpseo_tools' && isset( $_GET['tool'] ) ) ) { return; } $is_completed = ( (int) $this->get_unindexed_count( 0 ) === 0 ); $this->prominent_words_helper->set_indexing_completed( $is_completed ); \wp_enqueue_script( 'yoast-premium-prominent-words-indexation' ); \wp_localize_script( 'yoast-premium-prominent-words-indexation', 'wpseoPremiumIndexationData', [ 'licensedURL' => $this->url_helper->network_safe_home_url() ] ); } /** * Returns the total number of unindexed objects. * * @param int $unindexed_count The unindexed count. * * @return int The total number of indexables to recalculate. */ public function get_unindexed_count( $unindexed_count ) { foreach ( $this->indexing_actions as $indexing_action ) { $unindexed_count += $indexing_action->get_total_unindexed(); } return $unindexed_count; } /** * Returns a limited number of unindexed objects. * * @param int $unindexed_count The unindexed count. * @param int $limit Limit the number of unindexed objects that are counted. * * @return int The total number of unindexed objects. */ public function get_limited_unindexed_count( $unindexed_count, $limit ) { foreach ( $this->indexing_actions as $indexing_action ) { $unindexed_count += $indexing_action->get_limited_unindexed_count( $limit - $unindexed_count + 1 ); if ( $unindexed_count > $limit ) { return $unindexed_count; } } return $unindexed_count; } }