Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 49 |
|
0.00% |
0 / 5 |
CRAP | n/a |
0 / 0 |
|
| wpcom_eo_register_settings | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| wpcom_eo_get_options_v1_api | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| wpcom_eo_update_options_v1_api | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| wpcom_eo_settings_page_init | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
6 | |||
| wpcom_legacy_contact_render | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Enhanced Ownership |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-wpcom |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Registers Enhanced Ownership settings. |
| 10 | */ |
| 11 | function wpcom_eo_register_settings() { |
| 12 | if ( ! wpcom_site_has_feature( WPCOM_Features::LEGACY_CONTACT ) ) { |
| 13 | return; |
| 14 | } |
| 15 | |
| 16 | register_setting( |
| 17 | 'general', |
| 18 | 'wpcom_legacy_contact', |
| 19 | array( |
| 20 | 'type' => 'string', |
| 21 | 'description' => 'The legacy contact for this site.', |
| 22 | 'show_in_rest' => true, |
| 23 | 'default' => '', |
| 24 | ) |
| 25 | ); |
| 26 | } |
| 27 | add_action( 'admin_init', 'wpcom_eo_register_settings' ); |
| 28 | add_action( 'rest_api_init', 'wpcom_eo_register_settings' ); |
| 29 | |
| 30 | /** |
| 31 | * Adds settings to the v1 API site settings endpoint. |
| 32 | * |
| 33 | * @param array $settings A single site's settings. |
| 34 | * @return array |
| 35 | */ |
| 36 | function wpcom_eo_get_options_v1_api( $settings ) { |
| 37 | if ( wpcom_site_has_feature( WPCOM_Features::LEGACY_CONTACT ) ) { |
| 38 | $settings['wpcom_legacy_contact'] = get_option( 'wpcom_legacy_contact' ); |
| 39 | } |
| 40 | |
| 41 | return $settings; |
| 42 | } |
| 43 | add_filter( 'site_settings_endpoint_get', 'wpcom_eo_get_options_v1_api' ); |
| 44 | |
| 45 | /** |
| 46 | * Updates settings via public-api.wordpress.com. |
| 47 | * |
| 48 | * @param array $input Associative array of site settings to be updated. |
| 49 | * Cast and filtered based on documentation. |
| 50 | * @param array $unfiltered_input Associative array of site settings to be updated. |
| 51 | * Neither cast nor filtered. Contains raw input. |
| 52 | * @return array |
| 53 | */ |
| 54 | function wpcom_eo_update_options_v1_api( $input, $unfiltered_input ) { |
| 55 | if ( isset( $unfiltered_input['wpcom_legacy_contact'] ) ) { |
| 56 | $input['wpcom_legacy_contact'] = sanitize_text_field( $unfiltered_input['wpcom_legacy_contact'] ); |
| 57 | } |
| 58 | |
| 59 | return $input; |
| 60 | } |
| 61 | add_filter( 'rest_api_update_site_settings', 'wpcom_eo_update_options_v1_api', 10, 2 ); |
| 62 | |
| 63 | /** |
| 64 | * Registers the settings section and fields. |
| 65 | */ |
| 66 | function wpcom_eo_settings_page_init() { |
| 67 | if ( ! wpcom_site_has_feature( WPCOM_Features::LEGACY_CONTACT ) ) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | add_settings_section( |
| 72 | 'wpcom_enhanced_ownership_section', |
| 73 | __( 'Enhanced Ownership', 'jetpack-mu-wpcom' ), |
| 74 | '', // No callback needed. |
| 75 | 'general' |
| 76 | ); |
| 77 | |
| 78 | add_settings_field( |
| 79 | 'wpcom_legacy_contact', |
| 80 | __( 'Legacy Contact', 'jetpack-mu-wpcom' ), |
| 81 | 'wpcom_legacy_contact_render', |
| 82 | 'general', |
| 83 | 'wpcom_enhanced_ownership_section', |
| 84 | array( |
| 85 | 'label_for' => 'wpcom_legacy_contact', |
| 86 | ) |
| 87 | ); |
| 88 | } |
| 89 | add_action( 'admin_init', 'wpcom_eo_settings_page_init' ); |
| 90 | |
| 91 | /** |
| 92 | * Renders the Legacy Contact settings markup. |
| 93 | */ |
| 94 | function wpcom_legacy_contact_render() { |
| 95 | ?> |
| 96 | <input type="text" id="wpcom_legacy_contact" class="regular-text" name="wpcom_legacy_contact" value="<?php echo esc_attr( get_option( 'wpcom_legacy_contact' ) ); ?>"> |
| 97 | <p class="description"><?php esc_html_e( 'Choose someone to look after your site when you pass away.', 'jetpack-mu-wpcom' ); ?></p> |
| 98 | <p class="description"> |
| 99 | <?php |
| 100 | printf( |
| 101 | /* translators: link to the help page: https://wordpress.com/help */ |
| 102 | esc_html__( 'To take ownership of the site, we ask that the person you designate contacts us at %s with a copy of the death certificate.', 'jetpack-mu-wpcom' ), |
| 103 | '<a href="https://wordpress.com/help">wordpress.com/help</a>' |
| 104 | ); |
| 105 | ?> |
| 106 | </p> |
| 107 | <?php |
| 108 | } |