Skip to content

Commit

Permalink
Make sure WP is multisite before loading the Blogs endpoint.
Browse files Browse the repository at this point in the history
* This prevents a DB Error when BP Blogs component is active on a regular WP
* Update the Blogs compoment endpoint unit tests to reflect the change.

Props @renatonascalves
  • Loading branch information
imath authored Apr 18, 2024
1 parent 363c6aa commit 7297884
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bp-rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function bp_rest() {
$controller->register_routes();
}

if ( bp_is_active( 'blogs' ) ) {
if ( is_multisite() && bp_is_active( 'blogs' ) ) {
require_once dirname( __FILE__ ) . '/includes/bp-blogs/classes/class-bp-rest-blogs-endpoint.php';
$controller = new BP_REST_Blogs_Endpoint();
$controller->register_routes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ protected function prepare_links( $activity ) {
}

// Embed Blog.
if ( bp_is_active( 'blogs' ) && buddypress()->blogs->id === $activity->component && ! empty( $activity->item_id ) ) {
if ( is_multisite() && bp_is_active( 'blogs' ) && buddypress()->blogs->id === $activity->component && ! empty( $activity->item_id ) ) {
$links['blog'] = array(
'embeddable' => true,
'href' => rest_url(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ protected function prepare_links( $notification ) {
}

// Embed Blog.
if ( bp_is_active( 'blogs' ) && buddypress()->blogs->id === $notification->component_name && ! empty( $notification->item_id ) ) {
if ( is_multisite() && bp_is_active( 'blogs' ) && buddypress()->blogs->id === $notification->component_name && ! empty( $notification->item_id ) ) {
$links['blog'] = array(
'embeddable' => true,
'href' => rest_url(
Expand Down
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<testsuites>
<testsuite name="unit">
<directory prefix="test-" suffix=".php">./tests/testcases/</directory>
<exclude>tests/testcases/blogs/test-controller.php</exclude>
<exclude>tests/testcases/attachments/test-blog-avatar-controller.php</exclude>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit 7297884

Please sign in to comment.