2007-04-24 03:05:17 +02:00
< ? php
2008-08-16 09:27:34 +02:00
/**
* Widgets administration panel .
*
* @ package WordPress
* @ subpackage Administration
*/
2007-04-24 03:05:17 +02:00
2008-08-16 09:27:34 +02:00
/** WordPress Administration Bootstrap */
2008-01-05 00:34:33 +01:00
require_once ( 'admin.php' );
2008-08-16 09:27:34 +02:00
/** WordPress Administration Widgets API */
2008-02-07 22:57:54 +01:00
require_once ( ABSPATH . 'wp-admin/includes/widgets.php' );
2007-04-24 03:05:17 +02:00
2007-05-20 01:44:37 +02:00
if ( ! current_user_can ( 'switch_themes' ) )
2007-05-04 19:52:22 +02:00
wp_die ( __ ( 'Cheatin’ uh?' ));
2009-04-11 16:37:24 +02:00
wp_enqueue_script ( 'admin-widgets' );
2008-05-22 02:06:41 +02:00
wp_admin_css ( 'widgets' );
2007-04-24 03:05:17 +02:00
2008-01-05 00:34:33 +01:00
do_action ( 'sidebar_admin_setup' );
2007-06-14 04:25:30 +02:00
2008-01-05 00:34:33 +01:00
$title = __ ( 'Widgets' );
$parent_file = 'themes.php' ;
2007-06-14 04:25:30 +02:00
2009-04-11 16:37:24 +02: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-24 03:05:17 +02:00
2008-01-05 00:34:33 +01: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-14 04:25:30 +02:00
2009-04-11 16:37:24 +02:00
// look for "lost" widgets, perhaps run only after changin themes
function retrieve_widgets () {
global $wp_registered_widget_updates , $wp_registered_sidebars , $sidebars_widgets ;
$key_sidebars = array_keys ( ( array ) $wp_registered_sidebars );
$key_widgets = array_keys ( $sidebars_widgets );
if ( count ( $key_widgets ) > count ( $key_sidebars ) ) {
$changed_sidebars = array_diff ( $key_widgets , $key_sidebars );
foreach ( $changed_sidebars as $lost ) {
if ( is_array ( $sidebars_widgets [ $lost ]) )
$sidebars_widgets [ 'wp_inactive_widgets' ] = array_merge ( ( array ) $sidebars_widgets [ 'wp_inactive_widgets' ], $sidebars_widgets [ $lost ] );
unset ( $sidebars_widgets [ $lost ]);
2009-02-23 07:12:53 +01:00
}
}
2007-06-14 04:25:30 +02:00
2009-04-11 16:37:24 +02:00
$shown_widgets = array ();
foreach ( $sidebars_widgets as $sidebar ) {
if ( is_array ( $sidebar ) )
$shown_widgets = array_merge ( $shown_widgets , $sidebar );
}
2008-01-05 00:34:33 +01:00
2009-04-11 16:37:24 +02: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-24 03:05:17 +02:00
2009-04-11 16:37:24 +02: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-18 00:25:05 +01:00
}
}
}
2009-04-11 16:37:24 +02:00
$sidebars_widgets [ 'wp_inactive_widgets' ] = array_merge ( $lost_widgets , ( array ) $sidebars_widgets [ 'wp_inactive_widgets' ]);
wp_set_sidebars_widgets ( $sidebars_widgets );
2007-04-24 03:05:17 +02:00
}
2009-04-11 16:37:24 +02:00
retrieve_widgets ();
2007-04-24 03:05:17 +02:00
2009-04-11 16:37:24 +02: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-14 04:25:30 +02:00
2009-04-11 16:37:24 +02: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-14 04:25:30 +02:00
2009-04-11 16:37:24 +02:00
< ? php
require_once ( 'admin-footer.php' );
exit ;
}
2007-06-14 04:25:30 +02:00
2009-04-11 16:37:24 +02:00
/*
2008-01-05 00:34:33 +01:00
// Unsanitized!
$widget_search = isset ( $_GET [ 's' ]) ? $_GET [ 's' ] : false ;
2007-06-14 04:25:30 +02:00
2008-01-05 00:34:33 +01: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 16:37:24 +02:00
*/
2007-04-24 03:05:17 +02:00
2008-01-05 00:34:33 +01:00
$show = isset ( $_GET [ 'show' ]) && isset ( $show_values [ $_GET [ 'show' ]]) ? attribute_escape ( $_GET [ 'show' ] ) : false ;
2007-04-24 03:05:17 +02:00
2008-01-05 00:34:33 +01:00
$messages = array (
'updated' => __ ( 'Changes saved.' )
);
2007-06-14 04:25:30 +02:00
2008-09-11 20:54:05 +02:00
require_once ( 'admin-header.php' ); ?>
2007-06-14 04:25:30 +02:00
2008-01-05 00:34:33 +01:00
< div class = " wrap " >
2008-11-26 14:51:25 +01:00
< ? php screen_icon (); ?>
2008-12-09 19:03:31 +01:00
< h2 >< ? php echo wp_specialchars ( $title ); ?> </h2>
2007-04-24 03:05:17 +02:00
2009-04-13 03:17:59 +02: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 16:37:24 +02:00
<!--
2008-01-05 00:34:33 +01:00
< form id = " widgets-filter " action = " " method = " get " >
2007-04-24 03:05:17 +02:00
2008-01-05 00:34:33 +01:00
< div class = " widget-liquid-left-holder " >
< div id = " available-widgets-filter " class = " widget-liquid-left " >
2008-05-04 12:37:06 +02:00
< h3 >< label for = " show " >< ? php _e ( 'Available Widgets' ); ?> </label></h3>
2008-02-07 22:57:54 +01:00
< div class = " nav " >
2008-05-04 12:37:06 +02:00
< select name = " show " id = " show " >
2009-04-11 16:37:24 +02: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-05 00:34:33 +01:00
</ select >
2008-02-21 01:27:23 +01:00
< input type = " submit " value = " <?php _e('Show' ); ?> " class = " button-secondary " />
2008-02-07 22:57:54 +01:00
< p class = " pagenav " >
2009-04-11 16:37:24 +02:00
< ? php // echo $page_links; ?>
2008-02-07 22:57:54 +01:00
</ p >
</ div >
2008-01-05 00:34:33 +01:00
</ div >
2007-04-24 03:05:17 +02:00
</ div >
2007-06-14 04:25:30 +02:00
2008-01-05 00:34:33 +01:00
< div id = " available-sidebars " class = " widget-liquid-right " >
2008-05-04 12:37:06 +02:00
< h3 >< label for = " sidebar-selector " >< ? php _e ( 'Current Widgets' ); ?> </label></h3>
2008-01-05 00:34:33 +01:00
2008-02-07 22:57:54 +01:00
< div class = " nav " >
2008-01-05 00:34:33 +01:00
< select id = " sidebar-selector " name = " sidebar " >
2009-04-11 16:37:24 +02: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-05 00:34:33 +01:00
</ select >
2008-02-21 01:27:23 +01:00
< input type = " submit " value = " <?php _e('Show' ); ?> " class = " button-secondary " />
2008-02-07 22:57:54 +01:00
</ div >
2008-01-05 00:34:33 +01:00
</ div >
</ form >
2009-04-11 16:37:24 +02: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-05 00:34:33 +01:00
2009-04-11 16:37:24 +02: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-05 00:34:33 +01:00
</ div >
2007-04-24 03:05:17 +02:00
</ div >
2009-04-11 16:37:24 +02:00
</ div >
2007-06-14 04:25:30 +02:00
2009-04-11 16:37:24 +02:00
<!--
2008-01-05 00:34:33 +01:00
< div id = " current-widgets-head " class = " widget-liquid-right " >
< div id = " sidebar-info " >
2009-04-11 16:37:24 +02:00
< p >< ? php //echo $sidebar_info_text; ?></p>
2008-01-05 00:34:33 +01:00
< p >< ? php _e ( 'Add more from the Available Widgets section.' ); ?> </p>
</ div >
</ div >
2009-04-11 16:37:24 +02:00
-->
2008-01-05 00:34:33 +01:00
2009-04-11 16:37:24 +02: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-05 00:34:33 +01:00
</ div >
2008-03-18 00:25:05 +01:00
< ? php
2009-04-11 16:37:24 +02:00
$i ++ ;
} ?>
2008-03-10 06:19:12 +01:00
</ div >
2009-04-11 16:37:24 +02:00
< form action = " " method = " post " >
< ? php wp_nonce_field ( 'save-sidebar-widgets' , '_wpnonce_widgets' , false ); ?>
2008-01-05 00:34:33 +01:00
</ form >
2008-10-16 03:18:33 +02:00
< br class = " clear " />
2008-01-05 00:34:33 +01:00
</ div >
2009-04-11 16:37:24 +02:00
< ? php
do_action ( 'sidebar_admin_page' );
require_once ( 'admin-footer.php' );