22 | | * @type string $component The name of the component the button belongs to. |
23 | | * Default: 'core'. |
24 | | * @type bool $must_be_logged_in Optional. Does the user need to be logged |
25 | | * in to see this button? Default: true. |
26 | | * @type bool $block_self Optional. True if the button should be hidden |
27 | | * when a user is viewing his own profile. |
28 | | * Default: true. |
29 | | * @type string|bool $wrapper Optional. HTML element type that should wrap |
30 | | * the button: 'div', 'span', 'p', or 'li'. |
31 | | * False for no wrapper at all. Default: 'div'. |
32 | | * @type string $wrapper_id Optional. DOM ID of the button wrapper element. |
33 | | * Default: ''. |
34 | | * @type string $wrapper_class Optional. DOM class of the button wrapper |
35 | | * element. Default: ''. |
36 | | * @type string $link_href Optional. Destination link of the button. |
37 | | * Default: ''. |
38 | | * @type string $link_class Optional. DOM class of the button. Default: ''. |
39 | | * @type string $link_id Optional. DOM ID of the button. Default: ''. |
40 | | * @type string $link_rel Optional. DOM 'rel' attribute of the button. |
41 | | * Default: ''. |
42 | | * @type string $link_title Optional. Title attribute of the button. |
43 | | * Default: ''. |
44 | | * @type string $link_text Optional. Text to appear on the button. |
45 | | * Default: ''. |
| 25 | * @type string $component The name of the component the button belongs to. Default: 'core'. |
| 26 | * @type bool $must_be_logged_in Optional. Does the user need to be logged in to see this button? Default: |
| 27 | * true. |
| 28 | * @type bool $block_self Optional. True if the button should be hidden when a user is viewing his |
| 29 | * own profile. Default: true. |
| 30 | * @type string $parent_element Optional. Parent element to wrap button around. Default: 'div'. |
| 31 | * @type array $parent_attr Optional. Element attributes for parent element. Set whatever attributes |
| 32 | * like 'id', 'class' as array keys. |
| 33 | * @type string $button_element Optional. Button element. Default: 'a'. |
| 34 | * @type array $button_attr Optional. Button attributes. Set whatever attributes like 'id', 'class' as |
| 35 | * array keys. |
| 36 | * @type string $link_text Optional. Text to appear on the button. Default: ''. |
| 37 | * @type string|bool $wrapper Deprecated. Use $parent_element instead. |
| 38 | * @type string $wrapper_id Deprecated. Use $parent_attr and set 'id' as array key. |
| 39 | * @type string $wrapper_class Deprecated. Use $parent_attr and set 'class' as array key. |
| 40 | * @type string $link_href Deprecated. Use $button_attr and set 'href' as array key. |
| 41 | * @type string $link_class Deprecated. Use $button_attr and set 'class' as array key. |
| 42 | * @type string $link_id Deprecated. Use $button_attr and set 'id' as array key. |
| 43 | * @type string $link_rel Deprecated. Use $button_attr and set 'rel' as array key. |
| 44 | * @type string $link_title Deprecated. Use $button_attr and set 'title' as array key. |
| 82 | * Parent element to wrap button around. |
| 83 | * |
| 84 | * @since 2.7.0 |
| 85 | * |
| 86 | * @var string Default: 'div'. |
| 87 | */ |
| 88 | public $parent_element = 'div'; |
| 89 | |
| 90 | /** |
| 91 | * Element attributes for parent element. |
| 92 | * |
| 93 | * @since 2.7.0 |
| 94 | * |
| 95 | * @var array Set whatever attributes like 'id', 'class' as array key. |
| 96 | */ |
| 97 | public $parent_attr = array(); |
| 98 | |
| 99 | /** Button ****************************************************************/ |
| 100 | |
| 101 | /** |
| 102 | * Button element. |
| 103 | * |
| 104 | * @since 2.7.0 |
| 105 | * |
| 106 | * @var string Default: 'a'. |
| 107 | */ |
| 108 | public $button_element = 'a'; |
| 109 | |
| 110 | /** |
| 111 | * Button attributes. |
| 112 | * |
| 113 | * @since 2.7.0 |
| 114 | * |
| 115 | * @var array Set whatever attributes like 'id', 'href' as array key. |
| 116 | */ |
| 117 | public $button_attr = array(); |
| 118 | |
| 119 | /** |
| 120 | * The contents of the button link. |
| 121 | * |
| 122 | * @var string |
| 123 | */ |
| 124 | public $link_text = ''; |
| 125 | |
| 126 | /** HTML result |
| 127 | * |
| 128 | * @var string |
| 129 | */ |
| 130 | public $contents = ''; |
| 131 | |
| 132 | /** Deprecated ***********************************************************/ |
| 133 | |
| 134 | /** |
210 | | // Wrapper class. |
211 | | if ( !empty( $r['wrapper_class'] ) ) { |
212 | | $this->wrapper_class = ' class="generic-button ' . $r['wrapper_class'] . '"'; |
213 | | } else { |
214 | | $this->wrapper_class = ' class="generic-button"'; |
| 263 | // Always add 'generic-button' class. |
| 264 | if ( false === strpos( $r['parent_attr']['class'], 'generic-button' ) ) { |
| 265 | if ( ! empty( $r['parent_attr']['class'] ) ) { |
| 266 | $r['parent_attr']['class'] .= ' '; |
| 267 | } |
| 268 | $r['parent_attr']['class'] .= 'generic-button'; |
218 | | $before = '<' . $r['wrapper'] . $this->wrapper_class . $this->wrapper_id . '>'; |
219 | | $after = '</' . $r['wrapper'] . '>'; |
| 272 | $parent_attr = ''; |
| 273 | foreach( $r['parent_attr'] as $attr => $val ) { |
| 274 | $parent_attr .= sprintf( '%s="%s" ', sanitize_html_class( $attr ), esc_attr( $val ) ); |
| 275 | } |
| 276 | $before = sprintf( '<%1$s %2$s>', $parent_elem, $parent_attr ); |
| 277 | $after = sprintf( '</%s>', $parent_elem ); |
226 | | // Link properties. |
| 284 | // Button properties. |
| 285 | $button = ''; |
| 286 | $button_elem = sanitize_html_class( $r['button_element'] ); |
| 287 | if ( ! empty( $button_elem ) ) { |
| 288 | $button_attr = ''; |
| 289 | foreach( $r['button_attr'] as $attr => $val ) { |
| 290 | $button_attr .= sprintf( '%s="%s" ', sanitize_html_class( $attr ), esc_attr( $val ) ); |
| 291 | } |
| 292 | $button = sprintf( '<%1$s %2$s>%3$s</%1$s>', |
| 293 | $button_elem, |
| 294 | $button_attr, |
| 295 | ! empty( $r['link_text'] ) ? $r['link_text'] : '' |
| 296 | ); |
| 297 | } |
| 298 | |
| 299 | // Ugh... keep for backpat. |
250 | | $this->contents = apply_filters( 'bp_button_' . $this->component . '_' . $this->id, $this->contents, $this, $before, $after ); |
| 325 | $this->contents = apply_filters( 'bp_button_' . $this->component . '_' . $this->id, $this->contents, $this, $before, $after, $r ); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Provide backward compatibility for deprecated button arguments. |
| 330 | * |
| 331 | * @since 2.7.0. |
| 332 | * |
| 333 | * @param array $r See {@link BP_Button} class for full documentation. |
| 334 | * @return array |
| 335 | */ |
| 336 | protected function backward_compatibility_args( $r = array() ) { |
| 337 | // Array of deprecated arguments. |
| 338 | $backpat_args = array( |
| 339 | 'wrapper', 'wrapper_class', 'wrapper_id', |
| 340 | 'link_href', 'link_class', 'link_id', 'link_rel', 'link_title' |
| 341 | ); |
| 342 | |
| 343 | foreach ( $backpat_args as $prop ) { |
| 344 | if ( empty( $r[ $prop ] ) ) { |
| 345 | continue; |
| 346 | } |
| 347 | |
| 348 | $parent = $child = false; |
| 349 | $sep = strpos( $prop, '_' ); |
| 350 | |
| 351 | // Check if this is an attribute. |
| 352 | if ( false !== $sep ) { |
| 353 | $child = true; |
| 354 | $parent = substr( $prop, 0, $sep ); |
| 355 | } else { |
| 356 | $parent = $prop; |
| 357 | } |
| 358 | |
| 359 | if ( 'wrapper' === $parent ) { |
| 360 | $parent = 'parent'; |
| 361 | } else { |
| 362 | $parent = 'button'; |
| 363 | } |
| 364 | |
| 365 | // Set element. |
| 366 | if ( false === $child ) { |
| 367 | $r[ $parent . '_element' ] = $r[ $prop ]; |
| 368 | |
| 369 | // Set attributes. |
| 370 | } else { |
| 371 | $new_prop = substr( $prop, strpos( $prop, '_' ) +1 ); |
| 372 | if ( empty( $r[ "{$parent}_attr" ] ) ) { |
| 373 | $r[ "{$parent}_attr" ] = array(); |
| 374 | } |
| 375 | $r[ "{$parent}_attr" ][ $new_prop ] = $r[ $prop ]; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | return $r; |