diff --git src/wp-admin/admin-ajax.php src/wp-admin/admin-ajax.php
index 4a18fcf714..b80e4aafe0 100644
|
|
$core_actions_post = array( |
65 | 65 | 'generate-password', 'save-wporg-username', 'delete-plugin', 'search-plugins', |
66 | 66 | 'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme', 'install-theme', |
67 | 67 | 'get-post-thumbnail-html', 'get-community-events', 'edit-theme-plugin-file', |
| 68 | 'edit-theme-plugin-warning-dismissed', |
68 | 69 | ); |
69 | 70 | |
70 | 71 | // Deprecated |
diff --git src/wp-admin/css/common.css src/wp-admin/css/common.css
index d91e8a1368..2d64bca75e 100644
|
|
img { |
3147 | 3147 | line-height: 180%; |
3148 | 3148 | } |
3149 | 3149 | |
| 3150 | #file-editor-warning .file-editor-warning-content { |
| 3151 | margin: 25px; |
| 3152 | } |
| 3153 | |
3150 | 3154 | /* @todo: can we use a common class for these? */ |
3151 | 3155 | .nav-menus-php .item-edit:before, |
3152 | 3156 | .widget-top .widget-action .toggle-indicator:before, |
diff --git src/wp-admin/includes/ajax-actions.php src/wp-admin/includes/ajax-actions.php
index 8dbd75c5a3..2d9f156125 100644
|
|
function wp_ajax_edit_theme_plugin_file() { |
3989 | 3989 | ) ); |
3990 | 3990 | } |
3991 | 3991 | } |
| 3992 | |
| 3993 | /** |
| 3994 | * Update user meta when a user dismisses the 'Heads Up' warning modal displayed when using |
| 3995 | * the plugin or theme editor for the first time. |
| 3996 | */ |
| 3997 | function wp_ajax_edit_theme_plugin_warning_dismissed() { |
| 3998 | check_ajax_referer( 'dismiss-notice' ); |
| 3999 | |
| 4000 | $dismissed = isset( $_POST['dismissed'] ) ? sanitize_text_field( $_POST['dismissed'] ) : 'themes'; |
| 4001 | update_user_meta( get_current_user_id(), 'hide_' . $dismissed . '_editor_notice', true ); |
| 4002 | wp_die( 1 ); |
| 4003 | } |
diff --git src/wp-admin/js/theme-plugin-editor.js src/wp-admin/js/theme-plugin-editor.js
index 3bb0788a6b..9b20579bff 100644
|
|
wp.themePluginEditor = (function( $ ) { |
46 | 46 | component.form.on( 'submit', component.submit ); |
47 | 47 | component.textarea = component.form.find( '#newcontent' ); |
48 | 48 | component.textarea.on( 'change', component.onChange ); |
| 49 | component.warning = $( '.file-editor-warning' ); |
| 50 | |
| 51 | if ( component.warning.length > 0 ) { |
| 52 | $( 'body' ).addClass( 'modal-open' ); |
| 53 | component.warning.on( 'click', '.notice-dismiss', component.dismissWarning ); |
| 54 | }; |
| 55 | |
49 | 56 | |
50 | 57 | if ( false !== component.codeEditor ) { |
51 | 58 | /* |
… |
… |
wp.themePluginEditor = (function( $ ) { |
66 | 73 | } ); |
67 | 74 | }; |
68 | 75 | |
| 76 | /** |
| 77 | * Dismiss the warning modal. |
| 78 | */ |
| 79 | component.dismissWarning = function() { |
| 80 | |
| 81 | // update user meta |
| 82 | var request = wp.ajax.post( 'edit-theme-plugin-warning-dismissed', { |
| 83 | _ajax_nonce: wp.themePluginEditor.nonce, |
| 84 | dismissed: wp.themePluginEditor.themeOrPlugin |
| 85 | } ); |
| 86 | |
| 87 | // hide modal |
| 88 | component.warning.remove(); |
| 89 | $( 'body' ).removeClass( 'modal-open' ); |
| 90 | |
| 91 | // return focus |
| 92 | } |
| 93 | |
69 | 94 | /** |
70 | 95 | * Callback for when a change happens. |
71 | 96 | * |
diff --git src/wp-admin/plugin-editor.php src/wp-admin/plugin-editor.php
index 636e1cf739..b68fe12e9f 100644
|
|
if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { |
140 | 140 | $settings = array( |
141 | 141 | 'codeEditor' => wp_enqueue_code_editor( array( 'file' => $real_file ) ), |
142 | 142 | ); |
| 143 | $warning_dismissed = get_user_meta( get_current_user_id(), 'plugins_edit_warning_dismissed' ); |
143 | 144 | wp_enqueue_script( 'wp-theme-plugin-editor' ); |
144 | 145 | wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) ); |
| 146 | wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.themeOrPlugin = "plugin";' ) ); |
145 | 147 | |
146 | 148 | require_once(ABSPATH . 'wp-admin/admin-header.php'); |
147 | 149 | |
… |
… |
if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { |
280 | 282 | <br class="clear" /> |
281 | 283 | </div> |
282 | 284 | <?php |
| 285 | $hide_notice = get_user_meta( get_current_user_id(), 'hide_plugin_editor_notice', true ); |
| 286 | if ( empty( $hide_notice ) ) : |
| 287 | ?> |
| 288 | <div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js"> |
| 289 | <div class="notification-dialog-background"></div> |
| 290 | <div class="notification-dialog" role="dialog" aria-labelledby="file-editor-warning-title" tabindex="0"> |
| 291 | <div class="file-editor-warning-content"> |
| 292 | <h1 id="file-editor-warning-title"><?php _e( 'Heads up!' ); ?></h1> |
| 293 | <p><?php _e( 'You appear to be making direct edits to your plugin in the WordPress dashboard. We recommend that you don’t! Editing plugins directly may introduce incompatibilities that break your site or even leave you staring at the dreaded “White Screen of Death”. Your changes may also be overwritten by future updates.' ); ?></p> |
| 294 | <p><?php _e( 'If you absolutely must edit a plugin this way, WordPress will attempt to prevent you from being locked out from the dashboard entirely, but cannot guarantee results. Once dismissed, this notice will not appear again.' ); ?></p> |
| 295 | </div> |
| 296 | <button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php _e( 'Dismiss' ); ?></span></button> |
| 297 | </div> |
| 298 | </div> |
| 299 | <?php |
| 300 | endif; // editor warning notice |
283 | 301 | |
284 | 302 | include(ABSPATH . "wp-admin/admin-footer.php"); |
diff --git src/wp-admin/theme-editor.php src/wp-admin/theme-editor.php
index b49013ffd8..bbad318aa3 100644
|
|
if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { |
125 | 125 | $settings = array( |
126 | 126 | 'codeEditor' => wp_enqueue_code_editor( compact( 'file' ) ), |
127 | 127 | ); |
| 128 | $warning_dismissed = get_user_meta( get_current_user_id(), 'themes_edit_warning_dismissed' ); |
128 | 129 | wp_enqueue_script( 'wp-theme-plugin-editor' ); |
129 | 130 | wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) ); |
| 131 | wp_add_inline_script( 'wp-theme-plugin-editor', 'wp.themePluginEditor.themeOrPlugin = "theme";' ); |
130 | 132 | |
131 | 133 | require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
132 | 134 | |
… |
… |
endif; // $error |
309 | 311 | <br class="clear" /> |
310 | 312 | </div> |
311 | 313 | <?php |
| 314 | $hide_notice = get_user_meta( get_current_user_id(), 'hide_theme_editor_notice', true ); |
| 315 | if ( empty( $hide_notice ) ) : |
| 316 | ?> |
| 317 | <div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js"> |
| 318 | <div class="notification-dialog-background"></div> |
| 319 | <div class="notification-dialog" role="dialog" aria-labelledby="file-editor-warning-title" tabindex="0"> |
| 320 | <div class="file-editor-warning-content"> |
| 321 | <h1 id="file-editor-warning-title"><?php _e( 'Heads up!' ); ?></h1> |
| 322 | <p><?php _e( 'You appear to be making direct edits to your plugin in the WordPress dashboard. We recommend that you don’t! Editing plugins directly may introduce incompatibilities that break your site or even leave you staring at the dreaded “White Screen of Death”. Your changes may also be overwritten by future updates.' ); ?></p> |
| 323 | <p><?php _e( 'If you absolutely must edit a plugin this way, WordPress will attempt to prevent you from being locked out from the dashboard entirely, but cannot guarantee results. Once dismissed, this notice will not appear again.' ); ?></p> |
| 324 | </div> |
| 325 | <button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php _e( 'Dismiss' ); ?></span></button> |
| 326 | </div> |
| 327 | </div> |
| 328 | <?php |
| 329 | endif; // editor warning notice |
312 | 330 | |
313 | 331 | include(ABSPATH . 'wp-admin/admin-footer.php' ); |
diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php
index 1db13674be..2974a08686 100644
|
|
function wp_default_scripts( &$scripts ) { |
478 | 478 | array( 'singular', 'plural' ) |
479 | 479 | ), |
480 | 480 | ) ) ) ); |
| 481 | did_action( 'init' ) && $scripts->add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.nonce = "%s";', wp_create_nonce( 'dismiss-notice' ) ) ); |
481 | 482 | |
482 | 483 | $scripts->add( 'wp-playlist', "/wp-includes/js/mediaelement/wp-playlist$suffix.js", array( 'wp-util', 'backbone', 'mediaelement' ), false, 1 ); |
483 | 484 | |