Genesis Simple Sidebars - Version 0.9

Version Description

  • Fixed "is not array" errors reported by users
  • Added nonce verification for security purposes
  • Added error and success messages
  • Bump to pre-release 0.9 branch
Download this release

Release Info

Developer nathanrice
Plugin Icon 128x128 Genesis Simple Sidebars
Version 0.9
Comparing to
See all releases

Version 0.9

Files changed (6) hide show
  1. admin.php +181 -0
  2. functions.php +181 -0
  3. inpost.php +84 -0
  4. plugin.php +118 -0
  5. readme.txt +47 -0
  6. term.php +53 -0
admin.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This registers the settings field and adds empty array to the options table
4
+ */
5
+ add_action('admin_init', 'register_ss_settings');
6
+ function register_ss_settings() {
7
+ register_setting(SS_SETTINGS_FIELD, SS_SETTINGS_FIELD);
8
+ add_option(SS_SETTINGS_FIELD, '__return_empty_array', '', 'yes');
9
+ }
10
+
11
+ /**
12
+ * This function adds our "Simple Sidebars" submenu item
13
+ */
14
+ add_action('admin_menu', 'ss_settings_init', 15);
15
+ function ss_settings_init() {
16
+
17
+ add_submenu_page('genesis', __('Simple Sidebars','ss'), __('Simple Sidebars','ss'), 'manage_options', 'simple-sidebars', 'ss_settings_admin');
18
+
19
+ }
20
+
21
+ add_action('admin_init', 'ss_action_functions');
22
+ function ss_action_functions() {
23
+
24
+ if ( !isset( $_REQUEST['page'] ) || $_REQUEST['page'] != 'simple-sidebars' ) {
25
+ return;
26
+ }
27
+
28
+ /**
29
+ * This section handles the data if a new sidebar is created
30
+ */
31
+ if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'create' ) {
32
+ ss_create_sidebar( $_POST['new_sidebar'] );
33
+ }
34
+
35
+ /**
36
+ * This section will handle the data if a sidebar is deleted
37
+ */
38
+ if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'delete' && isset( $_REQUEST['id'] ) ) {
39
+ ss_delete_sidebar( $_REQUEST['id'] );
40
+ }
41
+
42
+ /**
43
+ * This section will handle the data if a sidebar is to be modified
44
+ */
45
+ if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' && !isset( $_REQUEST['id'] ) ) {
46
+ ss_edit_sidebar( $_POST['edit_sidebar'] );
47
+ }
48
+ }
49
+
50
+ /**
51
+ * This function is what actually gets output to the page.
52
+ * It handles the markup, builds the form, etc.
53
+ */
54
+ function ss_settings_admin() { ?>
55
+
56
+ <div class="wrap">
57
+
58
+ <?php
59
+ if ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'edit' ) :
60
+
61
+ $_sidebars = get_option( SS_SETTINGS_FIELD );
62
+
63
+ if ( array_key_exists( $_REQUEST['id'], (array)$_sidebars ) ) {
64
+ $_sidebar = stripslashes_deep( $_sidebars[$_REQUEST['id']] );
65
+ } else {
66
+ wp_die( __('Nice try, partner. But that sidebar doesn\'t exist. Click back and try again.', 'ss') );
67
+ }
68
+
69
+ ?>
70
+
71
+ <?php screen_icon('themes'); ?>
72
+ <h2><?php _e('Edit Sidebar', 'ss'); ?></h2>
73
+
74
+ <form method="post" action="<?php echo admin_url( 'admin.php?page=simple-sidebars&amp;action=edit' ); ?>">
75
+ <?php wp_nonce_field('simple-sidebars-action_edit-sidebar'); ?>
76
+ <table class="form-table">
77
+
78
+ <tr class="form-field">
79
+ <th scope="row" valign="top"><label for="edit_sidebar[name]"><?php _e('Name', 'ss'); ?></label></th>
80
+ <td><input name="edit_sidebar[name]" id="edit_sidebar[name]" type="text" value="<?php echo esc_html( $_sidebar['name'] ); ?>" size="40" />
81
+ <p class="description"><?php _e('A recognizable name for your new sidebar widget area', 'ss'); ?></p></td>
82
+ </tr>
83
+
84
+ <tr class="form-field">
85
+ <th scope="row" valign="top"><label for="edit_sidebar[id]"><?php _e('ID', 'ss'); ?></label></th>
86
+ <td>
87
+ <input type="text" value="<?php echo esc_html( $_REQUEST['id'] ); ?>" size="40" disabled="disabled" />
88
+ <input name="edit_sidebar[id]" id="edit_sidebar[id]" type="hidden" value="<?php echo esc_html( $_REQUEST['id'] ); ?>" size="40" />
89
+ <p class="description"><?php _e('The unique ID is used to register the sidebar widget area (cannot be changed)', 'ss'); ?></p></td>
90
+ </tr>
91
+
92
+ <tr class="form-field">
93
+ <th scope="row" valign="top"><label for="edit_sidebar[description]"><?php _e('Description', 'ss'); ?></label></th>
94
+ <td><textarea name="edit_sidebar[description]" id="edit_sidebar[description]" rows="3" cols="50" style="width: 97%;"><?php echo esc_html( $_sidebar['description'] ); ?></textarea></td>
95
+ </tr>
96
+
97
+ </table>
98
+
99
+ <p class="submit"><input type="submit" class="button-primary" name="submit" value="<?php _e('Update', 'ee'); ?>" /></p>
100
+
101
+ </form>
102
+
103
+ <?php else : ?>
104
+
105
+ <?php screen_icon('themes'); ?>
106
+ <h2><?php _e('Genesis - Simple Sidebars', 'ss'); ?></h2>
107
+
108
+ <div id="col-container">
109
+
110
+ <div id="col-right">
111
+ <div class="col-wrap">
112
+
113
+ <h3><?php _e('Current Sidebars', 'ss'); ?></h3>
114
+ <table class="widefat tag fixed" cellspacing="0">
115
+ <thead>
116
+ <tr>
117
+ <th scope="col" id="name" class="manage-column column-name"><?php _e('Name', 'ss'); ?></th>
118
+ <th scope="col" class="manage-column column-slug"><?php _e('ID', 'ss'); ?></th>
119
+ <th scope="col" id="description" class="manage-column column-description"><?php _e('Description', 'ss'); ?></th>
120
+ </tr>
121
+ </thead>
122
+
123
+ <tfoot>
124
+ <tr>
125
+ <th scope="col" class="manage-column column-name"><?php _e('Name', 'ss'); ?></th>
126
+ <th scope="col" class="manage-column column-slug"><?php _e('ID', 'ss'); ?></th>
127
+ <th scope="col" class="manage-column column-description"><?php _e('Description', 'ss'); ?></th>
128
+ </tr>
129
+ </tfoot>
130
+
131
+ <tbody id="the-list" class="list:tag">
132
+
133
+ <?php ss_sidebar_table_rows(); ?>
134
+
135
+ </tbody>
136
+ </table>
137
+
138
+ </div>
139
+ </div><!-- /col-right -->
140
+
141
+ <div id="col-left">
142
+ <div class="col-wrap">
143
+
144
+
145
+ <div class="form-wrap">
146
+ <h3><?php _e('Add New Sidebar', 'ss'); ?></h3>
147
+
148
+ <form method="post" action="<?php echo admin_url( 'admin.php?page=simple-sidebars&amp;action=create' ); ?>">
149
+ <?php wp_nonce_field('simple-sidebars-action_create-sidebar'); ?>
150
+
151
+ <div class="form-field form-required">
152
+ <label for="sidebar-name"><?php _e('Name', 'ss'); ?></label>
153
+ <input name="new_sidebar[name]" id="sidebar-name" type="text" value="" size="40" aria-required="true" />
154
+ <p><?php _e('A recognizable name for your new sidebar widget area', 'ss'); ?></p>
155
+ </div>
156
+
157
+ <div class="form-field">
158
+ <label for="sidebar-id"><?php _e('ID', 'ss'); ?></label>
159
+ <input name="new_sidebar[id]" id="sidebar-id" type="text" value="" size="40" />
160
+ <p><?php _e('The unique ID is used to register the sidebar widget area', 'ss'); ?></p>
161
+ </div>
162
+
163
+ <div class="form-field">
164
+ <label for="sidebar-description"><?php _e('Description', 'ss'); ?></label>
165
+ <textarea name="new_sidebar[description]" id="sidebar-description" rows="5" cols="40"></textarea>
166
+ </div>
167
+
168
+ <p class="submit"><input type="submit" class="button" name="submit" id="submit" value="<?php _e('Add New Sidebar', 'ss'); ?>" /></p>
169
+ </form></div>
170
+
171
+ </div>
172
+ </div><!-- /col-left -->
173
+
174
+ </div><!-- /col-container -->
175
+
176
+ <?php endif; ?>
177
+
178
+ </div><!-- /wrap -->
179
+
180
+ <?php
181
+ }
functions.php ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function ss_sidebar_table_rows() {
3
+ global $wp_registered_sidebars;
4
+
5
+ $_sidebars = $wp_registered_sidebars;
6
+
7
+ $alt = true;
8
+
9
+ foreach ( (array)$_sidebars as $id => $info ) { ?>
10
+
11
+ <?php
12
+ $is_editable = isset( $info['editable'] ) && $info['editable'] ? true : false;
13
+ ?>
14
+
15
+ <tr <?php if ( $alt ) { echo 'class="alternate"'; $alt = false; } else { $alt = true; } ?>>
16
+ <td class="name column-name">
17
+ <?php
18
+ if ( $is_editable ) {
19
+ printf( '<a class="row-title" href="%s" title="Edit %s">%s</a>', admin_url('admin.php?page=simple-sidebars&amp;action=edit&amp;id=' . esc_html( $id ) ), esc_html( $info['name'] ), esc_html( $info['name'] ) );
20
+ } else {
21
+ printf( '<strong class="row-title">%s</strong>', esc_html( $info['name'] ) );
22
+ }
23
+ ?>
24
+
25
+ <?php if ( $is_editable ) : ?>
26
+ <br />
27
+ <div class="row-actions">
28
+ <span class="edit"><a href="<?php echo admin_url('admin.php?page=simple-sidebars&amp;action=edit&amp;id=' . esc_html( $id ) ); ?>"><?php _e('Edit', 'ss'); ?></a> | </span>
29
+ <span class="delete"><a class="delete-tag" href="<?php echo wp_nonce_url( admin_url( 'admin.php?page=simple-sidebars&amp;action=delete&amp;id=' . esc_html( $id ) ), 'simple-sidebars-action_delete-sidebar' ); ?>"><?php _e('Delete', 'ss'); ?></a></span>
30
+ </div>
31
+ <?php endif; ?>
32
+
33
+ </td>
34
+ <td class="slug column-slug"><?php echo esc_html( $id ); ?></td>
35
+ <td class="description column-description"><?php echo esc_html( $info['description'] )?></td>
36
+ </tr>
37
+
38
+ <?php
39
+ }
40
+
41
+ }
42
+
43
+ function ss_create_sidebar( $args = array() ) {
44
+
45
+ if ( empty( $args['name'] ) || empty( $args['id'] ) ) {
46
+ wp_die( ss_error_message(1) );
47
+ exit;
48
+ }
49
+
50
+ // nonce verification
51
+ check_admin_referer('simple-sidebars-action_create-sidebar');
52
+
53
+ $db = (array)get_option(SS_SETTINGS_FIELD);
54
+ $new = array(
55
+ sanitize_title_with_dashes( $args['id'] ) => array(
56
+ 'name' => esc_html( $args['name'] ),
57
+ 'description' => esc_html( $args['description'] )
58
+ )
59
+ );
60
+
61
+ if ( array_key_exists( $args['id'], $db ) ) {
62
+ wp_die( ss_error_message(2) );
63
+ exit;
64
+ }
65
+
66
+ $_sidebars = wp_parse_args( $new, $db );
67
+
68
+ update_option( SS_SETTINGS_FIELD, $_sidebars );
69
+ wp_redirect( admin_url('admin.php?page=simple-sidebars&created=true') );
70
+ exit;
71
+
72
+ }
73
+
74
+ function ss_edit_sidebar( $args = array() ) {
75
+
76
+ if ( empty( $args['name'] ) || empty( $args['id'] ) ) {
77
+ wp_die( ss_error_message(3) );
78
+ exit;
79
+ }
80
+
81
+ // nonce verification
82
+ check_admin_referer('simple-sidebars-action_edit-sidebar');
83
+
84
+ $db = (array)get_option(SS_SETTINGS_FIELD);
85
+ $new = array(
86
+ sanitize_title_with_dashes( $args['id'] ) => array(
87
+ 'name' => esc_html( $args['name'] ),
88
+ 'description' => esc_html( $args['description'] )
89
+ )
90
+ );
91
+
92
+ if ( !array_key_exists( $args['id'], $db ) ) {
93
+ wp_die( ss_error_message(3) );
94
+ exit;
95
+ }
96
+
97
+ $_sidebars = wp_parse_args( $new, $db );
98
+
99
+ update_option( SS_SETTINGS_FIELD, $_sidebars );
100
+ wp_redirect( admin_url('admin.php?page=simple-sidebars&edited=true') );
101
+ exit;
102
+
103
+ }
104
+
105
+ function ss_delete_sidebar( $id = '' ) {
106
+
107
+ if ( empty( $id ) ) {
108
+ wp_die( ss_error_message(4) );
109
+ exit;
110
+ }
111
+
112
+ // nonce verification
113
+ check_admin_referer('simple-sidebars-action_delete-sidebar');
114
+
115
+ $_sidebars = (array)get_option( SS_SETTINGS_FIELD );
116
+
117
+ if ( !isset( $_sidebars[$id] ) ) {
118
+ wp_die( ss_error_message(4) );
119
+ exit;
120
+ }
121
+
122
+ unset( $_sidebars[$id] );
123
+
124
+ update_option( SS_SETTINGS_FIELD, $_sidebars );
125
+ wp_redirect( admin_url('admin.php?page=simple-sidebars&deleted=true') );
126
+ exit;
127
+
128
+ }
129
+
130
+ function ss_error_message( $error = false ) {
131
+
132
+ if ( !$error ) return false;
133
+
134
+ switch( (int)$error ) {
135
+
136
+ case 1:
137
+ return __('Oops! Please choose a valid Name and ID for this sidebar', 'ss');
138
+ break;
139
+ case 2:
140
+ return __('Oops! That sidebar ID already exists');
141
+ break;
142
+ case 3:
143
+ return __('Oops! You are trying to edit a sidebar that does not exist, or is not editable', 'ss');
144
+ break;
145
+ case 4:
146
+ return __('Oops! You are trying to delete a sidebar that does not exist, or cannot be deleted', 'ss');
147
+ break;
148
+ default:
149
+ return __('Oops! Something went wrong. Try again.', 'ss');
150
+
151
+ }
152
+
153
+ }
154
+
155
+ add_action('admin_notices', 'ss_success_message');
156
+ function ss_success_message() {
157
+
158
+ if ( !isset( $_REQUEST['page'] ) || $_REQUEST['page'] != 'simple-sidebars' ) {
159
+ return;
160
+ }
161
+
162
+ $format = '<div id="message" class="updated"><p><strong>%s</strong></p></div>';
163
+
164
+ if ( isset( $_REQUEST['created'] ) && $_REQUEST['created'] === 'true' ) {
165
+ printf( $format, __('New sidebar successfully created!', 'ss') );
166
+ return;
167
+ }
168
+
169
+ if ( isset( $_REQUEST['edited'] ) && $_REQUEST['edited'] === 'true' ) {
170
+ printf( $format, __('Sidebar successfully edited!', 'ss') );
171
+ return;
172
+ }
173
+
174
+ if ( isset( $_REQUEST['deleted'] ) && $_REQUEST['deleted'] === 'true' ) {
175
+ printf( $format, __('Sidebar successfully deleted.', 'ss') );
176
+ return;
177
+ }
178
+
179
+ return;
180
+
181
+ }
inpost.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This bit of code registers the meta box on posts/pages,
4
+ * so that users can choose what sidebar to use.
5
+ */
6
+ add_action('admin_menu', 'ss_add_inpost_metabox');
7
+ function ss_add_inpost_metabox() {
8
+ add_meta_box('ss_inpost_metabox', __('Sidebar Selection', 'genesis'), 'ss_inpost_metabox', 'post', 'side', 'low');
9
+ add_meta_box('ss_inpost_metabox', __('Sidebar Selection', 'genesis'), 'ss_inpost_metabox', 'page', 'side', 'low');
10
+ }
11
+
12
+ function ss_inpost_metabox() {
13
+ $_sidebars = stripslashes_deep( get_option( SS_SETTINGS_FIELD ) );
14
+ ?>
15
+
16
+ <input type="hidden" name="ss_inpost_nonce" value="<?php echo wp_create_nonce(plugin_basename(__FILE__)); ?>" />
17
+
18
+ <p>
19
+ <label class="howto" for="_ss_sidebar"><span><?php _e('Primary Sidebar', 'ss'); ?><span></label>
20
+ <select name="_ss_sidebar" id="_ss_sidebar" style="width: 99%">
21
+ <option value=""><?php _e('Default', 'ss'); ?></option>
22
+ <?php
23
+ foreach ( (array)$_sidebars as $id => $info ) {
24
+ printf( '<option value="%s" %s>%s</option>', esc_html( $id ), selected( $id, genesis_get_custom_field('_ss_sidebar'), false), esc_html( $info['name'] ) );
25
+ }
26
+ ?>
27
+ </select>
28
+ </p>
29
+
30
+ <p>
31
+ <label class="howto" for="_ss_sidebar_alt"><span><?php _e('Secondary Sidebar', 'ss'); ?><span></label>
32
+ <select name="_ss_sidebar_alt" id="_ss_sidebar_alt" style="width: 99%">
33
+ <option value=""><?php _e('Default', 'ss'); ?></option>
34
+ <?php
35
+ foreach ( (array)$_sidebars as $id => $info ) {
36
+ printf( '<option value="%s" %s>%s</option>', esc_html( $id ), selected( $id, genesis_get_custom_field('_ss_sidebar_alt'), false), esc_html( $info['name'] ) );
37
+ }
38
+ ?>
39
+ </select>
40
+ </p>
41
+
42
+ <?php
43
+ }
44
+
45
+ /**
46
+ * This bit of code saves the sidebars chosen as post meta.
47
+ */
48
+ add_action('save_post', 'ss_inpost_metabox_save', 1, 2);
49
+ function ss_inpost_metabox_save( $post_id, $post ) {
50
+
51
+ // verify the nonce
52
+ if ( !isset($_POST['ss_inpost_nonce']) || !wp_verify_nonce( $_POST['ss_inpost_nonce'], plugin_basename(__FILE__) ) )
53
+ return $post->ID;
54
+
55
+ // don't try to save the data under autosave, ajax, or future post.
56
+ if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
57
+ if ( defined('DOING_AJAX') && DOING_AJAX ) return;
58
+ if ( defined('DOING_CRON') && DOING_CRON ) return;
59
+
60
+ // is the user allowed to edit the post or page?
61
+ if ( ( 'page' == $_POST['post_type'] && !current_user_can('edit_page', $post->ID) ) || !current_user_can('edit_post', $post->ID ) )
62
+ return $post->ID;
63
+
64
+ $_sidebars = array(
65
+ '_ss_sidebar' => $_POST['_ss_sidebar'],
66
+ '_ss_sidebar_alt' => $_POST['_ss_sidebar_alt']
67
+ );
68
+
69
+ // store the custom fields
70
+ foreach ( $_sidebars as $key => $value ) {
71
+
72
+ if ( $post->post_type == 'revision' ) return; // don't try to store data during revision save
73
+
74
+ if ( $value ) {
75
+ // save/update
76
+ update_post_meta($post->ID, $key, $value);
77
+ } else {
78
+ // delete if blank
79
+ delete_post_meta($post->ID, $key);
80
+ }
81
+
82
+ }
83
+
84
+ }
plugin.php ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Genesis Simple Sidebars
4
+ Plugin URI: http://www.studiopress.com/plugins/simple-sidebars
5
+ Description: Genesis Simple Sidebars allows you to easily create and use new sidebar widget areas.
6
+ Version: 0.9
7
+ Author: Nathan Rice
8
+ Author URI: http://www.nathanrice.net/
9
+ */
10
+
11
+ // require Genesis 1.2 upon activation
12
+ register_activation_hook(__FILE__, 'ss_activation_check');
13
+ function ss_activation_check() {
14
+
15
+ $latest = '1.2';
16
+
17
+ $theme_info = get_theme_data(TEMPLATEPATH.'/style.css');
18
+
19
+ if( basename(TEMPLATEPATH) != 'genesis' ) {
20
+ deactivate_plugins(plugin_basename(__FILE__)); // Deactivate ourself
21
+ wp_die( sprintf( __('Sorry, you can\'t activate unless you have installed <a href="%s">Genesis</a>', 'ss'), 'http://www.studiopress.com/themes/genesis' ) );
22
+ }
23
+
24
+ if( version_compare( $theme_info['Version'], $latest, '<' ) ) {
25
+ deactivate_plugins(plugin_basename(__FILE__)); // Deactivate ourself
26
+ wp_die( sprintf( __('Sorry, you cannot activate without <a href="%s">Genesis %s</a> or greater', 'ss'), 'http://www.studiopress.com/support/showthread.php?t=19576', $latest ) );
27
+ }
28
+
29
+ }
30
+
31
+ // Define our constants
32
+ define('SS_SETTINGS_FIELD', 'ss-settings');
33
+ define('SS_PLUGIN_DIR', dirname(__FILE__));
34
+
35
+ // Include files
36
+ require_once(SS_PLUGIN_DIR . '/admin.php');
37
+ require_once(SS_PLUGIN_DIR . '/functions.php');
38
+ require_once(SS_PLUGIN_DIR . '/inpost.php');
39
+ require_once(SS_PLUGIN_DIR . '/term.php');
40
+
41
+ /**
42
+ * This function registers the created sidebars
43
+ */
44
+ add_action('widgets_init', 'ss_register_sidebars');
45
+ function ss_register_sidebars() {
46
+
47
+ $_sidebars = stripslashes_deep( get_option( SS_SETTINGS_FIELD ) );
48
+ if ( !$_sidebars ) return;
49
+
50
+ foreach ( (array)$_sidebars as $id => $info ) {
51
+
52
+ register_sidebar(array(
53
+ 'name' => esc_html( $info['name'] ),
54
+ 'id' => $id,
55
+ 'description' => esc_html( $info['description'] ),
56
+ 'editable' => 1,
57
+
58
+ 'before_widget' => '<div id="%1$s" class="widget %2$s"><div class="widget-wrap">',
59
+ 'after_widget' => "</div></div>\n",
60
+ 'before_title' => '<h4 class="widgettitle">',
61
+ 'after_title' => "</h4>\n"
62
+ ));
63
+
64
+ }
65
+
66
+ }
67
+
68
+
69
+ /**
70
+ * Remove the default sidebars, run some conditional logic,
71
+ * use alternate sidebars if necessary, else fallback on default sidebars.
72
+ */
73
+ add_action('get_header', 'ss_sidebars_init');
74
+ function ss_sidebars_init() {
75
+ remove_action('genesis_sidebar', 'genesis_do_sidebar');
76
+ remove_action('genesis_sidebar_alt', 'genesis_do_sidebar_alt');
77
+ add_action('genesis_sidebar', 'ss_do_sidebar');
78
+ add_action('genesis_sidebar_alt', 'ss_do_sidebar_alt');
79
+ }
80
+
81
+ function ss_do_sidebar() {
82
+
83
+ if ( is_singular() && $_sidebar = genesis_get_custom_field('_ss_sidebar') ) {
84
+ if ( dynamic_sidebar($_sidebar) ) return;
85
+ }
86
+
87
+ if ( is_category() ) {
88
+ $term = get_term( get_query_var('cat'), 'category' );
89
+ if( isset( $term->meta['_ss_sidebar'] ) && dynamic_sidebar( $term->meta['_ss_sidebar'] ) ) return;
90
+ }
91
+
92
+ if ( is_tag() ) {
93
+ $term = get_term( get_query_var('tag_id'), 'post_tag' );
94
+ if( isset( $term->meta['_ss_sidebar'] ) && dynamic_sidebar( $term->meta['_ss_sidebar'] ) ) return;
95
+ }
96
+
97
+ genesis_do_sidebar();
98
+
99
+ }
100
+ function ss_do_sidebar_alt() {
101
+
102
+ if ( is_singular() && $_sidebar_alt = genesis_get_custom_field('_ss_sidebar_alt') ) {
103
+ if ( dynamic_sidebar($_sidebar_alt) ) return;
104
+ }
105
+
106
+ if ( is_category() ) {
107
+ $term = get_term( get_query_var('cat'), 'category' );
108
+ if( isset( $term->meta['_ss_sidebar_alt'] ) && dynamic_sidebar( $term->meta['_ss_sidebar_alt'] ) ) return;
109
+ }
110
+
111
+ if ( is_tag() ) {
112
+ $term = get_term( get_query_var('tag_id'), 'post_tag' );
113
+ if( isset( $term->meta['_ss_sidebar_alt'] ) && dynamic_sidebar( $term->meta['_ss_sidebar_alt'] ) ) return;
114
+ }
115
+
116
+ genesis_do_sidebar_alt();
117
+
118
+ }
readme.txt ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: nathanrice
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5553118
4
+ Tags: hooks, genesis, genesiswp, studiopress
5
+ Requires at least: 2.9
6
+ Tested up to: 3.0
7
+ Stable tag: 0.9
8
+
9
+ This plugin allows you to create multiple, dynamic widget areas, and assign those widget areas to sidebar locations within the Genesis Theme Framework on a per post, per page, or per tag/category archive basis.
10
+
11
+ == Description ==
12
+
13
+ This plugin allows you to create multiple, dynamic widget areas, and assign those widget areas to sidebar locations within the Genesis Theme Framework on a per post, per page, or per tag/category archive basis.
14
+
15
+ Creating widget areas programmatically, then using conditional logic to properly assign them to sidebar locations can be a complex task for a beginner. This plugin allows you to do all this from a simple administration menu, and assign widget areas to sidebar locations with simple drop-down menus within the post/page edit screens, or when editing a tag or category.
16
+
17
+ == Installation ==
18
+
19
+ 1. Upload the entire `genesis-simple-sidebars` folder to the `/wp-content/plugins/` directory
20
+ 1. DO NOT change the name of the `genesis-simple-sidebars` folder
21
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
22
+ 1. Navigate to the `Genesis > Simple Sidebars` menu
23
+ 1. Create as many new sidebar widget areas as you need
24
+ 1. Choose the widget area you want to display by choosing it from the drop-down menu in the post/page or category/tag edit screen.
25
+
26
+ == Frequently Asked Questions ==
27
+
28
+ = Can I assign widget areas to locations other than the sidebars? =
29
+
30
+ No. You can only assign them to the primary and secondary sidebars, using the plugin.
31
+
32
+ However, once a widget area has been created, you can use hooks to programmatically display those widget areas throughout the theme. But if you're going to do that, it's very unlikely that you would want to use the plugin to create the widget areas. You might as well just create the widget areas programmatically too.
33
+
34
+ = Does this plugin give me the option of creating an entirely NEW sidebar? =
35
+
36
+ Not in the way you're probably thinking. The markup surrounding the widget area never changes. The only thing that changes is the dynamic content that displays within the pre-existing sidebar locations.
37
+
38
+ == Changelog ==
39
+
40
+ = 0.1 =
41
+ * Initial Alpha Release
42
+
43
+ = 0.9 =
44
+ * Fixed "is not array" errors reported by users
45
+ * Added nonce verification for security purposes
46
+ * Added error and success messages
47
+ * Bump to pre-release 0.9 branch
term.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * This function, hooked to display on the category/tag edit forms,
4
+ * adds new fields to select a sidebar. The variables $tag and $taxonomy
5
+ * are passed via the hook so that we can use them.
6
+ */
7
+ add_action('category_edit_form', 'ss_term_sidebar', 9, 2);
8
+ add_action('post_tag_edit_form', 'ss_term_sidebar', 9, 2);
9
+ function ss_term_sidebar($tag, $taxonomy) {
10
+
11
+ // Merge Defaults to prevent notices
12
+ $tag->meta = wp_parse_args( $tag->meta, array( '_ss_sidebar' => '', '_ss_sidebar_alt' => '' ) );
13
+
14
+ // Pull custom sidebars
15
+ $_sidebars = stripslashes_deep( get_option( SS_SETTINGS_FIELD ) );
16
+
17
+ ?>
18
+
19
+ <h3><?php _e('Sidebar Options', 'ss'); ?></h3>
20
+ <table class="form-table">
21
+
22
+ <tr class="form-field">
23
+ <th scope="row" valign="top"><label for="meta[_ss_sidebar]"><?php _e('Primary Sidebar', 'ss'); ?></label></th>
24
+ <td>
25
+ <select name="meta[_ss_sidebar]" id="meta[_ss_sidebar]" style="padding-right: 10px;">
26
+ <option value=""><?php _e('Default', 'ss'); ?></option>
27
+ <?php
28
+ foreach ( (array)$_sidebars as $id => $info ) {
29
+ printf( '<option value="%s" %s>%s</option>', esc_html( $id ), selected( $id, $tag->meta['_ss_sidebar'] , false), esc_html( $info['name'] ) );
30
+ }
31
+ ?>
32
+ </select>
33
+ </td>
34
+ </tr>
35
+
36
+ <tr class="form-field">
37
+ <th scope="row" valign="top"><label for="meta[_ss_sidebar_alt]"><?php _e('Secondary Sidebar', 'ss'); ?></label></th>
38
+ <td>
39
+ <select name="meta[_ss_sidebar_alt]" id="meta[_ss_sidebar_alt]" style="padding-right: 10px;">
40
+ <option value=""><?php _e('Default', 'ss'); ?></option>
41
+ <?php
42
+ foreach ( (array)$_sidebars as $id => $info ) {
43
+ printf( '<option value="%s" %s>%s</option>', esc_html( $id ), selected( $id, $tag->meta['_ss_sidebar_alt'] , false), esc_html( $info['name'] ) );
44
+ }
45
+ ?>
46
+ </select>
47
+ </td>
48
+ </tr>
49
+
50
+ </table>
51
+
52
+ <?php
53
+ }