Skip to:
Content

BuddyPress.org

Changeset 13343


Ignore:
Timestamp:
10/23/2022 02:21:19 AM (20 months ago)
Author:
imath
Message:

Make sure an activity is created when adding a site from network admin

When the Blogs component is active, creating a new public site from
front-end and now from the WordPress network administration is generating
a new_blog activity type.

Closes https://github.com/buddypress/buddypress/pull/28
Fixes #8756

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r13236 r13343  
    351351function bp_blogs_record_blog( $blog_id, $user_id, $no_activity = false ) {
    352352
    353     if ( empty( $user_id ) )
     353    if ( empty( $user_id ) ) {
    354354        $user_id = bp_loggedin_user_id();
     355    }
    355356
    356357    // If blog is not recordable, do not record the activity.
    357     if ( !bp_blogs_is_blog_recordable( $blog_id, $user_id ) )
     358    if ( ! bp_blogs_is_blog_recordable( $blog_id, $user_id ) ) {
    358359        return false;
     360    }
    359361
    360362    $name = get_blog_option( $blog_id, 'blogname' );
     
    382384    $recorded_blog->blog_id = $blog_id;
    383385    $recorded_blog_id       = $recorded_blog->save();
    384     $is_recorded            = !empty( $recorded_blog_id ) ? true : false;
     386    $is_recorded            = ! empty( $recorded_blog_id ) ? true : false;
    385387
    386388    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'url', $url );
     
    393395    bp_blogs_update_blogmeta( $recorded_blog->blog_id, 'comment_moderation', $moderation );
    394396
    395     $is_private = !empty( $_POST['blog_public'] ) && (int) $_POST['blog_public'] ? false : true;
    396 
    397397    /**
    398398     * Filters whether or not a new blog is public.
     
    402402     * @param bool $is_private Whether or not blog is public.
    403403     */
    404     $is_private = !apply_filters( 'bp_is_new_blog_public', !$is_private );
     404    $is_private = ! apply_filters(
     405        'bp_is_new_blog_public',
     406        (bool) get_blog_option( $blog_id, 'blog_public' )
     407    );
    405408
    406409    /**
  • trunk/tests/phpunit/testcases/activity/functions.php

    r13146 r13343  
    856856        }
    857857
    858         $b = self::factory()->blog->create();
    859         $u = self::factory()->user->create();
     858        $bp    = buddypress();
     859        $b     = self::factory()->blog->create();
     860        $u     = self::factory()->user->create();
     861        $reset = $bp->activity->track;
    860862
    861863        switch_to_blog( $b );
     864
     865        $bp->activity->track = array();
    862866
    863867        register_post_type( 'foo', array(
     
    884888
    885889        _unregister_post_type( 'foo' );
    886         bp_activity_get_actions();
    887 
    888890        restore_current_blog();
    889891
    890         $a = self::factory()->activity->create( $activity_args );
    891 
     892        $a     = self::factory()->activity->create( $activity_args );
    892893        $a_obj = new BP_Activity_Activity( $a );
    893894
     
    899900
    900901        $expected = sprintf( '%s wrote a new %s, on the site %s', $user_link, $post_link, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
     902        $bp->activity->track = $reset;
    901903
    902904        $this->assertSame( $expected, $a_obj->action );
     
    968970        }
    969971
    970         $b = self::factory()->blog->create();
    971         $u = self::factory()->user->create();
     972        $bp = buddypress();
     973        $b  = self::factory()->blog->create();
     974        $u  = self::factory()->user->create();
     975        $reset = $bp->activity->track;
    972976
    973977        switch_to_blog( $b );
     978
     979        $bp->activity->track = array();
    974980
    975981        $labels = array(
     
    10101016
    10111017        $user_link = bp_core_get_userlink( $u );
    1012         $blog_url = get_blog_option( $a_obj->item_id, 'home' );
    1013         $post_url = add_query_arg( 'p', $p, trailingslashit( $blog_url ) );
     1018        $blog_url  = get_blog_option( $a_obj->item_id, 'home' );
     1019        $post_url  = add_query_arg( 'p', $p, trailingslashit( $blog_url ) );
    10141020
    10151021        $expected = sprintf( '%1$s shared a new <a href="%2$s">bar</a>, on the site %3$s', $user_link, $post_url, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
     1022        $bp->activity->track = $reset;
    10161023
    10171024        $this->assertSame( $expected, $a_obj->action );
     
    10981105     */
    10991106    public function test_bp_activity_format_activity_action_custom_post_type_comment() {
     1107        $bp    = buddypress();
     1108        $reset = $bp->activity->track;
     1109
    11001110        if ( is_multisite() ) {
    11011111            $b = self::factory()->blog->create();
     1112
    11021113            switch_to_blog( $b );
     1114
     1115            $bp->activity->track = array();
    11031116            add_filter( 'comment_flood_filter', '__return_false' );
    11041117        } else {
     
    11601173
    11611174            $expected = sprintf( $labels['bp_activity_new_comment_ms'], $user_link, $comment_url, '<a href="' . $blog_url . '">' . get_blog_option( $a_obj->item_id, 'blogname' ) . '</a>' );
     1175
     1176            $bp->activity->track = $reset;
    11621177        } else {
    11631178            $expected = sprintf( $labels['bp_activity_new_comment'], $user_link, $comment_url );
  • trunk/tests/phpunit/testcases/blogs/functions.php

    r12606 r13343  
    886886     */
    887887    public function test_bp_blogs_comment_sync_activity_comment_for_custom_post_type() {
     888        $bp    = buddypress();
     889        $reset = $bp->activity->track;
     890
    888891        if ( is_multisite() ) {
    889892            $b = self::factory()->blog->create();
     893
    890894            switch_to_blog( $b );
     895
     896            $bp->activity->track = array();
    891897            add_filter( 'comment_flood_filter', '__return_false' );
    892898        } else {
     
    971977        if ( is_multisite() ) {
    972978            restore_current_blog();
     979
     980            $bp->activity->track = $reset;
    973981            remove_filter( 'comment_flood_filter', '__return_false' );
    974982        }
Note: See TracChangeset for help on using the changeset viewer.