id = $r['id']; $this->component = $r['component']; $this->must_be_logged_in = (bool) $r['must_be_logged_in']; $this->block_self = (bool) $r['block_self']; $this->wrapper = $r['wrapper']; // $id and $component are required if ( empty( $r['id'] ) || empty( $r['component'] ) ) return false; // No button if component is not active if ( ! bp_is_active( $this->component ) ) return false; // No button for guests if must be logged in if ( true == $this->must_be_logged_in && ! is_user_logged_in() ) return false; // block_self if ( true == $this->block_self ) { // No button if you are the current user in a members loop // This condition takes precedence, because members loops // can be found on user profiles if ( bp_get_member_user_id() ) { if ( is_user_logged_in() && bp_loggedin_user_id() == bp_get_member_user_id() ) { return false; } // No button if viewing your own profile (and not in // a members loop) } elseif ( bp_is_my_profile() ) { return false; } } // Wrapper properties if ( false !== $this->wrapper ) { // Wrapper ID if ( !empty( $r['wrapper_id'] ) ) { $this->wrapper_id = ' id="' . $r['wrapper_id'] . '"'; } // Wrapper class if ( !empty( $r['wrapper_class'] ) ) { $this->wrapper_class = ' class="generic-button ' . $r['wrapper_class'] . '"'; } else { $this->wrapper_class = ' class="generic-button"'; } // Set before and after $before = '<' . $r['wrapper'] . $this->wrapper_class . $this->wrapper_id . '>'; $after = ''; // No wrapper } else { $before = $after = ''; } // Link properties if ( !empty( $r['link_id'] ) ) $this->link_id = ' id="' . $r['link_id'] . '"'; if ( !empty( $r['link_href'] ) ) $this->link_href = ' href="' . $r['link_href'] . '"'; if ( !empty( $r['link_title'] ) ) $this->link_title = ' title="' . $r['link_title'] . '"'; if ( !empty( $r['link_rel'] ) ) $this->link_rel = ' rel="' . $r['link_rel'] . '"'; if ( !empty( $r['link_class'] ) ) $this->link_class = ' class="' . $r['link_class'] . '"'; if ( !empty( $r['link_text'] ) ) $this->link_text = $r['link_text']; // Build the button $this->contents = $before . 'link_href . $this->link_title . $this->link_id . $this->link_rel . $this->link_class . '>' . $this->link_text . '' . $after; /** * Filters the button based on class parameters. * * This filter is a dynamic filter based on component and component ID and * allows button to be manipulated externally. * * @since 1.2.6 * * @param string $contents HTML being used for the button. * @param BP_Button $this Current BP_Button instance. * @param string $before HTML appended before the actual button. * @param string $after HTML appended after the actual button. */ $this->contents = apply_filters( 'bp_button_' . $this->component . '_' . $this->id, $this->contents, $this, $before, $after ); } /** * Return the markup for the generated button. * * @since 1.2.6 * * @return string Button markup. */ public function contents() { return $this->contents; } /** * Output the markup of button. * * @since 1.2.6 */ public function display() { if ( !empty( $this->contents ) ) echo $this->contents; } }