From d9de76e2a7445516f3ec9634317098bf4a3802e7 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Tue, 5 Jul 2016 15:21:44 +0000 Subject: [PATCH] Dashboard: Don't add a "Configure" link to the toggle button. The HTML for the toggle gets appended to the widget name which is later used for the widget title and the screen reader text of the toggle button. Storing the original widget name in the arguments allows us to use the name without the HTML for the screen reader text and doesn't require further changes by plugin developers. Props nicholas_io, swissspidy. Fixes #35021. git-svn-id: https://develop.svn.wordpress.org/trunk@37972 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/dashboard.php | 8 ++++++++ src/wp-admin/includes/screen.php | 17 +++++++++++++---- src/wp-admin/includes/template.php | 10 +++++++++- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/wp-admin/includes/dashboard.php b/src/wp-admin/includes/dashboard.php index 98743939a3..ae40a94636 100644 --- a/src/wp-admin/includes/dashboard.php +++ b/src/wp-admin/includes/dashboard.php @@ -148,6 +148,14 @@ function wp_add_dashboard_widget( $widget_id, $widget_name, $callback, $control_ $screen = get_current_screen(); global $wp_dashboard_control_callbacks; + $private_callback_args = array( '__widget_basename' => $widget_name ); + + if ( is_null( $callback_args ) ) { + $callback_args = $private_callback_args; + } else if ( is_array( $callback_args ) ) { + $callback_args = array_merge( $callback_args, $private_callback_args ); + } + if ( $control_callback && current_user_can( 'edit_dashboard' ) && is_callable( $control_callback ) ) { $wp_dashboard_control_callbacks[$widget_id] = $control_callback; if ( isset( $_GET['edit'] ) && $widget_id == $_GET['edit'] ) { diff --git a/src/wp-admin/includes/screen.php b/src/wp-admin/includes/screen.php index 3c6a5131b9..1e57622003 100644 --- a/src/wp-admin/includes/screen.php +++ b/src/wp-admin/includes/screen.php @@ -117,10 +117,19 @@ function meta_box_prefs( $screen ) { // Submit box cannot be hidden if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) continue; - $box_id = $box['id']; - echo '\n"; + + $widget_title = $box['title']; + + if ( isset( $box['args']['__widget_basename'] ) ) { + $widget_title = $box['args']['__widget_basename']; + } + + printf( + '', + esc_attr( $box['id'] ), + checked( in_array( $box['id'], $hidden ), false, false ), + $widget_title + ); } } } diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php index cc590e3dfd..ef7621a02d 100644 --- a/src/wp-admin/includes/template.php +++ b/src/wp-admin/includes/template.php @@ -1027,8 +1027,16 @@ function do_meta_boxes( $screen, $context, $object ) { $hidden_class = in_array($box['id'], $hidden) ? ' hide-if-js' : ''; echo '
' . "\n"; if ( 'dashboard_browser_nag' != $box['id'] ) { + $widget_title = $box[ 'title' ]; + + if ( is_array( $box[ 'args' ] ) && isset( $box[ 'args' ][ '__widget_basename' ] ) ) { + $widget_title = esc_html( $box[ 'args' ][ '__widget_basename' ] ); + // Do not pass this parameter to the user callback function. + unset( $box[ 'args' ][ '__widget_basename' ] ); + } + echo ''; }