WordPress.org

Make WordPress Core

Ticket #31779: 31779.4.diff

File 31779.4.diff, 7.9 KB (added by adamsilverstein, 7 weeks ago)
  • src/wp-admin/admin-ajax.php

    diff --git src/wp-admin/admin-ajax.php src/wp-admin/admin-ajax.php
    index 4a18fcf714..b80e4aafe0 100644
    $core_actions_post = array( 
    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

    diff --git src/wp-admin/css/common.css src/wp-admin/css/common.css
    index d91e8a1368..2d64bca75e 100644
    img { 
    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

    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() { 
    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

    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( $ ) { 
    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' ); 
     50 
     51                if ( component.warning.length > 0 ) { 
     52                        $( 'body' ).addClass( 'modal-open' ); 
     53                        component.warning.on( 'click', '.notice-dismiss', component.dismissWarning ); 
     54                }; 
     55 
    4956 
    5057                if ( false !== component.codeEditor ) { 
    5158                        /* 
    wp.themePluginEditor = (function( $ ) { 
    6673                } ); 
    6774        }; 
    6875 
     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 
    6994        /** 
    7095         * Callback for when a change happens. 
    7196         * 
  • src/wp-admin/plugin-editor.php

    diff --git src/wp-admin/plugin-editor.php src/wp-admin/plugin-editor.php
    index 636e1cf739..b68fe12e9f 100644
    if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { 
    140140        $settings = array( 
    141141                'codeEditor' => wp_enqueue_code_editor( array( 'file' => $real_file ) ), 
    142142        ); 
     143        $warning_dismissed = get_user_meta( get_current_user_id(), 'plugins_edit_warning_dismissed' ); 
    143144        wp_enqueue_script( 'wp-theme-plugin-editor' ); 
    144145        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";' ) ); 
    145147 
    146148        require_once(ABSPATH . 'wp-admin/admin-header.php'); 
    147149 
    if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { 
    280282<br class="clear" /> 
    281283</div> 
    282284<?php 
     285$hide_notice = get_user_meta( get_current_user_id(), 'hide_plugin_editor_notice', true ); 
     286if ( 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&#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> 
     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 
     300endif; // editor warning notice 
    283301 
    284302include(ABSPATH . "wp-admin/admin-footer.php"); 
  • src/wp-admin/theme-editor.php

    diff --git src/wp-admin/theme-editor.php src/wp-admin/theme-editor.php
    index b49013ffd8..bbad318aa3 100644
    if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { 
    125125        $settings = array( 
    126126                'codeEditor' => wp_enqueue_code_editor( compact( 'file' ) ), 
    127127        ); 
     128        $warning_dismissed = get_user_meta( get_current_user_id(), 'themes_edit_warning_dismissed' ); 
    128129        wp_enqueue_script( 'wp-theme-plugin-editor' ); 
    129130        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";' ); 
    130132 
    131133        require_once( ABSPATH . 'wp-admin/admin-header.php' ); 
    132134 
    endif; // $error 
    309311<br class="clear" /> 
    310312</div> 
    311313<?php 
     314$hide_notice = get_user_meta( get_current_user_id(), 'hide_theme_editor_notice', true ); 
     315if ( 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&#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> 
     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 
     329endif; // editor warning notice 
    312330 
    313331include(ABSPATH . 'wp-admin/admin-footer.php' ); 
  • src/wp-includes/script-loader.php

    diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php
    index 1db13674be..2974a08686 100644
    function wp_default_scripts( &$scripts ) { 
    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