| 1 |
<?php |
| 2 |
|
| 3 |
namespace ABlocks\admin; |
| 4 |
|
| 5 |
class Export { |
| 6 |
|
| 7 |
public static function init() { |
| 8 |
$self = new self(); |
| 9 |
add_action( 'rss2_head', [ $self, 'add_options_to_rss' ] ); |
| 10 |
add_action( 'export_filters', [ $self, 'add_patterns_radio' ] ); |
| 11 |
} |
| 12 |
|
| 13 |
/** |
| 14 |
* Add options to WXR. |
| 15 |
* |
| 16 |
* @return void |
| 17 |
*/ |
| 18 |
public function add_options_to_rss() { |
| 19 |
global $pagenow; |
| 20 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Don't need nonce verification here, we're just checking if content's value. |
| 21 |
if ( 'export.php' !== $pagenow || ! isset( $_GET['content'] ) || 'all' !== sanitize_text_field( wp_unslash( $_GET['content'] ) ) ) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
$options = array( |
| 26 |
'show_on_front' => get_option( 'show_on_front', 'posts' ), |
| 27 |
'page_on_front' => get_option( 'page_on_front', 0 ), |
| 28 |
'page_for_posts' => get_option( 'page_for_posts', 0 ), |
| 29 |
); |
| 30 |
|
| 31 |
$custom_data_xml = '<ablocks_options>'; |
| 32 |
foreach ( $options as $key => $value ) { |
| 33 |
$custom_data_xml .= sprintf( |
| 34 |
'<%1$s>%2$s</%1$s>', |
| 35 |
esc_xml( $key ), |
| 36 |
esc_xml( $value ) |
| 37 |
); |
| 38 |
} |
| 39 |
$custom_data_xml .= '</ablocks_options>'; |
| 40 |
|
| 41 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Want to put valid xml in RSS head. |
| 42 |
echo $custom_data_xml; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Display "Patterns" radio in export page. |
| 47 |
* |
| 48 |
* @return void |
| 49 |
*/ |
| 50 |
public function add_patterns_radio() { |
| 51 |
?> |
| 52 |
<p> |
| 53 |
<label> |
| 54 |
<input type="radio" name="content" value="wp_block" /> |
| 55 |
<?php esc_html_e( 'Patterns', 'ablocks' ); ?> |
| 56 |
</label> |
| 57 |
</p> |
| 58 |
<?php |
| 59 |
} |
| 60 |
|
| 61 |
} |
| 62 |
|