Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/06/2012 04:45:50 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Buttons:

  • Clean up BP_Button class.
  • See r6311 for first pass.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-classes.php

    r6310 r6312  
    873873 * API to create BuddyPress buttons
    874874 *
     875 * component: Which component this button is for
     876 * must_be_logged_in: Button only appears for logged in users
     877 * block_self: Button will not appear when viewing your own profile.
     878 * wrapper: div|span|p|li|false for no wrapper
     879 * wrapper_id: The DOM ID of the button wrapper
     880 * wrapper_class: The DOM class of the button wrapper
     881 * link_href: The destination link of the button
     882 * link_title: Title of the button
     883 * link_id: The DOM ID of the button
     884 * link_class: The DOM class of the button
     885 * link_rel: The DOM rel of the button
     886 * link_text: The text of the button
     887 * contents: The contents of the button
     888 *
    875889 * @package BuddyPress Core
    876890 * @since BuddyPress (1.2.6)
     
    981995    public $contents = '';
    982996
    983     /**
    984      * Builds the button based on passed parameters:
    985      *
    986      * component: Which component this button is for
    987      * must_be_logged_in: Button only appears for logged in users
    988      * block_self: Button will not appear when viewing your own profile.
    989      * wrapper: div|span|p|li|false for no wrapper
    990      * wrapper_id: The DOM ID of the button wrapper
    991      * wrapper_class: The DOM class of the button wrapper
    992      * link_href: The destination link of the button
    993      * link_title: Title of the button
    994      * link_id: The DOM ID of the button
    995      * link_class: The DOM class of the button
    996      * link_rel: The DOM rel of the button
    997      * link_text: The contents of the button
     997    /** Methods ***************************************************************/
     998
     999    /**
     1000     * Builds the button based on class parameters:
     1001     *
     1002     * @since BuddyPress (1.2.6)
    9981003     *
    9991004     * @param array $args
     
    10031008
    10041009        $r = wp_parse_args( $args, get_class_vars( __CLASS__ ) );
    1005         extract( $r, EXTR_SKIP );
    10061010
    10071011        // Required button properties
    1008         $this->id                = $id;
    1009         $this->component         = $component;
    1010         $this->must_be_logged_in = (bool)$must_be_logged_in;
    1011         $this->block_self        = (bool)$block_self;
    1012         $this->wrapper           = $wrapper;
     1012        $this->id                = $r['id'];
     1013        $this->component         = $r['component'];
     1014        $this->must_be_logged_in = (bool) $r['must_be_logged_in'];
     1015        $this->block_self        = (bool) $r['block_self'];
     1016        $this->wrapper           = $r['wrapper'];
    10131017
    10141018        // $id and $component are required
    1015         if ( empty( $id ) || empty( $component ) )
     1019        if ( empty( $r['id'] ) || empty( $r['component'] ) )
    10161020            return false;
    10171021
    10181022        // No button if component is not active
    1019         if ( !bp_is_active( $this->component ) )
     1023        if ( ! bp_is_active( $this->component ) )
    10201024            return false;
    10211025
    10221026        // No button for guests if must be logged in
    1023         if ( true == $this->must_be_logged_in && !is_user_logged_in() )
     1027        if ( true == $this->must_be_logged_in && ! is_user_logged_in() )
    10241028            return false;
    10251029
     
    10321036
    10331037            // Wrapper ID
    1034             if ( !empty( $wrapper_id ) ) {
    1035                 $this->wrapper_id    = ' id="' . $wrapper_id . '"';
     1038            if ( !empty( $r['wrapper_id'] ) ) {
     1039                $this->wrapper_id    = ' id="' . $r['wrapper_id'] . '"';
    10361040            }
    10371041
    10381042            // Wrapper class
    1039             if ( !empty( $wrapper_class ) ) {
    1040                 $this->wrapper_class = ' class="generic-button ' . $wrapper_class . '"';
     1043            if ( !empty( $r['wrapper_class'] ) ) {
     1044                $this->wrapper_class = ' class="generic-button ' . $r['wrapper_class'] . '"';
    10411045            } else {
    10421046                $this->wrapper_class = ' class="generic-button"';
     
    10441048
    10451049            // Set before and after
    1046             $before = '<' . $wrapper . $this->wrapper_class . $this->wrapper_id . '>';
    1047             $after  = '</' . $wrapper . '>';
     1050            $before = '<' . $r['wrapper'] . $this->wrapper_class . $this->wrapper_id . '>';
     1051            $after  = '</' . $r['wrapper'] . '>';
    10481052
    10491053        // No wrapper
     
    10531057
    10541058        // Link properties
    1055         if ( !empty( $link_id ) )
    1056             $this->link_id    = ' id="' . $link_id . '"';
    1057 
    1058         if ( !empty( $link_href ) )
    1059             $this->link_href  = ' href="' . $link_href . '"';
    1060 
    1061         if ( !empty( $link_title ) )
    1062             $this->link_title = ' title="' . $link_title . '"';
    1063 
    1064         if ( !empty( $link_rel ) )
    1065             $this->link_rel   = ' rel="' . $link_rel . '"';
    1066 
    1067         if ( !empty( $link_class ) )
    1068             $this->link_class = ' class="' . $link_class . '"';
    1069 
    1070         if ( !empty( $link_text ) )
    1071             $this->link_text  = $link_text;
     1059        if ( !empty( $r['link_id']    ) ) $this->link_id    = ' id="' .    $r['link_id']    . '"';
     1060        if ( !empty( $r['link_href']  ) ) $this->link_href  = ' href="' .  $r['link_href']  . '"';
     1061        if ( !empty( $r['link_title'] ) ) $this->link_title = ' title="' . $r['link_title'] . '"';
     1062        if ( !empty( $r['link_rel']   ) ) $this->link_rel   = ' rel="' .   $r['link_rel']   . '"';
     1063        if ( !empty( $r['link_class'] ) ) $this->link_class = ' class="' . $r['link_class'] . '"';
     1064        if ( !empty( $r['link_text']  ) ) $this->link_text  =              $r['link_text'];
    10721065
    10731066        // Build the button
     
    10751068
    10761069        // Allow button to be manipulated externally
    1077         $this->contents = apply_filters( 'bp_button_' . $component . '_' . $id, $this->contents, $this, $before, $after );
     1070        $this->contents = apply_filters( 'bp_button_' . $this->component . '_' . $this->id, $this->contents, $this, $before, $after );
    10781071    }
    10791072
    10801073    /**
    10811074     * Return contents of button
     1075     *
     1076     * @since BuddyPress (1.2.6)
    10821077     *
    10831078     * @return string
     
    10891084    /**
    10901085     * Output contents of button
     1086     *
     1087     * @since BuddyPress (1.2.6)
    10911088     */
    10921089    public function display() {
Note: See TracChangeset for help on using the changeset viewer.