2007-04-23 21:05:17 -04:00
< ? php
2008-08-16 03:27:34 -04:00
/**
* Widgets administration panel .
*
* @ package WordPress
* @ subpackage Administration
*/
2007-04-23 21:05:17 -04:00
2008-08-16 03:27:34 -04:00
/** WordPress Administration Bootstrap */
2008-01-04 18:34:33 -05:00
require_once ( 'admin.php' );
2008-08-16 03:27:34 -04:00
/** WordPress Administration Widgets API */
2008-02-07 16:57:54 -05:00
require_once ( ABSPATH . 'wp-admin/includes/widgets.php' );
2007-04-23 21:05:17 -04:00
2007-05-19 19:44:37 -04:00
if ( ! current_user_can ( 'switch_themes' ) )
2007-05-04 13:52:22 -04:00
wp_die ( __ ( 'Cheatin’ uh?' ));
2009-04-11 10:37:24 -04:00
wp_enqueue_script ( 'admin-widgets' );
2008-05-21 20:06:41 -04:00
wp_admin_css ( 'widgets' );
2007-04-23 21:05:17 -04:00
2008-01-04 18:34:33 -05:00
do_action ( 'sidebar_admin_setup' );
2007-06-13 22:25:30 -04:00
2008-01-04 18:34:33 -05:00
$title = __ ( 'Widgets' );
$parent_file = 'themes.php' ;
2007-06-13 22:25:30 -04:00
2009-04-11 10:37:24 -04:00
// register the inactive_widgets area as sidebar
register_sidebar ( array (
'name' => '' ,
'id' => 'wp_inactive_widgets' ,
'before_widget' => '' ,
'after_widget' => '' ,
'before_title' => '' ,
'after_title' => '' ,
));
2007-04-23 21:05:17 -04:00
2008-01-04 18:34:33 -05:00
// These are the widgets grouped by sidebar
$sidebars_widgets = wp_get_sidebars_widgets ();
if ( empty ( $sidebars_widgets ) )
$sidebars_widgets = wp_get_widget_defaults ();
2007-06-13 22:25:30 -04:00
2009-04-13 21:17:57 -04:00
// look for "lost" widgets, this has to run at each theme change
2009-04-11 10:37:24 -04:00
function retrieve_widgets () {
global $wp_registered_widget_updates , $wp_registered_sidebars , $sidebars_widgets ;
2009-04-13 21:17:57 -04:00
$_sidebars_widgets = array ();
$sidebars = array_keys ( $wp_registered_sidebars );
$diff = array_diff ( array_keys ( $sidebars_widgets ), $sidebars );
if ( empty ( $diff ) )
return ;
unset ( $sidebars_widgets [ 'array_version' ] );
// Move the known-good ones first
foreach ( $sidebars as $id ) {
if ( array_key_exists ( $id , $sidebars_widgets ) ) {
$_sidebars_widgets [ $id ] = $sidebars_widgets [ $id ];
unset ( $sidebars_widgets [ $id ], $sidebars [ $id ]);
2009-02-23 01:12:53 -05:00
}
}
2007-06-13 22:25:30 -04:00
2009-04-13 21:17:57 -04:00
// Assign to each unmatched registered sidebar the first available orphan
while ( ( $sidebar = array_shift ( $sidebars ) ) && $widgets = array_shift ( $sidebars_widgets ) )
$_sidebars_widgets [ $sidebar ] = $widgets ;
// if new theme has less sidebars than the old theme
if ( ! empty ( $sidebars_widgets ) ) {
foreach ( $sidebars_widgets as $lost => $val ) {
if ( is_array ( $val ) )
$_sidebars_widgets [ 'wp_inactive_widgets' ] = array_merge ( ( array ) $_sidebars_widgets [ 'wp_inactive_widgets' ], $val );
}
}
$sidebars_widgets = $_sidebars_widgets ;
unset ( $_sidebars_widgets );
// find hidden/lost multi-widget instances
2009-04-11 10:37:24 -04:00
$shown_widgets = array ();
foreach ( $sidebars_widgets as $sidebar ) {
if ( is_array ( $sidebar ) )
$shown_widgets = array_merge ( $shown_widgets , $sidebar );
}
2008-01-04 18:34:33 -05:00
2009-04-11 10:37:24 -04:00
$all_widgets = array ();
foreach ( $wp_registered_widget_updates as $key => $val ) {
if ( isset ( $val [ 'id_base' ]) )
$all_widgets [] = $val [ 'id_base' ];
else
$all_widgets [] = $key ;
}
2007-04-23 21:05:17 -04:00
2009-04-11 10:37:24 -04:00
$all_widgets = array_unique ( $all_widgets );
$lost_widgets = array ();
foreach ( $all_widgets as $name ) {
$data = get_option ( str_replace ( '-' , '_' , " widget_ $name " ) );
if ( is_array ( $data ) ) {
foreach ( $data as $num => $value ) {
if ( ! is_numeric ( $num ) ) // skip single widgets, some don't delete their settings
continue ;
if ( is_array ( $value ) && ! in_array ( " $name - $num " , $shown_widgets , true ) )
$lost_widgets [] = " $name - $num " ;
2008-03-17 19:25:05 -04:00
}
}
}
2009-04-11 10:37:24 -04:00
$sidebars_widgets [ 'wp_inactive_widgets' ] = array_merge ( $lost_widgets , ( array ) $sidebars_widgets [ 'wp_inactive_widgets' ]);
2009-04-13 21:17:57 -04:00
$sidebars_widgets [ 'array_version' ] = 3 ;
2009-04-11 10:37:24 -04:00
wp_set_sidebars_widgets ( $sidebars_widgets );
2007-04-23 21:05:17 -04:00
}
2009-04-11 10:37:24 -04:00
retrieve_widgets ();
2007-04-23 21:05:17 -04:00
2009-04-11 10:37:24 -04:00
if ( count ( $wp_registered_sidebars ) == 1 ) {
// If only the "wp_inactive_widgets" is defined the theme has no sidebars, die.
require_once ( 'admin-header.php' );
?>
2007-06-13 22:25:30 -04:00
2009-04-11 10:37:24 -04:00
< div class = " wrap " >
< ? php screen_icon (); ?>
< h2 >< ? php echo wp_specialchars ( $title ); ?> </h2>
< div class = " error " >
< p >< ? php _e ( 'No Sidebars Defined' ); ?> </p>
</ div >
< p >< ? php _e ( 'The theme you are currently using isn’t widget-aware, meaning that it has no sidebars that you are able to change. For information on making your theme widget-aware, please <a href="http://codex.wordpress.org/Widgetizing_Themes">follow these instructions</a>.' ); ?> </p>
</ div >
2007-06-13 22:25:30 -04:00
2009-04-11 10:37:24 -04:00
< ? php
require_once ( 'admin-footer.php' );
exit ;
}
2007-06-13 22:25:30 -04:00
2009-04-11 10:37:24 -04:00
/*
2008-01-04 18:34:33 -05:00
// Unsanitized!
$widget_search = isset ( $_GET [ 's' ]) ? $_GET [ 's' ] : false ;
2007-06-13 22:25:30 -04:00
2008-01-04 18:34:33 -05:00
// 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' )
);
2009-04-11 10:37:24 -04:00
*/
2007-04-23 21:05:17 -04:00
2008-01-04 18:34:33 -05:00
$show = isset ( $_GET [ 'show' ]) && isset ( $show_values [ $_GET [ 'show' ]]) ? attribute_escape ( $_GET [ 'show' ] ) : false ;
2007-04-23 21:05:17 -04:00
2008-01-04 18:34:33 -05:00
$messages = array (
'updated' => __ ( 'Changes saved.' )
);
2007-06-13 22:25:30 -04:00
2008-09-11 14:54:05 -04:00
require_once ( 'admin-header.php' ); ?>
2007-06-13 22:25:30 -04:00
2008-01-04 18:34:33 -05:00
< div class = " wrap " >
2008-11-26 08:51:25 -05:00
< ? php screen_icon (); ?>
2008-12-09 13:03:31 -05:00
< h2 >< ? php echo wp_specialchars ( $title ); ?> </h2>
2007-04-23 21:05:17 -04:00
2009-04-12 21:17:59 -04:00
< ? php if ( isset ( $_GET [ 'message' ]) && isset ( $messages [ $_GET [ 'message' ]]) ) : ?>
< div id = " message " class = " updated fade " >< p >< ? php echo $messages [ $_GET [ 'message' ]]; ?> </p></div>
< ? php endif ; ?>
2009-04-11 10:37:24 -04:00
<!--
2008-01-04 18:34:33 -05:00
< form id = " widgets-filter " action = " " method = " get " >
2007-04-23 21:05:17 -04:00
2008-01-04 18:34:33 -05:00
< div class = " widget-liquid-left-holder " >
< div id = " available-widgets-filter " class = " widget-liquid-left " >
2008-05-04 06:37:06 -04:00
< h3 >< label for = " show " >< ? php _e ( 'Available Widgets' ); ?> </label></h3>
2008-02-07 16:57:54 -05:00
< div class = " nav " >
2008-05-04 06:37:06 -04:00
< select name = " show " id = " show " >
2009-04-11 10:37:24 -04:00
< ? php //foreach ( $show_values as $show_value => $show_text ) : $show_value = attribute_escape( $show_value ); ?>
< option value = '<?php //echo $show_value; ?>' < ? php //selected( $show_value, $show ); ?>><?php //echo wp_specialchars( $show_text ); ?></option>
< ? php //endforeach; ?>
2008-01-04 18:34:33 -05:00
</ select >
2008-02-20 19:27:23 -05:00
< input type = " submit " value = " <?php _e('Show' ); ?> " class = " button-secondary " />
2008-02-07 16:57:54 -05:00
< p class = " pagenav " >
2009-04-11 10:37:24 -04:00
< ? php // echo $page_links; ?>
2008-02-07 16:57:54 -05:00
</ p >
</ div >
2008-01-04 18:34:33 -05:00
</ div >
2007-04-23 21:05:17 -04:00
</ div >
2007-06-13 22:25:30 -04:00
2008-01-04 18:34:33 -05:00
< div id = " available-sidebars " class = " widget-liquid-right " >
2008-05-04 06:37:06 -04:00
< h3 >< label for = " sidebar-selector " >< ? php _e ( 'Current Widgets' ); ?> </label></h3>
2008-01-04 18:34:33 -05:00
2008-02-07 16:57:54 -05:00
< div class = " nav " >
2008-01-04 18:34:33 -05:00
< select id = " sidebar-selector " name = " sidebar " >
2009-04-11 10:37:24 -04:00
< ? php //foreach ( $wp_registered_sidebars as $sidebar_id => $registered_sidebar ) : $sidebar_id = attribute_escape( $sidebar_id ); ?>
< option value = '<?php //echo $sidebar_id; ?>' < ? php selected ( $sidebar_id , $open_sidebar ); ?> ><?php //echo wp_specialchars( $registered_sidebar['name'] ); ?></option>
< ? php //endforeach; ?>
2008-01-04 18:34:33 -05:00
</ select >
2008-02-20 19:27:23 -05:00
< input type = " submit " value = " <?php _e('Show' ); ?> " class = " button-secondary " />
2008-02-07 16:57:54 -05:00
</ div >
2008-01-04 18:34:33 -05:00
</ div >
</ form >
2009-04-11 10:37:24 -04:00
-->
< div class = " widget-liquid-left " >
< div id = " widgets-left " >
< div id = " available-widgets " class = " widgets-holder-wrap " >
< h3 class = " sidebar-name " >< ? php _e ( 'Available Widgets' ); ?> </h3>
< ? php wp_list_widgets (); ?>
< br class = " clear " />
</ div >
2008-01-04 18:34:33 -05:00
2009-04-11 10:37:24 -04:00
< div id = " wp_inactive_widgets " class = " widgets-holder-wrap " >
< h3 class = " sidebar-name " >< ? php _e ( 'Inactive Widgets' ); ?>
< span >< img src = " images/loading-publish.gif " class = " ajax-feedback " title = " " alt = " " /></ span ></ h3 >
< ? php wp_list_widget_controls ( 'wp_inactive_widgets' ); ?>
< br class = " clear " />
2008-01-04 18:34:33 -05:00
</ div >
2007-04-23 21:05:17 -04:00
</ div >
2009-04-11 10:37:24 -04:00
</ div >
2007-06-13 22:25:30 -04:00
2009-04-11 10:37:24 -04:00
<!--
2008-01-04 18:34:33 -05:00
< div id = " current-widgets-head " class = " widget-liquid-right " >
< div id = " sidebar-info " >
2009-04-11 10:37:24 -04:00
< p >< ? php //echo $sidebar_info_text; ?></p>
2008-01-04 18:34:33 -05:00
< p >< ? php _e ( 'Add more from the Available Widgets section.' ); ?> </p>
</ div >
</ div >
2009-04-11 10:37:24 -04:00
-->
2008-01-04 18:34:33 -05:00
2009-04-11 10:37:24 -04:00
< div class = " widget-liquid-right " >
< ? php
$i = 0 ;
foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) {
if ( 'wp_inactive_widgets' == $sidebar )
continue ;
?>
< div id = " <?php echo attribute_escape( $sidebar ); ?> " class = " widgets-holder-wrap " >
< h3 class = " sidebar-name " >< ? php echo wp_specialchars ( $registered_sidebar [ 'name' ] ); ?>
< span >< img src = " images/loading-publish.gif " class = " ajax-feedback " title = " " alt = " " /></ span ></ h3 >
< ? php wp_list_widget_controls ( $sidebar , $i ); // Show the control forms for each of the widgets in this sidebar ?>
2008-01-04 18:34:33 -05:00
</ div >
2008-03-17 19:25:05 -04:00
< ? php
2009-04-11 10:37:24 -04:00
$i ++ ;
} ?>
2008-03-10 01:19:12 -04:00
</ div >
2009-04-11 10:37:24 -04:00
< form action = " " method = " post " >
< ? php wp_nonce_field ( 'save-sidebar-widgets' , '_wpnonce_widgets' , false ); ?>
2008-01-04 18:34:33 -05:00
</ form >
2008-10-15 21:18:33 -04:00
< br class = " clear " />
2008-01-04 18:34:33 -05:00
</ div >
2009-04-11 10:37:24 -04:00
< ? php
do_action ( 'sidebar_admin_page' );
require_once ( 'admin-footer.php' );