PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.6
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 / actions / indexing / abstract-link-indexing-action.php

abstract-link-indexing-action.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.6, at src/actions/indexing/abstract-link-indexing-action.php

124 lines 3.1 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\Actions\Indexing;
4
5 use wpdb;
6 use Yoast\WP\SEO\Builders\Indexable_Link_Builder;
7 use Yoast\WP\SEO\Helpers\Indexable_Helper;
8 use Yoast\WP\SEO\Models\SEO_Links;
9 use Yoast\WP\SEO\Repositories\Indexable_Repository;
10
11 /**
12 * Reindexing action for link indexables.
13 */
14 abstract class Abstract_Link_Indexing_Action extends Abstract_Indexing_Action {
15
16 /**
17 * The link builder.
18 *
19 * @var Indexable_Link_Builder
20 */
21 protected $link_builder;
22
23 /**
24 * The indexable helper.
25 *
26 * @var Indexable_Helper
27 */
28 protected $indexable_helper;
29
30 /**
31 * The indexable repository.
32 *
33 * @var Indexable_Repository
34 */
35 protected $repository;
36
37 /**
38 * The WordPress database instance.
39 *
40 * @var wpdb
41 */
42 protected $wpdb;
43
44 /**
45 * Indexable_Post_Indexing_Action constructor
46 *
47 * @param Indexable_Link_Builder $link_builder The indexable link builder.
48 * @param Indexable_Helper $indexable_helper The indexable repository.
49 * @param Indexable_Repository $repository The indexable repository.
50 * @param wpdb $wpdb The WordPress database instance.
51 */
52 public function __construct(
53 Indexable_Link_Builder $link_builder,
54 Indexable_Helper $indexable_helper,
55 Indexable_Repository $repository,
56 wpdb $wpdb
57 ) {
58 $this->link_builder = $link_builder;
59 $this->indexable_helper = $indexable_helper;
60 $this->repository = $repository;
61 $this->wpdb = $wpdb;
62 }
63
64 /**
65 * Builds links for indexables which haven't had their links indexed yet.
66 *
67 * @return SEO_Links[] The created SEO links.
68 */
69 public function index() {
70 $objects = $this->get_objects();
71
72 $indexables = [];
73 foreach ( $objects as $object ) {
74 $indexable = $this->repository->find_by_id_and_type( $object->id, $object->type );
75 if ( $indexable ) {
76 $this->link_builder->build( $indexable, $object->content );
77 $this->indexable_helper->save_indexable( $indexable );
78
79 $indexables[] = $indexable;
80 }
81 }
82
83 if ( \count( $indexables ) > 0 ) {
84 \delete_transient( static::UNINDEXED_COUNT_TRANSIENT );
85 \delete_transient( static::UNINDEXED_LIMITED_COUNT_TRANSIENT );
86 }
87
88 return $indexables;
89 }
90
91 /**
92 * In the case of term-links and post-links we want to use the total unindexed count, because using
93 * the limited unindexed count actually leads to worse performance.
94 *
95 * @param int|bool $limit Unused.
96 *
97 * @return int The total number of unindexed links.
98 */
99 public function get_limited_unindexed_count( $limit = false ) {
100 return $this->get_total_unindexed();
101 }
102
103 /**
104 * Returns the number of texts that will be indexed in a single link indexing pass.
105 *
106 * @return int The limit.
107 */
108 public function get_limit() {
109 /**
110 * Filter 'wpseo_link_indexing_limit' - Allow filtering the number of texts indexed during each link indexing pass.
111 *
112 * @param int $limit The maximum number of texts indexed.
113 */
114 return \apply_filters( 'wpseo_link_indexing_limit', 5 );
115 }
116
117 /**
118 * Returns objects to be indexed.
119 *
120 * @return array Objects to be indexed, should be an array of objects with object_id, object_type and content.
121 */
122 abstract protected function get_objects();
123 }
124