Changes in trunk/wp-admin/widgets.php [17824:19572]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/widgets.php
r17824 r19572 16 16 wp_die( __( 'Cheatin’ uh?' )); 17 17 18 wp_admin_css( 'widgets' );19 20 18 $widgets_access = get_user_setting( 'widgets_access' ); 21 19 if ( isset($_GET['widgets-access']) ) { … … 24 22 } 25 23 24 function wp_widgets_access_body_class($classes) { 25 return "$classes widgets_access "; 26 } 27 26 28 if ( 'on' == $widgets_access ) 27 add_filter( 'admin_body_class', create_function('', '{return " widgets_access ";}'));29 add_filter( 'admin_body_class', 'wp_widgets_access_body_class' ); 28 30 else 29 31 wp_enqueue_script('admin-widgets'); … … 34 36 $parent_file = 'themes.php'; 35 37 36 $help = ' 37 <p>' . __('Widgets are independent sections of content that can be placed into any widgetized area provided by your theme (commonly called sidebars). To populate your sidebars/widget areas with individual widgets, drag and drop the title bars into the desired area. By default, only the first widget area is expanded. To populate additional widget areas, click on their title bars to expand them.') . '</p> 38 <p>' . __('The Available Widgets section contains all the widgets you can choose from. Once you drag a widget into a sidebar, it will open to allow you to configure its settings. When you are happy with the widget settings, click the Save button and the widget will go live on your site. If you click Delete, it will remove the widget.') . '</p> 39 <p>' . __('If you want to remove the widget but save its setting for possible future use, just drag it into the Inactive Widgets area. You can add them back anytime from there. This is especially helpful when you switch to a theme with fewer or different widget areas.') . '</p> 38 get_current_screen()->add_help_tab( array( 39 'id' => 'overview', 40 'title' => __('Overview'), 41 'content' => 42 '<p>' . __('Widgets are independent sections of content that can be placed into any widgetized area provided by your theme (commonly called sidebars). To populate your sidebars/widget areas with individual widgets, drag and drop the title bars into the desired area. By default, only the first widget area is expanded. To populate additional widget areas, click on their title bars to expand them.') . '</p> 43 <p>' . __('The Available Widgets section contains all the widgets you can choose from. Once you drag a widget into a sidebar, it will open to allow you to configure its settings. When you are happy with the widget settings, click the Save button and the widget will go live on your site. If you click Delete, it will remove the widget.') . '</p>' 44 ) ); 45 get_current_screen()->add_help_tab( array( 46 'id' => 'removing-reusing', 47 'title' => __('Removing and Reusing'), 48 'content' => 49 '<p>' . __('If you want to remove the widget but save its setting for possible future use, just drag it into the Inactive Widgets area. You can add them back anytime from there. This is especially helpful when you switch to a theme with fewer or different widget areas.') . '</p> 40 50 <p>' . __('Widgets may be used multiple times. You can give each widget a title, to display on your site, but it’s not required.') . '</p> 41 <p>' . __('Enabling Accessibility Mode, via Screen Options, allows you to use Add and Edit buttons instead of using drag and drop.') . '</p> 42 <p>' . __('Many themes show some sidebar widgets by default until you edit your sidebars, but they are not automatically displayed in your sidebar management tool. After you make your first widget change, you can re-add the default widgets by adding them from the Available Widgets area.') . '</p> 43 '; 44 $help .= '<p><strong>' . __('For more information:') . '</strong></p>'; 45 $help .= '<p>' . __('<a href="http://codex.wordpress.org/Appearance_Widgets_Screen" target="_blank">Documentation on Widgets</a>') . '</p>'; 46 $help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'; 47 add_contextual_help($current_screen, $help); 48 49 // register the inactive_widgets area as sidebar 50 register_sidebar(array( 51 'name' => __('Inactive Widgets'), 52 'id' => 'wp_inactive_widgets', 53 'description' => '', 54 'before_widget' => '', 55 'after_widget' => '', 56 'before_title' => '', 57 'after_title' => '', 58 )); 59 60 // These are the widgets grouped by sidebar 61 $sidebars_widgets = wp_get_sidebars_widgets(); 62 if ( empty( $sidebars_widgets ) ) 63 $sidebars_widgets = wp_get_widget_defaults(); 64 65 // look for "lost" widgets, this has to run at least on each theme change 66 function retrieve_widgets() { 67 global $wp_registered_widget_updates, $wp_registered_sidebars, $sidebars_widgets, $wp_registered_widgets; 68 69 $_sidebars_widgets = array(); 70 $sidebars = array_keys($wp_registered_sidebars); 71 72 unset( $sidebars_widgets['array_version'] ); 73 74 $old = array_keys($sidebars_widgets); 75 sort($old); 76 sort($sidebars); 77 78 if ( $old == $sidebars ) 79 return; 80 81 // Move the known-good ones first 82 foreach ( $sidebars as $id ) { 83 if ( array_key_exists( $id, $sidebars_widgets ) ) { 84 $_sidebars_widgets[$id] = $sidebars_widgets[$id]; 85 unset($sidebars_widgets[$id], $sidebars[$id]); 86 } 87 } 88 89 // if new theme has less sidebars than the old theme 90 if ( !empty($sidebars_widgets) ) { 91 foreach ( $sidebars_widgets as $lost => $val ) { 92 if ( is_array($val) ) 93 $_sidebars_widgets['wp_inactive_widgets'] = array_merge( (array) $_sidebars_widgets['wp_inactive_widgets'], $val ); 94 } 95 } 96 97 // discard invalid, theme-specific widgets from sidebars 98 $shown_widgets = array(); 99 foreach ( $_sidebars_widgets as $sidebar => $widgets ) { 100 if ( !is_array($widgets) ) 101 continue; 102 103 $_widgets = array(); 104 foreach ( $widgets as $widget ) { 105 if ( isset($wp_registered_widgets[$widget]) ) 106 $_widgets[] = $widget; 107 } 108 $_sidebars_widgets[$sidebar] = $_widgets; 109 $shown_widgets = array_merge($shown_widgets, $_widgets); 110 } 111 112 $sidebars_widgets = $_sidebars_widgets; 113 unset($_sidebars_widgets, $_widgets); 114 115 // find hidden/lost multi-widget instances 116 $lost_widgets = array(); 117 foreach ( $wp_registered_widgets as $key => $val ) { 118 if ( in_array($key, $shown_widgets, true) ) 119 continue; 120 121 $number = preg_replace('/.+?-([0-9]+)$/', '$1', $key); 122 123 if ( 2 > (int) $number ) 124 continue; 125 126 $lost_widgets[] = $key; 127 } 128 129 $sidebars_widgets['wp_inactive_widgets'] = array_merge($lost_widgets, (array) $sidebars_widgets['wp_inactive_widgets']); 130 wp_set_sidebars_widgets($sidebars_widgets); 131 } 132 retrieve_widgets(); 133 134 if ( count($wp_registered_sidebars) == 1 ) { 135 // If only "wp_inactive_widgets" is defined the theme has no sidebars, die. 51 <p>' . __('Enabling Accessibility Mode, via Screen Options, allows you to use Add and Edit buttons instead of using drag and drop.') . '</p>' 52 ) ); 53 get_current_screen()->add_help_tab( array( 54 'id' => 'missing-widgets', 55 'title' => __('Missing Widgets'), 56 'content' => 57 '<p>' . __('Many themes show some sidebar widgets by default until you edit your sidebars, but they are not automatically displayed in your sidebar management tool. After you make your first widget change, you can re-add the default widgets by adding them from the Available Widgets area.') . '</p>' . 58 '<p>' . __('When changing themes, there is often some variation in the number and setup of widget areas/sidebars and sometimes these conflicts make the transition a bit less smooth. If you changed themes and seem to be missing widgets, scroll down on this screen to the Inactive area, where all your widgets and their settings will have been saved.') . '</p>' 59 ) ); 60 61 get_current_screen()->set_help_sidebar( 62 '<p><strong>' . __('For more information:') . '</strong></p>' . 63 '<p>' . __('<a href="http://codex.wordpress.org/Appearance_Widgets_Screen" target="_blank">Documentation on Widgets</a>') . '</p>' . 64 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' 65 ); 66 67 if ( empty($wp_registered_sidebars) ) { 68 // the theme has no sidebars, die. 136 69 require_once( './admin-header.php' ); 137 70 ?> … … 150 83 exit; 151 84 } 85 86 // These are the widgets grouped by sidebar 87 $sidebars_widgets = wp_get_sidebars_widgets(); 88 89 if ( empty( $sidebars_widgets ) ) 90 $sidebars_widgets = wp_get_widget_defaults(); 91 92 foreach ( $sidebars_widgets as $sidebar_id => $widgets ) { 93 if ( 'wp_inactive_widgets' == $sidebar_id ) 94 continue; 95 96 if ( !isset( $wp_registered_sidebars[ $sidebar_id ] ) ) { 97 if ( ! empty( $widgets ) ) { // register the inactive_widgets area as sidebar 98 register_sidebar(array( 99 'name' => __( 'Inactive Sidebar (not used)' ), 100 'id' => $sidebar_id, 101 'class' => 'inactive-sidebar orphan-sidebar', 102 'description' => __( 'This sidebar is no longer available and does not show anywhere on your site. Remove each of the widgets below to fully remove this inactive sidebar.' ), 103 'before_widget' => '', 104 'after_widget' => '', 105 'before_title' => '', 106 'after_title' => '', 107 )); 108 } else { 109 unset( $sidebars_widgets[ $sidebar_id ] ); 110 } 111 } 112 } 113 114 // register the inactive_widgets area as sidebar 115 register_sidebar(array( 116 'name' => __('Inactive Widgets'), 117 'id' => 'wp_inactive_widgets', 118 'class' => 'inactive-sidebar', 119 'description' => __( 'Drag widgets here to remove them from the sidebar but keep their settings.' ), 120 'before_widget' => '', 121 'after_widget' => '', 122 'before_title' => '', 123 'after_title' => '', 124 )); 125 126 retrieve_widgets(); 152 127 153 128 // We're saving a widget without js … … 280 255 foreach ( $wp_registered_sidebars as $sbname => $sbvalue ) { 281 256 echo "\t\t<tr><td><label><input type='radio' name='sidebar' value='" . esc_attr($sbname) . "'" . checked( $sbname, $sidebar, false ) . " /> $sbvalue[name]</label></td><td>"; 282 if ( 'wp_inactive_widgets' == $sbname ) {257 if ( 'wp_inactive_widgets' == $sbname || 'orphaned_widgets' == substr( $sbname, 0, 16 ) ) { 283 258 echo ' '; 284 259 } else { … … 369 344 </div> 370 345 371 <div class="widgets-holder-wrap"> 372 <div class="sidebar-name"> 373 <div class="sidebar-name-arrow"><br /></div> 374 <h3><?php _e('Inactive Widgets'); ?> 375 <span><img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-feedback" title="" alt="" /></span></h3></div> 376 <div class="widget-holder inactive"> 377 <p class="description"><?php _e('Drag widgets here to remove them from the sidebar but keep their settings.'); ?></p> 378 <?php wp_list_widget_controls('wp_inactive_widgets'); ?> 379 <br class="clear" /> 346 <?php 347 foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) { 348 if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) { 349 $wrap_class = 'widgets-holder-wrap'; 350 if ( !empty( $registered_sidebar['class'] ) ) 351 $wrap_class .= ' ' . $registered_sidebar['class']; 352 353 ?> 354 355 <div class="<?php echo esc_attr( $wrap_class ); ?>"> 356 <div class="sidebar-name"> 357 <div class="sidebar-name-arrow"><br /></div> 358 <h3><?php echo esc_html( $registered_sidebar['name'] ); ?> 359 <span><img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" class="ajax-feedback" title="" alt="" /></span> 360 </h3> 361 </div> 362 <div class="widget-holder inactive"> 363 <?php wp_list_widget_controls( $registered_sidebar['id'] ); ?> 364 <br class="clear" /> 365 </div> 380 366 </div> 381 </div> 367 <?php 368 } 369 } 370 ?> 371 382 372 </div> 383 373 </div> … … 388 378 $i = 0; 389 379 foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) { 390 if ( 'wp_inactive_widgets' == $sidebar)380 if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' == substr( $sidebar, 0, 16 ) ) 391 381 continue; 392 $closed = $i ? ' closed' : ''; ?> 393 <div class="widgets-holder-wrap<?php echo $closed; ?>"> 382 383 $wrap_class = 'widgets-holder-wrap'; 384 if ( !empty( $registered_sidebar['class'] ) ) 385 $wrap_class .= ' sidebar-' . $registered_sidebar['class']; 386 387 if ( $i ) 388 $wrap_class .= ' closed'; ?> 389 390 <div class="<?php echo esc_attr( $wrap_class ); ?>"> 394 391 <div class="sidebar-name"> 395 392 <div class="sidebar-name-arrow"><br /></div>
Note: See TracChangeset
for help on using the changeset viewer.