Make WordPress Core

Ticket #31779: 31779.6.diff

File 31779.6.diff, 6.2 KB (added by westonruter, 7 years ago)

Re-use pointer dismissal API and add link to Custom CSS section in Customizer. Δ https://github.com/xwp/wordpress-develop/compare/92e0b6a...trac-31779

  • 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/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..69a72e3780 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.find( '.notice-dismiss' ).focus();
     54                        component.warning.on( 'click', '.notice-dismiss', component.dismissWarning );
     55                };
     56
    4957
    5058                if ( false !== component.codeEditor ) {
    5159                        /*
    wp.themePluginEditor = (function( $ ) { 
    6674                } );
    6775        };
    6876
     77        /**
     78         * Dismiss the warning modal.
     79         *
     80         * @since 4.9.0
     81         * @returns {void}
     82         */
     83        component.dismissWarning = function() {
     84
     85                wp.ajax.post( 'dismiss-wp-pointer', {
     86                        pointer: component.themeOrPlugin + '_editor_notice'
     87                });
     88
     89                // hide modal
     90                component.warning.remove();
     91                $( 'body' ).removeClass( 'modal-open' );
     92
     93                // return focus - is this a trap?
     94                component.instance.codemirror.focus();
     95        };
     96
    6997        /**
    7098         * Callback for when a change happens.
    7199         *
  • src/wp-admin/plugin-editor.php

    diff --git src/wp-admin/plugin-editor.php src/wp-admin/plugin-editor.php
    index 636e1cf739..42fa0fd74e 100644
    if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { 
    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
    if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { 
    280281<br class="clear" />
    281282</div>
    282283<?php
     284$dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
     285if ( ! in_array( 'plugin_editor_notice', $dismissed_pointers, true ) ) :
     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

    diff --git src/wp-admin/theme-editor.php src/wp-admin/theme-editor.php
    index b49013ffd8..fe17edd15b 100644
    if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { 
    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
    endif; // $error 
    309310<br class="clear" />
    310311</div>
    311312<?php
     313$dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
     314if ( ! in_array( 'theme_editor_notice', $dismissed_pointers, true ) ) :
     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>
     322                                <?php
     323                                echo sprintf(
     324                                        /* translators: %s is link to Custom CSS section in the Customizer. */
     325                                        __( '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 <a href="%s">built in CSS editor</a>.' ),
     326                                        esc_url( add_query_arg( 'autofocus[section]', 'custom_css', admin_url( 'customize.php' ) ) )
     327                                );
     328                                ?>
     329                        </p>
     330                        <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>
     331                </div>
     332                <button type="button" class="notice-dismiss"><span class="screen-reader-text"><?php _e( 'Dismiss' ); ?></span></button>
     333        </div>
     334</div>
     335<?php
     336endif; // editor warning notice
    312337
    313338include(ABSPATH . 'wp-admin/admin-footer.php' );