WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/27/2019 10:30:26 PM (13 months ago)
Author:
pento
Message:

Site Health: Improve the "Copy to clipboard" button.

The previous method for copying the debug report to the clipboard involved having a hidden <textarea>, but this shows up in screen readers and can't be reliably hidden.

To work around this, the button now uses the clipboard.js library, which automatically handles browser differences in the Clipboard API, and can load the text to copy from a data- attribute on the button.

Props pento, hedgefield, afercia.
Fixes #46647.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/site-health-info.php

    r45041 r45044  
    6262        WP_Debug_Data::check_for_updates();
    6363
    64         $info = WP_Debug_Data::debug_data();
     64        $info         = WP_Debug_Data::debug_data();
     65        $english_info = '';
     66        if ( 0 !== strpos( get_locale(), 'en' ) ) {
     67            $english_info = WP_Debug_Data::debug_data( 'en_US' );
     68        }
    6569        ?>
    6670
     
    7074
    7175        <p>
    72             <?php _e( 'You can export the information on this page so it can be easily copied and pasted in support requests such as on the WordPress.org forums, or shared with your website / theme / plugin developers.' ); ?>
     76            <?php _e( 'This page can show you every detail about the configuration of your WordPress website. If we see anything here that could be improved, we will let you know on the Site Status page.' ); ?>
     77        </p>
     78        <p>
     79            <?php _e( 'If you want to export a handy list of all the information on this page, you can use the button below to copy it to the clipboard. You can then paste it in a text file and save it to your harddrive, or paste it in an email exchange with a support engineer or theme/plugin developer for example.' ); ?>
    7380        </p>
    7481
    75         <div class="system-information-copy-wrapper">
    76             <textarea id="system-information-default-copy-field" readonly><?php WP_Debug_Data::textarea_format( $info ); ?></textarea>
    77 
    78             <?php
    79             if ( 0 !== strpos( get_locale(), 'en' ) ) :
    80 
    81                 $english_info = WP_Debug_Data::debug_data( 'en_US' );
    82                 ?>
    83                 <textarea id="system-information-english-copy-field" readonly><?php WP_Debug_Data::textarea_format( $english_info ); ?></textarea>
    84 
    85             <?php endif; ?>
    86 
     82        <div class="site-health-copy-buttons">
    8783            <div class="copy-button-wrapper">
    88                 <button type="button" class="button button-primary health-check-copy-field" data-copy-field="default"><?php _e( 'Copy to clipboard' ); ?></button>
    89                 <span class="copy-field-success" aria-hidden="true">Copied!</span>
     84                <button type="button" class="button button-primary copy-button" data-clipboard-text="<?php echo esc_attr( WP_Debug_Data::format( $info, 'text' ) ); ?>"><?php _e( 'Copy site info to clipboard' ); ?></button>
     85                <span class="success" aria-hidden="true">Copied!</span>
    9086            </div>
    91             <?php if ( 0 !== strpos( get_locale(), 'en' ) ) : ?>
     87            <?php if ( $english_info ) : ?>
    9288                <div class="copy-button-wrapper">
    93                     <button type="button" class="button health-check-copy-field" data-copy-field="english"><?php _e( 'Copy to clipboard (English)' ); ?></button>
    94                     <span class="copy-field-success" aria-hidden="true">Copied!</span>
     89                    <button type="button" class="button copy-button" data-clipboard-text="<?php echo esc_attr( WP_Debug_Data::format( $english_info, 'text' ) ); ?>"><?php _e( 'Copy site info to clipboard (English)' ); ?></button>
     90                    <span class="success" aria-hidden="true">Copied!</span>
    9591                </div>
    9692            <?php endif; ?>
Note: See TracChangeset for help on using the changeset viewer.