Skip to:
Content

BuddyPress.org

Changeset 13299


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

Introduce a function to only get the Public Message button arguments

BP Nouveau is doing a complex workaround to only get these arguments without generating the BP_Button HTML output. bp_activity_get_public_message_button_args() eases the process of getting these arguments and removes the need for such a workaround.

Props hnla

See #7126
See #8722

Location:
trunk/src
Files:
2 edited

Legend:

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

    r13215 r13299  
    34833483 * @since 1.2.0
    34843484 *
    3485  * @see bp_get_send_public_message_button() for description of parameters.
    3486  *
    3487  * @param array|string $args See {@link bp_get_send_public_message_button()}.
     3485 * @see bp_activity_get_public_message_button_args() for description of parameters.
     3486 *
     3487 * @param array|string $args See {@link bp_activity_get_public_message_button_args()}.
    34883488 */
    34893489function bp_send_public_message_button( $args = '' ) {
     
    34923492
    34933493        /**
    3494          * Return button for sending a public message (an @-mention).
    3495          *
    3496          * @since 1.2.0
    3497          *
     3494         * Get the arguments for the public message button.
     3495         *
     3496         * @since 11.0.0
    34983497         *
    34993498         * @param array|string $args {
    3500          *     All arguments are optional. See {@link BP_Button} for complete
    3501          *     descriptions.
    3502          *     @type string $id                Default: 'public_message'.
    3503          *     @type string $component         Default: 'activity'.
    3504          *     @type bool   $must_be_logged_in Default: true.
    3505          *     @type bool   $block_self        Default: true.
    3506          *     @type string $wrapper_id        Default: 'post-mention'.
    3507          *     @type string $link_href         Default: the public message link for
    3508          *                                     the current member in the loop.
    3509          *     @type string $link_text         Default: 'Public Message'.
    3510          *     @type string $link_class        Default: 'activity-button mention'.
     3499         *    All arguments are optional. See {@link BP_Button} for complete
     3500         *    descriptions.
     3501         *    @type string $id                Default: 'public_message'.
     3502         *    @type string $component         Default: 'activity'.
     3503         *    @type bool   $must_be_logged_in Default: true.
     3504         *    @type bool   $block_self        Default: true.
     3505         *    @type string $wrapper_id        Default: 'post-mention'.
     3506         *    @type string $link_href         Default: the public message link for
     3507         *                                    the current member in the loop.
     3508         *    @type string $link_title        Default: 'Send a public message on your
     3509         *                                    activity stream.'.
     3510         *    @type string $link_text         Default: 'Public Message'.
     3511         *    @type string $link_class        Default: 'activity-button mention'.
    35113512         * }
    3512          * @return string The button for sending a public message.
    3513          */
    3514         function bp_get_send_public_message_button( $args = '' ) {
    3515 
    3516                 $r = bp_parse_args(
     3513         * @return array The arguments for the public message button.
     3514         */
     3515        function bp_activity_get_public_message_button_args( $args = '' ) {
     3516                $button_args = bp_parse_args(
    35173517                        $args,
    35183518                        array(
     
    35233523                                'wrapper_id'        => 'post-mention',
    35243524                                'link_href'         => bp_get_send_public_message_link(),
     3525                                'link_title'        => __( 'Send a public message to this member.', 'buddypress' ),
    35253526                                'link_text'         => __( 'Public Message', 'buddypress' ),
    35263527                                'link_class'        => 'activity-button mention',
     
    35333534                 * @since 1.2.10
    35343535                 *
    3535                  * @param array $r Array of arguments for the public message button HTML.
    3536                  */
    3537                 return bp_get_button( apply_filters( 'bp_get_send_public_message_button', $r ) );
     3536                 * @param array $button_args Array of arguments for the public message button HTML.
     3537                 */
     3538                return apply_filters( 'bp_get_send_public_message_button', $button_args );
     3539        }
     3540
     3541        /**
     3542         * Return button for sending a public message (an @-mention).
     3543         *
     3544         * @since 1.2.0
     3545         * @since 11.0.0 uses `bp_activity_get_public_message_button_args()`.
     3546         *
     3547         * @see bp_activity_get_public_message_button_args() for description of parameters.
     3548         *
     3549         * @param array|string $args See {@link bp_activity_get_public_message_button_args()}.
     3550         * @return string The button for sending a public message.
     3551         */
     3552        function bp_get_send_public_message_button( $args = '' ) {
     3553                $button_args = bp_activity_get_public_message_button_args( $args );
     3554
     3555                if ( ! array_filter( $button_args ) ) {
     3556                        return '';
     3557                }
     3558
     3559                return bp_get_button( $button_args );
    35383560        }
    35393561
  • trunk/src/bp-templates/bp-nouveau/includes/members/template-tags.php

    r13276 r13299  
    373373                if ( 'profile' === $type ) {
    374374                        if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) {
     375                                $button_args = bp_activity_get_public_message_button_args();
     376
    375377                                /*
    376                                  * This filter workaround is waiting for a core adaptation
    377                                  * so that we can directly get the public message button arguments
    378                                  * instead of the button.
    379                                  *
    380                                  * See https://buddypress.trac.wordpress.org/ticket/7126
     378                                 * This button should remain as an anchor link.
     379                                 * Hardcode the use of anchor elements if button arg passed in for other elements.
    381380                                 */
    382                                 add_filter( 'bp_get_send_public_message_button', 'bp_nouveau_members_catch_button_args', 100, 1 );
    383 
    384                                 bp_get_send_public_message_button();
    385 
    386                                 remove_filter( 'bp_get_send_public_message_button', 'bp_nouveau_members_catch_button_args', 100, 1 );
    387 
    388                                 if ( isset( bp_nouveau()->members->button_args ) && bp_nouveau()->members->button_args ) {
    389                                         $button_args = bp_nouveau()->members->button_args;
    390 
    391                                         /*
    392                                          * This button should remain as an anchor link.
    393                                          * Hardcode the use of anchor elements if button arg passed in for other elements.
    394                                          */
    395                                         $buttons['public_message'] = array(
    396                                                 'id'                => $button_args['id'],
    397                                                 'position'          => 15,
    398                                                 'component'         => $button_args['component'],
    399                                                 'must_be_logged_in' => $button_args['must_be_logged_in'],
    400                                                 'block_self'        => $button_args['block_self'],
    401                                                 'parent_element'    => $parent_element,
    402                                                 'button_element'    => 'a',
    403                                                 'link_text'         => $button_args['link_text'],
    404                                                 'parent_attr'       => array(
    405                                                         'id'    => $button_args['wrapper_id'],
    406                                                         'class' => $parent_class,
    407                                                 ),
    408                                                 'button_attr'       => array(
    409                                                         'href'             => $button_args['link_href'],
    410                                                         'id'               => '',
    411                                                         'class'            => $button_args['link_class'],
    412                                                 ),
    413                                         );
    414                                         unset( bp_nouveau()->members->button_args );
    415                                 }
     381                                $buttons['public_message'] = array(
     382                                        'id'                => $button_args['id'],
     383                                        'position'          => 15,
     384                                        'component'         => $button_args['component'],
     385                                        'must_be_logged_in' => $button_args['must_be_logged_in'],
     386                                        'block_self'        => $button_args['block_self'],
     387                                        'parent_element'    => $parent_element,
     388                                        'button_element'    => 'a',
     389                                        'link_text'         => $button_args['link_text'],
     390                                        'link_title'        => $button_args['link_title'],
     391                                        'parent_attr'       => array(
     392                                                'id'    => $button_args['wrapper_id'],
     393                                                'class' => $parent_class,
     394                                        ),
     395                                        'button_attr'       => array(
     396                                                'href'             => $button_args['link_href'],
     397                                                'id'               => '',
     398                                                'class'            => $button_args['link_class'],
     399                                        ),
     400                                );
    416401                        }
    417402
Note: See TracChangeset for help on using the changeset viewer.