Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
CRAP | n/a |
0 / 0 |
|
| wpcom_writing_features_moved_notice | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
12 | |||
| add_wpcom_writing_features_moved_script | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
2 | |||
| dismiss_wpcom_writing_features_moved_notice | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Handles notices regarding Simple site features that are "moved" to Jetpack after Atomic transfers. |
| 4 | * |
| 5 | * @package wpcomsh |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Displays a dismissible admin notice on 'options-writing.php' informing the user that some settings have moved |
| 10 | * to Jetpack Settings > Writing. |
| 11 | */ |
| 12 | function wpcom_writing_features_moved_notice() { |
| 13 | global $pagenow; |
| 14 | if ( 'options-writing.php' === $pagenow ) { |
| 15 | $has_dismissed = get_option( 'wpcom_writing_features_notice_dismissed' ); |
| 16 | if ( ! $has_dismissed ) { |
| 17 | $jetpack_settings_url = admin_url( 'admin.php?page=jetpack#/writing' ); |
| 18 | echo '<div class="notice notice-info is-dismissible" data-notice="options_writing"><p>' . |
| 19 | sprintf( |
| 20 | // Translators: %1$s: Start HTML link tag with the URL to Jetpack settings, %2$s: End HTML link tag. |
| 21 | esc_html__( 'Visit %1$sJetpack Settings%2$s for more writing settings powered by Jetpack.', 'wpcomsh' ), |
| 22 | '<a href="' . esc_url( $jetpack_settings_url ) . '">', |
| 23 | '</a>' |
| 24 | ) |
| 25 | . '</p></div>'; |
| 26 | add_action( 'admin_footer', 'add_wpcom_writing_features_moved_script' ); |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | add_action( 'admin_notices', 'wpcom_writing_features_moved_notice' ); |
| 31 | |
| 32 | /** |
| 33 | * Enqueues and outputs inline JavaScript in the admin footer for AJAX dismissal of notices. |
| 34 | */ |
| 35 | function add_wpcom_writing_features_moved_script() { |
| 36 | $ajax_nonce = wp_create_nonce( 'dismiss_wpcom_writing_features_moved_nonce' ); |
| 37 | ?> |
| 38 | <script> |
| 39 | document.addEventListener('DOMContentLoaded', function() { |
| 40 | document.addEventListener('click', function(event) { |
| 41 | if (event.target.closest('.notice[data-notice="options_writing"] .notice-dismiss')) { |
| 42 | wp.ajax.post('dismiss_wpcom_writing_features_moved_notice', { |
| 43 | nonce: <?php echo wp_json_encode( $ajax_nonce, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?> |
| 44 | }); |
| 45 | } |
| 46 | }); |
| 47 | }); |
| 48 | </script> |
| 49 | <?php |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Handles the AJAX request to dismiss the admin notice. |
| 54 | */ |
| 55 | function dismiss_wpcom_writing_features_moved_notice() { |
| 56 | check_ajax_referer( 'dismiss_wpcom_writing_features_moved_nonce', 'nonce' ); |
| 57 | update_option( 'wpcom_writing_features_notice_dismissed', true ); |
| 58 | wp_die(); |
| 59 | } |
| 60 | add_action( 'wp_ajax_dismiss_wpcom_writing_features_moved_notice', 'dismiss_wpcom_writing_features_moved_notice' ); |
| 61 |