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