Changeset 3260 for branches/1.2/bp-core/bp-core-classes.php
- Timestamp:
- 09/13/2010 01:08:31 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.2/bp-core/bp-core-classes.php
r3224 r3260 496 496 } 497 497 498 /** 499 * BP_Button 500 * 501 * API to create BuddyPress buttons 502 * 503 * @package BuddyPress Core 504 * @since 1.2.6 505 */ 506 class BP_Button { 507 508 // Button properties 509 var $id; 510 var $component; 511 var $must_be_logged_in; 512 var $block_self; 513 514 // Wrapper div 515 var $wrapper_class; 516 var $wrapper_id; 517 518 // Button 519 var $link_href; 520 var $link_class; 521 var $link_id; 522 var $link_rel; 523 var $link_title; 524 var $link_text; 525 526 // HTML result 527 var $contents; 528 529 /** 530 * bp_button() 531 * 532 * Builds the button based on passed parameters: 533 * 534 * component: Which component this button is for 535 * must_be_logged_in: Button only appears for logged in users 536 * block_self: Button will not appear when viewing your own profile. 537 * wrapper_id: The DOM ID of the button wrapper 538 * wrapper_class: The DOM class of the button wrapper 539 * link_href: The destination link of the button 540 * link_title: Title of the button 541 * link_id: The DOM ID of the button 542 * link_class: The DOM class of the button 543 * link_rel: The DOM rel of the button 544 * link_text: The contents of the button 545 * 546 * @param array $args 547 * @return bool False if not allowed 548 */ 549 function bp_button( $args = '' ) { 550 551 $defaults = array( 552 'id' => '', 553 'component' => 'core', 554 'must_be_logged_in' => true, 555 'block_self' => true, 556 557 'wrapper_id' => '', 558 'wrapper_class' => '', 559 560 'link_href' => '', 561 'link_title' => '', 562 'link_id' => '', 563 'link_class' => '', 564 'link_rel' => '', 565 'link_text' => '', 566 ); 567 568 $r = wp_parse_args( $args, $defaults ); 569 extract( $r, EXTR_SKIP ); 570 571 // Required button properties 572 $this->id = $id; 573 $this->component = $component; 574 $this->must_be_logged_in = (bool)$must_be_logged_in; 575 $this->block_self = (bool)$block_self; 576 577 // $id and $component are required 578 if ( empty( $id ) || empty( $component ) ) 579 return false; 580 581 // No button if component is not active 582 if ( !bp_is_active( $this->component ) ) 583 return false; 584 585 // No button for guests if must be logged in 586 if ( true == $this->must_be_logged_in && !is_user_logged_in ) 587 return false; 588 589 // No button if viewing your own profile 590 if ( true == $this->block_self && bp_is_my_profile() ) 591 return false; 592 593 // Wrapper properties 594 if ( !empty( $wrapper_id ) ) 595 $this->wrapper_id = ' id="' . $wrapper_id . '"'; 596 597 if ( !empty( $wrapper_class ) ) 598 $this->wrapper_class = ' class="generic-button ' . $wrapper_class . '"'; 599 else 600 $this->wrapper_class = ' class="generic-button"'; 601 602 // Link properties 603 if ( !empty( $link_id ) ) 604 $this->link_id = ' id="' . $link_id . '"'; 605 606 if ( !empty( $link_href ) ) 607 $this->link_href = ' href="' . $link_href . '"'; 608 609 if ( !empty( $link_title ) ) 610 $this->link_title = ' title="' . $link_title . '"'; 611 612 if ( !empty( $link_rel ) ) 613 $this->link_rel = ' rel="' . $link_rel . '"'; 614 615 if ( !empty( $link_class ) ) 616 $this->link_class = ' class="' . $link_class . '"'; 617 618 if ( !empty( $link_text ) ) 619 $this->link_text = $link_text; 620 621 // Build the button 622 $this->contents = '<div' . $this->wrapper_class . $this->wrapper_id . '>'; 623 $this->contents .= '<a'. $this->link_href . $this->link_title . $this->link_id . $this->link_rel . $this->link_class . '>' . $this->link_text . '</a>'; 624 $this->contents .= '</div>'; 625 626 // Allow button to be manipulated externally 627 $this->contents = apply_filters( 'bp_button_' . $component . '_' . $id, $this->contents, $this ); 628 } 629 630 /** 631 * contents() 632 * 633 * Return contents of button 634 * 635 * @return string 636 */ 637 function contents() { 638 return $this->contents; 639 } 640 641 /** 642 * display() 643 * 644 * Output contents of button 645 */ 646 function display() { 647 if ( !empty( $this->contents ) ) 648 echo $this->contents; 649 } 650 } 498 651 499 652 ?>
Note: See TracChangeset
for help on using the changeset viewer.