Version Description
- Added an Edit Sidebar screen for updating a sidebar name and associated pages.
- Added an update message when a sidebar is saved on the Add/Edit Page screen.
- Made the sidebar column sortable on the All Pages screen.
- Refactored the codebase (formatting, improved comments, static classes, organization, etc).
- Added better feedback throughout the dashboard when something goes wrong.
- Saved spinner image to plugin folder due to updates coming in 3.5.
- Removed deprecated filters.
Download this release
Release Info
Developer | blazersix |
Plugin | Simple Page Sidebars |
Version | 1.1 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 1.1
- admin/admin.php +526 -204
- admin/images/wpspin_light.gif +0 -0
- admin/includes/class-simple-page-sidebars-walker-page-checklist.php +36 -0
- admin/views/edit-sidebar-screen.php +79 -0
- admin/views/meta-box-page-sidebar.php +115 -0
- admin/views/meta-box-sidebar-pages.php +35 -0
- includes/widget-area.php +58 -20
- languages/simple-page-sidebars.pot +69 -29
- readme.txt +12 -3
- simple-page-sidebars.php +129 -78
- uninstall.php +1 -0
admin/admin.php
CHANGED
@@ -1,45 +1,92 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
class Simple_Page_Sidebars_Admin {
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
|
|
|
|
|
|
6 |
}
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
add_action( '
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
add_action( '
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
}
|
20 |
|
21 |
/**
|
22 |
-
* Register setting for choosing the default sidebar
|
23 |
-
*
|
24 |
-
* @since 0.2
|
25 |
*/
|
26 |
-
function
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
}
|
30 |
|
31 |
-
function register_reading_setting( $input ) { return $input; }
|
32 |
-
|
33 |
/**
|
34 |
-
* Default sidebar option dropdown
|
35 |
-
*
|
36 |
-
* @since 0.2
|
37 |
* @uses $wp_registered_sidebars
|
38 |
*/
|
39 |
-
function default_sidebar_settings_field() {
|
40 |
global $wp_registered_sidebars;
|
41 |
-
$default_sidebar_id = get_option( 'simple_page_sidebars_default_sidebar' );
|
42 |
|
|
|
43 |
$custom_sidebars = simple_page_sidebars_get_names();
|
44 |
?>
|
45 |
<select name="simple_page_sidebars_default_sidebar" id="simple-page-sidebars-default-sidebar">
|
@@ -56,204 +103,142 @@ class Simple_Page_Sidebars_Admin {
|
|
56 |
}
|
57 |
?>
|
58 |
</select>
|
59 |
-
<span class="description"><?php _e( 'The sidebar that
|
60 |
<?php
|
61 |
}
|
62 |
|
63 |
/**
|
64 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
*
|
66 |
-
*
|
67 |
-
* @since 0.2
|
68 |
*/
|
69 |
-
function
|
70 |
-
|
71 |
-
$post_id = $_POST['post_id'];
|
72 |
|
73 |
-
|
74 |
-
|
75 |
|
76 |
-
//
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
return;
|
82 |
}
|
83 |
|
84 |
-
|
85 |
-
// if 'sidebar_name' is blank or it equals 'default', delete meta
|
86 |
-
// if 'sidebar_name' is set and not empty, update to new name
|
87 |
-
// if 'sidebar_name' is -1, skip
|
88 |
|
89 |
-
|
90 |
-
if ( isset( $_REQUEST['new_sidebar_name' ] ) && ! empty( $_REQUEST['new_sidebar_name'] ) ) {
|
91 |
-
update_post_meta( $post_id, '_sidebar_name', $_REQUEST['new_sidebar_name'] );
|
92 |
-
} else {
|
93 |
-
// if $_REQUEST['sidebar_name'] isn't set, we don't want to update the sidebar meta value
|
94 |
-
$sidebar = ( isset( $_REQUEST['sidebar_name'] ) ) ? $_REQUEST['sidebar_name'] : -1;
|
95 |
-
|
96 |
-
if ( empty( $sidebar ) || 'default' == $sidebar ) {
|
97 |
-
delete_post_meta( $post_id, '_sidebar_name' );
|
98 |
-
} elseif ( -1 != intval( $sidebar ) ) {
|
99 |
-
update_post_meta( $post_id, '_sidebar_name', $_REQUEST['sidebar_name'] );
|
100 |
-
}
|
101 |
-
}
|
102 |
}
|
103 |
|
104 |
/**
|
105 |
-
*
|
106 |
-
*
|
107 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
*/
|
109 |
-
function
|
110 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
}
|
112 |
|
113 |
/**
|
114 |
-
*
|
115 |
-
*
|
116 |
-
* @since 0.2
|
117 |
-
* @
|
|
|
118 |
*/
|
119 |
-
function
|
120 |
-
|
121 |
-
|
122 |
-
$sidebar = get_post_meta( $page->ID, '_sidebar_name', true );
|
123 |
-
|
124 |
-
$custom_sidebars = simple_page_sidebars_get_names();
|
125 |
-
|
126 |
-
wp_nonce_field( 'update-page-sidebar-name-' . $page->ID, 'sidebar_name_nonce', false );
|
127 |
-
|
128 |
-
$default_sidebar_id = get_option( 'simple_page_sidebars_default_sidebar' );
|
129 |
-
if ( ! $default_sidebar_id ) {
|
130 |
-
echo '<p class="error">';
|
131 |
-
printf( __( 'For Simple Page Sidebars to work, a default sidebar needs to be selected on the %s', 'simple-page-sidebars' ),
|
132 |
-
' <a href="' . admin_url( 'options-reading.php' ) . '">' . __( 'Reading options panel', 'simple-page-sidebars') . '</a>.'
|
133 |
-
);
|
134 |
-
echo '</p>';
|
135 |
-
}
|
136 |
-
?>
|
137 |
-
<p>
|
138 |
-
<label for="sidebar-name"><?php _e( 'Current sidebar:', 'simple-page-sidebars' ); ?></label>
|
139 |
-
<select name="sidebar_name" id="sidebar-name" class="widefat">
|
140 |
-
<option value="default"><?php _e( 'Default Sidebar', 'simple-page-sidebars' ); ?></option>
|
141 |
-
<?php
|
142 |
-
foreach ( $custom_sidebars as $sb ) {
|
143 |
-
printf( '<option value="%s"%s>%s</option>',
|
144 |
-
esc_attr( $sb ),
|
145 |
-
selected( $sb, $sidebar, false ),
|
146 |
-
esc_html( $sb )
|
147 |
-
);
|
148 |
-
}
|
149 |
-
?>
|
150 |
-
</select>
|
151 |
-
<label for="new-sidebar-name" class="screen-reader-text"><?php _e( 'Or create a new sidebar:', 'simple-page-sidebars' ); ?></label>
|
152 |
-
<input type="text" name="new_sidebar_name" id="new-sidebar-name" class="widefat hide-if-js" value="" />
|
153 |
-
<span id="sidebarnew" class="hide-if-no-js"><?php _e( 'Enter New', 'simple-page-sidebars' ); ?></span>
|
154 |
-
<span id="sidebarcancel" class="hidden"><?php _e( 'Cancel', 'simple-page-sidebars' ); ?></span>
|
155 |
-
</p>
|
156 |
-
|
157 |
-
<p style="margin-top: 10px; margin-bottom: 0; text-align: right">
|
158 |
-
<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" id="sidebar-update-feedback" style="display: none" />
|
159 |
-
<button class="button"><?php _e( 'Update', 'simple-page-sidebars' ); ?></button>
|
160 |
-
</p>
|
161 |
-
|
162 |
-
<style type="text/css">
|
163 |
-
#sidebar-update-feedback { display: none; margin: 0 5px 0 0; vertical-align: middle;}
|
164 |
-
#sidebarcancel, #sidebarnew { cursor: pointer; float: left; margin: 3px 3px 0 3px; color: #21759b; font-size: 12px;}
|
165 |
-
#sidebarcancel, #sidebarnew:hover { color: #d54e21;}
|
166 |
-
#simplepagesidebarsdiv .error { color: #ee0000;}
|
167 |
-
</style>
|
168 |
-
|
169 |
-
<script type="text/javascript">
|
170 |
-
jQuery(function($) {
|
171 |
-
$('#sidebarcancel, #sidebarnew').click(function() {
|
172 |
-
$('#new-sidebar-name, #sidebar-name, #sidebarcancel, #sidebarnew').toggle();
|
173 |
-
|
174 |
-
// clear the new sidebar name field when cancel is clicked
|
175 |
-
if ( 'sidebarcancel' == $(this).attr('id') ) {
|
176 |
-
$('#new-sidebar-name').val('');
|
177 |
-
}
|
178 |
-
});
|
179 |
-
|
180 |
-
$('#simplepagesidebarsdiv').find('button').click(function(e) {
|
181 |
-
e.preventDefault();
|
182 |
-
|
183 |
-
$('#sidebar-update-feedback').show();
|
184 |
-
$.post(ajaxurl, {
|
185 |
-
action : 'simple_page_sidebars_update_page_sidebar',
|
186 |
-
post_id : $('#post_ID').val(),
|
187 |
-
sidebar_name : $('select[name="sidebar_name"]').val(),
|
188 |
-
new_sidebar_name : $('input[name="new_sidebar_name"]').val(),
|
189 |
-
sidebar_name_nonce : $('input[name="sidebar_name_nonce"]').val()
|
190 |
-
},
|
191 |
-
function(data){
|
192 |
-
new_sidebar_name = $('#new-sidebar-name').val();
|
193 |
-
|
194 |
-
if ( '' != new_sidebar_name ) {
|
195 |
-
if ( $('#simplepagesidebarsdiv select option[value="' + new_sidebar_name + '"]').length < 1 ) {
|
196 |
-
$('#simplepagesidebarsdiv select').append('<option selected="selected">' + new_sidebar_name + '</option>').val(new_sidebar_name);
|
197 |
-
} else {
|
198 |
-
$('#simplepagesidebarsdiv select option[value="' + new_sidebar_name + '"]').attr('selected','selected');
|
199 |
-
}
|
200 |
-
|
201 |
-
$('#new-sidebar-name, #sidebar-name, #sidebarcancel, #sidebarnew').toggle().filter('input').val('');
|
202 |
-
}
|
203 |
-
|
204 |
-
$('#sidebar-update-feedback').hide();
|
205 |
-
}
|
206 |
-
);
|
207 |
-
});
|
208 |
-
});
|
209 |
-
</script>
|
210 |
-
|
211 |
-
<br class="clear" />
|
212 |
-
<?php
|
213 |
}
|
214 |
|
215 |
/**
|
216 |
-
* Register
|
217 |
-
*
|
218 |
-
* @since 0
|
|
|
|
|
219 |
*/
|
220 |
-
function
|
221 |
-
$columns['sidebar'] =
|
|
|
222 |
return $columns;
|
223 |
}
|
224 |
|
225 |
/**
|
226 |
-
* Display sidebar column on All Pages screen
|
227 |
*
|
228 |
-
* @since 0.2
|
|
|
|
|
229 |
*/
|
230 |
-
function
|
231 |
-
if ( 'sidebar' == $column ) {
|
232 |
-
$sidebar =
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
234 |
|
235 |
-
//
|
236 |
-
wp_nonce_field( 'update-page-
|
237 |
}
|
238 |
}
|
239 |
|
240 |
/**
|
241 |
-
* Sidebar dropdown field for quick edit mode
|
242 |
-
*
|
243 |
-
* @since 0.2
|
|
|
|
|
244 |
*/
|
245 |
-
function quick_edit_custom_box( $column, $post_type ) {
|
246 |
-
if ( 'page' != $post_type || 'sidebar' != $column )
|
247 |
return;
|
|
|
248 |
|
249 |
$sidebars = simple_page_sidebars_get_names();
|
250 |
?>
|
251 |
<fieldset class="inline-edit-col-left">
|
252 |
<div class="inline-edit-col">
|
253 |
-
<div class="inline-edit-group" id="sidebar-edit-group">
|
254 |
<label>
|
255 |
<span class="title"><?php _e( 'Sidebar', 'simple-page-sidebars' ); ?></span>
|
256 |
-
<select name="
|
257 |
<option value="default"><?php _e( 'Default Sidebar', 'simple-page-sidebars' ); ?></option>
|
258 |
<?php
|
259 |
foreach ( $sidebars as $sb ) {
|
@@ -269,50 +254,57 @@ class Simple_Page_Sidebars_Admin {
|
|
269 |
}
|
270 |
|
271 |
/**
|
272 |
-
* Quick edit javascript
|
273 |
-
*
|
274 |
-
* Selects the correct sidebar during quick edit and copies the nonce for
|
275 |
-
*
|
276 |
-
*
|
|
|
277 |
*/
|
278 |
-
function quick_edit_js() {
|
279 |
-
$
|
280 |
|
281 |
-
if ( 'edit-page' != $
|
282 |
return;
|
|
|
283 |
?>
|
284 |
<script type="text/javascript">
|
285 |
jQuery(function($) {
|
286 |
$('table.pages').on('click', 'a.editinline', function(e) {
|
287 |
inlineEditPost.revert();
|
288 |
|
289 |
-
var id = inlineEditPost.getId(this)
|
290 |
-
|
|
|
291 |
|
292 |
-
//
|
293 |
-
|
294 |
if ( '' != currentSidebar ) {
|
295 |
-
|
296 |
}
|
297 |
|
298 |
-
//
|
299 |
-
$('#sidebar-edit-group').find('input[name="
|
300 |
});
|
301 |
});
|
302 |
</script>
|
303 |
<style type="text/css">
|
304 |
-
.widefat .column-sidebar { width: 15%;}
|
305 |
</style>
|
306 |
<?php
|
307 |
}
|
308 |
|
309 |
/**
|
310 |
-
* Sidebar dropdown field for bulk edit mode
|
311 |
-
*
|
312 |
-
* @since 0.2
|
|
|
|
|
313 |
*/
|
314 |
-
function bulk_edit_custom_box( $column, $post_type ) {
|
315 |
-
if ( 'page' != $post_type || 'sidebar' != $column ) {
|
|
|
|
|
316 |
|
317 |
$sidebars = simple_page_sidebars_get_names();
|
318 |
?>
|
@@ -320,7 +312,7 @@ class Simple_Page_Sidebars_Admin {
|
|
320 |
<div class="inline-edit-col">
|
321 |
<label>
|
322 |
<span class="title"><?php _e( 'Sidebar', 'simple-page-sidebars' ); ?></span>
|
323 |
-
<select name="
|
324 |
<option value="-1"><?php _e( '— No Change —', 'simple-page-sidebars' ); ?></option>
|
325 |
<option value="default"><?php _e( 'Default Sidebar', 'simple-page-sidebars' ); ?></option>
|
326 |
<?php
|
@@ -330,11 +322,341 @@ class Simple_Page_Sidebars_Admin {
|
|
330 |
?>
|
331 |
</select>
|
332 |
</label>
|
333 |
-
<?php wp_nonce_field( 'bulk-update-page-sidebar
|
334 |
</div>
|
335 |
</fieldset>
|
336 |
<?php
|
337 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
}
|
339 |
-
$simple_page_sidebars_admin = new Simple_Page_Sidebars_Admin();
|
340 |
?>
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* @package Simple Page Sidebars
|
4 |
+
* @subpackage Simple Page Sidebars Admin
|
5 |
+
*
|
6 |
+
* @todo Consider adding a Sidebars submenu to the Appearance menu for
|
7 |
+
* selecting and editing a sidebar.
|
8 |
+
* @todo Consider how to report any sidebars that get wiped out.
|
9 |
+
*/
|
10 |
+
|
11 |
+
/**
|
12 |
+
* Main admin class. Contains all the functionality to handle the various
|
13 |
+
* administrative tasks for creating, editing, and assigning sidebars to
|
14 |
+
* pages.
|
15 |
+
*
|
16 |
+
* @since 1.1.0
|
17 |
+
*/
|
18 |
class Simple_Page_Sidebars_Admin {
|
19 |
+
/**
|
20 |
+
* Load the admin functionality.
|
21 |
+
*
|
22 |
+
* @since 1.1.0
|
23 |
+
*/
|
24 |
+
public static function load() {
|
25 |
+
add_action( 'init', array( __CLASS__, 'init' ) );
|
26 |
}
|
27 |
|
28 |
+
/**
|
29 |
+
* Attaches the various hooks and methods for integrating with the
|
30 |
+
* dashboard.
|
31 |
+
*
|
32 |
+
* @since 0.2.0
|
33 |
+
*/
|
34 |
+
public static function init() {
|
35 |
+
// Process submissions from custom Sidebar Edit screen.
|
36 |
+
self::process_sidebar_update();
|
37 |
+
|
38 |
+
// Process Add/Edit Page screen submissions.
|
39 |
+
add_action( 'save_post', array( __CLASS__, 'update_page_sidebar' ) );
|
40 |
+
// Process quick edit and bulk edit from All Pages screen.
|
41 |
+
add_action( 'wp_ajax_simplepagesidebars_update_page_sidebar', array( __CLASS__, 'update_page_sidebar' ) );
|
42 |
+
|
43 |
+
add_action( 'admin_menu', array( __CLASS__, 'add_page_sidebar_meta_box' ) );
|
44 |
+
add_action( 'admin_menu', array( __CLASS__, 'add_sidebar_edit_screen' ) );
|
45 |
|
46 |
+
add_action( 'admin_init', array( __CLASS__, 'register_default_sidebar_setting' ) );
|
47 |
|
48 |
+
add_action( 'parent_file', array( __CLASS__, 'highlight_widget_submenu' ) );
|
49 |
+
|
50 |
+
add_filter( 'parse_query', array( __CLASS__, 'parse_admin_query' ) );
|
51 |
+
add_filter( 'manage_pages_columns', array( __CLASS__, 'register_columns' ) );
|
52 |
+
add_action( 'manage_edit-page_sortable_columns', array( __CLASS__, 'register_sortable_columns' ) );
|
53 |
+
add_action( 'manage_pages_custom_column', array( __CLASS__, 'display_columns' ), 10, 2 );
|
54 |
+
add_action( 'quick_edit_custom_box', array( __CLASS__, 'quick_edit_custom_box' ), 10, 2 );
|
55 |
+
add_action( 'bulk_edit_custom_box', array( __CLASS__, 'bulk_edit_custom_box' ), 10, 2 );
|
56 |
+
add_action( 'admin_footer-edit.php', array( __CLASS__, 'quick_edit_js' ) );
|
57 |
+
|
58 |
+
add_action( 'widgets_admin_page', array( __CLASS__, 'widgets_page_messages' ) );
|
59 |
}
|
60 |
|
61 |
/**
|
62 |
+
* Register setting for choosing the default sidebar.
|
63 |
+
*
|
64 |
+
* @since 0.2.0
|
65 |
*/
|
66 |
+
public static function register_default_sidebar_setting() {
|
67 |
+
register_setting(
|
68 |
+
'reading',
|
69 |
+
'simple_page_sidebars_default_sidebar'
|
70 |
+
);
|
71 |
+
|
72 |
+
add_settings_field(
|
73 |
+
'simple_page_sidebars_default_sidebar',
|
74 |
+
'<label for="simple-page-sidebars-default-sidebar">' . __( 'Default Sidebar', 'simple-page-sidebars' ) . '</label>',
|
75 |
+
array( __CLASS__, 'default_sidebar_settings_field' ),
|
76 |
+
'reading'
|
77 |
+
);
|
78 |
}
|
79 |
|
|
|
|
|
80 |
/**
|
81 |
+
* Default sidebar option dropdown.
|
82 |
+
*
|
83 |
+
* @since 0.2.0
|
84 |
* @uses $wp_registered_sidebars
|
85 |
*/
|
86 |
+
public static function default_sidebar_settings_field() {
|
87 |
global $wp_registered_sidebars;
|
|
|
88 |
|
89 |
+
$default_sidebar_id = get_option( 'simple_page_sidebars_default_sidebar' );
|
90 |
$custom_sidebars = simple_page_sidebars_get_names();
|
91 |
?>
|
92 |
<select name="simple_page_sidebars_default_sidebar" id="simple-page-sidebars-default-sidebar">
|
103 |
}
|
104 |
?>
|
105 |
</select>
|
106 |
+
<span class="description"><?php _e( 'The sidebar that should be replaced by custom sidebars.', 'simple-page-sidebars' ); ?></span>
|
107 |
<?php
|
108 |
}
|
109 |
|
110 |
/**
|
111 |
+
* Register page sidebar meta box.
|
112 |
+
*
|
113 |
+
* @since 0.2.0
|
114 |
+
*/
|
115 |
+
public static function add_page_sidebar_meta_box() {
|
116 |
+
add_meta_box( 'simplepagesidebarsdiv', __( 'Sidebar', 'simple-page-sidebars' ), array( __CLASS__, 'page_sidebar_meta_box' ), 'page', 'side', 'default' );
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Meta box for adding a new sidebar or choosing an existing sidebar.
|
121 |
+
*
|
122 |
+
* @since 0.2.0
|
123 |
+
* @uses $wpdb, $wp_registered_sidebars
|
124 |
+
* @todo Improve the update message delivery and only show it on success.
|
125 |
*
|
126 |
+
* @param object $page The post object being added or edited.
|
|
|
127 |
*/
|
128 |
+
public static function page_sidebar_meta_box( $page ) {
|
129 |
+
global $wpdb, $wp_registered_sidebars;
|
|
|
130 |
|
131 |
+
$sidebar = self::get_page_sidebar( $page->ID );
|
132 |
+
$custom_sidebars = simple_page_sidebars_get_names();
|
133 |
|
134 |
+
// Show an error message if a default sidebar hasn't been selected on the Reading settings screen.
|
135 |
+
if ( ! get_option( 'simple_page_sidebars_default_sidebar' )) {
|
136 |
+
echo '<div class="simple-page-sidebars-page-sidebar-feedback simple-page-sidebars-page-sidebar-feedback-error"><p>';
|
137 |
+
echo self::get_empty_default_sidebar_error();
|
138 |
+
echo '</p></div>';
|
|
|
139 |
}
|
140 |
|
141 |
+
wp_nonce_field( 'update-page-sidebar_' . $page->ID, 'simplepagesidebars_page_sidebar_update_nonce', false );
|
|
|
|
|
|
|
142 |
|
143 |
+
include_once( SIMPLE_PAGE_SIDEBARS_DIR . 'admin/views/meta-box-page-sidebar.php' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
}
|
145 |
|
146 |
/**
|
147 |
+
* Custom sort the pages on the All Pages screen.
|
148 |
+
*
|
149 |
+
* Any pages without the '_sidebar_name' meta field won't appear in the
|
150 |
+
* list when the pages are custom sorted.
|
151 |
+
*
|
152 |
+
* The $wp_query object is passed be reference and any changes made to it
|
153 |
+
* will be reflected globally.
|
154 |
+
*
|
155 |
+
* @since 1.1.0
|
156 |
+
* @link http://codex.wordpress.org/Class_Reference/WP_Query
|
157 |
+
*
|
158 |
+
* @param object $wp_query The WP_Query object passed by reference.
|
159 |
*/
|
160 |
+
public static function parse_admin_query( $wp_query ) {
|
161 |
+
// Ensure this only affects requests in the dashboard.
|
162 |
+
if ( is_admin() && isset( $_GET['post_type'] ) && 'page' == $_GET['post_type'] ) {
|
163 |
+
if ( ! empty( $_GET['orderby'] ) && 'simple-page-sidebar' == $_GET['orderby'] ) {
|
164 |
+
// An example to sort results by a custom meta field.
|
165 |
+
$wp_query->set( 'meta_key', '_sidebar_name' );
|
166 |
+
$wp_query->set( 'orderby', 'meta_value' );
|
167 |
+
|
168 |
+
// Set the order.
|
169 |
+
$order = ( isset( $_GET['order'] ) && 'desc' == $_GET['order'] ) ? 'desc' : 'asc';
|
170 |
+
$wp_query->set( 'order', $order );
|
171 |
+
}
|
172 |
+
}
|
173 |
}
|
174 |
|
175 |
/**
|
176 |
+
* Register sidebar column on the All Pages screen.
|
177 |
+
*
|
178 |
+
* @since 0.2.0
|
179 |
+
* @param array $columns Array of column names and corresponding IDs as keys.
|
180 |
+
* @param array $columns The filtered columns array.
|
181 |
*/
|
182 |
+
public static function register_columns( $columns ) {
|
183 |
+
$columns['simple-page-sidebar'] = __( 'Sidebar', 'simple-page-sidebars' );
|
184 |
+
return $columns;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
185 |
}
|
186 |
|
187 |
/**
|
188 |
+
* Register sortable columns on the All Pages screen.
|
189 |
+
*
|
190 |
+
* @since 1.1.0
|
191 |
+
* @param array $columns Array of query vars and corresponding column IDs as keys.
|
192 |
+
* @return array $columns The filtered columns array.
|
193 |
*/
|
194 |
+
public static function register_sortable_columns( $columns ) {
|
195 |
+
$columns['simple-page-sidebar'] = 'simple-page-sidebar';
|
196 |
+
|
197 |
return $columns;
|
198 |
}
|
199 |
|
200 |
/**
|
201 |
+
* Display sidebar column on All Pages screen.
|
202 |
*
|
203 |
+
* @since 0.2.0
|
204 |
+
* @param string $column The ID of the column being displayed.
|
205 |
+
* @param int $page_id The ID of the page the column is associated with.
|
206 |
*/
|
207 |
+
public static function display_columns( $column, $page_id ) {
|
208 |
+
if ( 'simple-page-sidebar' == $column ) {
|
209 |
+
$sidebar = self::get_page_sidebar( $page_id );
|
210 |
+
if ( $sidebar ) {
|
211 |
+
printf( '<a href="%s">%s</a>',
|
212 |
+
esc_url( self::get_sidebar_edit_link( $sidebar ) ),
|
213 |
+
$sidebar
|
214 |
+
);
|
215 |
+
}
|
216 |
|
217 |
+
// Add the nonce here and copy it to the inline editor with javascript.
|
218 |
+
wp_nonce_field( 'update-page-sidebar_' . $page_id, 'simplepagesidebars_page_sidebar_update_nonce', false );
|
219 |
}
|
220 |
}
|
221 |
|
222 |
/**
|
223 |
+
* Sidebar dropdown field for quick edit mode.
|
224 |
+
*
|
225 |
+
* @since 0.2.0
|
226 |
+
* @param string $column The ID of the column being rendered.
|
227 |
+
* @param string $post_type The type of post being updated.
|
228 |
*/
|
229 |
+
public static function quick_edit_custom_box( $column, $post_type ) {
|
230 |
+
if ( 'page' != $post_type || 'simple-page-sidebar' != $column ) {
|
231 |
return;
|
232 |
+
}
|
233 |
|
234 |
$sidebars = simple_page_sidebars_get_names();
|
235 |
?>
|
236 |
<fieldset class="inline-edit-col-left">
|
237 |
<div class="inline-edit-col">
|
238 |
+
<div class="inline-edit-group" id="simple-page-sidebars-page-sidebar-edit-group">
|
239 |
<label>
|
240 |
<span class="title"><?php _e( 'Sidebar', 'simple-page-sidebars' ); ?></span>
|
241 |
+
<select name="simplepagesidebars_page_sidebar_name" id="simple-page-sidebars-page-sidebar-name">
|
242 |
<option value="default"><?php _e( 'Default Sidebar', 'simple-page-sidebars' ); ?></option>
|
243 |
<?php
|
244 |
foreach ( $sidebars as $sb ) {
|
254 |
}
|
255 |
|
256 |
/**
|
257 |
+
* Quick edit javascript.
|
258 |
+
*
|
259 |
+
* Selects the correct sidebar during quick edit and copies the nonce for
|
260 |
+
* saving.
|
261 |
+
*
|
262 |
+
* @since 0.2.0
|
263 |
*/
|
264 |
+
public static function quick_edit_js() {
|
265 |
+
$screen = get_current_screen();
|
266 |
|
267 |
+
if ( 'edit-page' != $screen->id || 'page' != $screen->post_type ) {
|
268 |
return;
|
269 |
+
}
|
270 |
?>
|
271 |
<script type="text/javascript">
|
272 |
jQuery(function($) {
|
273 |
$('table.pages').on('click', 'a.editinline', function(e) {
|
274 |
inlineEditPost.revert();
|
275 |
|
276 |
+
var id = inlineEditPost.getId(this),
|
277 |
+
currentSidebar = $('#post-' + id + ' .simple-page-sidebar').text(),
|
278 |
+
sidebarNameField = $('#simple-page-sidebars-page-sidebar-name');
|
279 |
|
280 |
+
// Select the current sidebar option.
|
281 |
+
sidebarNameField.find('option').attr('selected', false);
|
282 |
if ( '' != currentSidebar ) {
|
283 |
+
sidebarNameField.find('option:contains(' + currentSidebar + ')').attr('selected', true);
|
284 |
}
|
285 |
|
286 |
+
// Copy the sidebar name nonce.
|
287 |
+
$('#simple-page-sidebars-page-sidebar-edit-group').find('input[name="simplepagesidebars_page_sidebar_update_nonce"]').remove().end().append( $('#post-' + id + ' input[name="simplepagesidebars_page_sidebar_update_nonce"]').clone() );
|
288 |
});
|
289 |
});
|
290 |
</script>
|
291 |
<style type="text/css">
|
292 |
+
.widefat .column-simple-page-sidebar { width: 15%;}
|
293 |
</style>
|
294 |
<?php
|
295 |
}
|
296 |
|
297 |
/**
|
298 |
+
* Sidebar dropdown field for bulk edit mode.
|
299 |
+
*
|
300 |
+
* @since 0.2.0
|
301 |
+
* @param string $column The ID of the column being rendered.
|
302 |
+
* @param string $post_type The type of post being updated.
|
303 |
*/
|
304 |
+
public static function bulk_edit_custom_box( $column, $post_type ) {
|
305 |
+
if ( 'page' != $post_type || 'simple-page-sidebar' != $column ) {
|
306 |
+
return;
|
307 |
+
}
|
308 |
|
309 |
$sidebars = simple_page_sidebars_get_names();
|
310 |
?>
|
312 |
<div class="inline-edit-col">
|
313 |
<label>
|
314 |
<span class="title"><?php _e( 'Sidebar', 'simple-page-sidebars' ); ?></span>
|
315 |
+
<select name="simplepagesidebars_page_sidebar_name" id="simple-page-sidebars-page-sidebar-name">
|
316 |
<option value="-1"><?php _e( '— No Change —', 'simple-page-sidebars' ); ?></option>
|
317 |
<option value="default"><?php _e( 'Default Sidebar', 'simple-page-sidebars' ); ?></option>
|
318 |
<?php
|
322 |
?>
|
323 |
</select>
|
324 |
</label>
|
325 |
+
<?php wp_nonce_field( 'bulk-update-page-sidebar', 'simplepagesidebars_bulk_update_nonce', false ); ?>
|
326 |
</div>
|
327 |
</fieldset>
|
328 |
<?php
|
329 |
}
|
330 |
+
|
331 |
+
/**
|
332 |
+
* Save custom page sidebar.
|
333 |
+
*
|
334 |
+
* Processes requests coming from normal page edits, quick edit, and bulk
|
335 |
+
* edit. Requires a valid nonce.
|
336 |
+
*
|
337 |
+
* @since 0.2.0
|
338 |
+
* @param int $post_id Optional. The ID of the page whose sidebar should be updated.
|
339 |
+
*/
|
340 |
+
public static function update_page_sidebar( $post_id = null ) {
|
341 |
+
if ( empty( $post_id ) ) {
|
342 |
+
$post_id = $_REQUEST['post_id'];
|
343 |
+
}
|
344 |
+
|
345 |
+
// Verify either an individual post nonce or the bulk edit nonce.
|
346 |
+
// Requests can come from a page update, AJAX from the sidebar meta box, quick edit, or bulk edit.
|
347 |
+
$is_nonce_valid = ( isset( $_REQUEST['simplepagesidebars_page_sidebar_update_nonce'] ) && wp_verify_nonce( $_REQUEST['simplepagesidebars_page_sidebar_update_nonce'], 'update-page-sidebar_' . $post_id ) ) ? true : false;
|
348 |
+
$is_bulk_nonce_valid = ( isset( $_REQUEST['simplepagesidebars_bulk_update_nonce'] ) && wp_verify_nonce( $_REQUEST['simplepagesidebars_bulk_update_nonce'], 'bulk-update-page-sidebar' ) ) ? true : false;
|
349 |
+
$is_autosave = ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) ? true : false;
|
350 |
+
$is_revision = wp_is_post_revision( $post_id );
|
351 |
+
|
352 |
+
if ( ( $is_autosave || $is_revision ) || ( ! $is_nonce_valid && ! $is_bulk_nonce_valid ) ) {
|
353 |
+
return $post_id;
|
354 |
+
}
|
355 |
+
|
356 |
+
// If 'new_sidebar_name' is set and not empty, it supercedes any 'sidebar_name' setting.
|
357 |
+
// If 'sidebar_name' is blank or it equals 'default', delete meta.
|
358 |
+
// If 'sidebar_name' is set and not empty, update to new name.
|
359 |
+
// If 'sidebar_name' is -1, skip.
|
360 |
+
|
361 |
+
// Bulk edit uses $_GET for some reason, so we use the $_REQUEST global to catch everything.
|
362 |
+
$sidebar = ( isset( $_REQUEST['simplepagesidebars_page_sidebar_name'] ) ) ? self::sanitize_sidebar_name( $_REQUEST['simplepagesidebars_page_sidebar_name'] ) : -1;
|
363 |
+
$new_sidebar_name = ( isset( $_REQUEST['simplepagesidebars_page_sidebar_name_new'] ) ) ? self::sanitize_sidebar_name( $_REQUEST['simplepagesidebars_page_sidebar_name_new'] ) : '';
|
364 |
+
|
365 |
+
if ( isset( $new_sidebar_name ) && ! empty( $new_sidebar_name ) ) {
|
366 |
+
update_post_meta( $post_id, '_sidebar_name', $new_sidebar_name );
|
367 |
+
} elseif ( empty( $sidebar ) || 'default' == $sidebar ) {
|
368 |
+
delete_post_meta( $post_id, '_sidebar_name' );
|
369 |
+
} elseif ( -1 != intval( $sidebar ) ) {
|
370 |
+
update_post_meta( $post_id, '_sidebar_name', $sidebar );
|
371 |
+
}
|
372 |
+
}
|
373 |
+
|
374 |
+
/**
|
375 |
+
* Add a custom Sidebar Edit screen.
|
376 |
+
*
|
377 |
+
* The menu title argument in add_submenu_page() is null so the page won't
|
378 |
+
* appear in the admin menu. It simply registers the screen so it's
|
379 |
+
* available when visited.
|
380 |
+
*
|
381 |
+
* @since 1.1.0
|
382 |
+
*/
|
383 |
+
public static function add_sidebar_edit_screen() {
|
384 |
+
add_submenu_page( 'themes.php', __( 'Edit Sidebar', 'simple-page-sidebars' ), null, 'edit_theme_options', 'simple-page-sidebars', array( __CLASS__, 'edit_sidebar_screen' ) );
|
385 |
+
|
386 |
+
add_meta_box( 'simplepagesidebarseditdiv', 'Pages', array( __CLASS__, 'edit_sidebar_pages_meta_box' ), 'appearance_page_simple-page-sidebars', 'normal', 'default' );
|
387 |
+
}
|
388 |
+
|
389 |
+
/**
|
390 |
+
* Highlight the widget submenu when the Edit Sidebar screen is being
|
391 |
+
* iewed.
|
392 |
+
*
|
393 |
+
* @since 1.1.0
|
394 |
+
* @uses $submenu_file
|
395 |
+
*
|
396 |
+
* @param string $parent_file The top level menu item being viewed.
|
397 |
+
* @return string $parent_file
|
398 |
+
*/
|
399 |
+
function highlight_widget_submenu( $parent_file ) {
|
400 |
+
global $submenu_file;
|
401 |
+
|
402 |
+
$screen = get_current_screen();
|
403 |
+
if ( 'appearance_page_simple-page-sidebars' == $screen->id ) {
|
404 |
+
$submenu_file = 'widgets.php';
|
405 |
+
}
|
406 |
+
|
407 |
+
return $parent_file;
|
408 |
+
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Display the Edit Sidebar screen.
|
412 |
+
*
|
413 |
+
* The sidebar being edited is passed as a variable through the query
|
414 |
+
* string. If it's determined that the sidebar isn't valid, an error will
|
415 |
+
* be shown.
|
416 |
+
*
|
417 |
+
* @since 1.1.0
|
418 |
+
*/
|
419 |
+
public static function edit_sidebar_screen() {
|
420 |
+
global $wpdb;
|
421 |
+
|
422 |
+
wp_enqueue_script( 'post' );
|
423 |
+
|
424 |
+
$screen = get_current_screen();
|
425 |
+
$sidebar_name = self::sanitize_sidebar_name( $_GET['sidebar'] );
|
426 |
+
|
427 |
+
include( SIMPLE_PAGE_SIDEBARS_DIR . 'admin/views/edit-sidebar-screen.php' );
|
428 |
+
}
|
429 |
+
|
430 |
+
/**
|
431 |
+
* Add a page checbox list meta box to the Edit Sidebar screen.
|
432 |
+
*
|
433 |
+
* @since 1.1.0
|
434 |
+
* @param object $post The post being edited.
|
435 |
+
* @param array $metabox Any additional arguments passed during the meta box registration.
|
436 |
+
*/
|
437 |
+
public static function edit_sidebar_pages_meta_box( $post, $metabox ) {
|
438 |
+
$default_sidebar = get_option( 'simple_page_sidebars_default_sidebar' );
|
439 |
+
|
440 |
+
include_once( SIMPLE_PAGE_SIDEBARS_DIR . 'admin/includes/class-simple-page-sidebars-walker-page-checklist.php' );
|
441 |
+
include_once( SIMPLE_PAGE_SIDEBARS_DIR . 'admin/views/meta-box-sidebar-pages.php' );
|
442 |
+
}
|
443 |
+
|
444 |
+
/**
|
445 |
+
* Process submissions for the Edit Sidebar screen.
|
446 |
+
*
|
447 |
+
* Handles cases where the sidebar is renamed, reassigns pages, and
|
448 |
+
* removes the sidebar if no pages are selected. Requires a valid nonce.
|
449 |
+
*
|
450 |
+
* @since 1.1.0
|
451 |
+
*/
|
452 |
+
public static function process_sidebar_update() {
|
453 |
+
if ( isset( $_POST['simplepagesidebars_sidebar_name'] ) ) {
|
454 |
+
$current_name = $_POST['simplepagesidebars_sidebar_name'];
|
455 |
+
|
456 |
+
check_admin_referer( 'update-sidebar_' . $current_name, 'simplepagesidebars_sidebar_update_nonce' );
|
457 |
+
|
458 |
+
$new_name = $_POST['simplepagesidebars_sidebar_name_new'];
|
459 |
+
$new_name = ( ! empty( $new_name ) && $new_name != $current_name ) ? trim( wp_strip_all_tags( $new_name ) ) : null;
|
460 |
+
|
461 |
+
$pages = ( isset( $_POST['simplepagesidebars_sidebar_pages'] ) ) ? wp_parse_id_list( $_POST['simplepagesidebars_sidebar_pages'] ) : array();
|
462 |
+
|
463 |
+
// Retrieve IDs of pages using the existing sidebar name.
|
464 |
+
$current_pages = self::get_page_ids_using_sidebar( $current_name );
|
465 |
+
|
466 |
+
// Pages to reset to the default sidebar.
|
467 |
+
$reset_pages = array_diff( $current_pages, $pages );
|
468 |
+
if ( $reset_pages ) {
|
469 |
+
foreach( $reset_pages as $page_id ) {
|
470 |
+
delete_post_meta( $page_id, '_sidebar_name' );
|
471 |
+
}
|
472 |
+
}
|
473 |
+
|
474 |
+
// Update submitted page sidebars if there is a new sidebar name.
|
475 |
+
if ( $new_name && ! empty( $pages ) ) {
|
476 |
+
foreach( $pages as $page_id ) {
|
477 |
+
update_post_meta( $page_id, '_sidebar_name', $new_name );
|
478 |
+
}
|
479 |
+
}
|
480 |
+
// Update newly selected pages with the current sidebar name.
|
481 |
+
elseif ( $update_pages = array_diff( $pages, $current_pages ) ) {
|
482 |
+
foreach( $update_pages as $page_id ) {
|
483 |
+
update_post_meta( $page_id, '_sidebar_name', $current_name );
|
484 |
+
}
|
485 |
+
}
|
486 |
+
|
487 |
+
// The sidebar should have been removed from all pages.
|
488 |
+
// Let WordPress move widgets to Inactive Sidebar, redirect to Widgets screen, and notify user.
|
489 |
+
if ( empty( $pages ) ) {
|
490 |
+
wp_safe_redirect( esc_url_raw( add_query_arg( 'simple-page-sidebars-message', 1, admin_url( 'widgets.php' ) ) ) );
|
491 |
+
exit;
|
492 |
+
}
|
493 |
+
|
494 |
+
// Migrate widgets if the sidebar name was changed.
|
495 |
+
if ( $new_name ) {
|
496 |
+
$sidebars_widgets = wp_get_sidebars_widgets();
|
497 |
+
|
498 |
+
$old_id = 'page-sidebar-' . sanitize_key( $current_name );
|
499 |
+
$new_id = 'page-sidebar-' . sanitize_key( $new_name );
|
500 |
+
|
501 |
+
// If new id matches an existing id, merge old widgets with new.
|
502 |
+
if ( isset( $sidebars_widgets[ $new_id ] ) ) {
|
503 |
+
$sidebars_widgets[ $new_id ] = array_merge( $sidebars_widgets[ $new_id ], $sidebars_widgets[ $old_id ] );
|
504 |
+
}
|
505 |
+
// Otherwise, copy old widgets to new.
|
506 |
+
elseif ( isset( $sidebars_widgets[ $old_id ] ) ) {
|
507 |
+
$sidebars_widgets[ $new_id ] = $sidebars_widgets[ $old_id ];
|
508 |
+
}
|
509 |
+
|
510 |
+
// Remove old widget area and save.
|
511 |
+
unset( $sidebars_widgets[ $old_id ] );
|
512 |
+
#echo '<pre>'; print_r( $sidebars_widgets ); echo '</pre>'; exit;
|
513 |
+
wp_set_sidebars_widgets( $sidebars_widgets );
|
514 |
+
}
|
515 |
+
|
516 |
+
// Redirect back to sidebar edit screen with an update message.
|
517 |
+
$name = ( ! empty( $new_name ) ) ? $new_name : $current_name;
|
518 |
+
$redirect_link = self::get_sidebar_edit_link( $name, array( 'message' => 1 ) );
|
519 |
+
wp_safe_redirect( esc_url_raw( $redirect_link ) );
|
520 |
+
exit;
|
521 |
+
}
|
522 |
+
}
|
523 |
+
|
524 |
+
/**
|
525 |
+
* Display messages on the widgets page.
|
526 |
+
*
|
527 |
+
* @since 1.1.0
|
528 |
+
*/
|
529 |
+
public static function widgets_page_messages() {
|
530 |
+
$sidebars = simple_page_sidebars_get_names();
|
531 |
+
|
532 |
+
// Display an error message if a default sidebar hasn't been selected on the Reading settings screen.
|
533 |
+
if ( ! get_option( 'simple_page_sidebars_default_sidebar' ) && ! empty( $sidebars ) ) {
|
534 |
+
echo '<div class="error"><p>' . self::get_empty_default_sidebar_error() . '</p></div>';
|
535 |
+
}
|
536 |
+
|
537 |
+
// Display any custom update messages.
|
538 |
+
if ( isset( $_REQUEST['simple-page-sidebars-message'] ) && ! empty( $_REQUEST['simple-page-sidebars-message'] ) ) {
|
539 |
+
?>
|
540 |
+
<div id="message" class="updated">
|
541 |
+
<p>
|
542 |
+
<?php
|
543 |
+
$messages = array(
|
544 |
+
1 => __( 'The sidebar you were editing is no longer assigned to any pages and has been removed. Any widgets it contained should be in an "Inactive Widgets" area below.', 'simple-page-sidebars' )
|
545 |
+
);
|
546 |
+
|
547 |
+
$message_id = $_REQUEST['simple-page-sidebars-message'];
|
548 |
+
if ( isset( $messages[ $message_id ] ) ) {
|
549 |
+
echo $messages[ $message_id ];
|
550 |
+
}
|
551 |
+
?>
|
552 |
+
</p>
|
553 |
+
</div>
|
554 |
+
<?php
|
555 |
+
}
|
556 |
+
}
|
557 |
+
|
558 |
+
/**
|
559 |
+
* Get a page's sidebar.
|
560 |
+
*
|
561 |
+
* Sanitizes the sidebar name before returning it.
|
562 |
+
*
|
563 |
+
* @since 1.1.0
|
564 |
+
* @param int $page_id ID of the page whose sidebar should be returned.
|
565 |
+
* @return string Sanitized sidebar name.
|
566 |
+
*/
|
567 |
+
public static function get_page_sidebar( $page_id ) {
|
568 |
+
return self::sanitize_sidebar_name( get_post_meta( $page_id, '_sidebar_name', true ) );
|
569 |
+
}
|
570 |
+
|
571 |
+
/**
|
572 |
+
* Retrieve IDs of pages using a particular sidebar.
|
573 |
+
*
|
574 |
+
* @since 1.1.0
|
575 |
+
* @param string $sidebar The sidebar name.
|
576 |
+
* @return array An array of page IDs or an empty array.
|
577 |
+
*/
|
578 |
+
public static function get_page_ids_using_sidebar( $sidebar ) {
|
579 |
+
global $wpdb;
|
580 |
+
|
581 |
+
$ids = $wpdb->get_col( $wpdb->prepare( "SELECT p.ID
|
582 |
+
FROM $wpdb->posts p
|
583 |
+
INNER JOIN $wpdb->postmeta pm ON p.ID=pm.post_id
|
584 |
+
WHERE p.post_type='page' AND p.post_status!='auto-draft' AND pm.meta_key='_sidebar_name' AND pm.meta_value=%s",
|
585 |
+
$sidebar
|
586 |
+
) );
|
587 |
+
|
588 |
+
return ( empty( $ids ) ) ? array() : $ids;
|
589 |
+
}
|
590 |
+
|
591 |
+
/**
|
592 |
+
* Sanitize a sidebar name.
|
593 |
+
*
|
594 |
+
* @since 1.1.0
|
595 |
+
* @param string $name The sidebar name.
|
596 |
+
* @return string Sanitized sidebar name.
|
597 |
+
*/
|
598 |
+
public static function sanitize_sidebar_name( $name ) {
|
599 |
+
return trim( wp_strip_all_tags( $name ) );
|
600 |
+
}
|
601 |
+
|
602 |
+
/**
|
603 |
+
* Get the edit link for a sidebar.
|
604 |
+
*
|
605 |
+
* @since 1.1.0
|
606 |
+
* @param string $sidebar The sidebar name.
|
607 |
+
* @param array $query_args Optional. An array of additional query args to append to the edit link.
|
608 |
+
* @return string The URL to edit the sidebar.
|
609 |
+
*/
|
610 |
+
public static function get_sidebar_edit_link( $sidebar, $query_args = array() ) {
|
611 |
+
$query_args = wp_parse_args( $query_args, array(
|
612 |
+
'page' => 'simple-page-sidebars',
|
613 |
+
'sidebar' => rawurlencode( $sidebar )
|
614 |
+
) );
|
615 |
+
|
616 |
+
$link = add_query_arg( $query_args, admin_url( 'themes.php' ) );
|
617 |
+
|
618 |
+
return $link;
|
619 |
+
}
|
620 |
+
|
621 |
+
/**
|
622 |
+
* The error message to display if a default sidebar hasn't been selected.
|
623 |
+
*
|
624 |
+
* This is used a few times throughout the dashboard, so the string is
|
625 |
+
* abstracted out here.
|
626 |
+
*
|
627 |
+
* @since 1.1.0
|
628 |
+
* @return string Error message
|
629 |
+
*/
|
630 |
+
public static function get_empty_default_sidebar_error() {
|
631 |
+
return sprintf( __( 'For Simple Page Sidebars to work, a default sidebar needs to be selected on the %s', 'simple-page-sidebars' ),
|
632 |
+
' <a href="' . admin_url( 'options-reading.php' ) . '">' . __( 'Reading settings screen', 'simple-page-sidebars' ) . '</a>.'
|
633 |
+
);
|
634 |
+
}
|
635 |
+
|
636 |
+
/**
|
637 |
+
* Backward compatible AJAX spinner.
|
638 |
+
*
|
639 |
+
* Displays the correct AJAX spinner depending on the version of WordPress.
|
640 |
+
*
|
641 |
+
* @since 1.1.0
|
642 |
+
*
|
643 |
+
* @param array $args Array of args to modify output.
|
644 |
+
*/
|
645 |
+
public static function spinner( $args = array() ) {
|
646 |
+
$args = wp_parse_args( $args, array(
|
647 |
+
'id' => '',
|
648 |
+
'class' => ''
|
649 |
+
) );
|
650 |
+
|
651 |
+
if ( version_compare( get_bloginfo( 'version' ), '3.5-beta-1', '<' ) ) {
|
652 |
+
printf( '<img src="%1$s" id="%2$s" class="%3$s" alt="">',
|
653 |
+
esc_url( SIMPLE_PAGE_SIDEBARS_URL . 'admin/images/wpspin_light.gif' ),
|
654 |
+
esc_attr( $args['id'] ),
|
655 |
+
esc_attr( $args['class'] )
|
656 |
+
);
|
657 |
+
} else {
|
658 |
+
printf( '<span id="%s" class="spinner"></span>', esc_attr( $args['id'] ) );
|
659 |
+
}
|
660 |
+
}
|
661 |
}
|
|
|
662 |
?>
|
admin/images/wpspin_light.gif
ADDED
Binary file
|
admin/includes/class-simple-page-sidebars-walker-page-checklist.php
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Custom page checklist walker.
|
4 |
+
*
|
5 |
+
* @since 1.1.0
|
6 |
+
*/
|
7 |
+
class Simple_Page_Siders_Walker_Page_Checklist extends Walker_Page {
|
8 |
+
/**
|
9 |
+
* @see Walker::start_el()
|
10 |
+
* @since 1.1.0
|
11 |
+
*
|
12 |
+
* @param string $output Passed by reference. Used to append additional content.
|
13 |
+
* @param object $page Page data object.
|
14 |
+
* @param int $depth Depth of page. Used for padding.
|
15 |
+
* @param int $current_page Page ID.
|
16 |
+
* @param array $args
|
17 |
+
*/
|
18 |
+
function start_el( &$output, $page, $depth, $args, $current_page = 0 ) {
|
19 |
+
if ( $depth ) {
|
20 |
+
$indent = str_repeat( "\t", $depth );
|
21 |
+
} else {
|
22 |
+
$indent = '';
|
23 |
+
}
|
24 |
+
|
25 |
+
$current_sidebar = Simple_Page_Sidebars_Admin::get_page_sidebar( $page->ID );
|
26 |
+
|
27 |
+
$output .= sprintf( '%s<li><label class="selectit"><input type="checkbox" name="simplepagesidebars_sidebar_pages[]" value="%d"%s> %s%s</label>',
|
28 |
+
$indent,
|
29 |
+
$page->ID,
|
30 |
+
checked( in_array( $page->ID, $args['selected'] ), true, false ),
|
31 |
+
apply_filters( 'the_title', $page->post_title, $page->ID ),
|
32 |
+
( $current_sidebar ) ? ' <em class="description" style="font-size: 11px">(' . $current_sidebar . ')</em>' : ''
|
33 |
+
);
|
34 |
+
}
|
35 |
+
}
|
36 |
+
?>
|
admin/views/edit-sidebar-screen.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div class="wrap simple-page-sidebars-edit-sidebar">
|
2 |
+
<div id="icon-tools" class="icon32"><br></div>
|
3 |
+
<h2>Edit Sidebar</h2>
|
4 |
+
|
5 |
+
<?php
|
6 |
+
// Display an error message if a default sidebar hasn't been selected on the Reading settings screen.
|
7 |
+
if ( ! get_option( 'simple_page_sidebars_default_sidebar' ) ) {
|
8 |
+
echo '<div class="error"><p>' . self::get_empty_default_sidebar_error() . '</p></div>';
|
9 |
+
}
|
10 |
+
|
11 |
+
// Display an error message and stop rendering the screen if the requested sidebar is not valid.
|
12 |
+
if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_sidebar_name' AND meta_value=%s", $sidebar_name ) ) ) {
|
13 |
+
echo '<div class="error"><p>' . __( 'Whoops, that doesn\'t appear to be a sidebar that can be edited.', 'simple-page-sidebars' ) . '</p></div>';
|
14 |
+
echo '</div>'; // close div.wrap
|
15 |
+
return;
|
16 |
+
}
|
17 |
+
|
18 |
+
// Display any custom update messages.
|
19 |
+
if ( isset( $_REQUEST['message'] ) ) {
|
20 |
+
?>
|
21 |
+
<div id="message" class="updated">
|
22 |
+
<p>
|
23 |
+
<?php
|
24 |
+
$messages = array(
|
25 |
+
1 => sprintf( '%s <a href="' . esc_url( admin_url( 'widgets.php' ) ) . '">%s</a>',
|
26 |
+
__( 'Sidebar settings updated.', 'simple-page-sidebars' ),
|
27 |
+
__( 'Update widgets now.', 'simple-page-sidebars' )
|
28 |
+
)
|
29 |
+
);
|
30 |
+
|
31 |
+
if ( ! empty( $_REQUEST['message'] ) && isset( $messages[ $_REQUEST['message'] ] ) ) {
|
32 |
+
echo $messages[ $_REQUEST['message'] ];
|
33 |
+
}
|
34 |
+
|
35 |
+
$_SERVER['REQUEST_URI'] = remove_query_arg( array( 'message' ), $_SERVER['REQUEST_URI'] );
|
36 |
+
?>
|
37 |
+
</p>
|
38 |
+
</div>
|
39 |
+
<?php
|
40 |
+
}
|
41 |
+
?>
|
42 |
+
|
43 |
+
<form action="" method="post">
|
44 |
+
<div id="poststuff">
|
45 |
+
<div id="post-body" class="metabox-holder"><!--columns-2-->
|
46 |
+
|
47 |
+
<div id="post-body-content">
|
48 |
+
<div class="sidebar-name-wrap">
|
49 |
+
<label for="simple-page-sidebars-sidebar-name-new" class="screen-reader-text">Sidebar Name:</label>
|
50 |
+
<input type="text" name="simplepagesidebars_sidebar_name_new" id="simple-page-sidebars-sidebar-name-new" value="<?php echo esc_attr( $sidebar_name ); ?>" placeholder="Enter sidebar name here" autocomplete="off">
|
51 |
+
<input type="hidden" name="simplepagesidebars_sidebar_name" value="<?php echo esc_attr( $sidebar_name ); ?>">
|
52 |
+
</div>
|
53 |
+
|
54 |
+
<?php do_meta_boxes( $screen->id, 'normal', '' ); ?>
|
55 |
+
|
56 |
+
<p class="submit">
|
57 |
+
<?php
|
58 |
+
wp_nonce_field( 'update-sidebar_' . $sidebar_name, 'simplepagesidebars_sidebar_update_nonce', true );
|
59 |
+
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
|
60 |
+
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
|
61 |
+
?>
|
62 |
+
<input type="submit" name="simplepagesidebars_sidebar_update" value="<?php esc_attr_e( 'Update Sidebar', 'simple-page-sidebars' ); ?>" class="button-primary">
|
63 |
+
<!--<a href="#">Delete Sidebar</a>-->
|
64 |
+
</p>
|
65 |
+
</div>
|
66 |
+
|
67 |
+
<!--<div id="postbox-container-1" class="postbox-container"></div>-->
|
68 |
+
</div>
|
69 |
+
</div>
|
70 |
+
</form>
|
71 |
+
|
72 |
+
</div>
|
73 |
+
|
74 |
+
<style type="text/css">
|
75 |
+
.sidebar-name-wrap { margin: 0 0 20px 0;}
|
76 |
+
.sidebar-name-wrap input { padding: 3px 8px; width: 100%; font-size: 1.7em;}
|
77 |
+
.sidebar-name-wrap input:-moz-placeholder { color: #a9a9a9;}
|
78 |
+
.sidebar-name-wrap input::-webkit-input-placeholder { padding: 3px 0; color: #a9a9a9;}
|
79 |
+
</style>
|
admin/views/meta-box-page-sidebar.php
ADDED
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div id="simple-page-sidebars-page-sidebar-update-message" class="simple-page-sidebars-page-sidebar-feedback" style="display: none">
|
2 |
+
<p>
|
3 |
+
<?php _e( 'Page sidebar saved.', 'simple-page-sidebars' ); ?>
|
4 |
+
<a href="<?php echo admin_url( 'widgets.php' ); ?>"><?php _e( 'Update widgets now.', 'simple-page-sidebars' ); ?></a>
|
5 |
+
</p>
|
6 |
+
</div>
|
7 |
+
|
8 |
+
<p>
|
9 |
+
<label for="simple-page-sidebars-page-sidebar-name"><?php _e( 'Current sidebar:', 'simple-page-sidebars' ); ?></label>
|
10 |
+
<select name="simplepagesidebars_page_sidebar_name" id="simple-page-sidebars-page-sidebar-name" class="widefat">
|
11 |
+
<option value="default"><?php _e( 'Default Sidebar', 'simple-page-sidebars' ); ?></option>
|
12 |
+
<?php
|
13 |
+
foreach ( $custom_sidebars as $sb ) {
|
14 |
+
printf( '<option value="%s"%s>%s</option>',
|
15 |
+
esc_attr( $sb ),
|
16 |
+
selected( $sb, $sidebar, false ),
|
17 |
+
esc_html( $sb )
|
18 |
+
);
|
19 |
+
}
|
20 |
+
?>
|
21 |
+
</select>
|
22 |
+
|
23 |
+
<label for="simple-page-sidebars-page-sidebar-name-new" class="screen-reader-text"><?php _e( 'Or create a new sidebar:', 'simple-page-sidebars' ); ?></label>
|
24 |
+
<input type="text" name="simplepagesidebars_page_sidebar_name_new" id="simple-page-sidebars-page-sidebar-name-new" class="widefat hide-if-js" value="">
|
25 |
+
|
26 |
+
<span id="sidebarnew" class="hide-if-no-js"><?php _e( 'Enter New', 'simple-page-sidebars' ); ?></span>
|
27 |
+
<span id="sidebarcancel" class="hidden"><?php _e( 'Cancel', 'simple-page-sidebars' ); ?></span>
|
28 |
+
</p>
|
29 |
+
|
30 |
+
<p style="margin-top: 10px; margin-bottom: 0; text-align: right">
|
31 |
+
<?php self::spinner( array( 'id' => 'simple-page-sidebars-page-sidebar-update-spinner' ) ); ?>
|
32 |
+
<button class="button"><?php _e( 'Update', 'simple-page-sidebars' ); ?></button>
|
33 |
+
</p>
|
34 |
+
|
35 |
+
<style type="text/css">
|
36 |
+
#sidebarcancel, #sidebarnew { cursor: pointer; float: left; margin: 3px 3px 0 3px; color: #21759b; font-size: 12px;}
|
37 |
+
#sidebarcancel, #sidebarnew:hover { color: #d54e21;}
|
38 |
+
#simple-page-sidebars-page-sidebar-update-spinner { display: none; margin: 0 5px 0 0; vertical-align: middle;}
|
39 |
+
|
40 |
+
.simple-page-sidebars-page-sidebar-feedback { clear: both; margin: 1em 0; padding: 0 0.6em; color: #333; background-color: #ffffe0; border: 1px solid #e6db55;
|
41 |
+
-moz-border-radius: 3px;
|
42 |
+
-webkit-border-radius: 3px;
|
43 |
+
border-radius: 3px;}
|
44 |
+
.simple-page-sidebars-page-sidebar-feedback a { text-decoration: none;}
|
45 |
+
.simple-page-sidebars-page-sidebar-feedback p { margin: 0.5em 0; padding: 2px;}
|
46 |
+
.simple-page-sidebars-page-sidebar-feedback-error { background-color: #ffebe8; border-color: #cc0000;}
|
47 |
+
.simple-page-sidebars-page-sidebar-feedback-error a { color: #cc0000; text-decoration: underline;}
|
48 |
+
</style>
|
49 |
+
|
50 |
+
<script type="text/javascript">
|
51 |
+
jQuery(function($) {
|
52 |
+
var simplePageSidebars = {
|
53 |
+
spinner : $('#simple-page-sidebars-page-sidebar-update-spinner'),
|
54 |
+
nameField : $('#simple-page-sidebars-page-sidebar-name'),
|
55 |
+
nameFieldNew : $('#simple-page-sidebars-page-sidebar-name-new'),
|
56 |
+
|
57 |
+
init : function() {
|
58 |
+
$('#sidebarcancel, #sidebarnew').on('click', function(e) {
|
59 |
+
e.preventDefault();
|
60 |
+
|
61 |
+
simplePageSidebars.nameField.toggle();
|
62 |
+
simplePageSidebars.nameFieldNew.toggle();
|
63 |
+
|
64 |
+
$('#sidebarcancel, #sidebarnew').toggle();
|
65 |
+
|
66 |
+
// Clear the new sidebar name field when cancel is clicked.
|
67 |
+
if ( 'sidebarcancel' == $(this).attr('id') ) {
|
68 |
+
simplePageSidebars.nameFieldNew.val('');
|
69 |
+
}
|
70 |
+
});
|
71 |
+
},
|
72 |
+
|
73 |
+
update : function() {
|
74 |
+
simplePageSidebars.spinner.show();
|
75 |
+
|
76 |
+
$.post(
|
77 |
+
ajaxurl,
|
78 |
+
{
|
79 |
+
action : 'simplepagesidebars_update_page_sidebar',
|
80 |
+
post_id : $('#post_ID').val(),
|
81 |
+
simplepagesidebars_page_sidebar_name : simplePageSidebars.nameField.val(),
|
82 |
+
simplepagesidebars_page_sidebar_name_new : simplePageSidebars.nameFieldNew.val(),
|
83 |
+
simplepagesidebars_page_sidebar_update_nonce : $('input[name="simplepagesidebars_page_sidebar_update_nonce"]').val()
|
84 |
+
},
|
85 |
+
function( data ){
|
86 |
+
var newName = simplePageSidebars.nameFieldNew.val();
|
87 |
+
|
88 |
+
if ( '' != newName ) {
|
89 |
+
if ( simplePageSidebars.nameField.find('option[value="' + newName + '"]').length < 1 ) {
|
90 |
+
simplePageSidebars.nameField.append('<option selected="selected">' + newName + '</option>').val( newName );
|
91 |
+
} else {
|
92 |
+
simplePageSidebars.nameField.find('option[value="' + newName + '"]').attr('selected', 'selected');
|
93 |
+
}
|
94 |
+
|
95 |
+
simplePageSidebars.nameField.toggle();
|
96 |
+
simplePageSidebars.nameFieldNew.toggle().val('');
|
97 |
+
$('#sidebarcancel, #sidebarnew').toggle();
|
98 |
+
}
|
99 |
+
|
100 |
+
$('#simple-page-sidebars-page-sidebar-update-message').show();
|
101 |
+
simplePageSidebars.spinner.hide();
|
102 |
+
}
|
103 |
+
);
|
104 |
+
}
|
105 |
+
};
|
106 |
+
|
107 |
+
simplePageSidebars.init();
|
108 |
+
|
109 |
+
$('#simplepagesidebarsdiv').find('button').on( 'click', function(e) {
|
110 |
+
e.preventDefault();
|
111 |
+
simplePageSidebars.update();
|
112 |
+
});
|
113 |
+
});
|
114 |
+
</script>
|
115 |
+
<div class="clear"></div>
|
admin/views/meta-box-sidebar-pages.php
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div id="posttype-page" class="posttypediv">
|
2 |
+
<p>
|
3 |
+
<?php
|
4 |
+
printf( __( 'The above sidebar will replace the "<strong>%s</strong>" sidebar for all pages selected below.', 'simple-page-sidebars' ), $default_sidebar );
|
5 |
+
echo ' ';
|
6 |
+
_e( 'Any currently assigned custom sidebars will also be overridden for the selected pages.', 'simple-page-sidebars' );
|
7 |
+
?>
|
8 |
+
</p>
|
9 |
+
|
10 |
+
<div id="page-all" class="tabs-panel tabs-panel-view-all tabs-panel-active">
|
11 |
+
<ul id="pagechecklist" class="list:page categorychecklist form-no-clear">
|
12 |
+
<?php
|
13 |
+
$posts = get_posts( array(
|
14 |
+
'post_type' => 'page',
|
15 |
+
'order' => 'ASC',
|
16 |
+
'orderby' => 'title',
|
17 |
+
'posts_per_page' => -1,
|
18 |
+
'suppress_filters' => true,
|
19 |
+
'cache_results' => false
|
20 |
+
) );
|
21 |
+
|
22 |
+
$args['sidebar'] = self::sanitize_sidebar_name( $_GET['sidebar'] );
|
23 |
+
$args['selected'] = self::get_page_ids_using_sidebar( $args['sidebar'] );
|
24 |
+
$args['walker'] = new Simple_Page_Siders_Walker_Page_Checklist;
|
25 |
+
|
26 |
+
$items = walk_page_tree( $posts, 0, 0, $args );
|
27 |
+
echo $items;
|
28 |
+
?>
|
29 |
+
</ul>
|
30 |
+
</div><!-- end div.tabs-panel -->
|
31 |
+
|
32 |
+
<p style="margin: 5px 0 0 0">
|
33 |
+
<span class="description"><?php _e( 'To delete this sidebar, simply uncheck all pages and click the "Update Sidebar" button.', 'simple-page-sidebars' ); ?></span>
|
34 |
+
</p>
|
35 |
+
</div><!-- end div.posttypediv -->
|
includes/widget-area.php
CHANGED
@@ -1,22 +1,41 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
class Simple_Page_Sidebars_Widget_Area extends WP_Widget {
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
4 |
$widget_ops = array(
|
5 |
'classname' => 'widget_area',
|
6 |
'description' => __( 'Include all widgets from another widget area', 'simple-page-sidebars' )
|
7 |
);
|
8 |
|
|
|
9 |
$this->WP_Widget( 'area', __( 'Widget Area', 'simple-page-sidebars' ), $widget_ops );
|
10 |
}
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
12 |
function widget( $args, $instance ) {
|
13 |
extract( $args );
|
14 |
|
15 |
-
//
|
16 |
if ( $id != $instance['area_id'] ) {
|
17 |
echo $before_widget;
|
18 |
|
19 |
-
|
|
|
20 |
|
21 |
echo '<div class="widget-area-inside">';
|
22 |
dynamic_sidebar( $instance['area_id'] );
|
@@ -25,37 +44,56 @@ class Simple_Page_Sidebars_Widget_Area extends WP_Widget {
|
|
25 |
echo $after_widget;
|
26 |
}
|
27 |
}
|
28 |
-
|
29 |
-
function update($new_instance, $old_instance) {
|
30 |
-
$instance = $old_instance;
|
31 |
-
$instance['title'] = esc_html( $new_instance['title'] );
|
32 |
-
$instance['area_id'] = $new_instance['area_id'];
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
?>
|
40 |
<p>
|
41 |
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'simple-page-sidebars' ); ?></label>
|
42 |
-
<input type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" id="<?php echo $this->get_field_id('title'); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat"
|
43 |
</p>
|
44 |
<p>
|
45 |
<label for="<?php echo $this->get_field_id( 'area_id' ); ?>"><?php _e( 'Area Name:', 'simple-page-sidebars' ); ?></label>
|
46 |
<select name="<?php echo $this->get_field_name( 'area_id' ); ?>" id="<?php echo $this->get_field_id( 'area_id' ); ?>" class="widefat">
|
47 |
-
<option value=""></option>
|
48 |
<?php
|
49 |
-
global $wp_registered_sidebars;
|
50 |
-
|
51 |
foreach ( $wp_registered_sidebars as $id => $area ) {
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
54 |
?>
|
55 |
</select>
|
56 |
</p>
|
57 |
<?php
|
58 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
}
|
60 |
-
add_action( 'widgets_init', create_function( '', 'return register_widget("Simple_Page_Sidebars_Widget_Area");' ) );
|
61 |
?>
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Area widget class.
|
4 |
+
*
|
5 |
+
* A widget for display another widget area within a sidebar.
|
6 |
+
*
|
7 |
+
* @since 0.2.0
|
8 |
+
*/
|
9 |
class Simple_Page_Sidebars_Widget_Area extends WP_Widget {
|
10 |
+
/**
|
11 |
+
* Widget constructor method.
|
12 |
+
*
|
13 |
+
* @since 0.2.0
|
14 |
+
*/
|
15 |
+
function __construct() {
|
16 |
$widget_ops = array(
|
17 |
'classname' => 'widget_area',
|
18 |
'description' => __( 'Include all widgets from another widget area', 'simple-page-sidebars' )
|
19 |
);
|
20 |
|
21 |
+
// Call the parent constructor.
|
22 |
$this->WP_Widget( 'area', __( 'Widget Area', 'simple-page-sidebars' ), $widget_ops );
|
23 |
}
|
24 |
+
|
25 |
+
/**
|
26 |
+
* Display the widget.
|
27 |
+
*
|
28 |
+
* @since 0.2.0
|
29 |
+
*/
|
30 |
function widget( $args, $instance ) {
|
31 |
extract( $args );
|
32 |
|
33 |
+
// Don't allow an infinite loop.
|
34 |
if ( $id != $instance['area_id'] ) {
|
35 |
echo $before_widget;
|
36 |
|
37 |
+
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
|
38 |
+
echo ( empty( $title ) ) ? '' : $before_title . $title . $after_title;
|
39 |
|
40 |
echo '<div class="widget-area-inside">';
|
41 |
dynamic_sidebar( $instance['area_id'] );
|
44 |
echo $after_widget;
|
45 |
}
|
46 |
}
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
+
/**
|
49 |
+
* Display the form for modifying the widget settings.
|
50 |
+
*
|
51 |
+
* @since 0.2.0
|
52 |
+
*/
|
53 |
+
function form( $instance ) {
|
54 |
+
global $wp_registered_sidebars;
|
55 |
+
|
56 |
+
$instance = wp_parse_args( (array) $instance, array(
|
57 |
+
'area_id' => '',
|
58 |
+
'title' => ''
|
59 |
+
) );
|
60 |
?>
|
61 |
<p>
|
62 |
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'simple-page-sidebars' ); ?></label>
|
63 |
+
<input type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" id="<?php echo $this->get_field_id('title'); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat">
|
64 |
</p>
|
65 |
<p>
|
66 |
<label for="<?php echo $this->get_field_id( 'area_id' ); ?>"><?php _e( 'Area Name:', 'simple-page-sidebars' ); ?></label>
|
67 |
<select name="<?php echo $this->get_field_name( 'area_id' ); ?>" id="<?php echo $this->get_field_id( 'area_id' ); ?>" class="widefat">
|
68 |
+
<option value=""></option>
|
69 |
<?php
|
|
|
|
|
70 |
foreach ( $wp_registered_sidebars as $id => $area ) {
|
71 |
+
if ( false === strpos( $id, 'orphaned_widgets_' ) && 'wp_inactive_widgets' != $id ) {
|
72 |
+
printf( '<option value="%s"%s>%s</option>',
|
73 |
+
esc_attr( $id ),
|
74 |
+
selected( $id, $instance['area_id'], false ),
|
75 |
+
esc_html( $area['name'] )
|
76 |
+
);
|
77 |
+
}
|
78 |
}
|
79 |
?>
|
80 |
</select>
|
81 |
</p>
|
82 |
<?php
|
83 |
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Update the widget settings.
|
87 |
+
*
|
88 |
+
* @since 0.2.0
|
89 |
+
*/
|
90 |
+
function update( $new_instance, $old_instance ) {
|
91 |
+
$instance = $old_instance;
|
92 |
+
|
93 |
+
$instance['title'] = wp_strip_all_tags( $new_instance['title'] );
|
94 |
+
$instance['area_id'] = $new_instance['area_id'];
|
95 |
+
|
96 |
+
return $instance;
|
97 |
+
}
|
98 |
}
|
|
|
99 |
?>
|
languages/simple-page-sidebars.pot
CHANGED
@@ -2,8 +2,8 @@ msgid ""
|
|
2 |
msgstr ""
|
3 |
"Project-Id-Version: Simple Page Sidebars\n"
|
4 |
"Report-Msgid-Bugs-To: \n"
|
5 |
-
"POT-Creation-Date: 2012-
|
6 |
-
"PO-Revision-Date: 2012-
|
7 |
"Last-Translator: Brady Vercher <brady@blazersix.com>\n"
|
8 |
"Language-Team: \n"
|
9 |
"MIME-Version: 1.0\n"
|
@@ -13,72 +13,112 @@ msgstr ""
|
|
13 |
"X-Poedit-Basepath: ../\n"
|
14 |
"X-Poedit-SearchPath-0: .\n"
|
15 |
|
16 |
-
#: admin/admin.php:
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
msgstr ""
|
19 |
|
20 |
-
#: admin/admin.php:
|
21 |
-
msgid "The sidebar
|
22 |
msgstr ""
|
23 |
|
24 |
-
#: admin/admin.php:
|
25 |
#, php-format
|
26 |
msgid "For Simple Page Sidebars to work, a default sidebar needs to be selected on the %s"
|
27 |
msgstr ""
|
28 |
|
29 |
-
#: admin/admin.php:
|
30 |
-
msgid "Reading
|
31 |
msgstr ""
|
32 |
|
33 |
-
#: admin/
|
34 |
-
msgid "
|
35 |
msgstr ""
|
36 |
|
37 |
-
#: admin/
|
38 |
-
|
39 |
-
#: admin/admin.php:334
|
40 |
-
msgid "Default Sidebar"
|
41 |
msgstr ""
|
42 |
|
43 |
-
#: admin/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
msgid "Or create a new sidebar:"
|
45 |
msgstr ""
|
46 |
|
47 |
-
#: admin/
|
48 |
msgid "Enter New"
|
49 |
msgstr ""
|
50 |
|
51 |
-
#: admin/
|
52 |
msgid "Cancel"
|
53 |
msgstr ""
|
54 |
|
55 |
-
#: admin/
|
56 |
msgid "Update"
|
57 |
msgstr ""
|
58 |
|
59 |
-
#: admin/
|
60 |
-
|
61 |
-
|
62 |
-
msgid "Sidebar"
|
63 |
msgstr ""
|
64 |
|
65 |
-
#: admin/
|
66 |
-
msgid "
|
|
|
|
|
|
|
|
|
67 |
msgstr ""
|
68 |
|
69 |
-
#: includes/widget-area.php:
|
70 |
msgid "Include all widgets from another widget area"
|
71 |
msgstr ""
|
72 |
|
73 |
-
#: includes/widget-area.php:
|
74 |
msgid "Widget Area"
|
75 |
msgstr ""
|
76 |
|
77 |
-
#: includes/widget-area.php:
|
78 |
msgid "Title:"
|
79 |
msgstr ""
|
80 |
|
81 |
-
#: includes/widget-area.php:
|
82 |
msgid "Area Name:"
|
83 |
msgstr ""
|
84 |
|
2 |
msgstr ""
|
3 |
"Project-Id-Version: Simple Page Sidebars\n"
|
4 |
"Report-Msgid-Bugs-To: \n"
|
5 |
+
"POT-Creation-Date: 2012-11-13 06:36-0800\n"
|
6 |
+
"PO-Revision-Date: 2012-11-13 06:50-0800\n"
|
7 |
"Last-Translator: Brady Vercher <brady@blazersix.com>\n"
|
8 |
"Language-Team: \n"
|
9 |
"MIME-Version: 1.0\n"
|
13 |
"X-Poedit-Basepath: ../\n"
|
14 |
"X-Poedit-SearchPath-0: .\n"
|
15 |
|
16 |
+
#: admin/admin.php:74
|
17 |
+
#: admin/admin.php:242
|
18 |
+
#: admin/admin.php:317
|
19 |
+
#: admin/views/meta-box-page-sidebar.php:11
|
20 |
+
msgid "Default Sidebar"
|
21 |
+
msgstr ""
|
22 |
+
|
23 |
+
#: admin/admin.php:106
|
24 |
+
msgid "The sidebar that should be replaced by custom sidebars."
|
25 |
+
msgstr ""
|
26 |
+
|
27 |
+
#: admin/admin.php:116
|
28 |
+
#: admin/admin.php:183
|
29 |
+
#: admin/admin.php:240
|
30 |
+
#: admin/admin.php:314
|
31 |
+
msgid "Sidebar"
|
32 |
+
msgstr ""
|
33 |
+
|
34 |
+
#: admin/admin.php:316
|
35 |
+
msgid "— No Change —"
|
36 |
+
msgstr ""
|
37 |
+
|
38 |
+
#: admin/admin.php:384
|
39 |
+
msgid "Edit Sidebar"
|
40 |
msgstr ""
|
41 |
|
42 |
+
#: admin/admin.php:544
|
43 |
+
msgid "The sidebar you were editing is no longer assigned to any pages and has been removed. Any widgets it contained should be in an \"Inactive Widgets\" area below."
|
44 |
msgstr ""
|
45 |
|
46 |
+
#: admin/admin.php:631
|
47 |
#, php-format
|
48 |
msgid "For Simple Page Sidebars to work, a default sidebar needs to be selected on the %s"
|
49 |
msgstr ""
|
50 |
|
51 |
+
#: admin/admin.php:632
|
52 |
+
msgid "Reading settings screen"
|
53 |
msgstr ""
|
54 |
|
55 |
+
#: admin/views/edit-sidebar-screen.php:13
|
56 |
+
msgid "Whoops, that doesn't appear to be a sidebar that can be edited."
|
57 |
msgstr ""
|
58 |
|
59 |
+
#: admin/views/edit-sidebar-screen.php:26
|
60 |
+
msgid "Sidebar settings updated."
|
|
|
|
|
61 |
msgstr ""
|
62 |
|
63 |
+
#: admin/views/edit-sidebar-screen.php:27
|
64 |
+
#: admin/views/meta-box-page-sidebar.php:4
|
65 |
+
msgid "Update widgets now."
|
66 |
+
msgstr ""
|
67 |
+
|
68 |
+
#: admin/views/edit-sidebar-screen.php:62
|
69 |
+
msgid "Update Sidebar"
|
70 |
+
msgstr ""
|
71 |
+
|
72 |
+
#: admin/views/meta-box-page-sidebar.php:3
|
73 |
+
msgid "Page sidebar saved."
|
74 |
+
msgstr ""
|
75 |
+
|
76 |
+
#: admin/views/meta-box-page-sidebar.php:9
|
77 |
+
msgid "Current sidebar:"
|
78 |
+
msgstr ""
|
79 |
+
|
80 |
+
#: admin/views/meta-box-page-sidebar.php:23
|
81 |
msgid "Or create a new sidebar:"
|
82 |
msgstr ""
|
83 |
|
84 |
+
#: admin/views/meta-box-page-sidebar.php:26
|
85 |
msgid "Enter New"
|
86 |
msgstr ""
|
87 |
|
88 |
+
#: admin/views/meta-box-page-sidebar.php:27
|
89 |
msgid "Cancel"
|
90 |
msgstr ""
|
91 |
|
92 |
+
#: admin/views/meta-box-page-sidebar.php:32
|
93 |
msgid "Update"
|
94 |
msgstr ""
|
95 |
|
96 |
+
#: admin/views/meta-box-sidebar-pages.php:4
|
97 |
+
#, php-format
|
98 |
+
msgid "The above sidebar will replace the \"<strong>%s</strong>\" sidebar for all pages selected below."
|
|
|
99 |
msgstr ""
|
100 |
|
101 |
+
#: admin/views/meta-box-sidebar-pages.php:6
|
102 |
+
msgid "Any currently assigned custom sidebars will also be overridden for the selected pages."
|
103 |
+
msgstr ""
|
104 |
+
|
105 |
+
#: admin/views/meta-box-sidebar-pages.php:33
|
106 |
+
msgid "To delete this sidebar, simply uncheck all pages and click the \"Update Sidebar\" button."
|
107 |
msgstr ""
|
108 |
|
109 |
+
#: includes/widget-area.php:18
|
110 |
msgid "Include all widgets from another widget area"
|
111 |
msgstr ""
|
112 |
|
113 |
+
#: includes/widget-area.php:22
|
114 |
msgid "Widget Area"
|
115 |
msgstr ""
|
116 |
|
117 |
+
#: includes/widget-area.php:62
|
118 |
msgid "Title:"
|
119 |
msgstr ""
|
120 |
|
121 |
+
#: includes/widget-area.php:66
|
122 |
msgid "Area Name:"
|
123 |
msgstr ""
|
124 |
|
readme.txt
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
Contributors: blazersix, bradyvercher
|
3 |
Donate link: http://bit.ly/s2zcgD
|
4 |
Tags: sidebars, custom sidebars, dynamic sidebar, simple, widget, widgets
|
5 |
-
Requires at least: 3.2
|
6 |
-
Tested up to: 3.
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -68,6 +68,15 @@ Some themes create different sidebars for their various page templates, which me
|
|
68 |
|
69 |
== Changelog ==
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
= 1.0.1 =
|
72 |
* Fixed bug causing issues with other plugins that don't submit the sidebar nonce on the All Pages screen.
|
73 |
|
2 |
Contributors: blazersix, bradyvercher
|
3 |
Donate link: http://bit.ly/s2zcgD
|
4 |
Tags: sidebars, custom sidebars, dynamic sidebar, simple, widget, widgets
|
5 |
+
Requires at least: 3.4.2
|
6 |
+
Tested up to: 3.5
|
7 |
+
Stable tag: 1.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
68 |
|
69 |
== Changelog ==
|
70 |
|
71 |
+
= 1.1 =
|
72 |
+
* Added an Edit Sidebar screen for updating a sidebar name and associated pages.
|
73 |
+
* Added an update message when a sidebar is saved on the Add/Edit Page screen.
|
74 |
+
* Made the sidebar column sortable on the All Pages screen.
|
75 |
+
* Refactored the codebase (formatting, improved comments, static classes, organization, etc).
|
76 |
+
* Added better feedback throughout the dashboard when something goes wrong.
|
77 |
+
* Saved spinner image to plugin folder due to updates coming in 3.5.
|
78 |
+
* Removed deprecated filters.
|
79 |
+
|
80 |
= 1.0.1 =
|
81 |
* Fixed bug causing issues with other plugins that don't submit the sidebar nonce on the All Pages screen.
|
82 |
|
simple-page-sidebars.php
CHANGED
@@ -1,74 +1,111 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
-
Plugin Name: Simple Page Sidebars
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
Author: Blazer Six, Inc.
|
8 |
-
Author URI: http://www.blazersix.com/
|
9 |
-
License: GPLv2 or later
|
10 |
-
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
29 |
|
|
|
|
|
|
|
|
|
30 |
|
|
|
|
|
|
|
|
|
|
|
31 |
class Simple_Page_Sidebars {
|
32 |
-
function __construct() {
|
33 |
-
add_action( 'plugins_loaded', array( &$this, 'load_plugin' ) );
|
34 |
-
}
|
35 |
-
|
36 |
/**
|
37 |
-
* Setup the plugin
|
38 |
-
*
|
39 |
-
* @since 0.2
|
40 |
*/
|
41 |
-
function
|
42 |
load_plugin_textdomain( 'simple-page-sidebars', false, 'simple-page-sidebars/languages' );
|
43 |
|
44 |
-
require_once( plugin_dir_path( __FILE__ ) . '
|
45 |
|
|
|
46 |
if ( is_admin() ) {
|
|
|
|
|
47 |
require_once( plugin_dir_path( __FILE__ ) . 'admin/admin.php' );
|
|
|
48 |
}
|
49 |
|
50 |
-
//
|
51 |
-
add_action( 'widgets_init', array(
|
|
|
52 |
|
53 |
if ( ! is_admin() ) {
|
54 |
-
add_filter( 'sidebars_widgets', array(
|
55 |
}
|
56 |
}
|
57 |
|
58 |
/**
|
59 |
-
*
|
60 |
-
*
|
61 |
-
* @since 0
|
62 |
*/
|
63 |
-
function
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
$widget_areas = array();
|
65 |
|
66 |
-
//
|
67 |
$widget_areas = apply_filters( 'simple_page_sidebars_widget_areas', $widget_areas );
|
68 |
-
$widget_areas = apply_filters( 'simpsid_widget_areas', $widget_areas ); // deprecated
|
69 |
|
70 |
-
//
|
71 |
-
//
|
72 |
if ( ! empty( $widget_areas ) && is_array( $widget_areas ) ) {
|
73 |
foreach ( $widget_areas as $key => $area ) {
|
74 |
if ( is_numeric( $key ) ) {
|
@@ -78,7 +115,7 @@ class Simple_Page_Sidebars {
|
|
78 |
}
|
79 |
}
|
80 |
|
81 |
-
//
|
82 |
$widget_area_defaults = array(
|
83 |
'before_widget' => '<div id="%1$s" class="widget %2$s">',
|
84 |
'after_widget' => '</div>',
|
@@ -86,15 +123,14 @@ class Simple_Page_Sidebars {
|
|
86 |
'after_title' => '</h4>'
|
87 |
);
|
88 |
$widget_area_defaults = apply_filters( 'simple_page_sidebars_widget_defaults', $widget_area_defaults );
|
89 |
-
$widget_area_defaults = apply_filters( 'simpsid_widget_area_defaults', $widget_area_defaults ); // deprecated
|
90 |
|
91 |
-
//
|
92 |
$sidebars = simple_page_sidebars_get_names();
|
93 |
if ( ! empty( $sidebars ) ) {
|
94 |
foreach ( $sidebars as $sidebar ) {
|
95 |
$page_sidebars[ 'page-sidebar-' . sanitize_key( $sidebar ) ] = array(
|
96 |
-
'name'
|
97 |
-
'description' =>
|
98 |
);
|
99 |
}
|
100 |
|
@@ -103,27 +139,28 @@ class Simple_Page_Sidebars {
|
|
103 |
}
|
104 |
|
105 |
if ( ! empty( $widget_areas ) && is_array( $widget_areas ) ) {
|
106 |
-
//
|
107 |
foreach ( $widget_areas as $key => $area ) {
|
108 |
register_sidebar(array(
|
109 |
-
'id'
|
110 |
-
'name'
|
111 |
-
'description'
|
112 |
'before_widget' => ( ! isset( $area['before_widget'] ) ) ? $widget_area_defaults['before_widget'] : $area['before_widget'],
|
113 |
-
'after_widget'
|
114 |
-
'before_title'
|
115 |
-
'after_title'
|
116 |
));
|
117 |
}
|
118 |
}
|
119 |
}
|
120 |
|
121 |
/**
|
122 |
-
* Replaces the default sidebar with a custom defined page sidebar
|
123 |
*
|
124 |
-
* @since 0.2
|
|
|
125 |
*/
|
126 |
-
function replace_sidebar( $sidebars_widgets ) {
|
127 |
global $post;
|
128 |
|
129 |
if ( is_page() || ( is_home() && $posts_page = get_option( 'page_for_posts' ) ) ) {
|
@@ -135,7 +172,7 @@ class Simple_Page_Sidebars {
|
|
135 |
if ( $custom_sidebar && $default_sidebar_id ) {
|
136 |
$custom_sidebar_id = 'page-sidebar-' . sanitize_key( $custom_sidebar );
|
137 |
|
138 |
-
//
|
139 |
if ( ! empty( $sidebars_widgets[ $custom_sidebar_id ] ) ) {
|
140 |
$sidebars_widgets[ $default_sidebar_id ] = $sidebars_widgets[ $custom_sidebar_id ];
|
141 |
}
|
@@ -144,27 +181,42 @@ class Simple_Page_Sidebars {
|
|
144 |
|
145 |
return $sidebars_widgets;
|
146 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
}
|
148 |
-
$simple_page_sidebars = new Simple_Page_Sidebars();
|
149 |
|
150 |
/**
|
151 |
-
* Get an array of custom sidebar names
|
152 |
*
|
153 |
-
* @since 0.2
|
154 |
-
* @return array Custom sidebar names
|
155 |
*/
|
156 |
function simple_page_sidebars_get_names() {
|
157 |
global $wpdb;
|
158 |
|
159 |
-
$
|
160 |
FROM $wpdb->posts p, $wpdb->postmeta pm
|
161 |
WHERE p.post_type='page' AND p.post_status!='auto-draft' AND p.ID=pm.post_id
|
162 |
AND pm.meta_key='_sidebar_name'
|
163 |
GROUP BY pm.meta_value
|
164 |
-
ORDER BY pm.meta_value ASC";
|
165 |
|
166 |
$sidebars = array();
|
167 |
-
$sidebar_names = $wpdb->get_results($sql);
|
168 |
if ( ! empty( $sidebar_names ) ) {
|
169 |
foreach ( $sidebar_names as $meta ) {
|
170 |
$sidebars[] = $meta->meta_value;
|
@@ -175,16 +227,16 @@ function simple_page_sidebars_get_names() {
|
|
175 |
}
|
176 |
|
177 |
/**
|
178 |
-
* Sidebar display template tag
|
179 |
-
*
|
180 |
-
* Call this function in the template where custom sidebars should be displayed.
|
181 |
-
* If a custom sidebar hasn't been defined, the sidebar name passed as the parameter
|
182 |
-
* will be served as a fallback.
|
183 |
*
|
184 |
* This is no longer the recommended usage. No code changes to the theme are
|
185 |
* are required for the plugin to work.
|
186 |
*
|
187 |
-
*
|
|
|
|
|
|
|
|
|
188 |
* @param string $default_sidebar
|
189 |
*/
|
190 |
function simple_page_sidebar( $default_sidebar ) {
|
@@ -192,16 +244,15 @@ function simple_page_sidebar( $default_sidebar ) {
|
|
192 |
|
193 |
$sidebar_name = get_post_meta( $post->ID, '_sidebar_name', true );
|
194 |
|
195 |
-
//
|
196 |
$sidebar_name = apply_filters( 'simple_page_sidebars_last_call', $sidebar_name );
|
197 |
-
$sidebar_name = apply_filters( 'simpsid_sidebar_name', $sidebar_name ); // deprecated
|
198 |
|
199 |
if ( is_page() && ! empty( $sidebar_name ) ) {
|
200 |
$sidebars_widgets = wp_get_sidebars_widgets();
|
201 |
if ( count( $sidebars_widgets ) ) {
|
202 |
foreach ( $wp_registered_sidebars as $id => $sidebar ) {
|
203 |
if ( $sidebar['name'] == $sidebar_name ) {
|
204 |
-
if ( count( $sidebars_widgets[$id] ) ) {
|
205 |
dynamic_sidebar( $sidebar_name );
|
206 |
} elseif ( ! empty( $default_sidebar ) ) {
|
207 |
dynamic_sidebar( $default_sidebar );
|
@@ -215,7 +266,7 @@ function simple_page_sidebar( $default_sidebar ) {
|
|
215 |
}
|
216 |
|
217 |
/**
|
218 |
-
* Deprecated
|
219 |
*/
|
220 |
if ( ! function_exists( 'simple_sidebar' ) ) :
|
221 |
function simple_sidebar( $default_sidebar ) {
|
1 |
<?php
|
2 |
+
/**
|
3 |
+
* Plugin Name: Simple Page Sidebars
|
4 |
+
* Plugin URI: http://wordpress.org/extend/plugins/simple-page-sidebars/
|
5 |
+
* Description: Assign custom, widget-enabled sidebars to any page with ease.
|
6 |
+
* Version: 1.1
|
7 |
+
* Author: Blazer Six, Inc.
|
8 |
+
* Author URI: http://www.blazersix.com/
|
9 |
+
* License: GPLv2 or later
|
10 |
+
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
11 |
+
*
|
12 |
+
* This program is free software; you can redistribute it and/or modify it
|
13 |
+
* under the terms of the GNU General Public License as published by the Free
|
14 |
+
* Software Foundation; either version 2 of the License, or (at your option)
|
15 |
+
* any later version.
|
16 |
+
*
|
17 |
+
* This program is distributed in the hope that it will be useful, but WITHOUT
|
18 |
+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
20 |
+
* more details.
|
21 |
+
*
|
22 |
+
* You should have received a copy of the GNU General Public License along
|
23 |
+
* with this program; if not, write to the Free Software Foundation, Inc., 59
|
24 |
+
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
25 |
+
*
|
26 |
+
* @package Simple Page Sidebars
|
27 |
+
* @author Brady Vercher <brady@blazersix.com>
|
28 |
+
* @copyright Copyright (c) 2012, Blazer Six, Inc.
|
29 |
+
* @license http://www.gnu.org/licenses/gpl-2.0.html
|
30 |
+
*/
|
31 |
|
32 |
+
/**
|
33 |
+
* Set a constant path to the plugin's root directory.
|
34 |
+
*/
|
35 |
+
if ( ! defined( 'SIMPLE_PAGE_SIDEBARS_DIR' ) )
|
36 |
+
define( 'SIMPLE_PAGE_SIDEBARS_DIR', plugin_dir_path( __FILE__ ) );
|
37 |
|
38 |
+
/**
|
39 |
+
* Set a constant URL to the plugin's root directory.
|
40 |
+
*/
|
41 |
+
if ( ! defined( 'SIMPLE_PAGE_SIDEBARS_URL' ) )
|
42 |
+
define( 'SIMPLE_PAGE_SIDEBARS_URL', plugin_dir_url( __FILE__ ) );
|
43 |
|
44 |
+
/**
|
45 |
+
* Load the plugin whens plugins are loaded.
|
46 |
+
*/
|
47 |
+
add_action( 'plugins_loaded', array( 'Simple_Page_Sidebars', 'load' ) );
|
48 |
|
49 |
+
/**
|
50 |
+
* Main plugin class.
|
51 |
+
*
|
52 |
+
* @since 0.2.0
|
53 |
+
*/
|
54 |
class Simple_Page_Sidebars {
|
|
|
|
|
|
|
|
|
55 |
/**
|
56 |
+
* Setup the plugin.
|
57 |
+
*
|
58 |
+
* @since 0.2.0
|
59 |
*/
|
60 |
+
public static function load() {
|
61 |
load_plugin_textdomain( 'simple-page-sidebars', false, 'simple-page-sidebars/languages' );
|
62 |
|
63 |
+
require_once( plugin_dir_path( __FILE__ ) . 'includes/widget-area.php' );
|
64 |
|
65 |
+
// Load the admin functionality.
|
66 |
if ( is_admin() ) {
|
67 |
+
add_action( 'admin_init', array( __CLASS__, 'upgrade' ) );
|
68 |
+
|
69 |
require_once( plugin_dir_path( __FILE__ ) . 'admin/admin.php' );
|
70 |
+
Simple_Page_Sidebars_Admin::load();
|
71 |
}
|
72 |
|
73 |
+
// Lower priority registers sidebars below those typically added by themes.
|
74 |
+
add_action( 'widgets_init', array( __CLASS__, 'register_sidebars' ), 20 );
|
75 |
+
add_action( 'widgets_init', array( __CLASS__, 'register_widgets' ) );
|
76 |
|
77 |
if ( ! is_admin() ) {
|
78 |
+
add_filter( 'sidebars_widgets', array( __CLASS__, 'replace_sidebar' ) );
|
79 |
}
|
80 |
}
|
81 |
|
82 |
/**
|
83 |
+
* Register the Area widget.
|
84 |
+
*
|
85 |
+
* @since 1.1.0
|
86 |
*/
|
87 |
+
public static function register_widgets() {
|
88 |
+
register_widget( 'Simple_Page_Sidebars_Widget_Area' );
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Add custom widget areas and automatically register page sidebars.
|
93 |
+
*
|
94 |
+
* @todo Try to insert a link into the description of custom sidebars so
|
95 |
+
* they can be edited. It'd be useful for when the Sidebar column is
|
96 |
+
* disabled, since there isn't any other way to access the Edit
|
97 |
+
* Sidebar screen.
|
98 |
+
*
|
99 |
+
* @since 0.2.0
|
100 |
+
*/
|
101 |
+
public static function register_sidebars() {
|
102 |
$widget_areas = array();
|
103 |
|
104 |
+
// Add widget areas using this filter.
|
105 |
$widget_areas = apply_filters( 'simple_page_sidebars_widget_areas', $widget_areas );
|
|
|
106 |
|
107 |
+
// Verify id's exist, otherwise create them.
|
108 |
+
// Help ensure widgets don't get mixed up if widget areas are added or removed.
|
109 |
if ( ! empty( $widget_areas ) && is_array( $widget_areas ) ) {
|
110 |
foreach ( $widget_areas as $key => $area ) {
|
111 |
if ( is_numeric( $key ) ) {
|
115 |
}
|
116 |
}
|
117 |
|
118 |
+
// Override the default widget properties.
|
119 |
$widget_area_defaults = array(
|
120 |
'before_widget' => '<div id="%1$s" class="widget %2$s">',
|
121 |
'after_widget' => '</div>',
|
123 |
'after_title' => '</h4>'
|
124 |
);
|
125 |
$widget_area_defaults = apply_filters( 'simple_page_sidebars_widget_defaults', $widget_area_defaults );
|
|
|
126 |
|
127 |
+
// If any custom sidebars have been assigned to pages, merge them with already defined widget areas.
|
128 |
$sidebars = simple_page_sidebars_get_names();
|
129 |
if ( ! empty( $sidebars ) ) {
|
130 |
foreach ( $sidebars as $sidebar ) {
|
131 |
$page_sidebars[ 'page-sidebar-' . sanitize_key( $sidebar ) ] = array(
|
132 |
+
'name' => $sidebar,
|
133 |
+
'description' => ''
|
134 |
);
|
135 |
}
|
136 |
|
139 |
}
|
140 |
|
141 |
if ( ! empty( $widget_areas ) && is_array( $widget_areas ) ) {
|
142 |
+
// Register the widget areas.
|
143 |
foreach ( $widget_areas as $key => $area ) {
|
144 |
register_sidebar(array(
|
145 |
+
'id' => $key,
|
146 |
+
'name' => $area['name'],
|
147 |
+
'description' => $area['description'],
|
148 |
'before_widget' => ( ! isset( $area['before_widget'] ) ) ? $widget_area_defaults['before_widget'] : $area['before_widget'],
|
149 |
+
'after_widget' => ( ! isset( $area['after_widget'] ) ) ? $widget_area_defaults['after_widget'] : $area['after_widget'],
|
150 |
+
'before_title' => ( ! isset( $area['before_title'] ) ) ? $widget_area_defaults['before_title'] : $area['before_title'],
|
151 |
+
'after_title' => ( ! isset( $area['after_title'] ) ) ? $widget_area_defaults['after_title'] : $area['after_title']
|
152 |
));
|
153 |
}
|
154 |
}
|
155 |
}
|
156 |
|
157 |
/**
|
158 |
+
* Replaces the default sidebar with a custom defined page sidebar.
|
159 |
*
|
160 |
+
* @since 0.2.0
|
161 |
+
* @param array $sidebars_widgets
|
162 |
*/
|
163 |
+
public static function replace_sidebar( $sidebars_widgets ) {
|
164 |
global $post;
|
165 |
|
166 |
if ( is_page() || ( is_home() && $posts_page = get_option( 'page_for_posts' ) ) ) {
|
172 |
if ( $custom_sidebar && $default_sidebar_id ) {
|
173 |
$custom_sidebar_id = 'page-sidebar-' . sanitize_key( $custom_sidebar );
|
174 |
|
175 |
+
// Only replace the default sidebar if the custom sidebar has widgets.
|
176 |
if ( ! empty( $sidebars_widgets[ $custom_sidebar_id ] ) ) {
|
177 |
$sidebars_widgets[ $default_sidebar_id ] = $sidebars_widgets[ $custom_sidebar_id ];
|
178 |
}
|
181 |
|
182 |
return $sidebars_widgets;
|
183 |
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Save version information for future upgrades.
|
187 |
+
*
|
188 |
+
* @since 1.1.0
|
189 |
+
*/
|
190 |
+
public static function upgrade() {
|
191 |
+
$saved_version = get_option( 'simple_page_sidebars_version' );
|
192 |
+
|
193 |
+
// If the plugin version setting isn't set or if it's less than or equal to 1.1.0, update the saved version.
|
194 |
+
if ( ! $saved_version || version_compare( $saved_version, '1.1.0', '<=' ) ) {
|
195 |
+
$plugin_data = get_plugin_data( __FILE__ );
|
196 |
+
|
197 |
+
// Update saved version number.
|
198 |
+
update_option( 'simple_page_sidebars_version', $plugin_data['Version'] );
|
199 |
+
}
|
200 |
+
}
|
201 |
}
|
|
|
202 |
|
203 |
/**
|
204 |
+
* Get an array of custom sidebar names.
|
205 |
*
|
206 |
+
* @since 0.2.0
|
207 |
+
* @return array Custom sidebar names.
|
208 |
*/
|
209 |
function simple_page_sidebars_get_names() {
|
210 |
global $wpdb;
|
211 |
|
212 |
+
$sidebar_names = $wpdb->get_results( "SELECT meta_value
|
213 |
FROM $wpdb->posts p, $wpdb->postmeta pm
|
214 |
WHERE p.post_type='page' AND p.post_status!='auto-draft' AND p.ID=pm.post_id
|
215 |
AND pm.meta_key='_sidebar_name'
|
216 |
GROUP BY pm.meta_value
|
217 |
+
ORDER BY pm.meta_value ASC" );
|
218 |
|
219 |
$sidebars = array();
|
|
|
220 |
if ( ! empty( $sidebar_names ) ) {
|
221 |
foreach ( $sidebar_names as $meta ) {
|
222 |
$sidebars[] = $meta->meta_value;
|
227 |
}
|
228 |
|
229 |
/**
|
230 |
+
* Sidebar display template tag.
|
|
|
|
|
|
|
|
|
231 |
*
|
232 |
* This is no longer the recommended usage. No code changes to the theme are
|
233 |
* are required for the plugin to work.
|
234 |
*
|
235 |
+
* Call this function in the template where custom sidebars should be
|
236 |
+
* displayed. If a custom sidebar hasn't been defined, the sidebar name passed
|
237 |
+
* as the parameter will be served as a fallback.
|
238 |
+
*
|
239 |
+
* @since 0.2.0
|
240 |
* @param string $default_sidebar
|
241 |
*/
|
242 |
function simple_page_sidebar( $default_sidebar ) {
|
244 |
|
245 |
$sidebar_name = get_post_meta( $post->ID, '_sidebar_name', true );
|
246 |
|
247 |
+
// Last chance to override which sidebar is displayed.
|
248 |
$sidebar_name = apply_filters( 'simple_page_sidebars_last_call', $sidebar_name );
|
|
|
249 |
|
250 |
if ( is_page() && ! empty( $sidebar_name ) ) {
|
251 |
$sidebars_widgets = wp_get_sidebars_widgets();
|
252 |
if ( count( $sidebars_widgets ) ) {
|
253 |
foreach ( $wp_registered_sidebars as $id => $sidebar ) {
|
254 |
if ( $sidebar['name'] == $sidebar_name ) {
|
255 |
+
if ( count( $sidebars_widgets[ $id ] ) ) {
|
256 |
dynamic_sidebar( $sidebar_name );
|
257 |
} elseif ( ! empty( $default_sidebar ) ) {
|
258 |
dynamic_sidebar( $default_sidebar );
|
266 |
}
|
267 |
|
268 |
/**
|
269 |
+
* Deprecated.
|
270 |
*/
|
271 |
if ( ! function_exists( 'simple_sidebar' ) ) :
|
272 |
function simple_sidebar( $default_sidebar ) {
|
uninstall.php
CHANGED
@@ -7,4 +7,5 @@ global $wpdb;
|
|
7 |
|
8 |
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key='_sidebar_name'");
|
9 |
delete_option( 'simple_page_sidebars_default_sidebar' );
|
|
|
10 |
?>
|
7 |
|
8 |
$wpdb->query("DELETE FROM $wpdb->postmeta WHERE meta_key='_sidebar_name'");
|
9 |
delete_option( 'simple_page_sidebars_default_sidebar' );
|
10 |
+
delete_option( 'simple_page_sidebars_version' );
|
11 |
?>
|