/** * Return a comma-delimited list of group types. * * @since 2.7.0 * * @param int $group_id Group ID. Defaults to current group ID if on a group page. * @param array|string $args { * Array of parameters. All items are optional. * @type string $parent_element Element to wrap around the list. Defaults to 'p'. * @type array $parent_attr Element attributes for parent element. Defaults to * array( 'class' => 'bp-group-type-list' ). * @type string $label Label to add before the list. Defaults to 'Group Types:'. * @type string $label_element Element to wrap around the label. Defaults to 'strong'. * @type array $label_attr Element attributes for label element. Defaults to array(). * @type bool $show_all Whether to show all registered group types. Defaults to 'false'. If * 'false', only shows group types with the 'show_in_list' parameter set to * true. See bp_groups_register_group_type() for more info. * } * @return string */ function bp_get_group_type_list($group_id = 0, $r = array()) { if (empty($group_id)) { $group_id = bp_get_current_group_id(); } $r = bp_parse_args($r, array('parent_element' => 'p', 'parent_attr' => array('class' => 'bp-group-type-list'), 'label' => __('Group Types:', 'buddypress'), 'label_element' => 'strong', 'label_attr' => array(), 'show_all' => false), 'group_type_list'); $retval = ''; if ($types = bp_groups_get_group_type($group_id, false)) { // Make sure we can show the type in the list. if (false === $r['show_all']) { $types = array_intersect(bp_groups_get_group_types(array('show_in_list' => true)), $types); if (empty($types)) { return $retval; } } $before = $after = $label = ''; // Render parent element. if (!empty($r['parent_element'])) { $parent_elem = new BP_Core_HTML_Element(array('element' => $r['parent_element'], 'attr' => $r['parent_attr'])); // Set before and after. $before = $parent_elem->get('open_tag'); $after = $parent_elem->get('close_tag'); } // Render label element. if (!empty($r['label_element'])) { $label = new BP_Core_HTML_Element(array('element' => $r['label_element'], 'attr' => $r['label_attr'], 'inner_html' => esc_html($r['label']))); $label = $label->contents() . ' '; // No element, just the label. } else { $label = esc_html($r['label']); } // Comma-delimit each type into the group type directory link. $label .= implode(', ', array_map('bp_get_group_type_directory_link', $types)); // Retval time! $retval = $before . $label . $after; } return $retval; }
/** * Builds the button based on class parameters. * * @since 1.2.6 * * @param array|string $args See {@BP_Button}. */ public function __construct($args = '') { $r = wp_parse_args($args, get_class_vars(__CLASS__)); // Backward compatibility with deprecated parameters. $r = $this->backward_compatibility_args($r); // Deprecated. Subject to removal in a future release. $this->wrapper = $r['wrapper']; 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']; } // Required button properties. $this->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']; // $id and $component are required and component must be active. if (empty($r['id']) || empty($r['component']) || !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; } // The block_self property. 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; } } // Should we use a parent element? if (!empty($r['parent_element'])) { if (!isset($r['parent_attr']['class'])) { $r['parent_attr']['class'] = ''; } // Always add 'generic-button' class. if (false === strpos($r['parent_attr']['class'], 'generic-button')) { if (!empty($r['parent_attr']['class'])) { $r['parent_attr']['class'] .= ' '; } $r['parent_attr']['class'] .= 'generic-button'; } // Render parent element attributes. $parent_elem = new BP_Core_HTML_Element(array('element' => $r['parent_element'], 'attr' => $r['parent_attr'])); // Set before and after. $before = $parent_elem->get('open_tag'); $after = $parent_elem->get('close_tag'); // No parent element. } else { $before = $after = ''; } // Button properties. $button = ''; if (!empty($r['button_element'])) { $button = new BP_Core_HTML_Element(array('element' => $r['button_element'], 'attr' => $r['button_attr'], 'inner_html' => !empty($r['link_text']) ? $r['link_text'] : '')); $button = $button->contents(); } // Build the button. $this->contents = $before . $button . $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 * @since 2.7.0 Added $r as a parameter. * * @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. * @param array $r Parsed button arguments. */ $this->contents = apply_filters('bp_button_' . $this->component . '_' . $this->id, $this->contents, $this, $before, $after, $r); }