Skip to:
Content

BuddyPress.org

Changeset 13300


Ignore:
Timestamp:
07/22/2022 09:32:13 AM (4 years ago)
Author:
imath
Message:

Introduce a function to only get the Private Message button arguments

bp_get_send_message_button_args() eases the process of getting these arguments and removes the need for BP Nouveau's workaround.

Props hnla

See #7126
See #8722

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-template.php

    r13295 r13300  
    15051505 * @since 3.0.0 Added `$args` parameter.
    15061506 *
    1507  * @param array|string $args See {@link bp_get_send_message_button()}.
     1507 * @see bp_get_send_message_button_args() for description of parameters.
     1508 *
     1509 * @param array|string $args See {@link bp_get_send_message_button_args()}.
    15081510 */
    15091511function bp_send_message_button( $args = '' ) {
    15101512        echo bp_get_send_message_button( $args );
    15111513}
    1512         /**
    1513          * Generate the 'Private Message' button for member profile headers.
    1514          *
    1515          * @since 1.2.0
    1516          * @since 3.0.0 Added `$args` parameter.
     1514
     1515        /**
     1516         * Get the arguments for the private message button.
     1517         *
     1518         * @since 11.0.0
    15171519         *
    15181520         * @param array|string $args {
    1519          *     All arguments are optional. See {@link BP_Button} for complete
    1520          *     descriptions.
    1521          *     @type string $id                Default: 'private_message'.
    1522          *     @type string $component         Default: 'messages'.
    1523          *     @type bool   $must_be_logged_in Default: true.
    1524          *     @type bool   $block_self        Default: true.
    1525          *     @type string $wrapper_id        Default: 'send-private-message'.
    1526          *     @type string $link_href         Default: the private message link for
    1527          *                                     the current member in the loop.
    1528          *     @type string $link_text         Default: 'Private Message'.
    1529          *     @type string $link_class        Default: 'send-message'.
     1521         *    All arguments are optional. See {@link BP_Button} for complete
     1522         *    descriptions.
     1523         *    @type string $id                Default: 'private_message'.
     1524         *    @type string $component         Default: 'messages'.
     1525         *    @type bool   $must_be_logged_in Default: true.
     1526         *    @type bool   $block_self        Default: true.
     1527         *    @type string $wrapper_id        Default: 'send-private-message'.
     1528         *    @type string $link_href         Default: the private message link for
     1529         *                                    the current member in the loop.
     1530         *    @type string $link_title        Default: 'Send a private message to this member.'.
     1531         *    @type string $link_text         Default: 'Private Message'.
     1532         *    @type string $link_class        Default: 'send-message'.
    15301533         * }
    1531          * @return string
    1532          */
    1533         function bp_get_send_message_button( $args = '' ) {
    1534 
    1535                 $r = bp_parse_args(
     1534         * @return array The arguments for the public message button.
     1535         */
     1536        function bp_get_send_message_button_args( $args = '' ) {
     1537                $button_args = bp_parse_args(
    15361538                        $args,
    15371539                        array(
     
    15431545                                'link_href'         => bp_get_send_private_message_link(),
    15441546                                'link_text'         => __( 'Private Message', 'buddypress' ),
     1547                                'link_title'        => __( 'Send a private message to this member.', 'buddypress' ),
    15451548                                'link_class'        => 'send-message',
    15461549                        )
    15471550                );
    15481551
    1549                 // Note: 'bp_get_send_message_button' is a legacy filter. Use
    1550                 // 'bp_get_send_message_button_args' instead. See #4536.
    1551                 return apply_filters( 'bp_get_send_message_button',
    1552 
    1553                         /**
    1554                          * Filters the "Private Message" button for member profile headers.
    1555                          *
    1556                          * @since 1.8.0
    1557                          *
    1558                          * @param array $value See {@link BP_Button}.
    1559                          */
    1560                         bp_get_button( apply_filters( 'bp_get_send_message_button_args', $r ) )
     1552                /**
     1553                 * Filters the "Private Message" button for member profile headers.
     1554                 *
     1555                 * @since 1.8.0
     1556                 *
     1557                 * @param array $button_args See {@link BP_Button}.
     1558                 */
     1559                return apply_filters( 'bp_get_send_message_button_args', $button_args );
     1560        }
     1561
     1562        /**
     1563         * Generate the 'Private Message' button for member profile headers.
     1564         *
     1565         * @since 1.2.0
     1566         * @since 3.0.0 Added `$args` parameter.
     1567         * @since 11.0.0 uses `bp_get_send_message_button_args()`.
     1568         *
     1569         * @see bp_get_send_message_button_args() for description of parameters.
     1570         *
     1571         * @param array|string $args See {@link bp_get_send_message_button_args()}.
     1572         * @return string
     1573         */
     1574        function bp_get_send_message_button( $args = '' ) {
     1575                $button_args = bp_get_send_message_button_args( $args );
     1576
     1577                if ( ! array_filter( $button_args ) ) {
     1578                        return '';
     1579                }
     1580
     1581                /** This filter is documented in wp-includes/deprecated.php */
     1582                $button = apply_filters_deprecated(
     1583                        'bp_get_send_message_button',
     1584                        array( bp_get_button( $button_args ) ),
     1585                        '1.8.0',
     1586                        'bp_get_send_message_button_args'
    15611587                );
     1588
     1589                return $button;
    15621590        }
    15631591
  • trunk/src/bp-templates/bp-nouveau/includes/members/template-tags.php

    r13299 r13300  
    402402
    403403                        if ( bp_is_active( 'messages' ) ) {
    404                                 /**
    405                                  * This filter workaround is waiting for a core adaptation
    406                                  * so that we can directly get the private messages button arguments
    407                                  * instead of the button.
    408                                  * @see https://buddypress.trac.wordpress.org/ticket/7126
     404                                $button_args = bp_get_send_message_button_args();
     405
     406                                /*
     407                                 * This button should remain as an anchor link.
     408                                 * Hardcode the use of anchor elements if button arg passed in for other elements.
    409409                                 */
    410                                 add_filter( 'bp_get_send_message_button_args', 'bp_nouveau_members_catch_button_args', 100, 1 );
    411 
    412                                 bp_get_send_message_button();
    413 
    414                                 remove_filter( 'bp_get_send_message_button_args', 'bp_nouveau_members_catch_button_args', 100, 1 );
    415 
    416                                 if ( isset( bp_nouveau()->members->button_args ) && bp_nouveau()->members->button_args ) {
    417                                         $button_args = bp_nouveau()->members->button_args;
    418 
    419                                         /*
    420                                          * This button should remain as an anchor link.
    421                                          * Hardcode the use of anchor elements if button arg passed in for other elements.
    422                                          */
    423                                         $buttons['private_message'] = array(
    424                                                 'id'                => $button_args['id'],
    425                                                 'position'          => 25,
    426                                                 'component'         => $button_args['component'],
    427                                                 'must_be_logged_in' => $button_args['must_be_logged_in'],
    428                                                 'block_self'        => $button_args['block_self'],
    429                                                 'parent_element'    => $parent_element,
    430                                                 'button_element'    => 'a',
    431                                                 'link_text'         => $button_args['link_text'],
    432                                                 'parent_attr'       => array(
    433                                                         'id'    => $button_args['wrapper_id'],
    434                                                         'class' => $parent_class,
    435                                                 ),
    436                                                 'button_attr'       => array(
    437                                                         'href'  => bp_get_send_private_message_link(),
    438                                                         'id'    => false,
    439                                                         'class' => $button_args['link_class'],
    440                                                         'rel'   => '',
    441                                                         'title' => '',
    442                                                 ),
    443                                         );
    444 
    445                                         unset( bp_nouveau()->members->button_args );
    446                                 }
     410                                $buttons['private_message'] = array(
     411                                        'id'                => $button_args['id'],
     412                                        'position'          => 25,
     413                                        'component'         => $button_args['component'],
     414                                        'must_be_logged_in' => $button_args['must_be_logged_in'],
     415                                        'block_self'        => $button_args['block_self'],
     416                                        'parent_element'    => $parent_element,
     417                                        'button_element'    => 'a',
     418                                        'link_text'         => $button_args['link_text'],
     419                                        'link_title'        => $button_args['link_title'],
     420                                        'parent_attr'       => array(
     421                                                'id'    => $button_args['wrapper_id'],
     422                                                'class' => $parent_class,
     423                                        ),
     424                                        'button_attr'       => array(
     425                                                'href'  => bp_get_send_private_message_link(),
     426                                                'id'    => false,
     427                                                'class' => $button_args['link_class'],
     428                                                'rel'   => '',
     429                                                'title' => '',
     430                                        ),
     431                                );
    447432                        }
    448433                }
Note: See TracChangeset for help on using the changeset viewer.