bp_nouveau_get_members_buttons( $args )
Get the action buttons for the displayed user profile
Description
Return
(array)
Source
File: bp-templates/bp-nouveau/includes/members/template-tags.php
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 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 | function bp_nouveau_get_members_buttons( $args ) { $buttons = array (); $type = ( ! empty ( $args [ 'type' ] ) ) ? $args [ 'type' ] : '' ; // @todo Not really sure why BP Legacy needed to do this... if ( 'profile' === $type && is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) { return $buttons ; } $user_id = bp_displayed_user_id(); if ( 'loop' === $type || 'friendship_request' === $type ) { $user_id = bp_get_member_user_id(); } elseif ( 'group_member' === $type ) { $user_id = bp_get_group_member_id(); } if ( ! $user_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. */ $parent_element = false; if ( ! empty ( $args [ 'container' ] ) && 'ul' === $args [ 'container' ] ) { $parent_element = 'li' ; } elseif ( ! empty ( $args [ 'parent_element' ] ) ) { $parent_element = $args [ 'parent_element' ]; } /* * 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. * * Icons sets a class for icon display if not using the button element */ $icons = '' ; if ( ! empty ( $args [ 'button_element' ] ) ) { $button_element = $args [ 'button_element' ] ; } else { $button_element = 'button' ; $icons = ' icons' ; } // If we pass through parent classes add them to $button array $parent_class = '' ; if ( ! empty ( $args [ 'parent_attr' ][ 'class' ] ) ) { $parent_class = $args [ 'parent_attr' ][ 'class' ]; } $bp_force_friendship_to_message = bp_force_friendship_to_message(); if ( bp_is_active( 'friends' ) ) { // It's the member's connection requests screen if ( 'friendship_request' === $type ) { $buttons = array ( 'accept_friendship' => array ( 'id' => 'accept_friendship' , 'position' => 5, 'component' => 'friends' , 'must_be_logged_in' => true, 'parent_element' => $parent_element , 'link_text' => __( 'Accept' , 'buddyboss' ), 'parent_attr' => array ( 'id' => '' , 'class' => $parent_class , ), 'button_element' => $button_element , 'button_attr' => array ( 'class' => 'button accept' , 'rel' => '' , ), ), 'reject_friendship' => array ( 'id' => 'reject_friendship' , 'position' => 15, 'component' => 'friends' , 'must_be_logged_in' => true, 'parent_element' => $parent_element , 'link_text' => __( 'Ignore' , 'buddyboss' ), 'parent_attr' => array ( 'id' => '' , 'class' => $parent_class , ), 'button_element' => $button_element , 'button_attr' => array ( 'class' => 'button reject' , 'rel' => '' , ), ), ); // If button element set add nonce link to data attr if ( 'button' === $button_element ) { $buttons [ 'accept_friendship' ][ 'button_attr' ][ 'data-bp-nonce' ] = bp_get_friend_accept_request_link(); $buttons [ 'reject_friendship' ][ 'button_attr' ][ 'data-bp-nonce' ] = bp_get_friend_reject_request_link(); } else { $buttons [ 'accept_friendship' ][ 'button_attr' ][ 'href' ] = bp_get_friend_accept_request_link(); $buttons [ 'reject_friendship' ][ 'button_attr' ][ 'href' ] = bp_get_friend_reject_request_link(); } // It's any other members screen } else { /* * This filter workaround is waiting for a core adaptation * so that we can directly get the friends button arguments * instead of the button. * */ add_filter( 'bp_get_add_friend_button' , 'bp_nouveau_members_catch_button_args' , 100, 1 ); bp_get_add_friend_button( $user_id ); remove_filter( 'bp_get_add_friend_button' , 'bp_nouveau_members_catch_button_args' , 100, 1 ); if ( ! empty ( bp_nouveau()->members->button_args ) ) { $button_args = bp_nouveau()->members->button_args; $buttons [ 'member_friendship' ] = array ( 'id' => 'member_friendship' , 'position' => 5, 'component' => $button_args [ 'component' ], 'must_be_logged_in' => $button_args [ 'must_be_logged_in' ], 'block_self' => $button_args [ 'block_self' ], 'parent_element' => $parent_element , 'link_text' => $button_args [ 'link_text' ], 'parent_attr' => array ( 'id' => $button_args [ 'wrapper_id' ], 'class' => $parent_class . ' ' . $button_args [ 'wrapper_class' ], ), 'button_element' => $button_element , 'button_attr' => array ( 'id' => $button_args [ 'link_id' ], 'class' => $button_args [ 'link_class' ], 'rel' => $button_args [ 'link_rel' ], 'title' => '' , ), ); if ( ! empty ( $button_args [ 'button_attr' ] ) ) { foreach ( $button_args [ 'button_attr' ] as $title => $value ) { $buttons [ 'member_friendship' ][ 'button_attr' ][ $title ] = $value ; } } // If button element set add nonce link to data attr if ( 'button' === $button_element && 'awaiting_response' !== $button_args [ 'id' ] ) { $buttons [ 'member_friendship' ][ 'button_attr' ][ 'data-bp-nonce' ] = $button_args [ 'link_href' ]; } else { $buttons [ 'member_friendship' ][ 'button_element' ] = 'a' ; $buttons [ 'member_friendship' ][ 'button_attr' ][ 'href' ] = $button_args [ 'link_href' ]; } unset( bp_nouveau()->members->button_args ); } } } if ( bp_is_active( 'activity' ) && bp_is_activity_follow_active() ) { // add follow button /* * This filter workaround is waiting for a core adaptation * so that we can directly get the follow button arguments * instead of the button. * */ add_filter( 'bp_get_add_follow_button' , 'bp_nouveau_members_catch_button_args' , 100, 1 ); bp_get_add_follow_button( $user_id , bp_loggedin_user_id() ); remove_filter( 'bp_get_add_follow_button' , 'bp_nouveau_members_catch_button_args' , 100, 1 ); if ( ! empty ( bp_nouveau()->members->button_args ) ) { $button_args = bp_nouveau()->members->button_args; $buttons [ 'member_follow' ] = array ( 'id' => 'member_follow' , 'position' => 10, 'component' => $button_args [ 'component' ], 'must_be_logged_in' => $button_args [ 'must_be_logged_in' ], 'block_self' => $button_args [ 'block_self' ], 'parent_element' => $parent_element , 'link_text' => $button_args [ 'link_text' ], 'parent_attr' => array ( 'id' => $button_args [ 'wrapper_id' ], 'class' => $parent_class . ' ' . $button_args [ 'wrapper_class' ], ), 'button_element' => $button_element , 'button_attr' => array ( 'id' => $button_args [ 'link_id' ], 'class' => $button_args [ 'link_class' ], 'rel' => $button_args [ 'link_rel' ], 'title' => '' , ), ); if ( ! empty ( $button_args [ 'button_attr' ] ) ) { foreach ( $button_args [ 'button_attr' ] as $title => $value ) { $buttons [ 'member_follow' ][ 'button_attr' ][ $title ] = $value ; } } // If button element set add nonce link to data attr if ( 'button' === $button_element ) { $buttons [ 'member_follow' ][ 'button_attr' ][ 'data-bp-nonce' ] = $button_args [ 'link_href' ]; } else { $buttons [ 'member_follow' ][ 'button_element' ] = 'a' ; $buttons [ 'member_follow' ][ 'button_attr' ][ 'href' ] = $button_args [ 'link_href' ]; } unset( bp_nouveau()->members->button_args ); } } // Only add The public and private messages when not in a loop //if ( 'profile' === $type ) { if ( bp_is_active( 'activity' ) && bp_activity_do_mentions() ) { /* * This filter workaround is waiting for a core adaptation * so that we can directly get the public message button arguments * instead of the button. * */ if ( ! empty ( bp_nouveau()->members->button_args ) ) { $button_args = bp_nouveau()->members->button_args; /* * This button should remain as an anchor link. * Hardcode the use of anchor elements if button arg passed in for other elements. */ $buttons [ 'public_message' ] = array ( 'id' => $button_args [ 'id' ], 'position' => 15, 'component' => $button_args [ 'component' ], 'must_be_logged_in' => $button_args [ 'must_be_logged_in' ], 'block_self' => $button_args [ 'block_self' ], 'parent_element' => $parent_element , 'button_element' => 'a' , 'link_text' => $button_args [ 'link_text' ], 'parent_attr' => array ( 'id' => $button_args [ 'wrapper_id' ], 'class' => $parent_class , ), 'button_attr' => array ( 'href' => $button_args [ 'link_href' ], 'id' => '' , 'class' => $button_args [ 'link_class' ], ), ); unset( bp_nouveau()->members->button_args ); } } if ( ( bp_is_active( 'messages' ) && ! $bp_force_friendship_to_message ) || ( $bp_force_friendship_to_message && bp_is_active( 'friends' ) && friends_check_friendship( bp_loggedin_user_id(), $user_id ) ) ) { /** * This filter workaround is waiting for a core adaptation * so that we can directly get the private messages button arguments * instead of the button. */ add_filter( 'bp_get_send_message_button_args' , 'bp_nouveau_members_catch_button_args' , 100, 1 ); bp_get_send_message_button(); remove_filter( 'bp_get_send_message_button_args' , 'bp_nouveau_members_catch_button_args' , 100, 1 ); if ( ! empty ( bp_nouveau()->members->button_args ) ) { $button_args = bp_nouveau()->members->button_args; /* * This button should remain as an anchor link. * Hardcode the use of anchor elements if button arg passed in for other elements. */ $buttons [ 'private_message' ] = array ( 'id' => $button_args [ 'id' ], 'position' => 25, 'component' => $button_args [ 'component' ], 'must_be_logged_in' => $button_args [ 'must_be_logged_in' ], 'block_self' => $button_args [ 'block_self' ], 'parent_element' => $parent_element , 'button_element' => 'a' , 'link_text' => $button_args [ 'link_text' ], 'parent_attr' => array ( 'id' => $button_args [ 'wrapper_id' ], 'class' => $parent_class , ), 'button_attr' => array ( 'href' => wp_nonce_url( trailingslashit( bp_loggedin_user_domain() . bp_get_messages_slug() ) . 'compose/?r=' . bp_core_get_username( $user_id ) ), 'id' => false, 'class' => $button_args [ 'link_class' ], 'rel' => '' , 'title' => '' , ), ); unset( bp_nouveau()->members->button_args ); } } /* * This filter workaround is waiting for a core adaptation * so that we can directly get the follow button arguments * instead of the button. * */ add_filter( 'bp_get_add_switch_button' , 'bp_nouveau_members_catch_button_args' , 100, 1 ); bp_get_add_switch_button( $user_id ); remove_filter( 'bp_get_add_switch_button' , 'bp_nouveau_members_catch_button_args' , 100, 1 ); if ( ! empty ( bp_nouveau()->members->button_args ) ) { $button_args = bp_nouveau()->members->button_args; $buttons [ 'member_switch' ] = array ( 'id' => 'member_switch' , 'position' => 30, 'component' => $button_args [ 'component' ], 'must_be_logged_in' => $button_args [ 'must_be_logged_in' ], 'block_self' => $button_args [ 'block_self' ], 'parent_element' => $parent_element , 'link_href' => $button_args [ 'link_href' ], 'link_text' => $button_args [ 'link_text' ], 'parent_attr' => array ( 'id' => $button_args [ 'wrapper_id' ], 'class' => $parent_class . ' ' . $button_args [ 'wrapper_class' ], ), 'button_element' => 'a' , 'button_attr' => array ( 'id' => $button_args [ 'link_id' ], 'class' => $button_args [ 'link_class' ], 'rel' => $button_args [ 'link_rel' ], 'title' => '' , ), ); if ( ! empty ( $button_args [ 'button_attr' ] ) ) { foreach ( $button_args [ 'button_attr' ] as $title => $value ) { $buttons [ 'member_switch' ][ 'button_attr' ][ $title ] = $value ; } } // If button element set add nonce link to data attr if ( 'button' === $button_element ) { $buttons [ 'member_switch' ][ 'button_attr' ][ 'data-bp-nonce' ] = $button_args [ 'link_href' ]; } else { $buttons [ 'member_switch' ][ 'button_element' ] = 'a' ; $buttons [ 'member_switch' ][ 'button_attr' ][ 'href' ] = $button_args [ 'link_href' ]; } unset( bp_nouveau()->members->button_args ); } //} /** * 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 $user_id The displayed user ID. * @param string $type Whether we're displaying a members loop or a user's page */ $buttons_group = apply_filters( 'bp_nouveau_get_members_buttons' , $buttons , $user_id , $type ); if ( ! $buttons_group ) { return $buttons ; } // It's the first entry of the loop, so build the Group and sort it if ( ! isset( bp_nouveau()->members->member_buttons ) || ! is_a ( bp_nouveau()->members->member_buttons, 'BP_Buttons_Group' ) ) { $sort = true; bp_nouveau()->members->member_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()->members->member_buttons->update( $buttons_group ); } $return = bp_nouveau()->members->member_buttons->get( $sort ); if ( ! $return ) { return array (); } /** * Leave a chance to adjust the $return * * @since BuddyPress 3.0.0 * * @param array $return The list of buttons ordered. * @param int $user_id The displayed user ID. * @param string $type Whether we're displaying a members loop or a user's page */ do_action_ref_array( 'bp_nouveau_return_members_buttons' , array ( & $return , $user_id , $type ) ); 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.