1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
<?php
namespace Yoast\WP\SEO\Helpers;
use WP_Post; use Yoast\WP\SEO\Repositories\Indexable_Repository;
/** * A helper object for post related things. */ class Post_Helper {
/** * Holds the String_Helper instance. * * @var String_Helper */ private $string;
/** * Represents the indexables repository. * * @var Indexable_Repository */ private $repository;
/** * Post_Helper constructor. * * @param String_Helper $string The string helper. * * @codeCoverageIgnore It only sets dependencies. */ public function __construct( String_Helper $string ) { $this->string = $string; }
/** * Sets the indexable repository. Done to avoid circular dependencies. * * @param Indexable_Repository $repository The indexable repository. * * @required */ public function set_indexable_repository( Indexable_Repository $repository ) { $this->repository = $repository; }
/** * Removes all shortcode tags from the given content. * * @param string $content Content to remove all the shortcode tags from. * * @codeCoverageIgnore It only wraps a WordPress function. * * @return string Content without shortcode tags. */ public function strip_shortcodes( $content ) { return \strip_shortcodes( $content ); }
/** * Retrieves the post excerpt (without tags). * * @param int $post_id Post ID. * * @codeCoverageIgnore It only wraps another helper method. * * @return string Post excerpt (without tags). */ public function get_the_excerpt( $post_id ) { return $this->string->strip_all_tags( \get_the_excerpt( $post_id ) ); }
/** * Retrieves the post type of the current post. * * @param WP_Post $post The post. * * @codeCoverageIgnore It only wraps a WordPress function. * * @return string|false Post type on success, false on failure. */ public function get_post_type( $post = null ) { return \get_post_type( $post ); }
/** * Retrieves the post title with fallback to `No title`. * * @param int $post_id Optional. Post ID. * * @return string The post title with fallback to `No title`. */ public function get_post_title_with_fallback( $post_id = 0 ) { $post_title = \get_the_title( $post_id ); if ( $post_title ) { return $post_title; }
return \__( 'No title', 'wordpress-seo' ); }
/** * Retrieves post data given a post ID. * * @param int $post_id Post ID. * * @codeCoverageIgnore It wraps a WordPress function. * * @return WP_Post|null The post. */ public function get_post( $post_id ) { return \get_post( $post_id ); }
/** * Updates the has_public_posts field on attachments for a post_parent. * * An attachment is represented by their post parent when: * - The attachment has a post parent. * - The attachment inherits the post status. * * @param int $post_parent Post ID. * @param int $has_public_posts Whether the parent is public. * * @codeCoverageIgnore It relies too much on dependencies. * * @return bool Whether the update was successful. */ public function update_has_public_posts_on_attachments( $post_parent, $has_public_posts ) { $query = $this->repository->query() ->select( 'id' ) ->where( 'object_type', 'post' ) ->where( 'object_sub_type', 'attachment' ) ->where( 'post_status', 'inherit' ) ->where( 'post_parent', $post_parent );
if ( $has_public_posts !== null ) { $query->where_raw( '( has_public_posts IS NULL OR has_public_posts <> %s )', [ $has_public_posts ] ); } else { $query->where_not_null( 'has_public_posts' ); } $results = $query->find_array();
if ( empty( $results ) ) { return true; }
$updated = $this->repository->query() ->set( 'has_public_posts', $has_public_posts ) ->where_id_in( \wp_list_pluck( $results, 'id' ) ) ->update_many();
return $updated !== false; }
/** * Determines if the post can be indexed. * * @param int $post_id Post ID to check. * * @return bool True if the post can be indexed. */ public function is_post_indexable( $post_id ) { // Don't index auto-drafts. if ( \get_post_status( $post_id ) === 'auto-draft' ) { return false; }
// Don't index revisions of posts. if ( \wp_is_post_revision( $post_id ) ) { return false; }
// Don't index autosaves that are not caught by the auto-draft check. if ( \wp_is_post_autosave( $post_id ) ) { return false; }
return true; }
/** * Retrieves the list of public posts statuses. * * @return array The public post statuses. */ public function get_public_post_statuses() { /** * Filter: 'wpseo_public_post_statuses' - List of public post statuses. * * @api array $post_statuses Post status list, defaults to array( 'publish' ). */ return \apply_filters( 'wpseo_public_post_statuses', [ 'publish' ] ); } }
|