Make WordPress Core

Ticket #31779: 31779.5.diff

File 31779.5.diff, 7.7 KB (added by helen, 7 years ago)
  • src/wp-admin/admin-ajax.php

     
    6565        'generate-password', 'save-wporg-username', 'delete-plugin', 'search-plugins',
    6666        'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme', 'install-theme',
    6767        'get-post-thumbnail-html', 'get-community-events', 'edit-theme-plugin-file',
     68        'edit-theme-plugin-warning-dismissed',
    6869);
    6970
    7071// Deprecated
  • src/wp-admin/css/common.css

     
    31473147        line-height: 180%;
    31483148}
    31493149
     3150#file-editor-warning .file-editor-warning-content {
     3151        margin: 25px;
     3152}
     3153
    31503154/* @todo: can we use a common class for these? */
    31513155.nav-menus-php .item-edit:before,
    31523156.widget-top .widget-action .toggle-indicator:before,
  • src/wp-admin/includes/ajax-actions.php

     
    39893989                ) );
    39903990        }
    39913991}
     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 */
     3997function 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}
  • src/wp-admin/js/theme-plugin-editor.js

     
    4646                component.form.on( 'submit', component.submit );
    4747                component.textarea = component.form.find( '#newcontent' );
    4848                component.textarea.on( 'change', component.onChange );
     49                component.warning = $( '.file-editor-warning' );
    4950
     51                if ( component.warning.length > 0 ) {
     52                        $( 'body' ).addClass( 'modal-open' );
     53                        component.warning.find( '.notice-dismiss' ).focus();
     54                        component.warning.on( 'click', '.notice-dismiss', component.dismissWarning );
     55                };
     56
     57
    5058                if ( false !== component.codeEditor ) {
    5159                        /*
    5260                         * Defer adding notices until after DOM ready as workaround for WP Admin injecting
     
    6775        };
    6876
    6977        /**
     78         * Dismiss the warning modal.
     79         */
     80        component.dismissWarning = function() {
     81
     82                // update user meta
     83                var request = wp.ajax.post( 'edit-theme-plugin-warning-dismissed', {
     84                        _ajax_nonce: wp.themePluginEditor.nonce,
     85                        dismissed:   wp.themePluginEditor.themeOrPlugin
     86                } );
     87
     88                // hide modal
     89                component.warning.remove();
     90                $( 'body' ).removeClass( 'modal-open' );
     91
     92                // return focus - is this a trap?
     93                component.instance.codemirror.focus();
     94        }
     95
     96        /**
    7097         * Callback for when a change happens.
    7198         *
    7299         * @since 4.9.0
  • src/wp-admin/plugin-editor.php

     
    142142        );
    143143        wp_enqueue_script( 'wp-theme-plugin-editor' );
    144144        wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) );
     145        wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.themeOrPlugin = "plugin";' ) );
    145146
    146147        require_once(ABSPATH . 'wp-admin/admin-header.php');
    147148
     
    280281<br class="clear" />
    281282</div>
    282283<?php
     284$hide_notice = get_user_meta( get_current_user_id(), 'hide_plugin_editor_notice', true );
     285if ( empty( $hide_notice ) ) :
     286?>
     287<div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js">
     288        <div class="notification-dialog-background"></div>
     289        <div class="notification-dialog" role="dialog" aria-labelledby="file-editor-warning-title" tabindex="0">
     290                <div class="file-editor-warning-content">
     291                        <h1 id="file-editor-warning-title"><?php _e( 'Heads up!' ); ?></h1>
     292                        <p><?php _e( 'You appear to be making direct edits to your plugin in the WordPress dashboard. We recommend that you don&#8217;t! Editing plugins directly may introduce incompatibilities that break your site or even leave you staring at the dreaded &#8220;White Screen of Death&#8221;. Your changes may also be overwritten by future updates.' ); ?></p>
     293                        <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>
     294                </div>
     295                <button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php _e( 'Dismiss' ); ?></span></button>
     296        </div>
     297</div>
     298<?php
     299endif; // editor warning notice
    283300
    284301include(ABSPATH . "wp-admin/admin-footer.php");
  • src/wp-admin/theme-editor.php

     
    127127        );
    128128        wp_enqueue_script( 'wp-theme-plugin-editor' );
    129129        wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) );
     130        wp_add_inline_script( 'wp-theme-plugin-editor', 'wp.themePluginEditor.themeOrPlugin = "theme";' );
    130131
    131132        require_once( ABSPATH . 'wp-admin/admin-header.php' );
    132133
     
    309310<br class="clear" />
    310311</div>
    311312<?php
     313$hide_notice = get_user_meta( get_current_user_id(), 'hide_theme_editor_notice', true );
     314if ( empty( $hide_notice ) ) :
     315?>
     316<div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js">
     317        <div class="notification-dialog-background"></div>
     318        <div class="notification-dialog" role="dialog" aria-labelledby="file-editor-warning-title" tabindex="0">
     319                <div class="file-editor-warning-content">
     320                        <h1 id="file-editor-warning-title"><?php _e( 'Heads up!' ); ?></h1>
     321                        <p><?php _e( 'You appear to be making direct edits to your theme in the WordPress dashboard. We recommend that you don&#8217;t! Editing this code directly is dangerous, and can leave you unable to log back in to WordPress and undo changes. There’s no need to change your CSS here &mdash; you can edit and live preview CSS changes in WordPress&#8217;s built in CSS editor.' ); ?></p>
     322                        <p><?php _e( 'If you decide to go ahead with direct edits anyway, make sure to back up all your site&#8217;s files before making changes so you can restore a functional version if something goes wrong. Once dismissed, this notice will not appear again.' ); ?></p>
     323                </div>
     324                <button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php _e( 'Dismiss' ); ?></span></button>
     325        </div>
     326</div>
     327<?php
     328endif; // editor warning notice
    312329
    313330include(ABSPATH . 'wp-admin/admin-footer.php' );
  • src/wp-includes/script-loader.php

     
    478478                        array( 'singular', 'plural' )
    479479                ),
    480480        ) ) ) );
     481        did_action( 'init' ) && $scripts->add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.nonce = "%s";', wp_create_nonce( 'dismiss-notice' ) ) );
    481482
    482483        $scripts->add( 'wp-playlist', "/wp-includes/js/mediaelement/wp-playlist$suffix.js", array( 'wp-util', 'backbone', 'mediaelement' ), false, 1 );
    483484