Remove remnants from widgets search, see #9511
git-svn-id: https://develop.svn.wordpress.org/trunk@11041 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
3c2fd1ca40
commit
e3830feb21
@ -16,78 +16,45 @@
|
|||||||
* @param string $show Optional, default is all. What to display, can be 'all', 'unused', or 'used'.
|
* @param string $show Optional, default is all. What to display, can be 'all', 'unused', or 'used'.
|
||||||
* @param string $_search Optional. Search for widgets. Should be unsanitized.
|
* @param string $_search Optional. Search for widgets. Should be unsanitized.
|
||||||
*/
|
*/
|
||||||
function wp_list_widgets( $show = 'all', $_search = false ) {
|
function wp_list_widgets() {
|
||||||
global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls;
|
global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls;
|
||||||
|
|
||||||
if ( $_search ) {
|
$no_widgets_shown = true;
|
||||||
// sanitize
|
$already_shown = array(); ?>
|
||||||
$search = preg_replace( '/[^\w\s]/', '', $_search );
|
|
||||||
// array of terms
|
|
||||||
$search_terms = preg_split( '/[\s]/', $search, -1, PREG_SPLIT_NO_EMPTY );
|
|
||||||
} else {
|
|
||||||
$search_terms = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !in_array( $show, array( 'all', 'unused', 'used' ) ) )
|
|
||||||
$show = 'all';
|
|
||||||
?>
|
|
||||||
|
|
||||||
<ul id="widget-list">
|
<ul id="widget-list">
|
||||||
<?php
|
<?php
|
||||||
$no_widgets_shown = true;
|
foreach ( $wp_registered_widgets as $name => $widget ) {
|
||||||
$already_shown = array();
|
if ( in_array( $widget['callback'], $already_shown ) ) // We already showed this multi-widget
|
||||||
foreach ( $wp_registered_widgets as $name => $widget ) {
|
continue;
|
||||||
if ( 'all' == $show && in_array( $widget['callback'], $already_shown ) ) // We already showed this multi-widget
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if ( $search_terms ) {
|
$sidebar = is_active_widget( $widget['callback'], $widget['id'] );
|
||||||
$hit = false;
|
|
||||||
// Simple case-insensitive search. Boolean OR.
|
|
||||||
$search_text = preg_replace( '/[^\w]/', '', $widget['name'] );
|
|
||||||
if ( isset($widget['description']) )
|
|
||||||
$search_text .= preg_replace( '/[^\w]/', '', $widget['description'] );
|
|
||||||
|
|
||||||
foreach ( $search_terms as $search_term ) {
|
if ( ! isset( $widget['params'][0] ) )
|
||||||
if ( stristr( $search_text, $search_term ) ) {
|
$widget['params'][0] = array();
|
||||||
$hit = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( !$hit )
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sidebar = is_active_widget( $widget['callback'], $widget['id'] );
|
$already_shown[] = $widget['callback'];
|
||||||
|
$no_widgets_shown = false;
|
||||||
|
|
||||||
if ( ( 'unused' == $show && $sidebar ) || ( 'used' == $show && !$sidebar ) )
|
$args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' );
|
||||||
continue;
|
|
||||||
|
|
||||||
if ( ! isset( $widget['params'][0] ) )
|
if ( isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number']) ) {
|
||||||
$widget['params'][0] = array();
|
$id_base = $wp_registered_widget_controls[$widget['id']]['id_base'];
|
||||||
|
$args['_temp_id'] = "$id_base-__i__";
|
||||||
$already_shown[] = $widget['callback'];
|
$args['_multi_num'] = next_widget_id_number($id_base);
|
||||||
$no_widgets_shown = false;
|
$args['_add'] = 'multi';
|
||||||
|
} else {
|
||||||
$args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' );
|
$args['_add'] = 'single';
|
||||||
|
if ( $sidebar )
|
||||||
if ( isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number']) ) {
|
$args['_hide'] = '1';
|
||||||
$id_base = $wp_registered_widget_controls[$widget['id']]['id_base'];
|
|
||||||
$args['_temp_id'] = "$id_base-__i__";
|
|
||||||
$args['_multi_num'] = next_widget_id_number($id_base);
|
|
||||||
$args['_add'] = 'multi';
|
|
||||||
} else {
|
|
||||||
$args['_add'] = 'single';
|
|
||||||
if ( $sidebar )
|
|
||||||
$args['_hide'] = '1';
|
|
||||||
}
|
|
||||||
|
|
||||||
$args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
|
|
||||||
call_user_func_array( 'wp_widget_control', $args );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $no_widgets_shown )
|
$args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
|
||||||
echo '<li>' . __( 'No matching widgets' ) . "</li>\n";
|
call_user_func_array( 'wp_widget_control', $args );
|
||||||
?>
|
}
|
||||||
|
|
||||||
|
if ( $no_widgets_shown )
|
||||||
|
echo '<li>' . __( 'No matching widgets' ) . "</li>\n"; ?>
|
||||||
</ul>
|
</ul>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
@ -311,20 +311,6 @@ if ( isset($_GET['editwidget']) && $_GET['editwidget'] ) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// Unsanitized!
|
|
||||||
$widget_search = isset($_GET['s']) ? $_GET['s'] : false;
|
|
||||||
|
|
||||||
// Not entirely sure what all should be here
|
|
||||||
$show_values = array(
|
|
||||||
'' => $widget_search ? __( 'Show any widgets' ) : __( 'Show all widgets' ),
|
|
||||||
'unused' => __( 'Show unused widgets' ),
|
|
||||||
'used' => __( 'Show used widgets' )
|
|
||||||
);
|
|
||||||
|
|
||||||
$show = isset($_GET['show']) && isset($show_values[$_GET['show']]) ? attribute_escape( $_GET['show'] ) : false;
|
|
||||||
*/
|
|
||||||
|
|
||||||
$messages = array(
|
$messages = array(
|
||||||
__('Changes saved.')
|
__('Changes saved.')
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user