bp_nouveau_get_activity_comment_buttons( array $args )

Get the action buttons for the activity comments

Description

Parameters

$args

(Optional) See bp_nouveau_wrapper() for the description of parameters.

Return

(array)

Source

File: bp-templates/bp-nouveau/includes/activity/template-tags.php

850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
    function bp_nouveau_get_activity_comment_buttons($args) {
        $buttons = array();
 
        if ( ! isset( $GLOBALS['activities_template'] ) ) {
            return $buttons;
        }
 
        $activity_comment_id = bp_get_activity_comment_id();
        $activity_id         = bp_get_activity_id();
 
        if ( ! $activity_comment_id || ! $activity_id ) {
            return $buttons;
        }
 
        /*
         * If the 'container' is set to 'ul'
         * set a var $parent_element to li
         * otherwise simply pass any value found in args
         * or set var false.
         */
        if ( 'ul' === $args['container']  ) {
            $parent_element = 'li';
        } elseif ( ! empty( $args['parent_element'] ) ) {
            $parent_element = $args['parent_element'];
        } else {
            $parent_element = false;
        }
 
        $parent_attr = ( ! empty( $args['parent_attr'] ) ) ? $args['parent_attr'] : array();
 
        /*
         * If we have an arg value for $button_element passed through
         * use it to default all the $buttons['button_element'] values
         * otherwise default to 'a' (anchor).
         */
        if ( ! empty( $args['button_element'] ) ) {
            $button_element = $args['button_element'] ;
        } else {
            $button_element = 'a';
        }
 
        $buttons = array(
            'activity_comment_reply' => array(
                'id'                => 'activity_comment_reply',
                'position'          => 5,
                'component'         => 'activity',
                'must_be_logged_in' => true,
                'parent_element'    => $parent_element,
                'parent_attr'       => $parent_attr,
                'button_element'    => $button_element,
                'link_text'         => __( 'Reply', 'buddyboss' ),
                'button_attr'       => array(
                    'class' => "acomment-reply bp-primary-action",
                    'id'    => sprintf( 'acomment-reply-%1$s-from-%2$s', $activity_id, $activity_comment_id ),
                ),
            ),
            'activity_comment_delete' => array(
                'id'                => 'activity_comment_delete',
                'position'          => 15,
                'component'         => 'activity',
                'must_be_logged_in' => true,
                'parent_element'    => $parent_element,
                'parent_attr'       => $parent_attr,
                'button_element'    => $button_element,
                'link_text'         => __( 'Delete', 'buddyboss' ),
                'button_attr'       => array(
                    'class' => 'delete acomment-delete confirm bp-secondary-action',
                    'rel'   => 'nofollow',
                ),
            ),
        );
 
        // If button element set add nonce link to data-attr attr
        if ( 'button' === $button_element ) {
            $buttons['activity_comment_reply']['button_attr']['data-bp-act-reply-nonce'] = sprintf( '#acomment-%s', $activity_comment_id );
            $buttons['activity_comment_delete']['button_attr']['data-bp-act-reply-delete-nonce'] = bp_get_activity_comment_delete_link();
        } else {
            $buttons['activity_comment_reply']['button_attr']['href'] = sprintf( '#acomment-%s', $activity_comment_id );
            $buttons['activity_comment_delete']['button_attr']['href'] = bp_get_activity_comment_delete_link();
        }
 
        // Add the Spam Button if supported
        if ( bp_is_akismet_active() && isset( buddypress()->activity->akismet ) && bp_activity_user_can_mark_spam() ) {
            $buttons['activity_comment_spam'] = array(
                'id'                => 'activity_comment_spam',
                'position'          => 25,
                'component'         => 'activity',
                'must_be_logged_in' => true,
                'parent_element'    => $parent_element,
                'parent_attr'       => $parent_attr,
                'button_element'    => $button_element,
                'link_text'         => __( 'Spam', 'buddyboss' ),
                'button_attr'       => array(
                    'id'     => "activity_make_spam_{$activity_comment_id}",
                    'class'  => 'bp-secondary-action spam-activity-comment confirm',
                    'rel'    => 'nofollow',
                ),
            );
 
            // If button element set add nonce link to data-attr attr
            if ( 'button' === $button_element ) {
                $data_element = 'data-bp-act-spam-nonce';
            } else {
                $data_element = 'href';
            }
 
            $buttons['activity_comment_spam']['button_attr'][ $data_element ] = wp_nonce_url(
                bp_get_root_domain() . '/' . bp_get_activity_slug() . '/spam/' . $activity_comment_id . '/?cid=' . $activity_comment_id,
                'bp_activity_akismet_spam_' . $activity_comment_id
            );
        }
 
        /**
         * Filter to add your buttons, use the position argument to choose where to insert it.
         *
         * @since BuddyPress 3.0.0
         *
         * @param array $buttons             The list of buttons.
         * @param int   $activity_comment_id The current activity comment ID.
         * @param int   $activity_id         The current activity ID.
         */
        $buttons_group = apply_filters( 'bp_nouveau_get_activity_comment_buttons', $buttons, $activity_comment_id, $activity_id );
 
        if ( ! $buttons_group ) {
            return $buttons;
        }
 
        // It's the first comment of the loop, so build the Group and sort it
        if ( ! isset( bp_nouveau()->activity->comment_buttons ) || ! is_a( bp_nouveau()->activity->comment_buttons, 'BP_Buttons_Group' ) ) {
            $sort = true;
            bp_nouveau()->activity->comment_buttons = new BP_Buttons_Group( $buttons_group );
 
        // It's not the first comment, the order is set, we simply need to update the Buttons Group
        } else {
            $sort = false;
            bp_nouveau()->activity->comment_buttons->update( $buttons_group );
        }
 
        $return = bp_nouveau()->activity->comment_buttons->get( $sort );
 
        if ( ! $return ) {
            return array();
        }
 
        /**
         * If post comment / Activity comment sync is on, it's safer
         * to unset the comment button just before returning it.
         */
//      if ( ! bp_activity_can_comment_reply( bp_activity_current_comment() ) ) {
//          unset( $return['activity_comment_reply'] );
//      }
 
        /**
         * If there was an activity of the user before one af another
         * user as we're updating buttons, we need to unset the delete link
         */
        if ( ! bp_activity_user_can_delete() ) {
            unset( $return['activity_comment_delete'] );
        }
 
        if ( isset( $return['activity_comment_spam'] ) && ( ! bp_activity_current_comment() || ! in_array( bp_activity_current_comment()->type, BP_Akismet::get_activity_types(), true ) ) ) {
            unset( $return['activity_comment_spam'] );
        }
 
        /**
         * Leave a chance to adjust the $return
         *
         * @since BuddyPress 3.0.0
         *
         * @param array $return              The list of buttons ordered.
         * @param int   $activity_comment_id The current activity comment ID.
         * @param int   $activity_id         The current activity ID.
         */
        do_action_ref_array( 'bp_nouveau_return_activity_comment_buttons', array( &$return, $activity_comment_id, $activity_id ) );
 
        return $return;
    }

Changelog

Changelog
Version Description
BuddyPress 3.0.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.