Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
40.00% |
4 / 10 |
|
66.67% |
2 / 3 |
CRAP | n/a |
0 / 0 |
|
| wpcom_attachment_pages_settings_init | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| wpcom_attachment_pages_settings_display | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| wpcom_attachment_pages_setting_sanitization | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * WPCOM attachment pages settings. |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-wpcom |
| 6 | */ |
| 7 | |
| 8 | declare( strict_types = 1 ); |
| 9 | |
| 10 | /** |
| 11 | * Registers the attachment pages settings section, field, and the setting. |
| 12 | * |
| 13 | * @return void |
| 14 | */ |
| 15 | function wpcom_attachment_pages_settings_init() { |
| 16 | add_settings_section( 'wpcom_attachment_pages', esc_html__( 'Attachment pages', 'jetpack-mu-wpcom' ), function () {}, 'media' ); |
| 17 | add_settings_field( 'wp_attachment_pages_enabled', esc_html__( 'Attachment pages settings', 'jetpack-mu-wpcom' ), 'wpcom_attachment_pages_settings_display', 'media', 'wpcom_attachment_pages' ); |
| 18 | register_setting( 'media', 'wp_attachment_pages_enabled', array( 'sanitize_callback' => 'wpcom_attachment_pages_setting_sanitization' ) ); |
| 19 | } |
| 20 | |
| 21 | add_action( 'admin_init', 'wpcom_attachment_pages_settings_init', 11 ); |
| 22 | |
| 23 | /** |
| 24 | * Renders the attachment pages settings section. |
| 25 | * |
| 26 | * @return void |
| 27 | */ |
| 28 | function wpcom_attachment_pages_settings_display() { |
| 29 | printf( |
| 30 | '<label><input type="checkbox" name="wp_attachment_pages_enabled" id="wp_attachment_pages_enabled" value="1" %s/> <label for="wp_attachment_pages_enabled">%s</label>', |
| 31 | checked( '1', get_option( 'wp_attachment_pages_enabled' ), false ), |
| 32 | esc_html__( 'Enable attachment pages.', 'jetpack-mu-wpcom' ) |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Sanitizes the wp_attachment_pages option value. |
| 38 | * |
| 39 | * Turns the input value into either '1' or '0' based |
| 40 | * on the bool value of the input. |
| 41 | * |
| 42 | * @param string|null $value Value provided by the WordPress settings API. |
| 43 | * @return string '1' or '0'. |
| 44 | */ |
| 45 | function wpcom_attachment_pages_setting_sanitization( $value ) { |
| 46 | return $value ? '1' : '0'; |
| 47 | } |