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 | /** |
| 219 | // Backward compatibility with deprecated parameters. |
| 220 | $r = $this->backward_compatibility_args( $r ); |
| 221 | |
| 222 | // Deprecated. Subject to removal in a future release. |
| 223 | $this->wrapper = $r['wrapper']; |
| 224 | if ( !empty( $r['link_id'] ) ) $this->link_id = ' id="' . $r['link_id'] . '"'; |
| 225 | if ( !empty( $r['link_href'] ) ) $this->link_href = ' href="' . $r['link_href'] . '"'; |
| 226 | if ( !empty( $r['link_title'] ) ) $this->link_title = ' title="' . $r['link_title'] . '"'; |
| 227 | if ( !empty( $r['link_rel'] ) ) $this->link_rel = ' rel="' . $r['link_rel'] . '"'; |
| 228 | if ( !empty( $r['link_class'] ) ) $this->link_class = ' class="' . $r['link_class'] . '"'; |
| 229 | if ( !empty( $r['link_text'] ) ) $this->link_text = $r['link_text']; |
| 230 | |
226 | | // Link properties. |
227 | | if ( !empty( $r['link_id'] ) ) $this->link_id = ' id="' . $r['link_id'] . '"'; |
228 | | if ( !empty( $r['link_href'] ) ) $this->link_href = ' href="' . $r['link_href'] . '"'; |
229 | | if ( !empty( $r['link_title'] ) ) $this->link_title = ' title="' . $r['link_title'] . '"'; |
230 | | if ( !empty( $r['link_rel'] ) ) $this->link_rel = ' rel="' . $r['link_rel'] . '"'; |
231 | | if ( !empty( $r['link_class'] ) ) $this->link_class = ' class="' . $r['link_class'] . '"'; |
232 | | if ( !empty( $r['link_text'] ) ) $this->link_text = $r['link_text']; |
| 296 | // Button properties. |
| 297 | $button = ''; |
| 298 | $button_elem = sanitize_html_class( $r['button_element'] ); |
| 299 | if ( ! empty( $button_elem ) ) { |
| 300 | // Render button attributes. |
| 301 | $button_attr = ''; |
| 302 | foreach( $r['button_attr'] as $attr => $val ) { |
| 303 | if ( 'href' === $attr || 'formaction' === $attr || 'src' === $attr ) { |
| 304 | $val = esc_url( $val ); |
| 305 | } else { |
| 306 | $val = esc_attr( $val ); |
| 307 | } |
| 308 | |
| 309 | $button_attr .= sprintf( '%s="%s" ', sanitize_html_class( $attr ), $val ); |
| 310 | } |
| 311 | |
| 312 | // <input> / <img> is self-closing. |
| 313 | if ( 'input' === $button_elem || 'img' === $button_elem ) { |
| 314 | $button = sprintf( '<%1$s %2$s />', |
| 315 | $button_elem, |
| 316 | $button_attr |
| 317 | ); |
| 318 | |
| 319 | // All other elements. |
| 320 | } else { |
| 321 | $button = sprintf( '<%1$s %2$s>%3$s</%1$s>', |
| 322 | $button_elem, |
| 323 | $button_attr, |
| 324 | ! empty( $r['link_text'] ) ? $r['link_text'] : '' |
| 325 | ); |
| 326 | } |
| 327 | } |
250 | | $this->contents = apply_filters( 'bp_button_' . $this->component . '_' . $this->id, $this->contents, $this, $before, $after ); |
| 347 | $this->contents = apply_filters( 'bp_button_' . $this->component . '_' . $this->id, $this->contents, $this, $before, $after, $r ); |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * Provide backward compatibility for deprecated button arguments. |
| 352 | * |
| 353 | * @since 2.7.0. |
| 354 | * |
| 355 | * @param array $r See {@link BP_Button} class for full documentation. |
| 356 | * @return array |
| 357 | */ |
| 358 | protected function backward_compatibility_args( $r = array() ) { |
| 359 | // Array of deprecated arguments. |
| 360 | $backpat_args = array( |
| 361 | 'wrapper', 'wrapper_class', 'wrapper_id', |
| 362 | 'link_href', 'link_class', 'link_id', 'link_rel', 'link_title' |
| 363 | ); |
| 364 | |
| 365 | foreach ( $backpat_args as $prop ) { |
| 366 | if ( empty( $r[ $prop ] ) ) { |
| 367 | continue; |
| 368 | } |
| 369 | |
| 370 | $parent = $child = false; |
| 371 | $sep = strpos( $prop, '_' ); |
| 372 | |
| 373 | // Check if this is an attribute. |
| 374 | if ( false !== $sep ) { |
| 375 | $child = true; |
| 376 | $parent = substr( $prop, 0, $sep ); |
| 377 | } else { |
| 378 | $parent = $prop; |
| 379 | } |
| 380 | |
| 381 | if ( 'wrapper' === $parent ) { |
| 382 | $parent = 'parent'; |
| 383 | } else { |
| 384 | $parent = 'button'; |
| 385 | } |
| 386 | |
| 387 | // Set element. |
| 388 | if ( false === $child ) { |
| 389 | $r[ $parent . '_element' ] = $r[ $prop ]; |
| 390 | |
| 391 | // Set attributes. |
| 392 | } else { |
| 393 | $new_prop = substr( $prop, strpos( $prop, '_' ) +1 ); |
| 394 | if ( empty( $r[ "{$parent}_attr" ] ) ) { |
| 395 | $r[ "{$parent}_attr" ] = array(); |
| 396 | } |
| 397 | $r[ "{$parent}_attr" ][ $new_prop ] = $r[ $prop ]; |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | return $r; |