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 / analytics / application / to-be-cleaned-indexables-collector.php

to-be-cleaned-indexables-collector.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.6, at src/analytics/application/to-be-cleaned-indexables-collector.php

85 lines 4.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\Analytics\Application;
4
5 use WPSEO_Collection;
6 use Yoast\WP\SEO\Analytics\Domain\To_Be_Cleaned_Indexable_Bucket;
7 use Yoast\WP\SEO\Analytics\Domain\To_Be_Cleaned_Indexable_Count;
8 use Yoast\WP\SEO\Repositories\Indexable_Cleanup_Repository;
9
10 /**
11 * Collects data about to-be-cleaned indexables.
12 *
13 * @makePublic
14 */
15 class To_Be_Cleaned_Indexables_Collector implements WPSEO_Collection {
16
17 /**
18 * The cleanup query repository.
19 *
20 * @var Indexable_Cleanup_Repository
21 */
22 private $indexable_cleanup_repository;
23
24 /**
25 * The constructor.
26 *
27 * @param Indexable_Cleanup_Repository $indexable_cleanup_repository The Indexable cleanup repository.
28 */
29 public function __construct( Indexable_Cleanup_Repository $indexable_cleanup_repository ) {
30 $this->indexable_cleanup_repository = $indexable_cleanup_repository;
31 }
32
33 /**
34 * Gets the data for the collector.
35 *
36 * @return array
37 */
38 public function get() {
39 $to_be_cleaned_indexable_bucket = new To_Be_Cleaned_Indexable_Bucket();
40 $cleanup_tasks = [
41 'indexables_with_post_object_type_and_shop_order_object_sub_type' => $this->indexable_cleanup_repository->count_indexables_with_object_type_and_object_sub_type( 'post', 'shop_order' ),
42 'indexables_with_auto-draft_post_status' => $this->indexable_cleanup_repository->count_indexables_with_post_status( 'auto-draft' ),
43 'indexables_for_non_publicly_viewable_post' => $this->indexable_cleanup_repository->count_indexables_for_non_publicly_viewable_post(),
44 'indexables_for_non_publicly_viewable_taxonomies' => $this->indexable_cleanup_repository->count_indexables_for_non_publicly_viewable_taxonomies(),
45 'indexables_for_non_publicly_viewable_post_type_archive_pages' => $this->indexable_cleanup_repository->count_indexables_for_non_publicly_post_type_archive_pages(),
46 'indexables_for_authors_archive_disabled' => $this->indexable_cleanup_repository->count_indexables_for_authors_archive_disabled(),
47 'indexables_for_authors_without_archive' => $this->indexable_cleanup_repository->count_indexables_for_authors_without_archive(),
48 'indexables_for_object_type_and_source_table_users' => $this->indexable_cleanup_repository->count_indexables_for_orphaned_users(),
49 'indexables_for_object_type_and_source_table_posts' => $this->indexable_cleanup_repository->count_indexables_for_object_type_and_source_table( 'posts', 'ID', 'post' ),
50 'indexables_for_object_type_and_source_table_terms' => $this->indexable_cleanup_repository->count_indexables_for_object_type_and_source_table( 'terms', 'term_id', 'term' ),
51 'orphaned_from_table_indexable_hierarchy' => $this->indexable_cleanup_repository->count_orphaned_from_table( 'Indexable_Hierarchy', 'indexable_id' ),
52 'orphaned_from_table_indexable_id' => $this->indexable_cleanup_repository->count_orphaned_from_table( 'SEO_Links', 'indexable_id' ),
53 'orphaned_from_table_target_indexable_id' => $this->indexable_cleanup_repository->count_orphaned_from_table( 'SEO_Links', 'target_indexable_id' ),
54 ];
55
56 foreach ( $cleanup_tasks as $name => $count ) {
57 if ( $count !== null ) {
58 $count_object = new To_Be_Cleaned_Indexable_Count( $name, $count );
59 $to_be_cleaned_indexable_bucket->add_to_be_cleaned_indexable_count( $count_object );
60 }
61 }
62
63 $this->add_additional_counts( $to_be_cleaned_indexable_bucket );
64
65 return [ 'to_be_cleaned_indexables' => $to_be_cleaned_indexable_bucket->to_array() ];
66 }
67
68 /**
69 * Allows additional tasks to be added via the 'wpseo_add_cleanup_counts_to_indexable_bucket' action.
70 *
71 * @param To_Be_Cleaned_Indexable_Bucket $to_be_cleaned_indexable_bucket The current bucket with data.
72 *
73 * @return void
74 */
75 private function add_additional_counts( $to_be_cleaned_indexable_bucket ) {
76 /**
77 * Action: Adds the possibility to add additional to be cleaned objects.
78 *
79 * @internal
80 * @param To_Be_Cleaned_Indexable_Bucket $bucket An indexable cleanup bucket. New values are instances of To_Be_Cleaned_Indexable_Count.
81 */
82 \do_action( 'wpseo_add_cleanup_counts_to_indexable_bucket', $to_be_cleaned_indexable_bucket );
83 }
84 }
85