diff --git a/Gruntfile.js b/Gruntfile.js
index f40fa336cf..c71fe02612 100644
a
|
b
|
module.exports = function(grunt) { |
166 | 166 | files: [ |
167 | 167 | { |
168 | 168 | [ WORKING_DIR + 'wp-includes/js/backbone.js' ]: [ './node_modules/backbone/backbone.js' ], |
| 169 | [ WORKING_DIR + 'wp-includes/js/clipboard.js' ]: [ './node_modules/clipboard/dist/clipboard.js' ], |
169 | 170 | [ WORKING_DIR + 'wp-includes/js/hoverIntent.js' ]: [ './node_modules/jquery-hoverintent/jquery.hoverIntent.js' ], |
170 | 171 | [ WORKING_DIR + 'wp-includes/js/imagesloaded.min.js' ]: [ './node_modules/imagesloaded/imagesloaded.pkgd.min.js' ], |
171 | 172 | [ WORKING_DIR + 'wp-includes/js/jquery/jquery-migrate.js' ]: [ './node_modules/jquery-migrate/dist/jquery-migrate.js' ], |
diff --git a/package.json b/package.json
index 2e4c7ead45..3f777bce1e 100644
a
|
b
|
|
94 | 94 | "@wordpress/viewport": "2.3.0", |
95 | 95 | "@wordpress/wordcount": "2.2.0", |
96 | 96 | "backbone": "1.3.3", |
| 97 | "clipboard": "2.0.4", |
97 | 98 | "element-closest": "^2.0.2", |
98 | 99 | "formdata-polyfill": "3.0.13", |
99 | 100 | "imagesloaded": "3.2.0", |
diff --git a/src/js/_enqueues/admin/site-health.js b/src/js/_enqueues/admin/site-health.js
index fba118bb78..8683acca77 100644
a
|
b
|
jQuery( document ).ready( function( $ ) { |
10 | 10 | |
11 | 11 | var data; |
12 | 12 | |
13 | | // Debug information copy section. |
14 | | $( '.health-check-copy-field' ).click( function( e ) { |
15 | | var $textarea = $( '#system-information-' + $( this ).data( 'copy-field' ) + '-copy-field' ), |
16 | | $wrapper = $( this ).closest( 'div' ); |
17 | | |
18 | | e.preventDefault(); |
19 | | |
20 | | $textarea.select(); |
| 13 | var clipboard = new ClipboardJS( '.site-health-copy-buttons .copy-button' ); |
21 | 14 | |
22 | | if ( document.execCommand( 'copy' ) ) { |
23 | | $( '.copy-field-success', $wrapper ).addClass( 'visible' ); |
24 | | $( this ).focus(); |
| 15 | // Debug information copy section. |
| 16 | clipboard.on( 'success', function( e ) { |
| 17 | var $wrapper = $( e.trigger ).closest( 'div' ); |
| 18 | $( '.success', $wrapper ).addClass( 'visible' ); |
25 | 19 | |
26 | | wp.a11y.speak( SiteHealth.string.site_info_copied ); |
27 | | } |
| 20 | wp.a11y.speak( SiteHealth.string.site_info_copied ); |
28 | 21 | } ); |
29 | 22 | |
30 | 23 | // Accordion handling in various areas. |
diff --git a/src/wp-admin/css/site-health.css b/src/wp-admin/css/site-health.css
index c12b52b019..82013d18b5 100644
a
|
b
|
body.site-health .spinner { |
206 | 206 | float: none; |
207 | 207 | } |
208 | 208 | |
209 | | body.site-health .system-information-copy-wrapper { |
| 209 | .site-health-copy-buttons { |
210 | 210 | display: block; |
211 | 211 | margin: 1rem 0; |
212 | 212 | } |
213 | 213 | |
214 | | body.site-health .system-information-copy-wrapper textarea { |
215 | | border: 0; |
216 | | padding: 0; |
217 | | margin: 0; |
218 | | position: absolute; |
219 | | left: -9999px; |
220 | | top: -9999px; |
221 | | } |
222 | | |
223 | | body.site-health .health-check-toggle-copy-section:hover { |
224 | | background: none; |
225 | | } |
226 | | |
227 | | body.site-health .system-information-copy-wrapper .copy-button-wrapper { |
| 214 | .site-health-copy-buttons .copy-button-wrapper { |
228 | 215 | margin: 0.5rem 0 1rem; |
229 | 216 | } |
230 | 217 | |
231 | | body.site-health .copy-field-success { |
| 218 | .site-health-copy-buttons .success { |
232 | 219 | display: none; |
233 | 220 | color: #40860a; |
234 | 221 | line-height: 1.8; |
235 | 222 | margin-left: 0.5rem; |
236 | 223 | } |
237 | 224 | |
238 | | body.site-health .copy-field-success.visible { |
| 225 | .site-health-copy-buttons .success.visible { |
239 | 226 | display: inline-block; |
240 | 227 | height: 28px; |
241 | 228 | line-height: 28px; |
diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php
index 6e82e0b672..a49ffc2922 100644
a
|
b
|
class WP_Debug_Data { |
881 | 881 | } |
882 | 882 | |
883 | 883 | /** |
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. |
886 | 885 | * |
887 | 886 | * @since 5.2.0 |
888 | 887 | * |
889 | 888 | * @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. |
890 | 891 | */ |
891 | | public static function textarea_format( $info_array ) { |
892 | | echo "`\n"; |
| 892 | public static function format( $info_array, $type = 'text' ) { |
| 893 | $return = ''; |
893 | 894 | |
894 | 895 | foreach ( $info_array as $section => $details ) { |
895 | 896 | // Skip this section if there are no fields, or the section has been declared as private. |
… |
… |
class WP_Debug_Data { |
897 | 898 | continue; |
898 | 899 | } |
899 | 900 | |
900 | | printf( |
| 901 | $return .= sprintf( |
901 | 902 | "### %s%s ###\n\n", |
902 | 903 | $details['label'], |
903 | 904 | ( isset( $details['show_count'] ) && $details['show_count'] ? sprintf( ' (%d)', count( $details['fields'] ) ) : '' ) |
… |
… |
class WP_Debug_Data { |
921 | 922 | } |
922 | 923 | } |
923 | 924 | |
924 | | printf( |
| 925 | $return .= sprintf( |
925 | 926 | "%s: %s\n", |
926 | 927 | $field['label'], |
927 | 928 | $values |
928 | 929 | ); |
929 | 930 | } |
930 | | echo "\n"; |
| 931 | $return .= "\n"; |
931 | 932 | } |
932 | | echo '`'; |
| 933 | |
| 934 | return $return; |
933 | 935 | } |
934 | 936 | |
935 | 937 | /** |
diff --git a/src/wp-admin/site-health-info.php b/src/wp-admin/site-health-info.php
index 164ff989c4..dbf4aa27ec 100644
a
|
b
|
require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
59 | 59 | <?php |
60 | 60 | WP_Debug_Data::check_for_updates(); |
61 | 61 | |
62 | | $info = WP_Debug_Data::debug_data(); |
| 62 | $info = WP_Debug_Data::debug_data(); |
| 63 | $english_info = ''; |
| 64 | if ( 0 !== strpos( get_locale(), 'en' ) ) { |
| 65 | $english_info = WP_Debug_Data::debug_data( 'en_US' ); |
| 66 | } |
63 | 67 | ?> |
64 | 68 | |
65 | 69 | <h2> |
… |
… |
require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
70 | 74 | <?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.' ); ?> |
71 | 75 | </p> |
72 | 76 | |
73 | | <div class="system-information-copy-wrapper"> |
74 | | <textarea id="system-information-default-copy-field" readonly><?php WP_Debug_Data::textarea_format( $info ); ?></textarea> |
75 | | |
76 | | <?php |
77 | | if ( 0 !== strpos( get_locale(), 'en' ) ) : |
78 | | |
79 | | $english_info = WP_Debug_Data::debug_data( 'en_US' ); |
80 | | ?> |
81 | | <textarea id="system-information-english-copy-field" readonly><?php WP_Debug_Data::textarea_format( $english_info ); ?></textarea> |
82 | | |
83 | | <?php endif; ?> |
84 | | |
| 77 | <div class="site-health-copy-buttons"> |
85 | 78 | <div class="copy-button-wrapper"> |
86 | | <button type="button" class="button button-primary health-check-copy-field" data-copy-field="default"><?php _e( 'Copy to clipboard' ); ?></button> |
87 | | <span class="copy-field-success" aria-hidden="true">Copied!</span> |
| 79 | <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 report to clipboard' ); ?></button> |
| 80 | <span class="success" aria-hidden="true">Copied!</span> |
88 | 81 | </div> |
89 | | <?php if ( 0 !== strpos( get_locale(), 'en' ) ) : ?> |
| 82 | <?php if ( $english_info ) : ?> |
90 | 83 | <div class="copy-button-wrapper"> |
91 | | <button type="button" class="button health-check-copy-field" data-copy-field="english"><?php _e( 'Copy to clipboard (English)' ); ?></button> |
92 | | <span class="copy-field-success" aria-hidden="true">Copied!</span> |
| 84 | <button type="button" class="button copy-button" data-clipboard-text="<?php echo esc_attr( WP_Debug_Data::format( $english_info, 'text' ) ); ?>"><?php _e( 'Copy report to clipboard (English)' ); ?></button> |
| 85 | <span class="success" aria-hidden="true">Copied!</span> |
93 | 86 | </div> |
94 | 87 | <?php endif; ?> |
95 | 88 | </div> |
diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php
index 5bba581d8f..3a3f57eded 100644
a
|
b
|
function wp_default_scripts( &$scripts ) { |
924 | 924 | |
925 | 925 | $scripts->add( 'editor', "/wp-admin/js/editor$suffix.js", array( 'utils', 'jquery' ), false, 1 ); |
926 | 926 | |
| 927 | $scripts->add( 'clipboard', "/wp-includes/js/clipboard$suffix.js", array(), false, 1 ); |
| 928 | |
927 | 929 | // Back-compat for old DFW. To-do: remove at the end of 2016. |
928 | 930 | $scripts->add( 'wp-fullscreen-stub', "/wp-admin/js/wp-fullscreen-stub$suffix.js", array(), false, 1 ); |
929 | 931 | |
… |
… |
function wp_default_scripts( &$scripts ) { |
1688 | 1690 | ) |
1689 | 1691 | ); |
1690 | 1692 | |
1691 | | $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ), false, 1 ); |
| 1693 | $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'clipboard', 'jquery', 'wp-util', 'wp-a11y' ), false, 1 ); |
1692 | 1694 | |
1693 | 1695 | $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y' ), false, 1 ); |
1694 | 1696 | did_action( 'init' ) && $scripts->localize( |