Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 36 |
|
0.00% |
0 / 3 |
CRAP | n/a |
0 / 0 |
|
| wpcom_writing_features_moved_notice | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
30 | |||
| 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, or to My Jetpack › Features once settings consolidation is on. |
| 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 | $my_jetpack = 'Automattic\Jetpack\My_Jetpack\Initializer'; |
| 18 | // @phan-suppress-next-line PhanUndeclaredClassReference -- My Jetpack ships with the Jetpack plugin, at a version wpcomsh does not control. |
| 19 | if ( method_exists( $my_jetpack, 'is_settings_consolidation_enabled' ) && $my_jetpack::is_settings_consolidation_enabled() ) { |
| 20 | $url = admin_url( 'admin.php?page=my-jetpack#/features' ); |
| 21 | // Translators: %1$s: Start HTML link tag with the URL to My Jetpack's Features page, %2$s: End HTML link tag. |
| 22 | $message = __( 'Visit %1$sMy Jetpack › Features%2$s for more writing settings powered by Jetpack.', 'wpcomsh' ); |
| 23 | } else { |
| 24 | $url = admin_url( 'admin.php?page=jetpack#/writing' ); |
| 25 | // Translators: %1$s: Start HTML link tag with the URL to Jetpack settings, %2$s: End HTML link tag. |
| 26 | $message = __( 'Visit %1$sJetpack Settings%2$s for more writing settings powered by Jetpack.', 'wpcomsh' ); |
| 27 | } |
| 28 | echo '<div class="notice notice-info is-dismissible" data-notice="options_writing"><p>' . |
| 29 | sprintf( |
| 30 | esc_html( $message ), |
| 31 | '<a href="' . esc_url( $url ) . '">', |
| 32 | '</a>' |
| 33 | ) |
| 34 | . '</p></div>'; |
| 35 | add_action( 'admin_footer', 'add_wpcom_writing_features_moved_script' ); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | add_action( 'admin_notices', 'wpcom_writing_features_moved_notice' ); |
| 40 | |
| 41 | /** |
| 42 | * Enqueues and outputs inline JavaScript in the admin footer for AJAX dismissal of notices. |
| 43 | */ |
| 44 | function add_wpcom_writing_features_moved_script() { |
| 45 | $ajax_nonce = wp_create_nonce( 'dismiss_wpcom_writing_features_moved_nonce' ); |
| 46 | ?> |
| 47 | <script> |
| 48 | document.addEventListener('DOMContentLoaded', function() { |
| 49 | document.addEventListener('click', function(event) { |
| 50 | if (event.target.closest('.notice[data-notice="options_writing"] .notice-dismiss')) { |
| 51 | wp.ajax.post('dismiss_wpcom_writing_features_moved_notice', { |
| 52 | nonce: <?php echo wp_json_encode( $ajax_nonce, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ); ?> |
| 53 | }); |
| 54 | } |
| 55 | }); |
| 56 | }); |
| 57 | </script> |
| 58 | <?php |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Handles the AJAX request to dismiss the admin notice. |
| 63 | */ |
| 64 | function dismiss_wpcom_writing_features_moved_notice() { |
| 65 | check_ajax_referer( 'dismiss_wpcom_writing_features_moved_nonce', 'nonce' ); |
| 66 | update_option( 'wpcom_writing_features_notice_dismissed', true ); |
| 67 | wp_die(); |
| 68 | } |
| 69 | add_action( 'wp_ajax_dismiss_wpcom_writing_features_moved_notice', 'dismiss_wpcom_writing_features_moved_notice' ); |
| 70 |