Version Description
- Now works for the blog page when it's set in the Reading Settings.
- Bug fixes.
Download this release
Release Info
Developer | blazersix |
Plugin | Simple Page Sidebars |
Version | 0.2.1 |
Comparing to | |
See all releases |
Code changes from version 0.2 to 0.2.1
- admin/admin.php +92 -63
- includes/widget-area.php +1 -1
- languages/simple-page-sidebars.pot +18 -18
- readme.txt +7 -3
- simple-page-sidebars.php +47 -33
admin/admin.php
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
<?php
|
2 |
class Simple_Page_Sidebars_Admin {
|
3 |
-
function
|
4 |
add_action( 'init', array( &$this, 'init' ) );
|
5 |
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
6 |
}
|
7 |
|
8 |
-
|
9 |
function init() {
|
10 |
add_action( 'save_post', array( &$this, 'update_sidebar' ) );
|
11 |
add_action( 'wp_ajax_simple_page_sidebars_update_page_sidebar', array( &$this, 'update_sidebar' ) );
|
@@ -19,21 +18,25 @@ class Simple_Page_Sidebars_Admin {
|
|
19 |
add_action( 'bulk_edit_custom_box', array( &$this, 'bulk_edit_custom_box' ), 10, 2 );
|
20 |
}
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
*
|
26 |
*/
|
27 |
function admin_init() {
|
28 |
-
add_settings_field( 'simple_page_sidebars_default_sidebar', '<label for="simple-page-sidebars-default-sidebar">' . __( ' Default Sidebar', 'simple-page-sidebars' ) . '</label>', array( &$this, '
|
29 |
register_setting( 'reading', 'simple_page_sidebars_default_sidebar', array( &$this, 'register_reading_setting' ) );
|
30 |
}
|
31 |
|
32 |
-
|
33 |
function register_reading_setting( $input ) { return $input; }
|
34 |
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
37 |
global $wp_registered_sidebars;
|
38 |
$default_sidebar_id = get_option( 'simple_page_sidebars_default_sidebar' );
|
39 |
|
@@ -44,9 +47,11 @@ class Simple_Page_Sidebars_Admin {
|
|
44 |
<?php
|
45 |
foreach ( $wp_registered_sidebars as $sb ) {
|
46 |
if ( is_array( $custom_sidebars ) && ! in_array( $sb['name'], $custom_sidebars ) ) {
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
|
|
50 |
}
|
51 |
}
|
52 |
?>
|
@@ -55,63 +60,66 @@ class Simple_Page_Sidebars_Admin {
|
|
55 |
<?php
|
56 |
}
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
*
|
|
|
62 |
*/
|
63 |
function update_sidebar( $post_id = 0 ) {
|
64 |
-
if (
|
65 |
-
return $post_id;
|
66 |
-
|
67 |
-
if ( $post_id == 0 )
|
68 |
$post_id = $_POST['post_id'];
|
69 |
|
|
|
|
|
70 |
|
71 |
// verify either an individual post nonce or the bulk edit nonce
|
72 |
// requests can come from a page update, ajax from the sidebar meta box, quick edit, or bulk edit
|
73 |
$sidebar_name_nonce = ( isset( $_REQUEST['sidebar_name_nonce'] ) && wp_verify_nonce( $_REQUEST['sidebar_name_nonce'], 'update-page-sidebar-name-' . $post_id ) ) ? true : false;
|
74 |
$bulk_sidebar_name_nonce = ( isset( $_REQUEST['bulk_sidebar_name_nonce'] ) && wp_verify_nonce( $_REQUEST['bulk_sidebar_name_nonce'], 'bulk-update-page-sidebar-name' ) ) ? true : false;
|
75 |
if ( ! $sidebar_name_nonce && ! $bulk_sidebar_name_nonce ) {
|
76 |
-
if ( defined( '
|
77 |
exit;
|
78 |
} else {
|
79 |
return;
|
80 |
}
|
81 |
}
|
82 |
|
83 |
-
if
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
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 |
-
if ( defined( 'DOING AJAX' ) && DOING_AJAX )
|
105 |
-
exit;
|
106 |
}
|
107 |
|
108 |
-
|
|
|
|
|
|
|
|
|
109 |
function add_sidebar_meta_box() {
|
110 |
-
// wish the Page Attributes meta box had a hook. oh well.
|
111 |
add_meta_box( 'simplepagesidebarsdiv', 'Sidebar', array( &$this, 'sidebar_meta_box' ), 'page', 'side', 'core' );
|
112 |
}
|
113 |
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
115 |
function sidebar_meta_box( $page ) {
|
116 |
global $wp_registered_sidebars, $wpdb;
|
117 |
|
@@ -136,9 +144,11 @@ class Simple_Page_Sidebars_Admin {
|
|
136 |
<option value="default"><?php _e( 'Default Sidebar', 'simple-page-sidebars' ); ?></option>
|
137 |
<?php
|
138 |
foreach ( $custom_sidebars as $sb ) {
|
139 |
-
|
140 |
-
|
141 |
-
|
|
|
|
|
142 |
}
|
143 |
?>
|
144 |
</select>
|
@@ -206,19 +216,21 @@ class Simple_Page_Sidebars_Admin {
|
|
206 |
<?php
|
207 |
}
|
208 |
|
209 |
-
|
210 |
-
|
211 |
-
/*
|
212 |
-
* Quick Edit & Bulk Edit Implementation
|
213 |
*
|
214 |
-
*
|
215 |
*/
|
216 |
function manage_pages_columns( $columns ) {
|
217 |
$columns['sidebar'] = __( 'Sidebar', 'simple-page-sidebars' );
|
218 |
return $columns;
|
219 |
}
|
220 |
|
221 |
-
|
|
|
|
|
|
|
|
|
222 |
function manage_pages_custom_column( $column, $page_id ) {
|
223 |
if ( 'sidebar' == $column ) {
|
224 |
$sidebar = get_post_meta( $page_id, '_sidebar_name', true );
|
@@ -229,9 +241,14 @@ class Simple_Page_Sidebars_Admin {
|
|
229 |
}
|
230 |
}
|
231 |
|
232 |
-
|
|
|
|
|
|
|
|
|
233 |
function quick_edit_custom_box( $column, $post_type ) {
|
234 |
-
if ( 'page' != $post_type || 'sidebar' != $column )
|
|
|
235 |
|
236 |
$sidebars = simple_page_sidebars_get_names();
|
237 |
?>
|
@@ -244,7 +261,7 @@ class Simple_Page_Sidebars_Admin {
|
|
244 |
<option value="default"><?php _e( 'Default Sidebar', 'simple-page-sidebars' ); ?></option>
|
245 |
<?php
|
246 |
foreach ( $sidebars as $sb ) {
|
247 |
-
|
248 |
}
|
249 |
?>
|
250 |
</select>
|
@@ -255,14 +272,22 @@ class Simple_Page_Sidebars_Admin {
|
|
255 |
<?php
|
256 |
}
|
257 |
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
function quick_edit_js() {
|
260 |
-
|
261 |
-
|
|
|
|
|
262 |
?>
|
263 |
<script type="text/javascript">
|
264 |
jQuery(function($) {
|
265 |
-
$('table.pages').
|
266 |
inlineEditPost.revert();
|
267 |
|
268 |
var id = inlineEditPost.getId(this);
|
@@ -285,7 +310,11 @@ class Simple_Page_Sidebars_Admin {
|
|
285 |
<?php
|
286 |
}
|
287 |
|
288 |
-
|
|
|
|
|
|
|
|
|
289 |
function bulk_edit_custom_box( $column, $post_type ) {
|
290 |
if ( 'page' != $post_type || 'sidebar' != $column ) { return; }
|
291 |
|
@@ -300,7 +329,7 @@ class Simple_Page_Sidebars_Admin {
|
|
300 |
<option value="default"><?php _e( 'Default Sidebar', 'simple-page-sidebars' ); ?></option>
|
301 |
<?php
|
302 |
foreach ( $sidebars as $sb ) {
|
303 |
-
|
304 |
}
|
305 |
?>
|
306 |
</select>
|
1 |
<?php
|
2 |
class Simple_Page_Sidebars_Admin {
|
3 |
+
function __construct() {
|
4 |
add_action( 'init', array( &$this, 'init' ) );
|
5 |
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
6 |
}
|
7 |
|
|
|
8 |
function init() {
|
9 |
add_action( 'save_post', array( &$this, 'update_sidebar' ) );
|
10 |
add_action( 'wp_ajax_simple_page_sidebars_update_page_sidebar', array( &$this, 'update_sidebar' ) );
|
18 |
add_action( 'bulk_edit_custom_box', array( &$this, 'bulk_edit_custom_box' ), 10, 2 );
|
19 |
}
|
20 |
|
21 |
+
/**
|
22 |
+
* Register setting for choosing the default sidebar
|
23 |
+
*
|
24 |
+
* @since 0.2
|
25 |
*/
|
26 |
function admin_init() {
|
27 |
+
add_settings_field( 'simple_page_sidebars_default_sidebar', '<label for="simple-page-sidebars-default-sidebar">' . __( ' Default Sidebar', 'simple-page-sidebars' ) . '</label>', array( &$this, 'default_sidebar_settings_field' ), 'reading' );
|
28 |
register_setting( 'reading', 'simple_page_sidebars_default_sidebar', array( &$this, 'register_reading_setting' ) );
|
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 |
|
47 |
<?php
|
48 |
foreach ( $wp_registered_sidebars as $sb ) {
|
49 |
if ( is_array( $custom_sidebars ) && ! in_array( $sb['name'], $custom_sidebars ) ) {
|
50 |
+
printf( '<option value="%s"%s>%s</option>',
|
51 |
+
esc_attr( $sb['id'] ),
|
52 |
+
selected( $sb['id'], $default_sidebar_id, false ),
|
53 |
+
esc_html( $sb['name'] )
|
54 |
+
);
|
55 |
}
|
56 |
}
|
57 |
?>
|
60 |
<?php
|
61 |
}
|
62 |
|
63 |
+
/**
|
64 |
+
* Save custom page sidebar
|
65 |
+
*
|
66 |
+
* Processes AJAX requests and normal post backs.
|
67 |
+
* @since 0.2
|
68 |
*/
|
69 |
function update_sidebar( $post_id = 0 ) {
|
70 |
+
if ( 0 == $post_id )
|
|
|
|
|
|
|
71 |
$post_id = $_POST['post_id'];
|
72 |
|
73 |
+
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || wp_is_post_revision( $post_id ) || 'page' != get_post_type( $post_id ) )
|
74 |
+
return $post_id;
|
75 |
|
76 |
// verify either an individual post nonce or the bulk edit nonce
|
77 |
// requests can come from a page update, ajax from the sidebar meta box, quick edit, or bulk edit
|
78 |
$sidebar_name_nonce = ( isset( $_REQUEST['sidebar_name_nonce'] ) && wp_verify_nonce( $_REQUEST['sidebar_name_nonce'], 'update-page-sidebar-name-' . $post_id ) ) ? true : false;
|
79 |
$bulk_sidebar_name_nonce = ( isset( $_REQUEST['bulk_sidebar_name_nonce'] ) && wp_verify_nonce( $_REQUEST['bulk_sidebar_name_nonce'], 'bulk-update-page-sidebar-name' ) ) ? true : false;
|
80 |
if ( ! $sidebar_name_nonce && ! $bulk_sidebar_name_nonce ) {
|
81 |
+
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
|
82 |
exit;
|
83 |
} else {
|
84 |
return;
|
85 |
}
|
86 |
}
|
87 |
|
88 |
+
// if 'new_sidebar_name' is set and not empty, it supercedes any 'sidebar_name' setting
|
89 |
+
// if 'sidebar_name' is blank or it equals 'default', delete meta
|
90 |
+
// if 'sidebar_name' is set and not empty, update to new name
|
91 |
+
// if 'sidebar_name' is -1, skip
|
92 |
+
|
93 |
+
// bulk edit uses $_GET for some reason, so we use the $_REQUEST global
|
94 |
+
if ( isset( $_REQUEST['new_sidebar_name' ] ) && ! empty( $_REQUEST['new_sidebar_name'] ) ) {
|
95 |
+
update_post_meta( $post_id, '_sidebar_name', $_REQUEST['new_sidebar_name'] );
|
96 |
+
} else {
|
97 |
+
// if $_REQUEST['sidebar_name'] isn't set, we don't want to update the sidebar meta value
|
98 |
+
$sidebar = ( isset( $_REQUEST['sidebar_name'] ) ) ? $_REQUEST['sidebar_name'] : -1;
|
99 |
|
100 |
+
if ( empty( $sidebar ) || 'default' == $sidebar ) {
|
101 |
+
delete_post_meta( $post_id, '_sidebar_name' );
|
102 |
+
} elseif ( -1 != intval( $sidebar ) ) {
|
103 |
+
update_post_meta( $post_id, '_sidebar_name', $_REQUEST['sidebar_name'] );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
}
|
105 |
}
|
|
|
|
|
|
|
106 |
}
|
107 |
|
108 |
+
/**
|
109 |
+
* Register sidebar meta box
|
110 |
+
*
|
111 |
+
* @since 0.2
|
112 |
+
*/
|
113 |
function add_sidebar_meta_box() {
|
|
|
114 |
add_meta_box( 'simplepagesidebarsdiv', 'Sidebar', array( &$this, 'sidebar_meta_box' ), 'page', 'side', 'core' );
|
115 |
}
|
116 |
|
117 |
+
/**
|
118 |
+
* Meta box for adding a new sidebar or choosing an existing sidebar
|
119 |
+
*
|
120 |
+
* @since 0.2
|
121 |
+
* @uses $wp_registered_sidebars, $wpdb
|
122 |
+
*/
|
123 |
function sidebar_meta_box( $page ) {
|
124 |
global $wp_registered_sidebars, $wpdb;
|
125 |
|
144 |
<option value="default"><?php _e( 'Default Sidebar', 'simple-page-sidebars' ); ?></option>
|
145 |
<?php
|
146 |
foreach ( $custom_sidebars as $sb ) {
|
147 |
+
printf( '<option value="%s"%s>%s</option>',
|
148 |
+
esc_attr( $sb ),
|
149 |
+
selected( $sb, $sidebar, false ),
|
150 |
+
esc_html( $sb )
|
151 |
+
);
|
152 |
}
|
153 |
?>
|
154 |
</select>
|
216 |
<?php
|
217 |
}
|
218 |
|
219 |
+
/**
|
220 |
+
* Register sidebar column on All Pages screen
|
|
|
|
|
221 |
*
|
222 |
+
* @since 0.2
|
223 |
*/
|
224 |
function manage_pages_columns( $columns ) {
|
225 |
$columns['sidebar'] = __( 'Sidebar', 'simple-page-sidebars' );
|
226 |
return $columns;
|
227 |
}
|
228 |
|
229 |
+
/**
|
230 |
+
* Display sidebar column on All Pages screen
|
231 |
+
*
|
232 |
+
* @since 0.2
|
233 |
+
*/
|
234 |
function manage_pages_custom_column( $column, $page_id ) {
|
235 |
if ( 'sidebar' == $column ) {
|
236 |
$sidebar = get_post_meta( $page_id, '_sidebar_name', true );
|
241 |
}
|
242 |
}
|
243 |
|
244 |
+
/**
|
245 |
+
* Sidebar dropdown field for quick edit mode
|
246 |
+
*
|
247 |
+
* @since 0.2
|
248 |
+
*/
|
249 |
function quick_edit_custom_box( $column, $post_type ) {
|
250 |
+
if ( 'page' != $post_type || 'sidebar' != $column )
|
251 |
+
return;
|
252 |
|
253 |
$sidebars = simple_page_sidebars_get_names();
|
254 |
?>
|
261 |
<option value="default"><?php _e( 'Default Sidebar', 'simple-page-sidebars' ); ?></option>
|
262 |
<?php
|
263 |
foreach ( $sidebars as $sb ) {
|
264 |
+
printf( '<option value="%1$s">%1$s</option>', $sb );
|
265 |
}
|
266 |
?>
|
267 |
</select>
|
272 |
<?php
|
273 |
}
|
274 |
|
275 |
+
/**
|
276 |
+
* Quick edit javascript
|
277 |
+
*
|
278 |
+
* Selects the correct sidebar during quick edit and copies the nonce for saving.
|
279 |
+
*
|
280 |
+
* @since 0.2
|
281 |
+
*/
|
282 |
function quick_edit_js() {
|
283 |
+
$current_screen = get_current_screen();
|
284 |
+
|
285 |
+
if ( 'edit-page' != $current_screen->id || 'page' != $current_screen->post_type )
|
286 |
+
return;
|
287 |
?>
|
288 |
<script type="text/javascript">
|
289 |
jQuery(function($) {
|
290 |
+
$('table.pages').on('click', 'a.editinline', function(e) {
|
291 |
inlineEditPost.revert();
|
292 |
|
293 |
var id = inlineEditPost.getId(this);
|
310 |
<?php
|
311 |
}
|
312 |
|
313 |
+
/**
|
314 |
+
* Sidebar dropdown field for bulk edit mode
|
315 |
+
*
|
316 |
+
* @since 0.2
|
317 |
+
*/
|
318 |
function bulk_edit_custom_box( $column, $post_type ) {
|
319 |
if ( 'page' != $post_type || 'sidebar' != $column ) { return; }
|
320 |
|
329 |
<option value="default"><?php _e( 'Default Sidebar', 'simple-page-sidebars' ); ?></option>
|
330 |
<?php
|
331 |
foreach ( $sidebars as $sb ) {
|
332 |
+
printf( '<option value="%1$s">%1$s</option>', $sb );
|
333 |
}
|
334 |
?>
|
335 |
</select>
|
includes/widget-area.php
CHANGED
@@ -39,7 +39,7 @@ class Simple_Page_Sidebars_Widget_Area extends WP_Widget {
|
|
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 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>
|
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>
|
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:
|
6 |
-
"PO-Revision-Date:
|
7 |
"Last-Translator: Brady Vercher <brady@blazersix.com>\n"
|
8 |
"Language-Team: \n"
|
9 |
"MIME-Version: 1.0\n"
|
@@ -13,56 +13,56 @@ msgstr ""
|
|
13 |
"X-Poedit-Basepath: ../\n"
|
14 |
"X-Poedit-SearchPath-0: .\n"
|
15 |
|
16 |
-
#: admin/admin.php:
|
17 |
msgid " Default Sidebar"
|
18 |
msgstr ""
|
19 |
|
20 |
-
#: admin/admin.php:
|
21 |
msgid "The sidebar that will replaced by custom sidebars."
|
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 options panel"
|
31 |
msgstr ""
|
32 |
|
33 |
-
#: admin/admin.php:
|
34 |
msgid "Current sidebar:"
|
35 |
msgstr ""
|
36 |
|
37 |
-
#: admin/admin.php:
|
38 |
-
#: admin/admin.php:
|
39 |
-
#: admin/admin.php:
|
40 |
msgid "Default Sidebar"
|
41 |
msgstr ""
|
42 |
|
43 |
-
#: admin/admin.php:
|
44 |
msgid "Or create a new sidebar:"
|
45 |
msgstr ""
|
46 |
|
47 |
-
#: admin/admin.php:
|
48 |
msgid "Enter New"
|
49 |
msgstr ""
|
50 |
|
51 |
-
#: admin/admin.php:
|
52 |
msgid "Cancel"
|
53 |
msgstr ""
|
54 |
|
55 |
-
#: admin/admin.php:
|
56 |
msgid "Update"
|
57 |
msgstr ""
|
58 |
|
59 |
-
#: admin/admin.php:
|
60 |
-
#: admin/admin.php:
|
61 |
-
#: admin/admin.php:
|
62 |
msgid "Sidebar"
|
63 |
msgstr ""
|
64 |
|
65 |
-
#: admin/admin.php:
|
66 |
msgid "— No Change —"
|
67 |
msgstr ""
|
68 |
|
2 |
msgstr ""
|
3 |
"Project-Id-Version: Simple Page Sidebars\n"
|
4 |
"Report-Msgid-Bugs-To: \n"
|
5 |
+
"POT-Creation-Date: 2012-04-25 12:26-0800\n"
|
6 |
+
"PO-Revision-Date: 2012-04-25 13:17-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:27
|
17 |
msgid " Default Sidebar"
|
18 |
msgstr ""
|
19 |
|
20 |
+
#: admin/admin.php:59
|
21 |
msgid "The sidebar that will replaced by custom sidebars."
|
22 |
msgstr ""
|
23 |
|
24 |
+
#: admin/admin.php:140
|
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:141
|
30 |
msgid "Reading options panel"
|
31 |
msgstr ""
|
32 |
|
33 |
+
#: admin/admin.php:147
|
34 |
msgid "Current sidebar:"
|
35 |
msgstr ""
|
36 |
|
37 |
+
#: admin/admin.php:149
|
38 |
+
#: admin/admin.php:266
|
39 |
+
#: admin/admin.php:334
|
40 |
msgid "Default Sidebar"
|
41 |
msgstr ""
|
42 |
|
43 |
+
#: admin/admin.php:160
|
44 |
msgid "Or create a new sidebar:"
|
45 |
msgstr ""
|
46 |
|
47 |
+
#: admin/admin.php:162
|
48 |
msgid "Enter New"
|
49 |
msgstr ""
|
50 |
|
51 |
+
#: admin/admin.php:163
|
52 |
msgid "Cancel"
|
53 |
msgstr ""
|
54 |
|
55 |
+
#: admin/admin.php:168
|
56 |
msgid "Update"
|
57 |
msgstr ""
|
58 |
|
59 |
+
#: admin/admin.php:230
|
60 |
+
#: admin/admin.php:264
|
61 |
+
#: admin/admin.php:331
|
62 |
msgid "Sidebar"
|
63 |
msgstr ""
|
64 |
|
65 |
+
#: admin/admin.php:333
|
66 |
msgid "— No Change —"
|
67 |
msgstr ""
|
68 |
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== Simple Page Sidebars ===
|
2 |
-
Contributors: blazersix
|
3 |
Donate link: http://bit.ly/s2zcgD
|
4 |
Tags: sidebars, custom sidebars, dynamic sidebar, simple, widget, widgets
|
5 |
Requires at least: 3.2.1
|
6 |
-
Tested up to: 3.3
|
7 |
-
Stable tag: 0.2
|
8 |
|
9 |
Assign custom, widget-enabled sidebars to any page with ease.
|
10 |
|
@@ -31,6 +31,10 @@ After installation, go to the Reading options panel (the Reading link under Sett
|
|
31 |
|
32 |
== Changelog ==
|
33 |
|
|
|
|
|
|
|
|
|
34 |
= 0.2 =
|
35 |
* Added an option to define the default sidebar on the Reading options panel.
|
36 |
* Removed the template change requirement. It's no longer recommended.
|
1 |
=== Simple Page Sidebars ===
|
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.1
|
6 |
+
Tested up to: 3.3.2
|
7 |
+
Stable tag: 0.2.1
|
8 |
|
9 |
Assign custom, widget-enabled sidebars to any page with ease.
|
10 |
|
31 |
|
32 |
== Changelog ==
|
33 |
|
34 |
+
= 0.2.1 =
|
35 |
+
* Now works for the blog page when it's set in the Reading Settings.
|
36 |
+
* Bug fixes.
|
37 |
+
|
38 |
= 0.2 =
|
39 |
* Added an option to define the default sidebar on the Reading options panel.
|
40 |
* Removed the template change requirement. It's no longer recommended.
|
simple-page-sidebars.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Simple Page Sidebars
|
4 |
-
Version: 0.2
|
5 |
Plugin URI: http://wordpress.org/extend/plugins/simple-page-sidebars/
|
6 |
Description: Assign custom, widget-enabled sidebars to any page with ease.
|
7 |
Author: Blazer Six, Inc.
|
@@ -10,22 +10,25 @@ Author URI: http://www.blazersix.com/
|
|
10 |
|
11 |
|
12 |
class Simple_Page_Sidebars {
|
13 |
-
|
14 |
function __construct() {
|
15 |
add_action( 'plugins_loaded', array( &$this, 'load_plugin' ) );
|
16 |
}
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
function load_plugin() {
|
20 |
load_plugin_textdomain( 'simple-page-sidebars', false, 'simple-page-sidebars/languages' );
|
21 |
|
22 |
-
require_once( plugin_dir_path( __FILE__ ) .'/includes/widget-area.php' );
|
23 |
|
24 |
if ( is_admin() ) {
|
25 |
require_once( plugin_dir_path( __FILE__ ) . 'admin/admin.php' );
|
26 |
}
|
27 |
|
28 |
-
//
|
29 |
add_action( 'widgets_init', array( &$this, 'register_sidebars' ), 20 );
|
30 |
|
31 |
if ( ! is_admin() ) {
|
@@ -33,20 +36,21 @@ class Simple_Page_Sidebars {
|
|
33 |
}
|
34 |
}
|
35 |
|
36 |
-
|
37 |
/**
|
38 |
-
* Add widget areas and automatically register page sidebars
|
|
|
|
|
39 |
*/
|
40 |
function register_sidebars() {
|
41 |
$widget_areas = array();
|
42 |
|
43 |
-
//
|
44 |
-
$widget_areas = apply_filters( 'simpsid_widget_areas', $widget_areas ); // deprecated
|
45 |
$widget_areas = apply_filters( 'simple_page_sidebars_widget_areas', $widget_areas );
|
|
|
46 |
|
47 |
-
//
|
48 |
-
//
|
49 |
-
if ( is_array( $widget_areas ) ) {
|
50 |
foreach ( $widget_areas as $key => $area ) {
|
51 |
if ( is_numeric( $key ) ) {
|
52 |
$widget_areas[ 'widget-area-' . sanitize_key( $area['name'] ) ] = $area;
|
@@ -55,19 +59,19 @@ class Simple_Page_Sidebars {
|
|
55 |
}
|
56 |
}
|
57 |
|
58 |
-
//
|
59 |
$widget_area_defaults = array(
|
60 |
'before_widget' => '<div id="%1$s" class="widget %2$s">',
|
61 |
'after_widget' => '</div>',
|
62 |
'before_title' => '<h4 class="title">',
|
63 |
'after_title' => '</h4>'
|
64 |
);
|
65 |
-
$widget_area_defaults = apply_filters( 'simpsid_widget_area_defaults', $widget_area_defaults ); // deprecated
|
66 |
$widget_area_defaults = apply_filters( 'simple_page_sidebars_widget_defaults', $widget_area_defaults );
|
|
|
67 |
|
68 |
-
//
|
69 |
$sidebars = simple_page_sidebars_get_names();
|
70 |
-
if (
|
71 |
foreach ( $sidebars as $sidebar ) {
|
72 |
$page_sidebars[ 'page-sidebar-' . sanitize_key( $sidebar ) ] = array(
|
73 |
'name' => $sidebar,
|
@@ -75,12 +79,12 @@ class Simple_Page_Sidebars {
|
|
75 |
);
|
76 |
}
|
77 |
|
78 |
-
ksort($page_sidebars);
|
79 |
-
$widget_areas = array_merge_recursive($widget_areas, $page_sidebars);
|
80 |
}
|
81 |
|
82 |
-
if ( is_array( $widget_areas ) ) {
|
83 |
-
//
|
84 |
foreach ( $widget_areas as $key => $area ) {
|
85 |
register_sidebar(array(
|
86 |
'id' => $key,
|
@@ -95,12 +99,18 @@ class Simple_Page_Sidebars {
|
|
95 |
}
|
96 |
}
|
97 |
|
98 |
-
|
|
|
|
|
|
|
|
|
99 |
function replace_sidebar( $sidebars_widgets ) {
|
100 |
global $post;
|
101 |
|
102 |
-
if ( is_page() ) {
|
103 |
-
$
|
|
|
|
|
104 |
$default_sidebar_id = get_option( 'simple_page_sidebars_default_sidebar' );
|
105 |
|
106 |
if ( $custom_sidebar && $default_sidebar_id ) {
|
@@ -118,8 +128,12 @@ class Simple_Page_Sidebars {
|
|
118 |
}
|
119 |
$simple_page_sidebars = new Simple_Page_Sidebars();
|
120 |
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
123 |
function simple_page_sidebars_get_names() {
|
124 |
global $wpdb;
|
125 |
|
@@ -132,7 +146,7 @@ function simple_page_sidebars_get_names() {
|
|
132 |
|
133 |
$sidebars = array();
|
134 |
$sidebar_names = $wpdb->get_results($sql);
|
135 |
-
if (
|
136 |
foreach ( $sidebar_names as $meta ) {
|
137 |
$sidebars[] = $meta->meta_value;
|
138 |
}
|
@@ -141,17 +155,17 @@ function simple_page_sidebars_get_names() {
|
|
141 |
return $sidebars;
|
142 |
}
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
/*
|
147 |
* Sidebar display template tag
|
148 |
*
|
149 |
* Call this function in the template where custom sidebars should be displayed.
|
150 |
* If a custom sidebar hasn't been defined, the sidebar name passed as the parameter
|
151 |
* will be served as a fallback.
|
152 |
*
|
153 |
-
* This is no longer the recommended usage. No code changes are
|
|
|
154 |
*
|
|
|
155 |
* @param string $default_sidebar
|
156 |
*/
|
157 |
function simple_page_sidebar( $default_sidebar ) {
|
@@ -159,9 +173,9 @@ function simple_page_sidebar( $default_sidebar ) {
|
|
159 |
|
160 |
$sidebar_name = get_post_meta( $post->ID, '_sidebar_name', true );
|
161 |
|
162 |
-
//
|
163 |
-
$sidebar_name = apply_filters( 'simpsid_sidebar_name', $sidebar_name ); // deprecated
|
164 |
$sidebar_name = apply_filters( 'simple_page_sidebars_last_call', $sidebar_name );
|
|
|
165 |
|
166 |
if ( is_page() && ! empty( $sidebar_name ) ) {
|
167 |
$sidebars_widgets = wp_get_sidebars_widgets();
|
@@ -181,7 +195,7 @@ function simple_page_sidebar( $default_sidebar ) {
|
|
181 |
}
|
182 |
}
|
183 |
|
184 |
-
|
185 |
* Deprecated
|
186 |
*/
|
187 |
if ( ! function_exists( 'simple_sidebar' ) ) :
|
1 |
<?php
|
2 |
/*
|
3 |
Plugin Name: Simple Page Sidebars
|
4 |
+
Version: 0.2.1
|
5 |
Plugin URI: http://wordpress.org/extend/plugins/simple-page-sidebars/
|
6 |
Description: Assign custom, widget-enabled sidebars to any page with ease.
|
7 |
Author: Blazer Six, Inc.
|
10 |
|
11 |
|
12 |
class Simple_Page_Sidebars {
|
|
|
13 |
function __construct() {
|
14 |
add_action( 'plugins_loaded', array( &$this, 'load_plugin' ) );
|
15 |
}
|
16 |
|
17 |
+
/**
|
18 |
+
* Setup the plugin
|
19 |
+
*
|
20 |
+
* @since 0.2
|
21 |
+
*/
|
22 |
function load_plugin() {
|
23 |
load_plugin_textdomain( 'simple-page-sidebars', false, 'simple-page-sidebars/languages' );
|
24 |
|
25 |
+
require_once( plugin_dir_path( __FILE__ ) . '/includes/widget-area.php' );
|
26 |
|
27 |
if ( is_admin() ) {
|
28 |
require_once( plugin_dir_path( __FILE__ ) . 'admin/admin.php' );
|
29 |
}
|
30 |
|
31 |
+
// lower priority registers sidebars below those typically added in themes
|
32 |
add_action( 'widgets_init', array( &$this, 'register_sidebars' ), 20 );
|
33 |
|
34 |
if ( ! is_admin() ) {
|
36 |
}
|
37 |
}
|
38 |
|
|
|
39 |
/**
|
40 |
+
* Add custom widget areas and automatically register page sidebars
|
41 |
+
*
|
42 |
+
* @since 0.2
|
43 |
*/
|
44 |
function register_sidebars() {
|
45 |
$widget_areas = array();
|
46 |
|
47 |
+
// add widget areas using this filter
|
|
|
48 |
$widget_areas = apply_filters( 'simple_page_sidebars_widget_areas', $widget_areas );
|
49 |
+
$widget_areas = apply_filters( 'simpsid_widget_areas', $widget_areas ); // deprecated
|
50 |
|
51 |
+
// verify id's exist, otherwise create them
|
52 |
+
// helps ensure widgets don't get mixed up if widget areas are added or removed
|
53 |
+
if ( ! empty( $widget_areas ) && is_array( $widget_areas ) ) {
|
54 |
foreach ( $widget_areas as $key => $area ) {
|
55 |
if ( is_numeric( $key ) ) {
|
56 |
$widget_areas[ 'widget-area-' . sanitize_key( $area['name'] ) ] = $area;
|
59 |
}
|
60 |
}
|
61 |
|
62 |
+
// override the default widget properties
|
63 |
$widget_area_defaults = array(
|
64 |
'before_widget' => '<div id="%1$s" class="widget %2$s">',
|
65 |
'after_widget' => '</div>',
|
66 |
'before_title' => '<h4 class="title">',
|
67 |
'after_title' => '</h4>'
|
68 |
);
|
|
|
69 |
$widget_area_defaults = apply_filters( 'simple_page_sidebars_widget_defaults', $widget_area_defaults );
|
70 |
+
$widget_area_defaults = apply_filters( 'simpsid_widget_area_defaults', $widget_area_defaults ); // deprecated
|
71 |
|
72 |
+
// if any custom sidebars have been assigned to pages, merge them with already defined widget areas
|
73 |
$sidebars = simple_page_sidebars_get_names();
|
74 |
+
if ( ! empty( $sidebars ) ) {
|
75 |
foreach ( $sidebars as $sidebar ) {
|
76 |
$page_sidebars[ 'page-sidebar-' . sanitize_key( $sidebar ) ] = array(
|
77 |
'name' => $sidebar,
|
79 |
);
|
80 |
}
|
81 |
|
82 |
+
ksort( $page_sidebars );
|
83 |
+
$widget_areas = array_merge_recursive( $widget_areas, $page_sidebars );
|
84 |
}
|
85 |
|
86 |
+
if ( ! empty( $widget_areas ) && is_array( $widget_areas ) ) {
|
87 |
+
// register the widget areas
|
88 |
foreach ( $widget_areas as $key => $area ) {
|
89 |
register_sidebar(array(
|
90 |
'id' => $key,
|
99 |
}
|
100 |
}
|
101 |
|
102 |
+
/**
|
103 |
+
* Replaces the default sidebar with a custom defined page sidebar
|
104 |
+
*
|
105 |
+
* @since 0.2
|
106 |
+
*/
|
107 |
function replace_sidebar( $sidebars_widgets ) {
|
108 |
global $post;
|
109 |
|
110 |
+
if ( is_page() || ( is_home() && $posts_page = get_option( 'page_for_posts' ) ) ) {
|
111 |
+
$post_id = ( is_home() ) ? $posts_page : $post->ID;
|
112 |
+
|
113 |
+
$custom_sidebar = get_post_meta( $post_id, '_sidebar_name', true );
|
114 |
$default_sidebar_id = get_option( 'simple_page_sidebars_default_sidebar' );
|
115 |
|
116 |
if ( $custom_sidebar && $default_sidebar_id ) {
|
128 |
}
|
129 |
$simple_page_sidebars = new Simple_Page_Sidebars();
|
130 |
|
131 |
+
/**
|
132 |
+
* Get an array of custom sidebar names
|
133 |
+
*
|
134 |
+
* @since 0.2
|
135 |
+
* @return array Custom sidebar names
|
136 |
+
*/
|
137 |
function simple_page_sidebars_get_names() {
|
138 |
global $wpdb;
|
139 |
|
146 |
|
147 |
$sidebars = array();
|
148 |
$sidebar_names = $wpdb->get_results($sql);
|
149 |
+
if ( ! empty( $sidebar_names ) ) {
|
150 |
foreach ( $sidebar_names as $meta ) {
|
151 |
$sidebars[] = $meta->meta_value;
|
152 |
}
|
155 |
return $sidebars;
|
156 |
}
|
157 |
|
158 |
+
/**
|
|
|
|
|
159 |
* Sidebar display template tag
|
160 |
*
|
161 |
* Call this function in the template where custom sidebars should be displayed.
|
162 |
* If a custom sidebar hasn't been defined, the sidebar name passed as the parameter
|
163 |
* will be served as a fallback.
|
164 |
*
|
165 |
+
* This is no longer the recommended usage. No code changes to the theme are
|
166 |
+
* are required for the plugin to work.
|
167 |
*
|
168 |
+
* @since 0.2
|
169 |
* @param string $default_sidebar
|
170 |
*/
|
171 |
function simple_page_sidebar( $default_sidebar ) {
|
173 |
|
174 |
$sidebar_name = get_post_meta( $post->ID, '_sidebar_name', true );
|
175 |
|
176 |
+
// last chance to override which sidebar is displayed
|
|
|
177 |
$sidebar_name = apply_filters( 'simple_page_sidebars_last_call', $sidebar_name );
|
178 |
+
$sidebar_name = apply_filters( 'simpsid_sidebar_name', $sidebar_name ); // deprecated
|
179 |
|
180 |
if ( is_page() && ! empty( $sidebar_name ) ) {
|
181 |
$sidebars_widgets = wp_get_sidebars_widgets();
|
195 |
}
|
196 |
}
|
197 |
|
198 |
+
/**
|
199 |
* Deprecated
|
200 |
*/
|
201 |
if ( ! function_exists( 'simple_sidebar' ) ) :
|