PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.3
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 / builders / indexable-system-page-builder.php

indexable-system-page-builder.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.3, at src/builders/indexable-system-page-builder.php

83 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\Builders;
4
5 use Yoast\WP\SEO\Helpers\Options_Helper;
6 use Yoast\WP\SEO\Models\Indexable;
7 use Yoast\WP\SEO\Values\Indexables\Indexable_Builder_Versions;
8
9 /**
10 * System page builder for the indexables.
11 *
12 * Formats system pages ( search and error ) meta to indexable format.
13 *
14 * @phpcs:disable Yoast.NamingConventions.ObjectNameDepth.MaxExceeded
15 */
16 class Indexable_System_Page_Builder {
17
18 /**
19 * Mapping of object type to title option keys.
20 */
21 const OPTION_MAPPING = [
22 'search-result' => [
23 'title' => 'title-search-wpseo',
24 ],
25 '404' => [
26 'title' => 'title-404-wpseo',
27 'breadcrumb_title' => 'breadcrumbs-404crumb',
28 ],
29 ];
30
31 /**
32 * The options helper.
33 *
34 * @var Options_Helper
35 */
36 protected $options;
37
38 /**
39 * The latest version of the Indexable_System_Page_Builder.
40 *
41 * @var int
42 */
43 protected $version;
44
45 /**
46 * Indexable_System_Page_Builder constructor.
47 *
48 * @param Options_Helper $options The options helper.
49 * @param Indexable_Builder_Versions $versions The latest version of each Indexable Builder.
50 */
51 public function __construct(
52 Options_Helper $options,
53 Indexable_Builder_Versions $versions
54 ) {
55 $this->options = $options;
56 $this->version = $versions->get_latest_version_for_type( 'system-page' );
57 }
58
59 /**
60 * Formats the data.
61 *
62 * @param string $object_sub_type The object sub type of the system page.
63 * @param Indexable $indexable The indexable to format.
64 *
65 * @return Indexable The extended indexable.
66 */
67 public function build( $object_sub_type, Indexable $indexable ) {
68 $indexable->object_type = 'system-page';
69 $indexable->object_sub_type = $object_sub_type;
70 $indexable->title = $this->options->get( static::OPTION_MAPPING[ $object_sub_type ]['title'] );
71 $indexable->is_robots_noindex = true;
72 $indexable->blog_id = \get_current_blog_id();
73
74 if ( \array_key_exists( 'breadcrumb_title', static::OPTION_MAPPING[ $object_sub_type ] ) ) {
75 $indexable->breadcrumb_title = $this->options->get( static::OPTION_MAPPING[ $object_sub_type ]['breadcrumb_title'] );
76 }
77
78 $indexable->version = $this->version;
79
80 return $indexable;
81 }
82 }
83