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 / 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 18.4, at src/actions/indexing/abstract-link-indexing-action.php

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