PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.4
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.4
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 / integrations / watchers / indexable-author-watcher.php

indexable-author-watcher.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.4, at src/integrations/watchers/indexable-author-watcher.php

94 lines 2.2 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\Integrations\Watchers;
4
5 use Yoast\WP\SEO\Builders\Indexable_Builder;
6 use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
7 use Yoast\WP\SEO\Integrations\Integration_Interface;
8 use Yoast\WP\SEO\Repositories\Indexable_Repository;
9
10 /**
11 * Watches an Author to save the meta information to an Indexable when updated.
12 */
13 class Indexable_Author_Watcher implements Integration_Interface {
14
15 /**
16 * The indexable repository.
17 *
18 * @var Indexable_Repository
19 */
20 protected $repository;
21
22 /**
23 * The indexable builder.
24 *
25 * @var Indexable_Builder
26 */
27 protected $builder;
28
29 /**
30 * Returns the conditionals based on which this loadable should be active.
31 *
32 * @return array
33 */
34 public static function get_conditionals() {
35 return [ Migrations_Conditional::class ];
36 }
37
38 /**
39 * Indexable_Author_Watcher constructor.
40 *
41 * @param Indexable_Repository $repository The repository to use.
42 * @param Indexable_Builder $builder The builder to use.
43 */
44 public function __construct( Indexable_Repository $repository, Indexable_Builder $builder ) {
45 $this->repository = $repository;
46 $this->builder = $builder;
47 }
48
49 /**
50 * Initializes the integration.
51 *
52 * This is the place to register hooks and filters.
53 */
54 public function register_hooks() {
55 \add_action( 'user_register', [ $this, 'build_indexable' ], \PHP_INT_MAX );
56 \add_action( 'profile_update', [ $this, 'build_indexable' ], \PHP_INT_MAX );
57 \add_action( 'deleted_user', [ $this, 'delete_indexable' ] );
58 }
59
60 /**
61 * Deletes user meta.
62 *
63 * @param int $user_id User ID to delete the metadata of.
64 *
65 * @return void
66 */
67 public function delete_indexable( $user_id ) {
68 $indexable = $this->repository->find_by_id_and_type( $user_id, 'user', false );
69
70 if ( ! $indexable ) {
71 return;
72 }
73
74 $indexable->delete();
75 }
76
77 /**
78 * Saves user meta.
79 *
80 * @param int $user_id User ID.
81 *
82 * @return void
83 */
84 public function build_indexable( $user_id ) {
85 $indexable = $this->repository->find_by_id_and_type( $user_id, 'user', false );
86 $indexable = $this->builder->build_for_id_and_type( $user_id, 'user', $indexable );
87
88 if ( $indexable ) {
89 $indexable->object_last_modified = \max( $indexable->object_last_modified, \current_time( 'mysql' ) );
90 $indexable->save();
91 }
92 }
93 }
94