follow these instructions.' ); /* TODO: article on codex */; ?>
$control ) {
if ( in_array( $control['callback'], $already_done ) )
continue;
if ( is_callable( $control['callback'] ) ) {
call_user_func_array( $control['callback'], $control['params'] );
$control_output = ob_get_contents();
if ( false !== strpos( $control_output, '%i%' ) ) // if it's a multi-widget, only call control function once.
$already_done[] = $control['callback'];
}
ob_clean();
}
ob_end_clean();
// Prophylactic. Take out empty ids.
foreach ( (array) $_POST['widget-id'] as $key => $val )
if ( !$val )
unset($_POST['widget-id'][$key]);
// Reset the key numbering and stare
$new_sidebar = isset( $_POST['widget-id'] ) && is_array( $_POST['widget-id'] ) ? array_values( $_POST['widget-id'] ) : array();
$sidebars_widgets[$_POST['sidebar']] = $new_sidebar;
wp_set_sidebars_widgets( $sidebars_widgets );
wp_redirect( add_query_arg( 'message', 'updated' ) );
exit;
}
// What widget (if any) are we editing
$edit_widget = -1;
$query_args = array('add', 'remove', 'key', 'edit', '_wpnonce', 'message' );
if ( isset($_GET['add']) && $_GET['add'] ) {
// Add to the end of the sidebar
if ( isset($wp_registered_widgets[$_GET['add']]) ) {
check_admin_referer( "add-widget_$_GET[add]" );
$sidebars_widgets[$sidebar][] = $_GET['add'];
wp_set_sidebars_widgets( $sidebars_widgets );
}
wp_redirect( remove_query_arg( $query_args ) );
exit;
} elseif ( isset($_GET['remove']) && $_GET['remove'] && isset($_GET['key']) && is_numeric($_GET['key']) ) {
// Remove from sidebar the widget of type $_GET['remove'] and in position $_GET['key']
$key = (int) $_GET['key'];
if ( -1 < $key && ( $keys = array_keys($sidebars_widgets[$sidebar], $_GET['remove']) ) && in_array($key, $keys) ) {
check_admin_referer( "remove-widget_$_GET[remove]" );
unset($sidebars_widgets[$sidebar][$key]);
$sidebars_widgets[$sidebar] = array_values($sidebars_widgets[$sidebar]);
wp_set_sidebars_widgets( $sidebars_widgets );
}
wp_redirect( remove_query_arg( $query_args ) );
exit;
} elseif ( isset($_GET['edit']) && $_GET['edit'] && isset($_GET['key']) && is_numeric($_GET['key']) ) {
// Edit widget of type $_GET['edit'] and position $_GET['key']
$key = (int) $_GET['key'];
if ( -1 < $key && ( $keys = array_keys($sidebars_widgets[$sidebar], $_GET['edit']) ) && in_array($key, $keys) )
$edit_widget = $key;
}
// Total number of registered sidebars
$sidebar_widget_count = count($sidebars_widgets[$sidebar]);
// This is sort of lame since "widget" won't be converted to "widgets" in the JS
if ( 1 < $sidebars_count = count($wp_registered_sidebars) )
$sidebar_info_text = __ngettext( 'You are using %1$s widget in the "%2$s" sidebar.', 'You are using %1$s widgets in the "%2$s" sidebar.', $sidebar_widget_count );
else
$sidebar_info_text = __ngettext( 'You are using %1$s widget in the sidebar.', 'You are using %1$s widgets in the sidebar.', $sidebar_widget_count );
$sidebar_info_text = sprintf( wp_specialchars( $sidebar_info_text ), "