Skip to:
Content

BuddyPress.org

Ticket #7126: 7126.patch

File 7126.patch, 32.3 KB (added by imath, 7 years ago)
  • src/bp-activity/bp-activity-functions.php

    diff --git src/bp-activity/bp-activity-functions.php src/bp-activity/bp-activity-functions.php
    index 3c8abff..d272dc4 100644
    function bp_activity_do_heartbeat() { 
    35833583
    35843584        return $retval;
    35853585}
     3586/**
     3587 * Get the arguments for the public message button.
     3588 *
     3589 * @since ?
     3590 *
     3591 * @param array|string $args {
     3592 *    All arguments are optional. See {@link BP_Button} for complete
     3593 *    descriptions.
     3594 *    @type string $id                Default: 'public_message'.
     3595 *    @type string $component         Default: 'activity'.
     3596 *    @type bool   $must_be_logged_in Default: true.
     3597 *    @type bool   $block_self        Default: true.
     3598 *    @type string $wrapper_id        Default: 'post-mention'.
     3599 *    @type string $link_href         Default: the public message link for
     3600 *                                    the current member in the loop.
     3601 *    @type string $link_title        Default: 'Send a public message on your
     3602 *                                    activity stream.'.
     3603 *    @type string $link_text         Default: 'Public Message'.
     3604 *    @type string $link_class        Default: 'activity-button mention'.
     3605 * }
     3606 * @return array The arguments for the public message button.
     3607 */
     3608function bp_activity_get_public_message_button_args( $args = '' ) {
     3609        /**
     3610         * Filters the public message button HTML.
     3611         *
     3612         * @since 1.2.10
     3613         *
     3614         * @param array $value Array of arguments for the public message button HTML.
     3615         */
     3616        return apply_filters( 'bp_get_send_public_message_button', bp_parse_args( $args, array(
     3617                'id'                => 'public_message',
     3618                'component'         => 'activity',
     3619                'must_be_logged_in' => true,
     3620                'block_self'        => true,
     3621                'wrapper_id'        => 'post-mention',
     3622                'link_href'         => bp_get_send_public_message_link(),
     3623                'link_title'        => __( 'Send a public message on your activity stream.', 'buddypress' ),
     3624                'link_text'         => __( 'Public Message', 'buddypress' ),
     3625                'link_class'        => 'activity-button mention'
     3626        ) ) );
     3627}
  • src/bp-activity/bp-activity-template.php

    diff --git src/bp-activity/bp-activity-template.php src/bp-activity/bp-activity-template.php
    index 810b76e..7fb3c34 100644
    function bp_mentioned_user_display_name( $user_id_or_username = false ) { 
    31453145 *
    31463146 * @since 1.2.0
    31473147 *
    3148  * @see bp_get_send_public_message_button() for description of parameters.
     3148 * @see bp_activity_get_public_message_button_args() for description of parameters.
    31493149 *
    3150  * @param array|string $args See {@link bp_get_send_public_message_button()}.
     3150 * @param array|string $args See {@link bp_activity_get_public_message_button_args()}.
    31513151 */
    31523152function bp_send_public_message_button( $args = '' ) {
    31533153        echo bp_get_send_public_message_button( $args );
    function bp_send_public_message_button( $args = '' ) { 
    31583158         *
    31593159         * @since 1.2.0
    31603160         *
    3161          *
    3162          * @param array|string $args {
    3163          *     All arguments are optional. See {@link BP_Button} for complete
    3164          *     descriptions.
    3165          *     @type string $id                Default: 'public_message'.
    3166          *     @type string $component         Default: 'activity'.
    3167          *     @type bool   $must_be_logged_in Default: true.
    3168          *     @type bool   $block_self        Default: true.
    3169          *     @type string $wrapper_id        Default: 'post-mention'.
    3170          *     @type string $link_href         Default: the public message link for
    3171          *                                     the current member in the loop.
    3172          *     @type string $link_title        Default: 'Send a public message on your
    3173          *                                     activity stream.'.
    3174          *     @type string $link_text         Default: 'Public Message'.
    3175          *     @type string $link_class        Default: 'activity-button mention'.
    3176          * }
     3161         * @param array|string $args See {@link bp_activity_get_public_message_button_args()}.
    31773162         * @return string The button for sending a public message.
    31783163         */
    31793164        function bp_get_send_public_message_button( $args = '' ) {
    31803165
    3181                 $r = bp_parse_args( $args, array(
    3182                         'id'                => 'public_message',
    3183                         'component'         => 'activity',
    3184                         'must_be_logged_in' => true,
    3185                         'block_self'        => true,
    3186                         'wrapper_id'        => 'post-mention',
    3187                         'link_href'         => bp_get_send_public_message_link(),
    3188                         'link_title'        => __( 'Send a public message on your activity stream.', 'buddypress' ),
    3189                         'link_text'         => __( 'Public Message', 'buddypress' ),
    3190                         'link_class'        => 'activity-button mention'
    3191                 ) );
     3166                $button = bp_activity_get_public_message_button_args( $args );
    31923167
    3193                 /**
    3194                  * Filters the public message button HTML.
    3195                  *
    3196                  * @since 1.2.10
    3197                  *
    3198                  * @param array $r Array of arguments for the public message button HTML.
    3199                  */
    3200                 return bp_get_button( apply_filters( 'bp_get_send_public_message_button', $r ) );
     3168                if ( ! $button ) {
     3169                        return false;
     3170                }
     3171
     3172                return bp_get_button( $button );
    32013173        }
    32023174
    32033175/**
  • src/bp-blogs/bp-blogs-functions.php

    diff --git src/bp-blogs/bp-blogs-functions.php src/bp-blogs/bp-blogs-functions.php
    index 595c305..abf0111 100644
    function bp_blogs_restore_data( $user_id = 0 ) { 
    13491349        }
    13501350}
    13511351add_action( 'bp_make_ham_user', 'bp_blogs_restore_data', 10, 1 );
     1352
     1353/**
     1354 * Get the arguments for the create a site button.
     1355 *
     1356 * @since ?
     1357 *
     1358 * @return array Array of arguments to be used for the Create a Site button.
     1359 */
     1360function bp_blogs_get_create_button_args() {
     1361        /**
     1362         * Filters the Create a Site button.
     1363         *
     1364         * @since 2.0.0
     1365         *
     1366         * @param array $value Array of arguments to be used for the Create a Site button.
     1367         */
     1368        return apply_filters( 'bp_get_blog_create_button', array(
     1369                'id'         => 'create_blog',
     1370                'component'  => 'blogs',
     1371                'link_text'  => __( 'Create a Site', 'buddypress' ),
     1372                'link_title' => __( 'Create a Site', 'buddypress' ),
     1373                'link_class' => 'blog-create no-ajax',
     1374                'link_href'  => trailingslashit( bp_get_blogs_directory_permalink() . 'create' ),
     1375                'wrapper'    => false,
     1376                'block_self' => false,
     1377        ) );
     1378}
     1379
     1380/**
     1381 * Return the arguments of the button for visiting a blog in a loop.
     1382 *
     1383 * @see BP_Button for a complete description of arguments and return
     1384 *      value.
     1385 *
     1386 * @since ?
     1387 *
     1388 * @param array|string $args {
     1389 *     Arguments are listed below, with their default values. For a
     1390 *     complete description of arguments, see {@link BP_Button}.
     1391 *     @type string $id                Default: 'visit_blog'.
     1392 *     @type string $component         Default: 'blogs'.
     1393 *     @type bool   $must_be_logged_in Default: false.
     1394 *     @type bool   $block_self        Default: false.
     1395 *     @type string $wrapper_class     Default: 'blog-button visit'.
     1396 *     @type string $link_href         Permalink of the current blog in the loop.
     1397 *     @type string $link_class        Default: 'blog-button visit'.
     1398 *     @type string $link_text         Default: 'Visit Site'.
     1399 *     @type string $link_title        Default: 'Visit Site'.
     1400 * }
     1401 * @return array Thhe arguments of the button for visiting a blog in a loop.
     1402 */
     1403function bp_blogs_get_visit_button_args( $args = '' ) {
     1404        /**
     1405         * Filters the button for visiting a blog in a loop.
     1406         *
     1407         * @since 1.2.10
     1408         *
     1409         * @param array $value Array of arguments to be used for the button to visit a blog.
     1410         */
     1411        return apply_filters( 'bp_get_blogs_visit_blog_button', wp_parse_args( $args, array(
     1412                'id'                => 'visit_blog',
     1413                'component'         => 'blogs',
     1414                'must_be_logged_in' => false,
     1415                'block_self'        => false,
     1416                'wrapper_class'     => 'blog-button visit',
     1417                'link_href'         => bp_get_blog_permalink(),
     1418                'link_class'        => 'blog-button visit',
     1419                'link_text'         => __( 'Visit Site', 'buddypress' ),
     1420                'link_title'        => __( 'Visit Site', 'buddypress' ),
     1421        ) ) );
     1422}
  • src/bp-blogs/bp-blogs-template.php

    diff --git src/bp-blogs/bp-blogs-template.php src/bp-blogs/bp-blogs-template.php
    index 312056f..57e867f 100644
    function bp_blog_create_button() { 
    12761276                        return false;
    12771277                }
    12781278
    1279                 $button_args = array(
    1280                         'id'         => 'create_blog',
    1281                         'component'  => 'blogs',
    1282                         'link_text'  => __( 'Create a Site', 'buddypress' ),
    1283                         'link_title' => __( 'Create a Site', 'buddypress' ),
    1284                         'link_class' => 'blog-create no-ajax',
    1285                         'link_href'  => trailingslashit( bp_get_blogs_directory_permalink() . 'create' ),
    1286                         'wrapper'    => false,
    1287                         'block_self' => false,
    1288                 );
     1279                $button_args = bp_blogs_get_create_button_args();
    12891280
    1290                 /**
    1291                  * Filters the Create a Site button.
    1292                  *
    1293                  * @since 2.0.0
    1294                  *
    1295                  * @param array $button_args Array of arguments to be used for the Create a Site button.
    1296                  */
    1297                 return bp_get_button( apply_filters( 'bp_get_blog_create_button', $button_args ) );
     1281                if ( ! $button_args ) {
     1282                        return false;
     1283                }
     1284
     1285                return bp_get_button( $button_args );
    12981286        }
    12991287
    13001288/**
    add_action( 'bp_blogs_directory_blog_types', 'bp_blog_backcompat_create_nav_item 
    13531341/**
    13541342 * Output button for visiting a blog in a loop.
    13551343 *
    1356  * @see bp_get_blogs_visit_blog_button() for description of arguments.
     1344 * @see bp_blogs_get_visit_button_args() for description of arguments.
    13571345 *
    1358  * @param array|string $args See {@link bp_get_blogs_visit_blog_button()}.
     1346 * @param array|string $args See {@link bp_blogs_get_visit_button_args()}.
    13591347 */
    13601348function bp_blogs_visit_blog_button( $args = '' ) {
    13611349        echo bp_get_blogs_visit_blog_button( $args );
    function bp_blogs_visit_blog_button( $args = '' ) { 
    13661354         * @see BP_Button for a complete description of arguments and return
    13671355         *      value.
    13681356         *
    1369          * @param array|string $args {
    1370          *     Arguments are listed below, with their default values. For a
    1371          *     complete description of arguments, see {@link BP_Button}.
    1372          *     @type string $id                Default: 'visit_blog'.
    1373          *     @type string $component         Default: 'blogs'.
    1374          *     @type bool   $must_be_logged_in Default: false.
    1375          *     @type bool   $block_self        Default: false.
    1376          *     @type string $wrapper_class     Default: 'blog-button visit'.
    1377          *     @type string $link_href         Permalink of the current blog in the loop.
    1378          *     @type string $link_class        Default: 'blog-button visit'.
    1379          *     @type string $link_text         Default: 'Visit Site'.
    1380          *     @type string $link_title        Default: 'Visit Site'.
    1381          * }
     1357         * @param array|string $args See {@link bp_blogs_get_visit_button_args()}
    13821358         * @return string The HTML for the Visit button.
    13831359         */
    13841360        function bp_get_blogs_visit_blog_button( $args = '' ) {
    1385                 $defaults = array(
    1386                         'id'                => 'visit_blog',
    1387                         'component'         => 'blogs',
    1388                         'must_be_logged_in' => false,
    1389                         'block_self'        => false,
    1390                         'wrapper_class'     => 'blog-button visit',
    1391                         'link_href'         => bp_get_blog_permalink(),
    1392                         'link_class'        => 'blog-button visit',
    1393                         'link_text'         => __( 'Visit Site', 'buddypress' ),
    1394                         'link_title'        => __( 'Visit Site', 'buddypress' ),
    1395                 );
    1396 
    1397                 $button = wp_parse_args( $args, $defaults );
     1361                $button = bp_blogs_get_visit_button_args( $args );
    13981362
    1399                 /**
    1400                  * Filters the button for visiting a blog in a loop.
    1401                  *
    1402                  * @since 1.2.10
    1403                  *
    1404                  * @param array $button Array of arguments to be used for the button to visit a blog.
    1405                  */
    1406                 return bp_get_button( apply_filters( 'bp_get_blogs_visit_blog_button', $button ) );
     1363                if ( ! $button ) {
     1364                        return false;
     1365                }
     1366
     1367                return bp_get_button( $button );
    14071368        }
    14081369
    14091370/** Stats **********************************************************************/
  • src/bp-friends/bp-friends-functions.php

    diff --git src/bp-friends/bp-friends-functions.php src/bp-friends/bp-friends-functions.php
    index d9de4cb..95013c1 100644
    function bp_friends_prime_mentions_results() { 
    795795        ) );
    796796}
    797797add_action( 'bp_activity_mentions_prime_results', 'bp_friends_prime_mentions_results' );
     798
     799/**
     800 * Get the arguments for the add friend button
     801 *
     802 * @since ?
     803 *
     804 * @param  int  $potential_friend_id ID of the user to whom the button applies.
     805 *                                   Default: value of {@link bp_get_potential_friend_id()}.
     806 * @param  bool $friend_status       Not currently used.
     807 * @return array The button arguments.
     808 */
     809function bp_friends_get_add_friend_button_args( $potential_friend_id = 0, $friend_status = false ) {
     810        $button = array();
     811
     812        if ( empty( $potential_friend_id ) ) {
     813                $potential_friend_id = bp_get_potential_friend_id( $potential_friend_id );
     814        }
     815
     816        $is_friend = bp_is_friend( $potential_friend_id );
     817
     818        if ( empty( $is_friend ) ) {
     819                return $button;
     820        }
     821
     822        switch ( $is_friend ) {
     823                case 'pending' :
     824                        $button = array(
     825                                'id'                => 'pending',
     826                                'component'         => 'friends',
     827                                'must_be_logged_in' => true,
     828                                'block_self'        => true,
     829                                'wrapper_class'     => 'friendship-button pending_friend',
     830                                'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
     831                                'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $potential_friend_id . '/', 'friends_withdraw_friendship' ),
     832                                'link_text'         => __( 'Cancel Friendship Request', 'buddypress' ),
     833                                'link_title'        => __( 'Cancel Friendship Requested', 'buddypress' ),
     834                                'link_id'           => 'friend-' . $potential_friend_id,
     835                                'link_rel'          => 'remove',
     836                                'link_class'        => 'friendship-button pending_friend requested'
     837                        );
     838                        break;
     839
     840                case 'awaiting_response' :
     841                        $button = array(
     842                                'id'                => 'awaiting_response',
     843                                'component'         => 'friends',
     844                                'must_be_logged_in' => true,
     845                                'block_self'        => true,
     846                                'wrapper_class'     => 'friendship-button awaiting_response_friend',
     847                                'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
     848                                'link_href'         => bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/',
     849                                'link_text'         => __( 'Friendship Requested', 'buddypress' ),
     850                                'link_title'        => __( 'Friendship Requested', 'buddypress' ),
     851                                'link_id'           => 'friend-' . $potential_friend_id,
     852                                'link_rel'          => 'remove',
     853                                'link_class'        => 'friendship-button awaiting_response_friend requested'
     854                        );
     855                        break;
     856
     857                case 'is_friend' :
     858                        $button = array(
     859                                'id'                => 'is_friend',
     860                                'component'         => 'friends',
     861                                'must_be_logged_in' => true,
     862                                'block_self'        => false,
     863                                'wrapper_class'     => 'friendship-button is_friend',
     864                                'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
     865                                'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend' ),
     866                                'link_text'         => __( 'Cancel Friendship', 'buddypress' ),
     867                                'link_title'        => __( 'Cancel Friendship', 'buddypress' ),
     868                                'link_id'           => 'friend-' . $potential_friend_id,
     869                                'link_rel'          => 'remove',
     870                                'link_class'        => 'friendship-button is_friend remove'
     871                        );
     872                        break;
     873
     874                default:
     875                        $button = array(
     876                                'id'                => 'not_friends',
     877                                'component'         => 'friends',
     878                                'must_be_logged_in' => true,
     879                                'block_self'        => true,
     880                                'wrapper_class'     => 'friendship-button not_friends',
     881                                'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
     882                                'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' ),
     883                                'link_text'         => __( 'Add Friend', 'buddypress' ),
     884                                'link_title'        => __( 'Add Friend', 'buddypress' ),
     885                                'link_id'           => 'friend-' . $potential_friend_id,
     886                                'link_rel'          => 'add',
     887                                'link_class'        => 'friendship-button not_friends add'
     888                        );
     889                        break;
     890        }
     891
     892        /**
     893         * Filters the HTML for the add friend button.
     894         *
     895         * @since 1.1.0
     896         *
     897         * @param string $button HTML markup for add friend button.
     898         */
     899        return apply_filters( 'bp_get_add_friend_button', $button );
     900}
  • src/bp-friends/bp-friends-template.php

    diff --git src/bp-friends/bp-friends-template.php src/bp-friends/bp-friends-template.php
    index d3cc442..abffa4f 100644
    function bp_add_friend_button( $potential_friend_id = 0, $friend_status = false 
    349349         * @return string HTML for the Add Friend button.
    350350         */
    351351        function bp_get_add_friend_button( $potential_friend_id = 0, $friend_status = false ) {
     352                $button = bp_friends_get_add_friend_button_args( $potential_friend_id, $friend_status );
    352353
    353                 if ( empty( $potential_friend_id ) )
    354                         $potential_friend_id = bp_get_potential_friend_id( $potential_friend_id );
    355 
    356                 $is_friend = bp_is_friend( $potential_friend_id );
    357 
    358                 if ( empty( $is_friend ) )
     354                if ( ! $button ) {
    359355                        return false;
    360 
    361                 switch ( $is_friend ) {
    362                         case 'pending' :
    363                                 $button = array(
    364                                         'id'                => 'pending',
    365                                         'component'         => 'friends',
    366                                         'must_be_logged_in' => true,
    367                                         'block_self'        => true,
    368                                         'wrapper_class'     => 'friendship-button pending_friend',
    369                                         'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
    370                                         'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/cancel/' . $potential_friend_id . '/', 'friends_withdraw_friendship' ),
    371                                         'link_text'         => __( 'Cancel Friendship Request', 'buddypress' ),
    372                                         'link_title'        => __( 'Cancel Friendship Requested', 'buddypress' ),
    373                                         'link_id'           => 'friend-' . $potential_friend_id,
    374                                         'link_rel'          => 'remove',
    375                                         'link_class'        => 'friendship-button pending_friend requested'
    376                                 );
    377                                 break;
    378 
    379                         case 'awaiting_response' :
    380                                 $button = array(
    381                                         'id'                => 'awaiting_response',
    382                                         'component'         => 'friends',
    383                                         'must_be_logged_in' => true,
    384                                         'block_self'        => true,
    385                                         'wrapper_class'     => 'friendship-button awaiting_response_friend',
    386                                         'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
    387                                         'link_href'         => bp_loggedin_user_domain() . bp_get_friends_slug() . '/requests/',
    388                                         'link_text'         => __( 'Friendship Requested', 'buddypress' ),
    389                                         'link_title'        => __( 'Friendship Requested', 'buddypress' ),
    390                                         'link_id'           => 'friend-' . $potential_friend_id,
    391                                         'link_rel'          => 'remove',
    392                                         'link_class'        => 'friendship-button awaiting_response_friend requested'
    393                                 );
    394                                 break;
    395 
    396                         case 'is_friend' :
    397                                 $button = array(
    398                                         'id'                => 'is_friend',
    399                                         'component'         => 'friends',
    400                                         'must_be_logged_in' => true,
    401                                         'block_self'        => false,
    402                                         'wrapper_class'     => 'friendship-button is_friend',
    403                                         'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
    404                                         'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/remove-friend/' . $potential_friend_id . '/', 'friends_remove_friend' ),
    405                                         'link_text'         => __( 'Cancel Friendship', 'buddypress' ),
    406                                         'link_title'        => __( 'Cancel Friendship', 'buddypress' ),
    407                                         'link_id'           => 'friend-' . $potential_friend_id,
    408                                         'link_rel'          => 'remove',
    409                                         'link_class'        => 'friendship-button is_friend remove'
    410                                 );
    411                                 break;
    412 
    413                         default:
    414                                 $button = array(
    415                                         'id'                => 'not_friends',
    416                                         'component'         => 'friends',
    417                                         'must_be_logged_in' => true,
    418                                         'block_self'        => true,
    419                                         'wrapper_class'     => 'friendship-button not_friends',
    420                                         'wrapper_id'        => 'friendship-button-' . $potential_friend_id,
    421                                         'link_href'         => wp_nonce_url( bp_loggedin_user_domain() . bp_get_friends_slug() . '/add-friend/' . $potential_friend_id . '/', 'friends_add_friend' ),
    422                                         'link_text'         => __( 'Add Friend', 'buddypress' ),
    423                                         'link_title'        => __( 'Add Friend', 'buddypress' ),
    424                                         'link_id'           => 'friend-' . $potential_friend_id,
    425                                         'link_rel'          => 'add',
    426                                         'link_class'        => 'friendship-button not_friends add'
    427                                 );
    428                                 break;
    429356                }
    430357
    431                 /**
    432                  * Filters the HTML for the add friend button.
    433                  *
    434                  * @since 1.1.0
    435                  *
    436                  * @param string $button HTML markup for add friend button.
    437                  */
    438                 return bp_get_button( apply_filters( 'bp_get_add_friend_button', $button ) );
     358                return bp_get_button( $button );
    439359        }
    440360
    441361/**
  • src/bp-groups/bp-groups-functions.php

    diff --git src/bp-groups/bp-groups-functions.php src/bp-groups/bp-groups-functions.php
    index cb0753e..78f40c2 100644
    function bp_remove_group_type_on_group_delete( $group_id = 0 ) { 
    23932393        bp_groups_set_group_type( $group_id, '' );
    23942394}
    23952395add_action( 'groups_delete_group', 'bp_remove_group_type_on_group_delete' );
     2396
     2397/**
     2398 * Get the arguments for the Join button group
     2399 *
     2400 * @since ?
     2401 *
     2402 * @param BP_Groups_Group $group The group object.
     2403 * @return Array The arguments for the Join button group
     2404 */
     2405function bp_groups_get_group_join_button_args( $group = null ) {
     2406        $button = array();
     2407
     2408        if ( empty( $group->id ) ) {
     2409                return $button;
     2410        }
     2411
     2412        // Don't show button if not logged in or previously banned.
     2413        if ( ! is_user_logged_in() || bp_group_is_user_banned( $group ) ) {
     2414                return $button;
     2415        }
     2416
     2417        // Group creation was not completed or status is unknown.
     2418        if ( empty( $group->status ) ) {
     2419                return $button;
     2420        }
     2421
     2422        // Already a member.
     2423        if ( ! empty( $group->is_member ) ) {
     2424
     2425                // Stop sole admins from abandoning their group.
     2426                $group_admins = groups_get_group_admins( $group->id );
     2427                if ( ( 1 == count( $group_admins ) ) && ( bp_loggedin_user_id() === (int) $group_admins[0]->user_id ) ) {
     2428                        return false;
     2429                }
     2430
     2431                // Setup button attributes.
     2432                $button = array(
     2433                        'id'                => 'leave_group',
     2434                        'component'         => 'groups',
     2435                        'must_be_logged_in' => true,
     2436                        'block_self'        => false,
     2437                        'wrapper_class'     => 'group-button ' . $group->status,
     2438                        'wrapper_id'        => 'groupbutton-' . $group->id,
     2439                        'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ),
     2440                        'link_text'         => __( 'Leave Group', 'buddypress' ),
     2441                        'link_title'        => __( 'Leave Group', 'buddypress' ),
     2442                        'link_class'        => 'group-button leave-group',
     2443                );
     2444
     2445        // Not a member.
     2446        } else {
     2447
     2448                // Show different buttons based on group status.
     2449                switch ( $group->status ) {
     2450                        case 'hidden' :
     2451                                return false;
     2452
     2453                        case 'public':
     2454                                $button = array(
     2455                                        'id'                => 'join_group',
     2456                                        'component'         => 'groups',
     2457                                        'must_be_logged_in' => true,
     2458                                        'block_self'        => false,
     2459                                        'wrapper_class'     => 'group-button ' . $group->status,
     2460                                        'wrapper_id'        => 'groupbutton-' . $group->id,
     2461                                        'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ),
     2462                                        'link_text'         => __( 'Join Group', 'buddypress' ),
     2463                                        'link_title'        => __( 'Join Group', 'buddypress' ),
     2464                                        'link_class'        => 'group-button join-group',
     2465                                );
     2466                                break;
     2467
     2468                        case 'private' :
     2469
     2470                                // Member has outstanding invitation -
     2471                                // show an "Accept Invitation" button.
     2472                                if ( $group->is_invited ) {
     2473                                        $button = array(
     2474                                                'id'                => 'accept_invite',
     2475                                                'component'         => 'groups',
     2476                                                'must_be_logged_in' => true,
     2477                                                'block_self'        => false,
     2478                                                'wrapper_class'     => 'group-button ' . $group->status,
     2479                                                'wrapper_id'        => 'groupbutton-' . $group->id,
     2480                                                'link_href'         => add_query_arg( 'redirect_to', bp_get_group_permalink( $group ), bp_get_group_accept_invite_link( $group ) ),
     2481                                                'link_text'         => __( 'Accept Invitation', 'buddypress' ),
     2482                                                'link_title'        => __( 'Accept Invitation', 'buddypress' ),
     2483                                                'link_class'        => 'group-button accept-invite',
     2484                                        );
     2485
     2486                                // Member has requested membership but request is pending -
     2487                                // show a "Request Sent" button.
     2488                                } elseif ( $group->is_pending ) {
     2489                                        $button = array(
     2490                                                'id'                => 'membership_requested',
     2491                                                'component'         => 'groups',
     2492                                                'must_be_logged_in' => true,
     2493                                                'block_self'        => false,
     2494                                                'wrapper_class'     => 'group-button pending ' . $group->status,
     2495                                                'wrapper_id'        => 'groupbutton-' . $group->id,
     2496                                                'link_href'         => bp_get_group_permalink( $group ),
     2497                                                'link_text'         => __( 'Request Sent', 'buddypress' ),
     2498                                                'link_title'        => __( 'Request Sent', 'buddypress' ),
     2499                                                'link_class'        => 'group-button pending membership-requested',
     2500                                        );
     2501
     2502                                // Member has not requested membership yet -
     2503                                // show a "Request Membership" button.
     2504                                } else {
     2505                                        $button = array(
     2506                                                'id'                => 'request_membership',
     2507                                                'component'         => 'groups',
     2508                                                'must_be_logged_in' => true,
     2509                                                'block_self'        => false,
     2510                                                'wrapper_class'     => 'group-button ' . $group->status,
     2511                                                'wrapper_id'        => 'groupbutton-' . $group->id,
     2512                                                'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ),
     2513                                                'link_text'         => __( 'Request Membership', 'buddypress' ),
     2514                                                'link_title'        => __( 'Request Membership', 'buddypress' ),
     2515                                                'link_class'        => 'group-button request-membership',
     2516                                        );
     2517                                }
     2518
     2519                                break;
     2520                }
     2521        }
     2522
     2523        /**
     2524         * Filters the arguments of the button for joining a group.
     2525         *
     2526         * @since 1.2.6
     2527         * @since 2.4.0 Added $group parameter to filter args.
     2528         *
     2529         * @param array  $button The arguments for the button.
     2530         * @param object $group BuddyPress group object
     2531         */
     2532        return apply_filters( 'bp_get_group_join_button', $button, $group );
     2533}
     2534
     2535/**
     2536 * Get the arguments for the Create a group button.
     2537 *
     2538 * @since ?
     2539 *
     2540 * @return Array The arguments for the Create a group button.
     2541 */
     2542function bp_groups_get_create_group_button_args() {
     2543        /**
     2544         * Filters the arguments of the button for creating a group.
     2545         *
     2546         * @since 2.0.0
     2547         *
     2548         * @param array $value The arguments of the button for creating a group.
     2549         */
     2550        return apply_filters( 'bp_get_group_create_button', array(
     2551                'id'         => 'create_group',
     2552                'component'  => 'groups',
     2553                'link_text'  => __( 'Create a Group', 'buddypress' ),
     2554                'link_title' => __( 'Create a Group', 'buddypress' ),
     2555                'link_class' => 'group-create no-ajax',
     2556                'link_href'  => trailingslashit( bp_get_groups_directory_permalink() . 'create' ),
     2557                'wrapper'    => false,
     2558                'block_self' => false,
     2559        ) );
     2560}
  • src/bp-groups/bp-groups-template.php

    diff --git src/bp-groups/bp-groups-template.php src/bp-groups/bp-groups-template.php
    index be28ded..898d88b 100644
    function bp_group_join_button( $group = false ) { 
    32033203                        $group =& $groups_template->group;
    32043204                }
    32053205
    3206                 // Don't show button if not logged in or previously banned.
    3207                 if ( ! is_user_logged_in() || bp_group_is_user_banned( $group ) ) {
    3208                         return false;
    3209                 }
     3206                $button_args = bp_groups_get_group_join_button_args( $group );
    32103207
    3211                 // Group creation was not completed or status is unknown.
    3212                 if ( empty( $group->status ) ) {
     3208                if ( ! $button_args ) {
    32133209                        return false;
    32143210                }
    32153211
    3216                 // Already a member.
    3217                 if ( ! empty( $group->is_member ) ) {
    3218 
    3219                         // Stop sole admins from abandoning their group.
    3220                         $group_admins = groups_get_group_admins( $group->id );
    3221                         if ( ( 1 == count( $group_admins ) ) && ( bp_loggedin_user_id() === (int) $group_admins[0]->user_id ) ) {
    3222                                 return false;
    3223                         }
    3224 
    3225                         // Setup button attributes.
    3226                         $button = array(
    3227                                 'id'                => 'leave_group',
    3228                                 'component'         => 'groups',
    3229                                 'must_be_logged_in' => true,
    3230                                 'block_self'        => false,
    3231                                 'wrapper_class'     => 'group-button ' . $group->status,
    3232                                 'wrapper_id'        => 'groupbutton-' . $group->id,
    3233                                 'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'leave-group', 'groups_leave_group' ),
    3234                                 'link_text'         => __( 'Leave Group', 'buddypress' ),
    3235                                 'link_title'        => __( 'Leave Group', 'buddypress' ),
    3236                                 'link_class'        => 'group-button leave-group',
    3237                         );
    3238 
    3239                 // Not a member.
    3240                 } else {
    3241 
    3242                         // Show different buttons based on group status.
    3243                         switch ( $group->status ) {
    3244                                 case 'hidden' :
    3245                                         return false;
    3246 
    3247                                 case 'public':
    3248                                         $button = array(
    3249                                                 'id'                => 'join_group',
    3250                                                 'component'         => 'groups',
    3251                                                 'must_be_logged_in' => true,
    3252                                                 'block_self'        => false,
    3253                                                 'wrapper_class'     => 'group-button ' . $group->status,
    3254                                                 'wrapper_id'        => 'groupbutton-' . $group->id,
    3255                                                 'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'join', 'groups_join_group' ),
    3256                                                 'link_text'         => __( 'Join Group', 'buddypress' ),
    3257                                                 'link_title'        => __( 'Join Group', 'buddypress' ),
    3258                                                 'link_class'        => 'group-button join-group',
    3259                                         );
    3260                                         break;
    3261 
    3262                                 case 'private' :
    3263 
    3264                                         // Member has outstanding invitation -
    3265                                         // show an "Accept Invitation" button.
    3266                                         if ( $group->is_invited ) {
    3267                                                 $button = array(
    3268                                                         'id'                => 'accept_invite',
    3269                                                         'component'         => 'groups',
    3270                                                         'must_be_logged_in' => true,
    3271                                                         'block_self'        => false,
    3272                                                         'wrapper_class'     => 'group-button ' . $group->status,
    3273                                                         'wrapper_id'        => 'groupbutton-' . $group->id,
    3274                                                         'link_href'         => add_query_arg( 'redirect_to', bp_get_group_permalink( $group ), bp_get_group_accept_invite_link( $group ) ),
    3275                                                         'link_text'         => __( 'Accept Invitation', 'buddypress' ),
    3276                                                         'link_title'        => __( 'Accept Invitation', 'buddypress' ),
    3277                                                         'link_class'        => 'group-button accept-invite',
    3278                                                 );
    3279 
    3280                                         // Member has requested membership but request is pending -
    3281                                         // show a "Request Sent" button.
    3282                                         } elseif ( $group->is_pending ) {
    3283                                                 $button = array(
    3284                                                         'id'                => 'membership_requested',
    3285                                                         'component'         => 'groups',
    3286                                                         'must_be_logged_in' => true,
    3287                                                         'block_self'        => false,
    3288                                                         'wrapper_class'     => 'group-button pending ' . $group->status,
    3289                                                         'wrapper_id'        => 'groupbutton-' . $group->id,
    3290                                                         'link_href'         => bp_get_group_permalink( $group ),
    3291                                                         'link_text'         => __( 'Request Sent', 'buddypress' ),
    3292                                                         'link_title'        => __( 'Request Sent', 'buddypress' ),
    3293                                                         'link_class'        => 'group-button pending membership-requested',
    3294                                                 );
    3295 
    3296                                         // Member has not requested membership yet -
    3297                                         // show a "Request Membership" button.
    3298                                         } else {
    3299                                                 $button = array(
    3300                                                         'id'                => 'request_membership',
    3301                                                         'component'         => 'groups',
    3302                                                         'must_be_logged_in' => true,
    3303                                                         'block_self'        => false,
    3304                                                         'wrapper_class'     => 'group-button ' . $group->status,
    3305                                                         'wrapper_id'        => 'groupbutton-' . $group->id,
    3306                                                         'link_href'         => wp_nonce_url( bp_get_group_permalink( $group ) . 'request-membership', 'groups_request_membership' ),
    3307                                                         'link_text'         => __( 'Request Membership', 'buddypress' ),
    3308                                                         'link_title'        => __( 'Request Membership', 'buddypress' ),
    3309                                                         'link_class'        => 'group-button request-membership',
    3310                                                 );
    3311                                         }
    3312 
    3313                                         break;
    3314                         }
    3315                 }
    3316 
    3317                 /**
    3318                  * Filters the HTML button for joining a group.
    3319                  *
    3320                  * @since 1.2.6
    3321                  * @since 2.4.0 Added $group parameter to filter args.
    3322                  *
    3323                  * @param string $button HTML button for joining a group.
    3324                  * @param object $group BuddyPress group object
    3325                  */
    3326                 return bp_get_button( apply_filters( 'bp_get_group_join_button', $button, $group ) );
     3212                return bp_get_button( $button_args );
    33273213        }
    33283214
    33293215/**
    function bp_group_create_button() { 
    33503236                        return false;
    33513237                }
    33523238
    3353                 $button_args = array(
    3354                         'id'         => 'create_group',
    3355                         'component'  => 'groups',
    3356                         'link_text'  => __( 'Create a Group', 'buddypress' ),
    3357                         'link_title' => __( 'Create a Group', 'buddypress' ),
    3358                         'link_class' => 'group-create no-ajax',
    3359                         'link_href'  => trailingslashit( bp_get_groups_directory_permalink() . 'create' ),
    3360                         'wrapper'    => false,
    3361                         'block_self' => false,
    3362                 );
     3239                $button_args = bp_groups_get_create_group_button_args();
    33633240
    3364                 /**
    3365                  * Filters the HTML button for creating a group.
    3366                  *
    3367                  * @since 2.0.0
    3368                  *
    3369                  * @param string $button HTML button for creating a group.
    3370                  */
    3371                 return bp_get_button( apply_filters( 'bp_get_group_create_button', $button_args ) );
     3241                if ( ! $button_args ) {
     3242                        return false;
     3243                }
     3244
     3245                return bp_get_button(  $button_args );
    33723246        }
    33733247
    33743248/**