-
Notifications
You must be signed in to change notification settings - Fork 880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Indexable visibility columns #17757
base: trunk
Are you sure you want to change the base?
Changes from 1 commit
b3fd2cd
87c11c3
2eef6e2
b5bc8db
6c015ba
3d96968
acdf97a
e18c9ac
58d6a71
b7cfa04
c2d121e
38b552d
2fdce2f
3a18f72
5e89640
0a38f49
81e7421
1564f53
ecae28e
ea0a46e
6ccacd5
ccf7f9b
af7b219
510f9de
ed46abb
ff247f9
ca85a07
faf1180
f6a8adf
274df53
d51829e
5c1193a
661e9a3
82f8a78
66d6e4d
cf56df4
68aba31
3329a1b
e906ace
29739ee
66c9433
9eb9263
0c9ac1a
2059186
b95492e
101edcf
5d095a5
d8f754f
f613dfc
3e7e755
c24488e
4ed8b38
275c423
08c1f5f
e1c5055
6cf15bf
bad2929
148d47c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,22 +87,27 @@ public function build( $user_id, Indexable $indexable ) { | |
$indexable->is_robots_noarchive = null; | ||
$indexable->is_robots_noimageindex = null; | ||
$indexable->is_robots_nosnippet = null; | ||
$indexable->is_public = ( $indexable->is_robots_noindex ) ? false : null; | ||
$indexable->has_public_posts = $this->author_archive->author_has_public_posts( $user_id ); | ||
$indexable->blog_id = \get_current_blog_id(); | ||
|
||
$this->reset_social_images( $indexable ); | ||
$this->handle_social_images( $indexable ); | ||
|
||
$timestamps = $this->get_object_timestamps( $user_id ); | ||
$indexable->object_published_at = $timestamps->published_at; | ||
$indexable->object_last_modified = $timestamps->last_modified; | ||
$indexable = $this->set_aggregate_values( $indexable ); | ||
|
||
$indexable->version = $this->version; | ||
|
||
return $indexable; | ||
} | ||
|
||
public function set_aggregate_values( Indexable $indexable ) { | ||
$aggregates = $this->get_public_post_archive_aggregates( $indexable->object_id ); | ||
$indexable->object_published_at = $aggregates->first_published_at; | ||
$indexable->object_last_modified = max($indexable->object_last_modified, $aggregates->most_recent_last_modified); | ||
$indexable->number_of_public_posts = $aggregates->number_of_public_posts; | ||
|
||
return $indexable; | ||
} | ||
|
||
/** | ||
* Retrieves the meta data for this indexable. | ||
* | ||
|
@@ -168,24 +173,31 @@ protected function find_alternative_image( Indexable $indexable ) { | |
} | ||
|
||
/** | ||
* Returns the timestamps for a given author. | ||
* Returns public post aggregates for a given author. | ||
* | ||
* @param int $author_id The author ID. | ||
* @param int $author_id The author ID. | ||
* | ||
* @return object An object with last_modified and published_at timestamps. | ||
* @return object An object with the number of public posts, most recent last modified and first published at timestamps. | ||
*/ | ||
protected function get_object_timestamps( $author_id ) { | ||
protected function get_public_post_archive_aggregates( $author_id ) { | ||
$post_statuses = $this->post_helper->get_public_post_statuses(); | ||
$post_types = $this->author_archive->get_author_archive_post_types(); | ||
// TODO DIEDE: Protected pages krijgen _geen_ noindex. en staan gewoon in het author archive. moeten die meegeteld worden? | ||
// Private werkt wel zoals verwacht. | ||
|
||
$sql = " | ||
SELECT MAX(p.post_modified_gmt) AS last_modified, MIN(p.post_date_gmt) AS published_at | ||
SELECT | ||
COUNT(p.ID) as number_of_public_posts, | ||
MAX(p.post_modified_gmt) AS most_recent_last_modified, | ||
MIN(p.post_date_gmt) AS first_published_at | ||
FROM {$this->wpdb->posts} AS p | ||
WHERE p.post_status IN (" . implode( ', ', array_fill( 0, count( $post_statuses ), '%s' ) ) . ") | ||
AND p.post_password = '' | ||
AND p.post_author = %d | ||
AND p.post_type IN (" . implode( ', ', array_fill( 0, count( $post_types ), '%s' ) ) . ") | ||
"; | ||
|
||
$replacements = \array_merge( $post_statuses, [ $author_id ] ); | ||
$replacements = \array_merge( $post_statuses, [ $author_id ], $post_types ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a check if $post_types is array here, before merging it to the $replacement? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes! that could've been a nasty bug. I added validation higher up in the get_author_post_types so we're sure that we get an array. |
||
|
||
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- We are using wpdb prepare. | ||
return $this->wpdb->get_row( $this->wpdb->prepare( $sql, $replacements ) ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,19 +142,20 @@ public function build( $post_id, $indexable ) { | |
$indexable->author_id = $post->post_author; | ||
$indexable->post_parent = $post->post_parent; | ||
|
||
$indexable->number_of_pages = $this->get_number_of_pages_for_post( $post ); | ||
$indexable->post_status = $post->post_status; | ||
$indexable->is_protected = $post->post_password !== ''; | ||
$indexable->is_public = $this->is_public( $indexable ); | ||
$indexable->has_public_posts = $this->has_public_posts( $indexable ); | ||
$indexable->blog_id = \get_current_blog_id(); | ||
$indexable->number_of_pages = $this->get_number_of_pages_for_post( $post ); | ||
$indexable->post_status = $post->post_status; | ||
$indexable->is_protected = $post->post_password !== ''; | ||
|
||
$indexable->blog_id = \get_current_blog_id(); | ||
|
||
$indexable->schema_page_type = $this->get_meta_value( $post_id, 'schema_page_type' ); | ||
$indexable->schema_article_type = $this->get_meta_value( $post_id, 'schema_article_type' ); | ||
|
||
$indexable->object_last_modified = $post->post_modified_gmt; | ||
$indexable->object_published_at = $post->post_date_gmt; | ||
|
||
$indexable->number_of_public_posts = 0; | ||
|
||
$indexable->version = $this->version; | ||
|
||
return $indexable; | ||
|
@@ -181,31 +182,10 @@ protected function get_permalink( $post_type, $post_id ) { | |
* | ||
* @param Indexable $indexable The indexable. | ||
* | ||
* @return bool|null Whether or not the post type is public. Null if no override is set. | ||
* @return bool|null Whether the post type is public. Null if no override is set. | ||
*/ | ||
protected function is_public( $indexable ) { | ||
if ( $indexable->is_protected === true ) { | ||
return false; | ||
} | ||
|
||
if ( $indexable->is_robots_noindex === true ) { | ||
return false; | ||
} | ||
|
||
// Attachments behave differently than the other post types, since they inherit from their parent. | ||
if ( $indexable->object_sub_type === 'attachment' ) { | ||
return $this->is_public_attachment( $indexable ); | ||
} | ||
|
||
if ( ! \in_array( $indexable->post_status, $this->post_helper->get_public_post_statuses(), true ) ) { | ||
return false; | ||
} | ||
|
||
if ( $indexable->is_robots_noindex === false ) { | ||
return true; | ||
} | ||
|
||
return null; | ||
protected function is_accessible_post( $indexable ) { | ||
return is_post_type_viewable($indexable->object_sub_type) && is_post_status_viewable($indexable->post_status); | ||
} | ||
|
||
/** | ||
|
@@ -225,38 +205,6 @@ protected function is_public_attachment( $indexable ) { | |
return null; | ||
} | ||
|
||
/** | ||
* Determines the value of has_public_posts. | ||
* | ||
* @param Indexable $indexable The indexable. | ||
* | ||
* @return bool|null Whether the attachment has a public parent, can be true, false and null. Null when it is not an attachment. | ||
*/ | ||
protected function has_public_posts( $indexable ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would then remove the |
||
// Only attachments (and authors) have this value. | ||
if ( $indexable->object_sub_type !== 'attachment' ) { | ||
return null; | ||
} | ||
|
||
// The attachment should have a post parent. | ||
if ( empty( $indexable->post_parent ) ) { | ||
return false; | ||
} | ||
|
||
// The attachment should inherit the post status. | ||
if ( $indexable->post_status !== 'inherit' ) { | ||
return false; | ||
} | ||
|
||
// The post parent should be public. | ||
$post_parent_indexable = $this->indexable_repository->find_by_id_and_type( $indexable->post_parent, 'post' ); | ||
if ( $post_parent_indexable !== false ) { | ||
return $post_parent_indexable->is_public; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Converts the meta robots noindex value to the indexable value. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
idea: how about getting post ID's for an author first and iterating over those - using primary keys seems more efficient than where-ing over a set of fields.