wp/wp-admin/widgets.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * Widget administration panel
     3  * Widget administration screen.
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
    18 		'<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
    18 		'<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
    19 		403
    19 		403
    20 	);
    20 	);
    21 }
    21 }
    22 
    22 
    23 $widgets_access = get_user_setting( 'widgets_access' );
    23 if ( ! current_theme_supports( 'widgets' ) ) {
    24 if ( isset( $_GET['widgets-access'] ) ) {
    24 	wp_die( __( 'The theme you are currently using isn&#8217;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="https://developer.wordpress.org/themes/functionality/widgets/">follow these instructions</a>.' ) );
    25 	check_admin_referer( 'widgets-access' );
       
    26 
       
    27 	$widgets_access = 'on' === $_GET['widgets-access'] ? 'on' : 'off';
       
    28 	set_user_setting( 'widgets_access', $widgets_access );
       
    29 }
    25 }
    30 
       
    31 if ( 'on' === $widgets_access ) {
       
    32 	add_filter( 'admin_body_class', 'wp_widgets_access_body_class' );
       
    33 } else {
       
    34 	wp_enqueue_script( 'admin-widgets' );
       
    35 
       
    36 	if ( wp_is_mobile() ) {
       
    37 		wp_enqueue_script( 'jquery-touch-punch' );
       
    38 	}
       
    39 }
       
    40 
       
    41 /**
       
    42  * Fires early before the Widgets administration screen loads,
       
    43  * after scripts are enqueued.
       
    44  *
       
    45  * @since 2.2.0
       
    46  */
       
    47 do_action( 'sidebar_admin_setup' );
       
    48 
    26 
    49 $title       = __( 'Widgets' );
    27 $title       = __( 'Widgets' );
    50 $parent_file = 'themes.php';
    28 $parent_file = 'themes.php';
    51 
    29 
    52 get_current_screen()->add_help_tab(
    30 if ( wp_use_widgets_block_editor() ) {
    53 	array(
    31 	require ABSPATH . 'wp-admin/widgets-form-blocks.php';
    54 		'id'      => 'overview',
    32 } else {
    55 		'title'   => __( 'Overview' ),
    33 	require ABSPATH . 'wp-admin/widgets-form.php';
    56 		'content' =>
       
    57 				'<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>
       
    58 	<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>',
       
    59 	)
       
    60 );
       
    61 get_current_screen()->add_help_tab(
       
    62 	array(
       
    63 		'id'      => 'removing-reusing',
       
    64 		'title'   => __( 'Removing and Reusing' ),
       
    65 		'content' =>
       
    66 				'<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>
       
    67 	<p>' . __( 'Widgets may be used multiple times. You can give each widget a title, to display on your site, but it&#8217;s not required.' ) . '</p>
       
    68 	<p>' . __( 'Enabling Accessibility Mode, via Screen Options, allows you to use Add and Edit buttons instead of using drag and drop.' ) . '</p>',
       
    69 	)
       
    70 );
       
    71 get_current_screen()->add_help_tab(
       
    72 	array(
       
    73 		'id'      => 'missing-widgets',
       
    74 		'title'   => __( 'Missing Widgets' ),
       
    75 		'content' =>
       
    76 				'<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>' .
       
    77 					'<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 Widgets area, where all of your widgets and their settings will have been saved.' ) . '</p>',
       
    78 	)
       
    79 );
       
    80 
       
    81 get_current_screen()->set_help_sidebar(
       
    82 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
       
    83 	'<p>' . __( '<a href="https://wordpress.org/support/article/appearance-widgets-screen/">Documentation on Widgets</a>' ) . '</p>' .
       
    84 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
       
    85 );
       
    86 
       
    87 if ( ! current_theme_supports( 'widgets' ) ) {
       
    88 	wp_die( __( 'The theme you are currently using isn&#8217;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="https://developer.wordpress.org/themes/functionality/widgets/">follow these instructions</a>.' ) );
       
    89 }
    34 }
    90 
       
    91 // These are the widgets grouped by sidebar.
       
    92 $sidebars_widgets = wp_get_sidebars_widgets();
       
    93 
       
    94 if ( empty( $sidebars_widgets ) ) {
       
    95 	$sidebars_widgets = wp_get_widget_defaults();
       
    96 }
       
    97 
       
    98 foreach ( $sidebars_widgets as $sidebar_id => $widgets ) {
       
    99 	if ( 'wp_inactive_widgets' === $sidebar_id ) {
       
   100 		continue;
       
   101 	}
       
   102 
       
   103 	if ( ! is_registered_sidebar( $sidebar_id ) ) {
       
   104 		if ( ! empty( $widgets ) ) { // Register the inactive_widgets area as sidebar.
       
   105 			register_sidebar(
       
   106 				array(
       
   107 					'name'          => __( 'Inactive Sidebar (not used)' ),
       
   108 					'id'            => $sidebar_id,
       
   109 					'class'         => 'inactive-sidebar orphan-sidebar',
       
   110 					'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.' ),
       
   111 					'before_widget' => '',
       
   112 					'after_widget'  => '',
       
   113 					'before_title'  => '',
       
   114 					'after_title'   => '',
       
   115 				)
       
   116 			);
       
   117 		} else {
       
   118 			unset( $sidebars_widgets[ $sidebar_id ] );
       
   119 		}
       
   120 	}
       
   121 }
       
   122 
       
   123 // Register the inactive_widgets area as sidebar.
       
   124 register_sidebar(
       
   125 	array(
       
   126 		'name'          => __( 'Inactive Widgets' ),
       
   127 		'id'            => 'wp_inactive_widgets',
       
   128 		'class'         => 'inactive-sidebar',
       
   129 		'description'   => __( 'Drag widgets here to remove them from the sidebar but keep their settings.' ),
       
   130 		'before_widget' => '',
       
   131 		'after_widget'  => '',
       
   132 		'before_title'  => '',
       
   133 		'after_title'   => '',
       
   134 	)
       
   135 );
       
   136 
       
   137 retrieve_widgets();
       
   138 
       
   139 // We're saving a widget without JS.
       
   140 if ( isset( $_POST['savewidget'] ) || isset( $_POST['removewidget'] ) ) {
       
   141 	$widget_id = $_POST['widget-id'];
       
   142 	check_admin_referer( "save-delete-widget-$widget_id" );
       
   143 
       
   144 	$number = isset( $_POST['multi_number'] ) ? (int) $_POST['multi_number'] : '';
       
   145 	if ( $number ) {
       
   146 		foreach ( $_POST as $key => $val ) {
       
   147 			if ( is_array( $val ) && preg_match( '/__i__|%i%/', key( $val ) ) ) {
       
   148 				$_POST[ $key ] = array( $number => array_shift( $val ) );
       
   149 				break;
       
   150 			}
       
   151 		}
       
   152 	}
       
   153 
       
   154 	$sidebar_id = $_POST['sidebar'];
       
   155 	$position   = isset( $_POST[ $sidebar_id . '_position' ] ) ? (int) $_POST[ $sidebar_id . '_position' ] - 1 : 0;
       
   156 
       
   157 	$id_base = $_POST['id_base'];
       
   158 	$sidebar = isset( $sidebars_widgets[ $sidebar_id ] ) ? $sidebars_widgets[ $sidebar_id ] : array();
       
   159 
       
   160 	// Delete.
       
   161 	if ( isset( $_POST['removewidget'] ) && $_POST['removewidget'] ) {
       
   162 
       
   163 		if ( ! in_array( $widget_id, $sidebar, true ) ) {
       
   164 			wp_redirect( admin_url( 'widgets.php?error=0' ) );
       
   165 			exit;
       
   166 		}
       
   167 
       
   168 		$sidebar = array_diff( $sidebar, array( $widget_id ) );
       
   169 		$_POST   = array(
       
   170 			'sidebar'            => $sidebar_id,
       
   171 			'widget-' . $id_base => array(),
       
   172 			'the-widget-id'      => $widget_id,
       
   173 			'delete_widget'      => '1',
       
   174 		);
       
   175 
       
   176 		/**
       
   177 		 * Fires immediately after a widget has been marked for deletion.
       
   178 		 *
       
   179 		 * @since 4.4.0
       
   180 		 *
       
   181 		 * @param string $widget_id  ID of the widget marked for deletion.
       
   182 		 * @param string $sidebar_id ID of the sidebar the widget was deleted from.
       
   183 		 * @param string $id_base    ID base for the widget.
       
   184 		 */
       
   185 		do_action( 'delete_widget', $widget_id, $sidebar_id, $id_base );
       
   186 	}
       
   187 
       
   188 	$_POST['widget-id'] = $sidebar;
       
   189 
       
   190 	foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
       
   191 		if ( $name !== $id_base || ! is_callable( $control['callback'] ) ) {
       
   192 			continue;
       
   193 		}
       
   194 
       
   195 		ob_start();
       
   196 			call_user_func_array( $control['callback'], $control['params'] );
       
   197 		ob_end_clean();
       
   198 
       
   199 		break;
       
   200 	}
       
   201 
       
   202 	$sidebars_widgets[ $sidebar_id ] = $sidebar;
       
   203 
       
   204 	// Remove old position.
       
   205 	if ( ! isset( $_POST['delete_widget'] ) ) {
       
   206 		foreach ( $sidebars_widgets as $key => $sb ) {
       
   207 			if ( is_array( $sb ) ) {
       
   208 				$sidebars_widgets[ $key ] = array_diff( $sb, array( $widget_id ) );
       
   209 			}
       
   210 		}
       
   211 		array_splice( $sidebars_widgets[ $sidebar_id ], $position, 0, $widget_id );
       
   212 	}
       
   213 
       
   214 	wp_set_sidebars_widgets( $sidebars_widgets );
       
   215 	wp_redirect( admin_url( 'widgets.php?message=0' ) );
       
   216 	exit;
       
   217 }
       
   218 
       
   219 // Remove inactive widgets without JS.
       
   220 if ( isset( $_POST['removeinactivewidgets'] ) ) {
       
   221 	check_admin_referer( 'remove-inactive-widgets', '_wpnonce_remove_inactive_widgets' );
       
   222 
       
   223 	if ( $_POST['removeinactivewidgets'] ) {
       
   224 		foreach ( $sidebars_widgets['wp_inactive_widgets'] as $key => $widget_id ) {
       
   225 			$pieces       = explode( '-', $widget_id );
       
   226 			$multi_number = array_pop( $pieces );
       
   227 			$id_base      = implode( '-', $pieces );
       
   228 			$widget       = get_option( 'widget_' . $id_base );
       
   229 			unset( $widget[ $multi_number ] );
       
   230 			update_option( 'widget_' . $id_base, $widget );
       
   231 			unset( $sidebars_widgets['wp_inactive_widgets'][ $key ] );
       
   232 		}
       
   233 
       
   234 		wp_set_sidebars_widgets( $sidebars_widgets );
       
   235 	}
       
   236 
       
   237 	wp_redirect( admin_url( 'widgets.php?message=0' ) );
       
   238 	exit;
       
   239 }
       
   240 
       
   241 // Output the widget form without JS.
       
   242 if ( isset( $_GET['editwidget'] ) && $_GET['editwidget'] ) {
       
   243 	$widget_id = $_GET['editwidget'];
       
   244 
       
   245 	if ( isset( $_GET['addnew'] ) ) {
       
   246 		// Default to the first sidebar.
       
   247 		$keys    = array_keys( $wp_registered_sidebars );
       
   248 		$sidebar = reset( $keys );
       
   249 
       
   250 		if ( isset( $_GET['base'] ) && isset( $_GET['num'] ) ) { // Multi-widget.
       
   251 			// Copy minimal info from an existing instance of this widget to a new instance.
       
   252 			foreach ( $wp_registered_widget_controls as $control ) {
       
   253 				if ( $_GET['base'] === $control['id_base'] ) {
       
   254 					$control_callback                                = $control['callback'];
       
   255 					$multi_number                                    = (int) $_GET['num'];
       
   256 					$control['params'][0]['number']                  = -1;
       
   257 					$control['id']                                   = $control['id_base'] . '-' . $multi_number;
       
   258 					$widget_id                                       = $control['id'];
       
   259 					$wp_registered_widget_controls[ $control['id'] ] = $control;
       
   260 					break;
       
   261 				}
       
   262 			}
       
   263 		}
       
   264 	}
       
   265 
       
   266 	if ( isset( $wp_registered_widget_controls[ $widget_id ] ) && ! isset( $control ) ) {
       
   267 		$control          = $wp_registered_widget_controls[ $widget_id ];
       
   268 		$control_callback = $control['callback'];
       
   269 	} elseif ( ! isset( $wp_registered_widget_controls[ $widget_id ] ) && isset( $wp_registered_widgets[ $widget_id ] ) ) {
       
   270 		$name = esc_html( strip_tags( $wp_registered_widgets[ $widget_id ]['name'] ) );
       
   271 	}
       
   272 
       
   273 	if ( ! isset( $name ) ) {
       
   274 		$name = esc_html( strip_tags( $control['name'] ) );
       
   275 	}
       
   276 
       
   277 	if ( ! isset( $sidebar ) ) {
       
   278 		$sidebar = isset( $_GET['sidebar'] ) ? $_GET['sidebar'] : 'wp_inactive_widgets';
       
   279 	}
       
   280 
       
   281 	if ( ! isset( $multi_number ) ) {
       
   282 		$multi_number = isset( $control['params'][0]['number'] ) ? $control['params'][0]['number'] : '';
       
   283 	}
       
   284 
       
   285 	$id_base = isset( $control['id_base'] ) ? $control['id_base'] : $control['id'];
       
   286 
       
   287 	// Show the widget form.
       
   288 	$width = ' style="width:' . max( $control['width'], 350 ) . 'px"';
       
   289 	$key   = isset( $_GET['key'] ) ? (int) $_GET['key'] : 0;
       
   290 
       
   291 	require_once ABSPATH . 'wp-admin/admin-header.php'; ?>
       
   292 	<div class="wrap">
       
   293 	<h1><?php echo esc_html( $title ); ?></h1>
       
   294 	<div class="editwidget"<?php echo $width; ?>>
       
   295 	<h2>
       
   296 	<?php
       
   297 	/* translators: %s: Widget name. */
       
   298 	printf( __( 'Widget %s' ), $name );
       
   299 	?>
       
   300 	</h2>
       
   301 
       
   302 	<form action="widgets.php" method="post">
       
   303 	<div class="widget-inside">
       
   304 	<?php
       
   305 	if ( is_callable( $control_callback ) ) {
       
   306 		call_user_func_array( $control_callback, $control['params'] );
       
   307 	} else {
       
   308 		echo '<p>' . __( 'There are no options for this widget.' ) . "</p>\n";
       
   309 	}
       
   310 	?>
       
   311 	</div>
       
   312 
       
   313 	<p class="describe"><?php _e( 'Select both the sidebar for this widget and the position of the widget in that sidebar.' ); ?></p>
       
   314 	<div class="widget-position">
       
   315 	<table class="widefat"><thead><tr><th><?php _e( 'Sidebar' ); ?></th><th><?php _e( 'Position' ); ?></th></tr></thead><tbody>
       
   316 	<?php
       
   317 	foreach ( $wp_registered_sidebars as $sbname => $sbvalue ) {
       
   318 		echo "\t\t<tr><td><label><input type='radio' name='sidebar' value='" . esc_attr( $sbname ) . "'" . checked( $sbname, $sidebar, false ) . " /> $sbvalue[name]</label></td><td>";
       
   319 		if ( 'wp_inactive_widgets' === $sbname || 'orphaned_widgets' === substr( $sbname, 0, 16 ) ) {
       
   320 			echo '&nbsp;';
       
   321 		} else {
       
   322 			if ( ! isset( $sidebars_widgets[ $sbname ] ) || ! is_array( $sidebars_widgets[ $sbname ] ) ) {
       
   323 				$j                           = 1;
       
   324 				$sidebars_widgets[ $sbname ] = array();
       
   325 			} else {
       
   326 				$j = count( $sidebars_widgets[ $sbname ] );
       
   327 				if ( isset( $_GET['addnew'] ) || ! in_array( $widget_id, $sidebars_widgets[ $sbname ], true ) ) {
       
   328 					$j++;
       
   329 				}
       
   330 			}
       
   331 			$selected = '';
       
   332 			echo "\t\t<select name='{$sbname}_position'>\n";
       
   333 			echo "\t\t<option value=''>" . __( '&mdash; Select &mdash;' ) . "</option>\n";
       
   334 			for ( $i = 1; $i <= $j; $i++ ) {
       
   335 				if ( in_array( $widget_id, $sidebars_widgets[ $sbname ], true ) ) {
       
   336 					$selected = selected( $i, $key + 1, false );
       
   337 				}
       
   338 				echo "\t\t<option value='$i'$selected> $i </option>\n";
       
   339 			}
       
   340 			echo "\t\t</select>\n";
       
   341 		}
       
   342 		echo "</td></tr>\n";
       
   343 	}
       
   344 	?>
       
   345 	</tbody></table>
       
   346 	</div>
       
   347 
       
   348 	<div class="widget-control-actions">
       
   349 	<?php
       
   350 	if ( isset( $_GET['addnew'] ) ) {
       
   351 		?>
       
   352 	<a href="widgets.php" class="button alignleft"><?php _e( 'Cancel' ); ?></a>
       
   353 		<?php
       
   354 	} else {
       
   355 		submit_button( __( 'Delete' ), 'alignleft', 'removewidget', false );
       
   356 	}
       
   357 	submit_button( __( 'Save Widget' ), 'primary alignright', 'savewidget', false );
       
   358 	?>
       
   359 	<input type="hidden" name="widget-id" class="widget-id" value="<?php echo esc_attr( $widget_id ); ?>" />
       
   360 	<input type="hidden" name="id_base" class="id_base" value="<?php echo esc_attr( $id_base ); ?>" />
       
   361 	<input type="hidden" name="multi_number" class="multi_number" value="<?php echo esc_attr( $multi_number ); ?>" />
       
   362 	<?php	wp_nonce_field( "save-delete-widget-$widget_id" ); ?>
       
   363 	<br class="clear" />
       
   364 	</div>
       
   365 	</form>
       
   366 	</div>
       
   367 	</div>
       
   368 	<?php
       
   369 	require_once ABSPATH . 'wp-admin/admin-footer.php';
       
   370 	exit;
       
   371 }
       
   372 
       
   373 $messages = array(
       
   374 	__( 'Changes saved.' ),
       
   375 );
       
   376 
       
   377 $errors = array(
       
   378 	__( 'Error while saving.' ),
       
   379 	__( 'Error in displaying the widget settings form.' ),
       
   380 );
       
   381 
       
   382 require_once ABSPATH . 'wp-admin/admin-header.php';
       
   383 ?>
       
   384 
       
   385 <div class="wrap">
       
   386 <h1 class="wp-heading-inline">
       
   387 <?php
       
   388 echo esc_html( $title );
       
   389 ?>
       
   390 </h1>
       
   391 
       
   392 <?php
       
   393 if ( current_user_can( 'customize' ) ) {
       
   394 	printf(
       
   395 		' <a class="page-title-action hide-if-no-customize" href="%1$s">%2$s</a>',
       
   396 		esc_url(
       
   397 			add_query_arg(
       
   398 				array(
       
   399 					array( 'autofocus' => array( 'panel' => 'widgets' ) ),
       
   400 					'return' => urlencode( remove_query_arg( wp_removable_query_args(), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ),
       
   401 				),
       
   402 				admin_url( 'customize.php' )
       
   403 			)
       
   404 		),
       
   405 		__( 'Manage with Live Preview' )
       
   406 	);
       
   407 }
       
   408 
       
   409 $nonce = wp_create_nonce( 'widgets-access' );
       
   410 ?>
       
   411 <div class="widget-access-link">
       
   412 	<a id="access-on" href="widgets.php?widgets-access=on&_wpnonce=<?php echo urlencode( $nonce ); ?>"><?php _e( 'Enable accessibility mode' ); ?></a><a id="access-off" href="widgets.php?widgets-access=off&_wpnonce=<?php echo urlencode( $nonce ); ?>"><?php _e( 'Disable accessibility mode' ); ?></a>
       
   413 </div>
       
   414 
       
   415 <hr class="wp-header-end">
       
   416 
       
   417 <?php if ( isset( $_GET['message'] ) && isset( $messages[ $_GET['message'] ] ) ) { ?>
       
   418 <div id="message" class="updated notice is-dismissible"><p><?php echo $messages[ $_GET['message'] ]; ?></p></div>
       
   419 <?php } ?>
       
   420 <?php if ( isset( $_GET['error'] ) && isset( $errors[ $_GET['error'] ] ) ) { ?>
       
   421 <div id="message" class="error"><p><?php echo $errors[ $_GET['error'] ]; ?></p></div>
       
   422 <?php } ?>
       
   423 
       
   424 <?php
       
   425 /**
       
   426  * Fires before the Widgets administration page content loads.
       
   427  *
       
   428  * @since 3.0.0
       
   429  */
       
   430 do_action( 'widgets_admin_page' );
       
   431 ?>
       
   432 
       
   433 <div class="widget-liquid-left">
       
   434 <div id="widgets-left">
       
   435 	<div id="available-widgets" class="widgets-holder-wrap">
       
   436 		<div class="sidebar-name">
       
   437 			<button type="button" class="handlediv hide-if-no-js" aria-expanded="true">
       
   438 				<span class="screen-reader-text"><?php _e( 'Available Widgets' ); ?></span>
       
   439 				<span class="toggle-indicator" aria-hidden="true"></span>
       
   440 			</button>
       
   441 			<h2><?php _e( 'Available Widgets' ); ?> <span id="removing-widget"><?php _ex( 'Deactivate', 'removing-widget' ); ?> <span></span></span></h2>
       
   442 		</div>
       
   443 		<div class="widget-holder">
       
   444 			<div class="sidebar-description">
       
   445 				<p class="description"><?php _e( 'To activate a widget drag it to a sidebar or click on it. To deactivate a widget and delete its settings, drag it back.' ); ?></p>
       
   446 			</div>
       
   447 			<div id="widget-list">
       
   448 				<?php wp_list_widgets(); ?>
       
   449 			</div>
       
   450 			<br class='clear' />
       
   451 		</div>
       
   452 		<br class="clear" />
       
   453 	</div>
       
   454 
       
   455 <?php
       
   456 
       
   457 $theme_sidebars = array();
       
   458 foreach ( $wp_registered_sidebars as $sidebar => $registered_sidebar ) {
       
   459 	if ( false !== strpos( $registered_sidebar['class'], 'inactive-sidebar' ) || 'orphaned_widgets' === substr( $sidebar, 0, 16 ) ) {
       
   460 		$wrap_class = 'widgets-holder-wrap';
       
   461 		if ( ! empty( $registered_sidebar['class'] ) ) {
       
   462 			$wrap_class .= ' ' . $registered_sidebar['class'];
       
   463 		}
       
   464 
       
   465 		$is_inactive_widgets = 'wp_inactive_widgets' === $registered_sidebar['id'];
       
   466 		?>
       
   467 		<div class="<?php echo esc_attr( $wrap_class ); ?>">
       
   468 			<div class="widget-holder inactive">
       
   469 				<?php wp_list_widget_controls( $registered_sidebar['id'], $registered_sidebar['name'] ); ?>
       
   470 
       
   471 				<?php if ( $is_inactive_widgets ) { ?>
       
   472 				<div class="remove-inactive-widgets">
       
   473 					<form action="" method="post">
       
   474 						<p>
       
   475 							<?php
       
   476 							$attributes = array( 'id' => 'inactive-widgets-control-remove' );
       
   477 
       
   478 							if ( empty( $sidebars_widgets['wp_inactive_widgets'] ) ) {
       
   479 								$attributes['disabled'] = '';
       
   480 							}
       
   481 
       
   482 							submit_button( __( 'Clear Inactive Widgets' ), 'delete', 'removeinactivewidgets', false, $attributes );
       
   483 							?>
       
   484 							<span class="spinner"></span>
       
   485 						</p>
       
   486 						<?php wp_nonce_field( 'remove-inactive-widgets', '_wpnonce_remove_inactive_widgets' ); ?>
       
   487 					</form>
       
   488 				</div>
       
   489 				<?php } ?>
       
   490 			</div>
       
   491 			<?php if ( $is_inactive_widgets ) { ?>
       
   492 			<p class="description"><?php _e( 'This will clear all items from the inactive widgets list. You will not be able to restore any customizations.' ); ?></p>
       
   493 			<?php } ?>
       
   494 		</div>
       
   495 		<?php
       
   496 
       
   497 	} else {
       
   498 		$theme_sidebars[ $sidebar ] = $registered_sidebar;
       
   499 	}
       
   500 }
       
   501 
       
   502 ?>
       
   503 </div>
       
   504 </div>
       
   505 <?php
       
   506 
       
   507 $i                    = 0;
       
   508 $split                = 0;
       
   509 $single_sidebar_class = '';
       
   510 $sidebars_count       = count( $theme_sidebars );
       
   511 
       
   512 if ( $sidebars_count > 1 ) {
       
   513 	$split = (int) ceil( $sidebars_count / 2 );
       
   514 } else {
       
   515 	$single_sidebar_class = ' single-sidebar';
       
   516 }
       
   517 
       
   518 ?>
       
   519 <div class="widget-liquid-right">
       
   520 <div id="widgets-right" class="wp-clearfix<?php echo $single_sidebar_class; ?>">
       
   521 <div class="sidebars-column-1">
       
   522 <?php
       
   523 
       
   524 foreach ( $theme_sidebars as $sidebar => $registered_sidebar ) {
       
   525 	$wrap_class = 'widgets-holder-wrap';
       
   526 	if ( ! empty( $registered_sidebar['class'] ) ) {
       
   527 		$wrap_class .= ' sidebar-' . $registered_sidebar['class'];
       
   528 	}
       
   529 
       
   530 	if ( $i > 0 ) {
       
   531 		$wrap_class .= ' closed';
       
   532 	}
       
   533 
       
   534 	if ( $split && $i === $split ) {
       
   535 		?>
       
   536 		</div><div class="sidebars-column-2">
       
   537 		<?php
       
   538 	}
       
   539 
       
   540 	?>
       
   541 	<div class="<?php echo esc_attr( $wrap_class ); ?>">
       
   542 		<?php
       
   543 		// Show the control forms for each of the widgets in this sidebar.
       
   544 		wp_list_widget_controls( $sidebar, $registered_sidebar['name'] );
       
   545 		?>
       
   546 	</div>
       
   547 	<?php
       
   548 
       
   549 	$i++;
       
   550 }
       
   551 
       
   552 ?>
       
   553 </div>
       
   554 </div>
       
   555 </div>
       
   556 <form method="post">
       
   557 <?php wp_nonce_field( 'save-sidebar-widgets', '_wpnonce_widgets', false ); ?>
       
   558 </form>
       
   559 <br class="clear" />
       
   560 </div>
       
   561 
       
   562 <div class="widgets-chooser">
       
   563 	<ul class="widgets-chooser-sidebars"></ul>
       
   564 	<div class="widgets-chooser-actions">
       
   565 		<button class="button widgets-chooser-cancel"><?php _e( 'Cancel' ); ?></button>
       
   566 		<button class="button button-primary widgets-chooser-add"><?php _e( 'Add Widget' ); ?></button>
       
   567 	</div>
       
   568 </div>
       
   569 
       
   570 <?php
       
   571 
       
   572 /**
       
   573  * Fires after the available widgets and sidebars have loaded, before the admin footer.
       
   574  *
       
   575  * @since 2.2.0
       
   576  */
       
   577 do_action( 'sidebar_admin_page' );
       
   578 require_once ABSPATH . 'wp-admin/admin-footer.php';