| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Admin |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Generates and displays a metabox tab that consists of collapsible sections. |
| 10 |
*/ |
| 11 |
class WPSEO_Metabox_Collapsibles_Sections extends WPSEO_Abstract_Metabox_Tab_With_Sections { |
| 12 |
|
| 13 |
/** |
| 14 |
* Holds the tab's collapsibles. |
| 15 |
* |
| 16 |
* @var WPSEO_Metabox_Collapsible[] |
| 17 |
*/ |
| 18 |
private $collapsibles = []; |
| 19 |
|
| 20 |
/** |
| 21 |
* Constructor. |
| 22 |
* |
| 23 |
* @param string $name The name of the section, used as an identifier in the html. |
| 24 |
* Can only contain URL safe characters. |
| 25 |
* @param string $link_content The text content of the section link. |
| 26 |
* @param array $collapsibles The metabox collapsibles (`WPSEO_Metabox_Collapsible[]`) to be included in the section. |
| 27 |
* @param array $options Optional link attributes. |
| 28 |
*/ |
| 29 |
public function __construct( $name, $link_content, array $collapsibles = [], array $options = [] ) { |
| 30 |
parent::__construct( $name, $link_content, $options ); |
| 31 |
|
| 32 |
$this->collapsibles = $collapsibles; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Outputs the section content if any tab has been added. |
| 37 |
* |
| 38 |
* @return void |
| 39 |
*/ |
| 40 |
public function display_content() { |
| 41 |
if ( $this->has_sections() ) { |
| 42 |
printf( '<div id="%1$s" class="wpseo-meta-section">', esc_attr( 'wpseo-meta-section-' . $this->name ) ); |
| 43 |
echo '<div class="wpseo_content_wrapper">'; |
| 44 |
|
| 45 |
add_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_forms' ] ); |
| 46 |
add_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_a11y' ] ); |
| 47 |
foreach ( $this->collapsibles as $collapsible ) { |
| 48 |
echo wp_kses_post( $collapsible->content() ); |
| 49 |
} |
| 50 |
remove_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_forms' ] ); |
| 51 |
remove_filter( 'wp_kses_allowed_html', [ 'WPSEO_Utils', 'extend_kses_post_with_a11y' ] ); |
| 52 |
|
| 53 |
echo '</div></div>'; |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Checks whether the tab has any sections. |
| 59 |
* |
| 60 |
* @return bool Whether the tab has any sections |
| 61 |
*/ |
| 62 |
protected function has_sections() { |
| 63 |
return ! empty( $this->collapsibles ); |
| 64 |
} |
| 65 |
} |
| 66 |
|