diff --git a/projects/plugins/jetpack/changelog/get_author-add-wpcom-filter b/projects/plugins/jetpack/changelog/get_author-add-wpcom-filter new file mode 100644 index 0000000000000..00dad7f6cdb47 --- /dev/null +++ b/projects/plugins/jetpack/changelog/get_author-add-wpcom-filter @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +get_author: wpcom: Add a new wpcom_api_pre_get_active_blog_author filter diff --git a/projects/plugins/jetpack/class.json-api-endpoints.php b/projects/plugins/jetpack/class.json-api-endpoints.php index da9f96abbe3ca..11bf848542e68 100644 --- a/projects/plugins/jetpack/class.json-api-endpoints.php +++ b/projects/plugins/jetpack/class.json-api-endpoints.php @@ -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 ||