PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
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 / alerts / user-interface / default-seo-data / default-seo-data-watcher.php

default-seo-data-watcher.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at src/alerts/user-interface/default-seo-data/default-seo-data-watcher.php

79 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // phpcs:disable Yoast.NamingConventions.NamespaceName.TooLong -- Needed in the folder structure.
4 namespace Yoast\WP\SEO\Alerts\User_Interface\Default_SEO_Data;
5
6 use Yoast\WP\SEO\Conditionals\No_Conditionals;
7 use Yoast\WP\SEO\Helpers\Options_Helper;
8 use Yoast\WP\SEO\Integrations\Integration_Interface;
9 use Yoast\WP\SEO\Models\Indexable;
10 use Yoast\WP\SEO\Repositories\Indexable_Repository;
11
12 /**
13 * This handles the process of checking for non-default SEO in the latest content and updating the relevant options right away.
14 */
15 class Default_SEO_Data_Watcher implements Integration_Interface {
16
17 use No_Conditionals;
18
19 /**
20 * The indexable repository.
21 *
22 * @var Indexable_Repository
23 */
24 private $indexable_repository;
25
26 /**
27 * The options helper.
28 *
29 * @var Options_Helper
30 */
31 private $options_helper;
32
33 /**
34 * Constructor.
35 *
36 * @param Indexable_Repository $indexable_repository The indexable repository.
37 * @param Options_Helper $options_helper The options helper.
38 */
39 public function __construct(
40 Indexable_Repository $indexable_repository,
41 Options_Helper $options_helper
42 ) {
43 $this->indexable_repository = $indexable_repository;
44 $this->options_helper = $options_helper;
45 }
46
47 /**
48 * Registers the hooks with WordPress.
49 *
50 * @return void
51 */
52 public function register_hooks() {
53 \add_action( 'wpseo_saved_indexable', [ $this, 'check_for_default_seo_data' ], 10, 1 );
54 }
55
56 /**
57 * Checks for default SEO data in the saved indexable and the most recently modified posts.
58 *
59 * @param Indexable $saved_indexable The saved indexable.
60 *
61 * @return void
62 */
63 public function check_for_default_seo_data( $saved_indexable ): void {
64 // We have activated this feature only for posts for now.
65 if ( $saved_indexable->object_type !== 'post' || $saved_indexable->object_sub_type !== 'post' ) {
66 return;
67 }
68
69 // If the title or description is null, it means it's not default SEO data so let's reset the options.
70 if ( $saved_indexable->title !== null ) {
71 $this->options_helper->set( 'default_seo_title', [] );
72 }
73
74 if ( $saved_indexable->description !== null ) {
75 $this->options_helper->set( 'default_seo_meta_desc', [] );
76 }
77 }
78 }
79