PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.8
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.8
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / analytics / user-interface / last-completed-indexation-integration.php

last-completed-indexation-integration.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.8, at src/analytics/user-interface/last-completed-indexation-integration.php

68 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Analytics\User_Interface;
4
5 use Yoast\WP\SEO\Conditionals\No_Conditionals;
6 use Yoast\WP\SEO\Helpers\Options_Helper;
7 use Yoast\WP\SEO\Integrations\Integration_Interface;
8
9 /**
10 * Handles setting a timestamp when the indexation of a specific indexation action is completed.
11 */
12 class Last_Completed_Indexation_Integration implements Integration_Interface {
13
14 use No_Conditionals;
15
16 /**
17 * The options helper.
18 *
19 * @var Options_Helper The options helper.
20 */
21 private $options_helper;
22
23 /**
24 * The constructor.
25 *
26 * @param Options_Helper $options_helper The options helper.
27 */
28 public function __construct( Options_Helper $options_helper ) {
29 $this->options_helper = $options_helper;
30 }
31
32 /**
33 * Registers action hook to maybe save an option.
34 *
35 * @return void
36 */
37 public function register_hooks(): void {
38 \add_action(
39 'wpseo_indexables_unindexed_calculated',
40 [
41 $this,
42 'maybe_set_indexables_unindexed_calculated',
43 ],
44 10,
45 2,
46 );
47 }
48
49 /**
50 * Saves a timestamp option when there are no unindexed indexables.
51 *
52 * @param string $indexable_name The name of the indexable that is being checked.
53 * @param int $count The amount of missing indexables.
54 *
55 * @return void
56 */
57 public function maybe_set_indexables_unindexed_calculated( string $indexable_name, int $count ): void {
58 if ( $count === 0 ) {
59 $no_index = $this->options_helper->get( 'last_known_no_unindexed', [] );
60 $no_index[ $indexable_name ] = \time();
61
62 \remove_action( 'update_option_wpseo', [ 'WPSEO_Utils', 'clear_cache' ] );
63 $this->options_helper->set( 'last_known_no_unindexed', $no_index );
64 \add_action( 'update_option_wpseo', [ 'WPSEO_Utils', 'clear_cache' ] );
65 }
66 }
67 }
68