PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.8
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.8
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 / presentations / indexable-author-archive-presentation.php

indexable-author-archive-presentation.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 27.8, at src/presentations/indexable-author-archive-presentation.php

174 lines 4.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\Presentations;
4
5 use Yoast\WP\SEO\Helpers\Author_Archive_Helper;
6 use Yoast\WP\SEO\Helpers\Post_Type_Helper;
7
8 /**
9 * Class Indexable_Author_Archive_Presentation.
10 *
11 * Presentation object for indexables.
12 */
13 class Indexable_Author_Archive_Presentation extends Indexable_Presentation {
14
15 use Archive_Adjacent;
16
17 /**
18 * Holds the post type helper instance.
19 *
20 * @var Post_Type_Helper
21 */
22 protected $post_type;
23
24 /**
25 * Holds the author archive helper instance.
26 *
27 * @var Author_Archive_Helper
28 */
29 protected $author_archive;
30
31 /**
32 * Indexable_Author_Archive_Presentation constructor.
33 *
34 * @codeCoverageIgnore
35 *
36 * @param Post_Type_Helper $post_type The post type helper.
37 * @param Author_Archive_Helper $author_archive The author archive helper.
38 */
39 public function __construct( Post_Type_Helper $post_type, Author_Archive_Helper $author_archive ) {
40 $this->post_type = $post_type;
41 $this->author_archive = $author_archive;
42 }
43
44 /**
45 * Generates the canonical.
46 *
47 * @return string The canonical.
48 */
49 public function generate_canonical() {
50 if ( $this->model->canonical ) {
51 return $this->model->canonical;
52 }
53
54 if ( ! $this->permalink ) {
55 return '';
56 }
57
58 $current_page = $this->pagination->get_current_archive_page_number();
59 if ( $current_page > 1 ) {
60 return $this->pagination->get_paginated_url( $this->permalink, $current_page );
61 }
62
63 return $this->permalink;
64 }
65
66 /**
67 * Generates the title.
68 *
69 * @return string The title.
70 */
71 public function generate_title() {
72 if ( $this->model->title ) {
73 return $this->model->title;
74 }
75
76 $option_titles_key = 'title-author-wpseo';
77 $title = $this->options->get( $option_titles_key );
78 if ( $title ) {
79 return $title;
80 }
81
82 return $this->options->get_title_default( $option_titles_key );
83 }
84
85 /**
86 * Generates the meta description.
87 *
88 * @return string The meta description.
89 */
90 public function generate_meta_description() {
91 if ( $this->model->description ) {
92 return $this->model->description;
93 }
94
95 $option_titles_key = 'metadesc-author-wpseo';
96 $description = $this->options->get( $option_titles_key );
97 if ( $description ) {
98 return $description;
99 }
100
101 return $this->options->get_title_default( $option_titles_key );
102 }
103
104 /**
105 * Generates the robots value.
106 *
107 * @return array The robots value.
108 */
109 public function generate_robots() {
110 $robots = $this->get_base_robots();
111
112 // Global option: "Show author archives in search results".
113 if ( $this->options->get( 'noindex-author-wpseo', false ) ) {
114 $robots['index'] = 'noindex';
115 return $this->filter_robots( $robots );
116 }
117
118 $current_author = \get_userdata( $this->model->object_id );
119
120 // Safety check. The call to `get_user_data` could return false (called in `get_queried_object`).
121 if ( $current_author === false ) {
122 $robots['index'] = 'noindex';
123 return $this->filter_robots( $robots );
124 }
125
126 $author_archive_post_types = $this->author_archive->get_author_archive_post_types();
127
128 // Global option: "Show archives for authors without posts in search results".
129 if ( $this->options->get( 'noindex-author-noposts-wpseo', false ) && $this->user->count_posts( $current_author->ID, $author_archive_post_types ) === 0 ) {
130 $robots['index'] = 'noindex';
131 return $this->filter_robots( $robots );
132 }
133
134 // User option: "Do not allow search engines to show this author's archives in search results".
135 if ( $this->user->get_meta( $current_author->ID, 'wpseo_noindex_author', true ) === 'on' ) {
136 $robots['index'] = 'noindex';
137 return $this->filter_robots( $robots );
138 }
139
140 return $this->filter_robots( $robots );
141 }
142
143 /**
144 * Generates the Open Graph type.
145 *
146 * @return string The Open Graph type.
147 */
148 public function generate_open_graph_type() {
149 return 'profile';
150 }
151
152 /**
153 * Generates the open graph images.
154 *
155 * @return array The open graph images.
156 */
157 public function generate_open_graph_images() {
158 if ( $this->context->open_graph_enabled === false ) {
159 return [];
160 }
161
162 return $this->open_graph_image_generator->generate_for_author_archive( $this->context );
163 }
164
165 /**
166 * Generates the source.
167 *
168 * @return array The source.
169 */
170 public function generate_source() {
171 return [ 'post_author' => $this->model->object_id ];
172 }
173 }
174