2008-01-05 00:40:47 +01:00
|
|
|
<?php
|
2008-09-17 02:40:10 +02:00
|
|
|
/**
|
|
|
|
* WordPress Widgets Administration API
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Administration
|
|
|
|
*/
|
2008-01-05 00:40:47 +01:00
|
|
|
|
2008-09-17 02:40:10 +02:00
|
|
|
/**
|
2009-04-11 16:37:24 +02:00
|
|
|
* Display list of the available widgets, either all or matching search.
|
2008-09-17 02:40:10 +02:00
|
|
|
*
|
2008-10-02 03:03:26 +02:00
|
|
|
* The search parameter are search terms separated by spaces.
|
|
|
|
*
|
2008-09-17 02:40:10 +02:00
|
|
|
* @since unknown
|
|
|
|
*
|
2008-10-02 03:03:26 +02:00
|
|
|
* @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.
|
2008-09-17 02:40:10 +02:00
|
|
|
*/
|
2009-04-22 03:06:15 +02:00
|
|
|
function wp_list_widgets() {
|
2008-03-18 00:25:05 +01:00
|
|
|
global $wp_registered_widgets, $sidebars_widgets, $wp_registered_widget_controls;
|
2009-04-11 16:37:24 +02:00
|
|
|
|
2009-05-10 08:56:27 +02:00
|
|
|
$sort = $wp_registered_widgets;
|
|
|
|
usort( $sort, create_function( '$a, $b', 'return strnatcasecmp( $a["name"], $b["name"] );' ) );
|
2009-05-24 17:46:09 +02:00
|
|
|
$done = array();
|
2008-01-05 00:40:47 +01:00
|
|
|
|
2009-05-10 08:56:27 +02:00
|
|
|
foreach ( $sort as $widget ) {
|
2009-05-03 07:27:13 +02:00
|
|
|
if ( in_array( $widget['callback'], $done, true ) ) // We already showed this multi-widget
|
2009-04-22 03:06:15 +02:00
|
|
|
continue;
|
2008-01-05 00:40:47 +01:00
|
|
|
|
2009-05-04 01:20:26 +02:00
|
|
|
$sidebar = is_active_widget( $widget['callback'], $widget['id'], false, false );
|
2009-05-03 07:27:13 +02:00
|
|
|
$done[] = $widget['callback'];
|
2008-02-28 01:31:46 +01:00
|
|
|
|
2009-04-22 03:06:15 +02:00
|
|
|
if ( ! isset( $widget['params'][0] ) )
|
|
|
|
$widget['params'][0] = array();
|
2008-01-05 00:40:47 +01:00
|
|
|
|
2009-04-22 03:06:15 +02:00
|
|
|
$args = array( 'widget_id' => $widget['id'], 'widget_name' => $widget['name'], '_display' => 'template' );
|
2008-01-05 00:40:47 +01:00
|
|
|
|
2009-04-22 03:06:15 +02:00
|
|
|
if ( isset($wp_registered_widget_controls[$widget['id']]['id_base']) && isset($widget['params'][0]['number']) ) {
|
|
|
|
$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';
|
2009-04-11 16:37:24 +02:00
|
|
|
}
|
2008-01-05 00:40:47 +01:00
|
|
|
|
2009-04-22 03:06:15 +02:00
|
|
|
$args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
|
|
|
|
call_user_func_array( 'wp_widget_control', $args );
|
2009-05-24 17:46:09 +02:00
|
|
|
}
|
2008-01-05 00:40:47 +01:00
|
|
|
}
|
|
|
|
|
2008-09-17 02:40:10 +02:00
|
|
|
/**
|
2009-11-19 10:12:16 +01:00
|
|
|
* Show the widgets and their settings for a sidebar.
|
|
|
|
* Used in the the admin widget config screen.
|
2008-09-17 02:40:10 +02:00
|
|
|
*
|
|
|
|
* @since unknown
|
|
|
|
*
|
2009-11-19 10:12:16 +01:00
|
|
|
* @param string $sidebar id slug of the sidebar
|
2008-09-17 02:40:10 +02:00
|
|
|
*/
|
2009-05-03 07:27:13 +02:00
|
|
|
function wp_list_widget_controls( $sidebar ) {
|
2008-03-11 00:23:32 +01:00
|
|
|
add_filter( 'dynamic_sidebar_params', 'wp_list_widget_controls_dynamic_sidebar' );
|
2008-01-05 00:40:47 +01:00
|
|
|
|
2009-11-19 10:12:16 +01:00
|
|
|
echo "<div id='$sidebar' class='widgets-sortables'>\n";
|
|
|
|
|
|
|
|
$description = wp_sidebar_description( $sidebar );
|
|
|
|
|
|
|
|
if ( !empty( $description ) ) {
|
|
|
|
echo "<div class='sidebar-description'>\n";
|
2010-01-15 23:11:12 +01:00
|
|
|
echo "\t<p class='description'>$description</p>";
|
2009-11-19 10:12:16 +01:00
|
|
|
echo "</div>\n";
|
|
|
|
}
|
|
|
|
|
2009-05-03 07:27:13 +02:00
|
|
|
dynamic_sidebar( $sidebar );
|
2009-11-19 10:12:16 +01:00
|
|
|
echo "</div>\n";
|
2008-01-05 00:40:47 +01:00
|
|
|
}
|
|
|
|
|
2008-09-17 02:40:10 +02:00
|
|
|
/**
|
|
|
|
* {@internal Missing Short Description}}
|
|
|
|
*
|
|
|
|
* @since unknown
|
|
|
|
*
|
2008-10-02 03:03:26 +02:00
|
|
|
* @param array $params
|
|
|
|
* @return array
|
2008-09-17 02:40:10 +02:00
|
|
|
*/
|
2008-03-11 00:23:32 +01:00
|
|
|
function wp_list_widget_controls_dynamic_sidebar( $params ) {
|
|
|
|
global $wp_registered_widgets;
|
|
|
|
static $i = 0;
|
|
|
|
$i++;
|
|
|
|
|
|
|
|
$widget_id = $params[0]['widget_id'];
|
2009-04-11 16:37:24 +02:00
|
|
|
$id = isset($params[0]['_temp_id']) ? $params[0]['_temp_id'] : $widget_id;
|
|
|
|
$hidden = isset($params[0]['_hide']) ? ' style="display:none;"' : '';
|
2008-03-11 00:23:32 +01:00
|
|
|
|
2009-05-03 07:27:13 +02:00
|
|
|
$params[0]['before_widget'] = "<div id='widget-${i}_$id' class='widget'$hidden>";
|
|
|
|
$params[0]['after_widget'] = "</div>";
|
2009-04-11 16:37:24 +02:00
|
|
|
$params[0]['before_title'] = "%BEG_OF_TITLE%"; // deprecated
|
|
|
|
$params[0]['after_title'] = "%END_OF_TITLE%"; // deprecated
|
2008-03-11 18:42:09 +01:00
|
|
|
if ( is_callable( $wp_registered_widgets[$widget_id]['callback'] ) ) {
|
2009-04-20 12:58:50 +02:00
|
|
|
$wp_registered_widgets[$widget_id]['_callback'] = $wp_registered_widgets[$widget_id]['callback'];
|
2008-03-11 18:42:09 +01:00
|
|
|
$wp_registered_widgets[$widget_id]['callback'] = 'wp_widget_control';
|
|
|
|
}
|
2009-04-11 16:37:24 +02:00
|
|
|
|
2008-03-11 00:23:32 +01:00
|
|
|
return $params;
|
|
|
|
}
|
|
|
|
|
2009-04-11 16:37:24 +02:00
|
|
|
function next_widget_id_number($id_base) {
|
|
|
|
global $wp_registered_widgets;
|
2009-06-16 01:57:52 +02:00
|
|
|
$number = 1;
|
2009-04-11 16:37:24 +02:00
|
|
|
|
2009-06-16 01:57:52 +02:00
|
|
|
foreach ( $wp_registered_widgets as $widget_id => $widget ) {
|
|
|
|
if ( preg_match( '/' . $id_base . '-([0-9]+)$/', $widget_id, $matches ) )
|
|
|
|
$number = max($number, $matches[1]);
|
|
|
|
}
|
|
|
|
$number++;
|
2009-04-11 16:37:24 +02:00
|
|
|
|
|
|
|
return $number;
|
|
|
|
}
|
|
|
|
|
2008-09-17 02:40:10 +02:00
|
|
|
/**
|
|
|
|
* Meta widget used to display the control form for a widget.
|
|
|
|
*
|
|
|
|
* Called from dynamic_sidebar().
|
|
|
|
*
|
|
|
|
* @since unknown
|
|
|
|
*
|
2008-10-02 03:03:26 +02:00
|
|
|
* @param array $sidebar_args
|
|
|
|
* @return array
|
2008-01-05 00:40:47 +01:00
|
|
|
*/
|
2008-03-11 00:23:32 +01:00
|
|
|
function wp_widget_control( $sidebar_args ) {
|
2009-04-11 16:37:24 +02:00
|
|
|
global $wp_registered_widgets, $wp_registered_widget_controls, $sidebars_widgets;
|
|
|
|
|
2008-03-11 00:23:32 +01:00
|
|
|
$widget_id = $sidebar_args['widget_id'];
|
|
|
|
$sidebar_id = isset($sidebar_args['id']) ? $sidebar_args['id'] : false;
|
2009-04-20 12:58:50 +02:00
|
|
|
$key = $sidebar_id ? array_search( $widget_id, $sidebars_widgets[$sidebar_id] ) : '-1'; // position of widget in sidebar
|
2009-04-11 16:37:24 +02:00
|
|
|
$control = isset($wp_registered_widget_controls[$widget_id]) ? $wp_registered_widget_controls[$widget_id] : array();
|
2009-04-20 12:58:50 +02:00
|
|
|
$widget = $wp_registered_widgets[$widget_id];
|
2008-01-05 00:40:47 +01:00
|
|
|
|
|
|
|
$id_format = $widget['id'];
|
2009-04-11 16:37:24 +02:00
|
|
|
$widget_number = isset($control['params'][0]['number']) ? $control['params'][0]['number'] : '';
|
|
|
|
$id_base = isset($control['id_base']) ? $control['id_base'] : $widget_id;
|
2009-04-13 03:17:59 +02:00
|
|
|
$multi_number = isset($sidebar_args['_multi_num']) ? $sidebar_args['_multi_num'] : '';
|
|
|
|
$add_new = isset($sidebar_args['_add']) ? $sidebar_args['_add'] : '';
|
2008-09-21 22:41:25 +02:00
|
|
|
|
2009-04-20 12:58:50 +02:00
|
|
|
$query_arg = array( 'editwidget' => $widget['id'] );
|
|
|
|
if ( $add_new ) {
|
|
|
|
$query_arg['addnew'] = 1;
|
|
|
|
if ( $multi_number ) {
|
|
|
|
$query_arg['num'] = $multi_number;
|
|
|
|
$query_arg['base'] = $id_base;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$query_arg['sidebar'] = $sidebar_id;
|
|
|
|
$query_arg['key'] = $key;
|
|
|
|
}
|
|
|
|
|
2008-03-11 00:23:32 +01:00
|
|
|
// We aren't showing a widget control, we're outputing a template for a mult-widget control
|
2009-04-11 16:37:24 +02:00
|
|
|
if ( isset($sidebar_args['_display']) && 'template' == $sidebar_args['_display'] && $widget_number ) {
|
|
|
|
// number == -1 implies a template where id numbers are replaced by a generic '__i__'
|
2008-01-05 00:40:47 +01:00
|
|
|
$control['params'][0]['number'] = -1;
|
2009-04-20 12:58:50 +02:00
|
|
|
// with id_base widget id's are constructed like {$id_base}-{$id_number}
|
2008-01-05 00:40:47 +01:00
|
|
|
if ( isset($control['id_base']) )
|
2009-04-11 16:37:24 +02:00
|
|
|
$id_format = $control['id_base'] . '-__i__';
|
2008-03-11 00:23:32 +01:00
|
|
|
}
|
2009-04-11 16:37:24 +02:00
|
|
|
|
2008-03-11 00:23:32 +01:00
|
|
|
$wp_registered_widgets[$widget_id]['callback'] = $wp_registered_widgets[$widget_id]['_callback'];
|
|
|
|
unset($wp_registered_widgets[$widget_id]['_callback']);
|
2008-01-05 00:40:47 +01:00
|
|
|
|
2009-05-18 17:11:07 +02:00
|
|
|
$widget_title = esc_html( strip_tags( $sidebar_args['widget_name'] ) );
|
2009-05-02 02:21:16 +02:00
|
|
|
$has_form = 'noform';
|
2008-04-17 22:36:59 +02:00
|
|
|
|
2009-04-11 16:37:24 +02:00
|
|
|
echo $sidebar_args['before_widget']; ?>
|
2009-04-20 12:58:50 +02:00
|
|
|
<div class="widget-top">
|
|
|
|
<div class="widget-title-action">
|
2009-05-03 07:27:13 +02:00
|
|
|
<a class="widget-action hide-if-no-js" href="#available-widgets"></a>
|
2009-05-18 18:00:33 +02:00
|
|
|
<a class="widget-control-edit hide-if-js" href="<?php echo esc_url( add_query_arg( $query_arg ) ); ?>"><span class="edit"><?php _e('Edit'); ?></span><span class="add"><?php _e('Add'); ?></span></a>
|
2009-04-20 12:58:50 +02:00
|
|
|
</div>
|
2009-05-10 02:49:48 +02:00
|
|
|
<div class="widget-title"><h4><?php echo $widget_title ?><span class="in-widget-title"></span></h4></div>
|
2009-04-20 12:58:50 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="widget-inside">
|
|
|
|
<form action="" method="post">
|
2009-05-31 13:34:08 +02:00
|
|
|
<div class="widget-content">
|
2009-04-11 16:37:24 +02:00
|
|
|
<?php
|
2009-04-20 12:58:50 +02:00
|
|
|
if ( isset($control['callback']) )
|
|
|
|
$has_form = call_user_func_array( $control['callback'], $control['params'] );
|
|
|
|
else
|
|
|
|
echo "\t\t<p>" . __('There are no options for this widget.') . "</p>\n"; ?>
|
2009-05-31 13:34:08 +02:00
|
|
|
</div>
|
2009-05-05 21:43:53 +02:00
|
|
|
<input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr($id_format); ?>" />
|
|
|
|
<input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr($id_base); ?>" />
|
2009-11-26 12:29:54 +01:00
|
|
|
<input type="hidden" name="widget-width" class="widget-width" value="<?php if (isset( $control['width'] )) echo esc_attr($control['width']); ?>" />
|
|
|
|
<input type="hidden" name="widget-height" class="widget-height" value="<?php if (isset( $control['height'] )) echo esc_attr($control['height']); ?>" />
|
2009-05-05 21:43:53 +02:00
|
|
|
<input type="hidden" name="widget_number" class="widget_number" value="<?php echo esc_attr($widget_number); ?>" />
|
|
|
|
<input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr($multi_number); ?>" />
|
|
|
|
<input type="hidden" name="add_new" class="add_new" value="<?php echo esc_attr($add_new); ?>" />
|
2009-04-20 12:58:50 +02:00
|
|
|
|
|
|
|
<div class="widget-control-actions">
|
2009-05-31 13:34:08 +02:00
|
|
|
<div class="alignleft">
|
2009-12-10 09:51:36 +01:00
|
|
|
<a class="widget-control-remove" href="#remove"><?php _e('Delete'); ?></a> |
|
2009-05-31 13:34:08 +02:00
|
|
|
<a class="widget-control-close" href="#close"><?php _e('Close'); ?></a>
|
|
|
|
</div>
|
2009-06-04 02:52:31 +02:00
|
|
|
<div class="alignright<?php if ( 'noform' === $has_form ) echo ' widget-control-noform'; ?>">
|
2010-05-03 20:16:22 +02:00
|
|
|
<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-feedback " title="" alt="" />
|
2010-10-28 23:56:43 +02:00
|
|
|
<?php submit_button( __( 'Save' ), 'button-primary widget-control-save', 'savewidget', false ); ?>
|
2009-05-31 13:34:08 +02:00
|
|
|
</div>
|
2009-04-20 12:58:50 +02:00
|
|
|
<br class="clear" />
|
|
|
|
</div>
|
|
|
|
</form>
|
2009-05-03 07:27:13 +02:00
|
|
|
</div>
|
2009-04-20 12:58:50 +02:00
|
|
|
|
|
|
|
<div class="widget-description">
|
2009-04-11 16:37:24 +02:00
|
|
|
<?php echo ( $widget_description = wp_widget_description($widget_id) ) ? "$widget_description\n" : "$widget_title\n"; ?>
|
2009-04-20 12:58:50 +02:00
|
|
|
</div>
|
2008-01-05 00:40:47 +01:00
|
|
|
<?php
|
2009-04-11 16:37:24 +02:00
|
|
|
echo $sidebar_args['after_widget'];
|
|
|
|
return $sidebar_args;
|
2008-01-05 00:40:47 +01:00
|
|
|
}
|
2008-06-09 19:36:39 +02:00
|
|
|
|