WordPress.org

Make WordPress Core


Ignore:
Timestamp:
03/27/2019 10:30:26 PM (12 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/includes/class-wp-debug-data.php

    r44986 r45044  
    882882
    883883    /**
    884      * Print the formatted variation of the information gathered for debugging, in a manner
    885      * suitable for a text area that can be instantly copied to a forum or support ticket.
     884     * Format the information gathered for debugging, in a manner suitable for copying to a forum or support ticket.
    886885     *
    887886     * @since 5.2.0
    888887     *
    889888     * @param array $info_array Information gathered from the `WP_Debug_Data::debug_data` function.
     889     * @param string $type      Optional. The data type to format the information as. Default 'text'.
     890     * @return string The formatted data.
    890891     */
    891     public static function textarea_format( $info_array ) {
    892         echo "`\n";
     892    public static function format( $info_array, $type = 'text' ) {
     893        $return = '';
    893894
    894895        foreach ( $info_array as $section => $details ) {
     
    898899            }
    899900
    900             printf(
     901            $return .= sprintf(
    901902                "### %s%s ###\n\n",
    902903                $details['label'],
     
    922923                }
    923924
    924                 printf(
     925                $return .= sprintf(
    925926                    "%s: %s\n",
    926927                    $field['label'],
     
    928929                );
    929930            }
    930             echo "\n";
    931         }
    932         echo '`';
     931            $return .= "\n";
     932        }
     933
     934        return $return;
    933935    }
    934936
Note: See TracChangeset for help on using the changeset viewer.