Skip to content

Commit

Permalink
get_author: wpcom: Add a new wpcom_pre_get_active_blog_for_user filter (
Browse files Browse the repository at this point in the history
#33980)

Co-authored-by: Jeremy Herve <[email protected]>
Co-authored-by: daledupreez <[email protected]>
  • Loading branch information
3 people authored Nov 8, 2023
1 parent ceccb22 commit a3819b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

get_author: wpcom: Add a new wpcom_api_pre_get_active_blog_author filter
21 changes: 19 additions & 2 deletions projects/plugins/jetpack/class.json-api-endpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -1451,8 +1451,25 @@ public function get_author( $author, $show_email_and_ip = false ) {
$nice = $user->user_nicename;
}
if ( defined( 'IS_WPCOM' ) && IS_WPCOM && ! $is_jetpack ) {
$active_blog = get_active_blog_for_user( $id );
$site_id = $active_blog->blog_id;
$site_id = -1;

/**
* Allow customizing the blog ID returned with the author in WordPress.com REST API queries.
*
* @since $$next-version$$
*
* @module json-api
*
* @param bool|int $active_blog Blog ID, or false by default.
* @param int $id User ID.
*/
$active_blog = apply_filters( 'wpcom_api_pre_get_active_blog_author', false, $id );
if ( false === $active_blog ) {
$active_blog = get_active_blog_for_user( $id );
}
if ( ! empty( $active_blog ) ) {
$site_id = $active_blog->blog_id;
}
if ( $site_id > -1 ) {
$site_visible = (
-1 !== (int) $active_blog->public ||
Expand Down

0 comments on commit a3819b3

Please sign in to comment.