bp_nouveau_get_activity_entry_buttons( $args )
Get the action buttons inside an Activity Loop,
Description
Source
File: bp-templates/bp-nouveau/includes/activity/template-tags.php
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | function bp_nouveau_get_activity_entry_buttons( $args ) { $buttons = array (); if ( ! isset( $GLOBALS [ 'activities_template' ] ) ) { return $buttons ; } $activity_id = bp_get_activity_id(); $activity_type = bp_get_activity_type(); $parent_element = '' ; $button_element = 'a' ; if ( ! $activity_id ) { return $buttons ; } /* * If the container is set to 'ul' force the $parent_element to 'li', * else use parent_element args if set. * * This will render li elements around anchors/buttons. */ if ( isset( $args [ 'container' ] ) && 'ul' === $args [ 'container' ] ) { $parent_element = 'li' ; } elseif ( ! empty ( $args [ 'parent_element' ] ) ) { $parent_element = $args [ 'parent_element' ]; } $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) * Or override & hardcode the 'element' string on $buttons array. * */ if ( ! empty ( $args [ 'button_element' ] ) ) { $button_element = $args [ 'button_element' ]; } if ( bp_activity_can_favorite() && bp_is_activity_like_active() ) { // If button element set attr needs to be data-* else 'href' if ( 'button' === $button_element ) { $key = 'data-bp-nonce' ; } else { $key = 'href' ; } if ( ! bp_get_activity_is_favorite() ) { $fav_args = array ( 'parent_element' => $parent_element , 'parent_attr' => $parent_attr , 'button_element' => $button_element , 'link_class' => 'button fav bp-secondary-action' , //'data_bp_tooltip' => __( 'Like', 'buddyboss' ), 'link_text' => __( 'Like' , 'buddyboss' ), 'aria-pressed' => 'false' , 'link_attr' => bp_get_activity_favorite_link(), ); } else { $fav_args = array ( 'parent_element' => $parent_element , 'parent_attr' => $parent_attr , 'button_element' => $button_element , 'link_class' => 'button unfav bp-secondary-action' , //'data_bp_tooltip' => __( 'Unlike', 'buddyboss' ), 'link_text' => __( 'Unlike' , 'buddyboss' ), 'aria-pressed' => 'true' , 'link_attr' => bp_get_activity_unfavorite_link(), ); } $buttons [ 'activity_favorite' ] = array ( 'id' => 'activity_favorite' , 'position' => 4, 'component' => 'activity' , 'parent_element' => $parent_element , 'parent_attr' => $parent_attr , 'must_be_logged_in' => true, 'button_element' => $fav_args [ 'button_element' ], 'link_text' => sprintf( '<span class="bp-screen-reader-text">%1$s</span> <span class="like-count">%2$s</span>' , esc_html( $fav_args [ 'link_text' ] ), esc_html( $fav_args [ 'link_text' ] ) ), 'button_attr' => array ( $key => $fav_args [ 'link_attr' ], 'class' => $fav_args [ 'link_class' ], //'data-bp-tooltip' => $fav_args['data_bp_tooltip'], 'aria-pressed' => $fav_args [ 'aria-pressed' ], ), ); } /* * The view conversation button and the comment one are sharing * the same id because when display_comments is on stream mode, * it is not possible to comment an activity comment and as we * are updating the links to avoid sorting the activity buttons * for each entry of the loop, it's a convenient way to make * sure the right button will be displayed. */ if ( $activity_type === 'activity_comment' ) { $buttons [ 'activity_conversation' ] = array ( 'id' => 'activity_conversation' , 'position' => 5, 'component' => 'activity' , 'parent_element' => $parent_element , 'parent_attr' => $parent_attr , 'must_be_logged_in' => false, 'button_element' => $button_element , 'button_attr' => array ( 'class' => 'button view bp-secondary-action bp-tooltip' , 'data-bp-tooltip' => __( 'View Conversation' , 'buddyboss' ), 'data-bp-tooltip-pos' => 'up' , ), 'link_text' => sprintf( '<span class="bp-screen-reader-text">%1$s</span>' , __( 'View Conversation' , 'buddyboss' ) ), ); // If button element set add url link to data-attr if ( 'button' === $button_element ) { $buttons [ 'activity_conversation' ][ 'button_attr' ][ 'data-bp-url' ] = bp_get_activity_thread_permalink(); } else { $buttons [ 'activity_conversation' ][ 'button_attr' ][ 'href' ] = bp_get_activity_thread_permalink(); $buttons [ 'activity_conversation' ][ 'button_attr' ][ 'role' ] = 'button' ; } /* * We always create the Button to make sure we always have the right numbers of buttons, * no matter the previous activity had less. */ } else { $buttons [ 'activity_conversation' ] = array ( 'id' => 'activity_conversation' , 'position' => 5, 'component' => 'activity' , 'parent_element' => $parent_element , 'parent_attr' => $parent_attr , 'must_be_logged_in' => true, 'button_element' => $button_element , 'button_attr' => array ( 'id' => 'acomment-comment-' . $activity_id , 'class' => 'button acomment-reply bp-primary-action' , // 'data-bp-tooltip' => __( 'Comment', 'buddyboss' ), 'aria-expanded' => 'false' , ), 'link_text' => sprintf( '<span class="bp-screen-reader-text">%1$s</span> <span class="comment-count">%2$s</span>' , __( 'Comment' , 'buddyboss' ), __( 'Comment' , 'buddyboss' ) ), ); // If button element set add href link to data-attr if ( 'button' === $button_element ) { $buttons [ 'activity_conversation' ][ 'button_attr' ][ 'data-bp-url' ] = bp_get_activity_comment_link(); } else { $buttons [ 'activity_conversation' ][ 'button_attr' ][ 'href' ] = bp_get_activity_comment_link(); $buttons [ 'activity_conversation' ][ 'button_attr' ][ 'role' ] = 'button' ; } } // The delete button is always created, and removed later on if needed. $delete_args = array (); /* * As the delete link is filterable we need this workaround * to try to intercept the edits the filter made and build * a button out of it. */ if ( has_filter( 'bp_get_activity_delete_link' ) ) { preg_match( '/<a\s[^>]*>(.*)<\/a>/siU' , bp_get_activity_delete_link(), $link ); if ( ! empty ( $link [0] ) && ! empty ( $link [1] ) ) { $delete_args [ 'link_text' ] = $link [1]; $subject = str_replace ( $delete_args [ 'link_text' ], '' , $link [0] ); } preg_match_all( '/([\w\-]+)=([^"\'> ]+|([\'"]?)(?:[^\3]|\3+)+?\3)/' , $subject , $attrs ); if ( ! empty ( $attrs [1] ) && ! empty ( $attrs [2] ) ) { foreach ( $attrs [1] as $key_attr => $key_value ) { $delete_args [ 'link_' . $key_value ] = trim( $attrs [2][ $key_attr ], '"' ); } } $delete_args = wp_parse_args( $delete_args , array ( 'link_text' => '' , 'button_attr' => array ( 'link_id' => '' , 'link_href' => '' , 'link_class' => '' , 'link_rel' => 'nofollow' , 'data_bp_tooltip' => '' , ), ) ); } if ( empty ( $delete_args [ 'link_href' ] ) ) { $delete_args = array ( 'button_element' => $button_element , 'link_id' => '' , 'link_class' => 'button item-button bp-secondary-action delete-activity confirm' , 'link_rel' => 'nofollow' , 'data_bp_tooltip' => __( 'Delete' , 'buddyboss' ), 'link_text' => __( 'Delete' , 'buddyboss' ), 'link_href' => bp_get_activity_delete_url(), ); // If button element set add nonce link to data-attr attr if ( 'button' === $button_element ) { $delete_args [ 'data-attr' ] = bp_get_activity_delete_url(); $delete_args [ 'link_href' ] = '' ; } else { $delete_args [ 'link_href' ] = bp_get_activity_delete_url(); $delete_args [ 'data-attr' ] = '' ; } } $buttons [ 'activity_delete' ] = array ( 'id' => 'activity_delete' , 'position' => 35, 'component' => 'activity' , 'parent_element' => $parent_element , 'parent_attr' => $parent_attr , 'must_be_logged_in' => true, 'button_element' => $button_element , 'button_attr' => array ( 'id' => $delete_args [ 'link_id' ], 'href' => $delete_args [ 'link_href' ], 'class' => $delete_args [ 'link_class' ], //'data-bp-tooltip' => $delete_args['data_bp_tooltip'], 'data-bp-nonce' => $delete_args [ 'data-attr' ] , ), 'link_text' => sprintf( '<span class="bp-screen-reader-text">%s</span><span class="delete-label">%s</span>' , esc_html( $delete_args [ 'data_bp_tooltip' ] ), esc_html( $delete_args [ 'data_bp_tooltip' ] ) ), ); // Add the Spam Button if supported if ( bp_is_akismet_active() && isset( buddypress()->activity->akismet ) && bp_activity_user_can_mark_spam() ) { $buttons [ 'activity_spam' ] = array ( 'id' => 'activity_spam' , 'position' => 45, 'component' => 'activity' , 'parent_element' => $parent_element , 'parent_attr' => $parent_attr , 'must_be_logged_in' => true, 'button_element' => $button_element , 'button_attr' => array ( 'class' => 'bp-secondary-action spam-activity confirm button item-button bp-tooltip' , 'id' => 'activity_make_spam_' . $activity_id , 'data-bp-tooltip' => __( 'Spam' , 'buddyboss' ), 'data-bp-tooltip-pos' => 'up' , ), 'link_text' => sprintf( /** @todo: use a specific css rule for this *************************************************************/ '<span class="dashicons dashicons-flag" style="color:#a00;vertical-align:baseline;width:18px;height:18px" aria-hidden="true"></span><span class="bp-screen-reader-text">%s</span>' , esc_html__( 'Spam' , 'buddyboss' ) ), ); // If button element, add nonce link to data attribute. if ( 'button' === $button_element ) { $data_element = 'data-bp-nonce' ; } else { $data_element = 'href' ; } $buttons [ 'activity_spam' ][ 'button_attr' ][ $data_element ] = wp_nonce_url( bp_get_root_domain() . '/' . bp_get_activity_slug() . '/spam/' . $activity_id . '/' , 'bp_activity_akismet_spam_' . $activity_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_id The current activity ID. */ $buttons_group = apply_filters( 'bp_nouveau_get_activity_entry_buttons' , $buttons , $activity_id ); if ( ! $buttons_group ) { return $buttons ; } // It's the first entry of the loop, so build the Group and sort it if ( ! isset( bp_nouveau()->activity->entry_buttons ) || ! is_a ( bp_nouveau()->activity->entry_buttons, 'BP_Buttons_Group' ) ) { $sort = true; bp_nouveau()->activity->entry_buttons = new BP_Buttons_Group( $buttons_group ); // It's not the first entry, the order is set, we simply need to update the Buttons Group } else { $sort = false; bp_nouveau()->activity->entry_buttons->update( $buttons_group ); } $return = bp_nouveau()->activity->entry_buttons->get( $sort ); if ( ! $return ) { return array (); } // Remove the Comment button if the user can't comment if ( ! bp_activity_can_comment() && $activity_type !== 'activity_comment' ) { unset( $return [ 'activity_conversation' ] ); } // Remove the Delete button if the user can't delete if ( ! bp_activity_user_can_delete() ) { unset( $return [ 'activity_delete' ] ); } if ( isset( $return [ 'activity_spam' ] ) && ! in_array( $activity_type , BP_Akismet::get_activity_types() ) ) { unset( $return [ 'activity_spam' ] ); } /** * Leave a chance to adjust the $return * * @since BuddyPress 3.0.0 * * @param array $return The list of buttons ordered. * @param int $activity_id The current activity ID. */ do_action_ref_array( 'bp_nouveau_return_activity_entry_buttons' , array ( & $return , $activity_id ) ); return $return ; } |
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.