| 47 | | $r = bp_parse_args( |
| 48 | | (array) $arg, |
| 49 | | array( |
| 50 | | 'id' => '', |
| 51 | | 'position' => 99, |
| 52 | | 'component' => '', |
| 53 | | 'must_be_logged_in' => true, |
| 54 | | 'block_self' => false, |
| 55 | | 'parent_element' => false, |
| 56 | | 'parent_attr' => array(), |
| 57 | | 'button_element' => 'a', |
| 58 | | 'button_attr' => array(), |
| 59 | | 'link_text' => '', |
| 60 | | ), |
| 61 | | 'buttons_group_constructor' |
| 62 | | ); |
| 63 | | |
| 64 | | // Just don't set the button if a param is missing |
| 65 | | if ( empty( $r['id'] ) || empty( $r['component'] ) || empty( $r['link_text'] ) ) { |
| 66 | | continue; |
| 67 | | } |
| 68 | | |
| 69 | | $r['id'] = sanitize_key( $r['id'] ); |
| 70 | | |
| 71 | | // If the button already exist don't add it |
| 72 | | if ( isset( $this->group[ $r['id'] ] ) ) { |
| 73 | | continue; |
| 74 | | } |
| 75 | | |
| 76 | | /* |
| 77 | | * If, in bp_nouveau_get_*_buttons(), we pass through a false value for 'parent_element' |
| 78 | | * but we have attributtes for it in the array, let's default to setting a div. |
| 79 | | * |
| 80 | | * Otherwise, the original false value will be passed through to BP buttons. |
| 81 | | * @todo: this needs review, probably trying to be too clever |
| 82 | | */ |
| 83 | | if ( ( ! empty( $r['parent_attr'] ) ) && false === $r['parent_element'] ) { |
| 84 | | $r['parent_element'] = 'div'; |
| 85 | | } |
| 86 | | |
| 87 | | $this->group[ $r['id'] ] = $r; |
| | 47 | $this->add( $arg ); |
| | 140 | |
| | 141 | /** |
| | 142 | * Adds a button. |
| | 143 | * |
| | 144 | * @param array $args Optional array having the following parameters { |
| | 145 | * @type string $id A string to use as the unique ID for the button. Required. |
| | 146 | * @type int $position Where to insert the Button. Defaults to 99. |
| | 147 | * @type string $component The Component's the button is build for (eg: Activity, Groups..). Required. |
| | 148 | * @type bool $must_be_logged_in Whether the button should only be displayed to logged in users. Defaults to True. |
| | 149 | * @type bool $block_self Optional. True if the button should be hidden when a user is viewing his own profile. |
| | 150 | * Defaults to False. |
| | 151 | * @type string $parent_element Whether to use a wrapper. Defaults to false. |
| | 152 | * @type string $parent_attr set an array of attributes for the parent element. |
| | 153 | * @type string $button_element Set this to 'button', 'img', or 'a', defaults to anchor. |
| | 154 | * @type string $button_attr Any attributes required for the button_element |
| | 155 | * @type string $link_text The text of the link. Required. |
| | 156 | * } |
| | 157 | * |
| | 158 | * @return bool true on success, false on failure to add. |
| | 159 | */ |
| | 160 | private function add( $args ) { |
| | 161 | $r = bp_parse_args( |
| | 162 | (array) $args, |
| | 163 | array( |
| | 164 | 'id' => '', |
| | 165 | 'position' => 99, |
| | 166 | 'component' => '', |
| | 167 | 'must_be_logged_in' => true, |
| | 168 | 'block_self' => false, |
| | 169 | 'parent_element' => false, |
| | 170 | 'parent_attr' => array(), |
| | 171 | 'button_element' => 'a', |
| | 172 | 'button_attr' => array(), |
| | 173 | 'link_text' => '', |
| | 174 | ), |
| | 175 | 'buttons_group_constructor' |
| | 176 | ); |
| | 177 | |
| | 178 | // Just don't set the button if a param is missing |
| | 179 | if ( empty( $r['id'] ) || empty( $r['component'] ) || empty( $r['link_text'] ) ) { |
| | 180 | return false; |
| | 181 | } |
| | 182 | |
| | 183 | $r['id'] = sanitize_key( $r['id'] ); |
| | 184 | |
| | 185 | // If the button already exist don't add it |
| | 186 | if ( isset( $this->group[ $r['id'] ] ) ) { |
| | 187 | return false; |
| | 188 | } |
| | 189 | |
| | 190 | /* |
| | 191 | * If, in bp_nouveau_get_*_buttons(), we pass through a false value for 'parent_element' |
| | 192 | * but we have attributtes for it in the array, let's default to setting a div. |
| | 193 | * |
| | 194 | * Otherwise, the original false value will be passed through to BP buttons. |
| | 195 | * @todo: this needs review, probably trying to be too clever |
| | 196 | */ |
| | 197 | if ( ( ! empty( $r['parent_attr'] ) ) && false === $r['parent_element'] ) { |
| | 198 | $r['parent_element'] = 'div'; |
| | 199 | } |
| | 200 | |
| | 201 | $this->group[ $r['id'] ] = $r; |
| | 202 | return true; |
| | 203 | } |