Widgets on Pages - Version 0.0.6

Version Description

Sidebars can now be named via the options page. These names can be used in place of the numerical id used in older versions. Note that if you change the name you will need to manually update any shortcodes where this is being used.

Download this release

Release Info

Developer toddhalfpenny
Plugin Icon 128x128 Widgets on Pages
Version 0.0.6
Comparing to
See all releases

Code changes from version 0.0.5 to 0.0.6

Files changed (4) hide show
  1. readme.txt +14 -4
  2. screenshot-1.png +0 -0
  3. screenshot-2.png +0 -0
  4. widgets_on_pages.php +97 -25
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: toddhalfpenny
3
  Donate link: http://gingerbreaddesign.co.uk/wordpress/plugins/plugins.php
4
  Tags: widgets, sidebar, pages, post, shortcode, inline
5
  Requires at least: 2.8
6
- Tested up to: 2.9.2
7
- Stable tag: 0.0.5
8
 
9
  Allows 'in-page' widget areas so widgets can be defined via shortcode straight into page/post content
10
 
@@ -14,6 +14,9 @@ Allows 'in-page' widget areas so widgets can be defined via shortcut straight in
14
  There is one default widget area that can be used or you can add more from the settings menu. You can currently have an unlimited number of sidebars.
15
  Each sidebar can be called indepentenly by a shortcode and you can call more than one per post/page.
16
  Sidebars can be included in the post/page by using a shortcode like `[widgets_on_pages id=x]` where `x` is the number of the sidebar.
 
 
 
17
 
18
 
19
  == Installation ==
@@ -22,7 +25,7 @@ Sidebars can be included in the post/page by using a shortcode like `[widgets_on
22
  1. Install the plugin from within the Dashboard or upload the directory `widgets-on-pages` and all its contents to the `/wp-content/plugins/` directory
23
  1. Activate the plugin through the 'Plugins' menu in WordPress
24
  1. Add the widgets you want to the `Widgets on Pages` widget area in the admin screens
25
- 1. Add the shortcut `[widgets_on_pages id=x]` to the page or post in the place where you'd like your widgets to appear (where 'x' = the id of the sidebar to use. If using only the default sidebar then no 'id' argument is needed (i.e. `[widgets_on_pages]`).
26
 
27
 
28
  == Frequently Asked Questions ==
@@ -33,10 +36,17 @@ Yes... you can have an unlimited number of sidebars defined. The number availabl
33
 
34
  == Screenshots ==
35
 
36
- 1. The 'auto' defined Sidebar that can be called by the shortcode.
 
 
 
37
 
38
  == Changelog ==
39
 
 
 
 
 
40
  = 0.0.5 =
41
 
42
  Fix for activation errors. Looks like it might've been the use of php short open tags or line ending chars.
3
  Donate link: http://gingerbreaddesign.co.uk/wordpress/plugins/plugins.php
4
  Tags: widgets, sidebar, pages, post, shortcode, inline
5
  Requires at least: 2.8
6
+ Tested up to: 3.0.0
7
+ Stable tag: 0.0.6
8
 
9
  Allows 'in-page' widget areas so widgets can be defined via shortcode straight into page/post content
10
 
14
  There is one default widget area that can be used or you can add more from the settings menu. You can currently have an unlimited number of sidebars.
15
  Each sidebar can be called indepentenly by a shortcode and you can call more than one per post/page.
16
  Sidebars can be included in the post/page by using a shortcode like `[widgets_on_pages id=x]` where `x` is the number of the sidebar.
17
+ Sidebars can also be named via the Widgets on Pages options page and that name can be used instead of the `x` id.
18
+ ''NOTE'' : see changelog for use if using the named sidebars
19
+
20
 
21
 
22
  == Installation ==
25
  1. Install the plugin from within the Dashboard or upload the directory `widgets-on-pages` and all its contents to the `/wp-content/plugins/` directory
26
  1. Activate the plugin through the 'Plugins' menu in WordPress
27
  1. Add the widgets you want to the `Widgets on Pages` widget area in the admin screens
28
+ 1. Add the shortcut `[widgets_on_pages id=x]` to the page or post in the place where you'd like your widgets to appear (where 'x' = the id of the sidebar to use (or the name if you have named it such as `[widgets_on_pages id=TagCloud]`). If using only the default sidebar then no 'id' argument is needed (i.e. `[widgets_on_pages]`).
29
 
30
 
31
  == Frequently Asked Questions ==
36
 
37
  == Screenshots ==
38
 
39
+ 1. Setting up the sidebars.
40
+
41
+ 2. The 'options' page.
42
+
43
 
44
  == Changelog ==
45
 
46
+ = 0.0.6 =
47
+
48
+ Sidebars can now be named via the options page. These names can be used in place of the numerical id used in older versions. Note that if you change the name you will need to manually update any shortcodes where this is being used.
49
+
50
  = 0.0.5 =
51
 
52
  Fix for activation errors. Looks like it might've been the use of php short open tags or line ending chars.
screenshot-1.png CHANGED
Binary file
screenshot-2.png ADDED
Binary file
widgets_on_pages.php CHANGED
@@ -22,9 +22,9 @@ Plugin Name: Widgets on Pages
22
  Plugin URI: http://gingerbreaddesign.co.uk/wordpress/plugins/widgets-on-pages.php
23
  Description: Allows 'in-page' widget areas so widgets can be defined via shortcut straight into page/post content
24
  Author: Todd Halfpenny
25
- Version: 0.0.5
26
  Author URI: http://gingerbreaddesign.co.uk/todd
27
- */
28
 
29
  /* ===============================
30
  A D M I N M E N U / P A G E
@@ -41,7 +41,7 @@ function wop_menu() {
41
 
42
 
43
  function register_mysettings() { // whitelist options
44
- register_setting( 'wop_options', 'num_of_wop_sidebars' );
45
  }
46
 
47
 
@@ -54,9 +54,12 @@ function wop_plugin_options() {
54
  <div id="icon-tools" class="icon32"></div>
55
  <h2>Widgets on Pages: Options</h2>
56
  <form method="post" action="options.php">
57
- <?php wp_nonce_field('update-options'); ?>
58
- <?php settings_fields( 'wop_options' ); ?>
59
- <?php $cur_num_sidebars = get_option('num_of_wop_sidebars');?>
 
 
 
60
 
61
  <script language="JavaScript">
62
  function validate(evt) {
@@ -78,14 +81,33 @@ function wop_plugin_options() {
78
  <table class="form-table">
79
 
80
  <tr valign="top">
81
- <th scope="row">Number of additional sidebars</th>
82
- <td><input type='text' name="num_of_wop_sidebars" size='3' value="<?php echo get_option('num_of_wop_sidebars');?>" onkeypress='validate(event)' />
83
- </table>
84
- <input type="hidden" name="action" value="update" />
85
- <input type="hidden" name="page_options" value="num_of_wop_sidebars" />
86
- <p class="submit">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
88
- </p>
 
 
89
  </form>
90
  </div>
91
  <?php
@@ -93,6 +115,22 @@ function wop_plugin_options() {
93
 
94
 
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
  /* ===============================
98
  C O R E C O D E
@@ -102,10 +140,15 @@ function wop_plugin_options() {
102
  function widgets_on_page($atts){
103
  reg_wop_sidebar();
104
  extract(shortcode_atts( array('id' => '1'), $atts));
 
 
 
 
 
105
  $str = "<div id='widgets_on_page'>
106
  <ul>";
107
  ob_start();
108
- if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Widgets on Pages $id") ) :
109
  endif;
110
  $myStr = ob_get_contents();
111
  ob_end_clean();
@@ -118,23 +161,49 @@ function widgets_on_page($atts){
118
 
119
 
120
  function reg_wop_sidebar() {
 
 
121
  // register the main sidebar
122
- if ( function_exists('register_sidebar') )
123
- register_sidebar(array(
124
- 'name' => 'Widgets on Pages 1',
125
- 'before_widget' => '<li id="%1$s" class="widget %2$s">',
126
- 'after_widget' => '</li>',
127
- 'before_title' => '<h2 class="widgettitle">',
128
- 'after_title' => '</h2>',
 
 
 
 
 
 
 
 
 
 
 
 
129
  ));
130
 
131
  // register any other additional sidebars
132
- $num_sidebars = (get_option('num_of_wop_sidebars') + 1);
133
  if ($num_sidebars > 1) :
134
  for ( $sidebar = 2; $sidebar <= $num_sidebars; $sidebar++){
135
- if ( function_exists('register_sidebar') )
136
- register_sidebar(array(
137
- 'name' => "Widgets on Pages $sidebar",
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  'before_widget' => '<li id="%1$s" class="widget %2$s">',
139
  'after_widget' => '</li>',
140
  'before_title' => '<h2 class="widgettitle">',
@@ -144,6 +213,9 @@ function reg_wop_sidebar() {
144
  endif;
145
  }
146
 
 
 
 
147
  add_action('admin_init', 'reg_wop_sidebar');
148
  add_shortcode('widgets_on_pages', 'widgets_on_page');
149
 
22
  Plugin URI: http://gingerbreaddesign.co.uk/wordpress/plugins/widgets-on-pages.php
23
  Description: Allows 'in-page' widget areas so widgets can be defined via shortcut straight into page/post content
24
  Author: Todd Halfpenny
25
+ Version: 0.0.6
26
  Author URI: http://gingerbreaddesign.co.uk/todd
27
+ */
28
 
29
  /* ===============================
30
  A D M I N M E N U / P A G E
41
 
42
 
43
  function register_mysettings() { // whitelist options
44
+ register_setting( 'wop_options', 'wop_options_field' );
45
  }
46
 
47
 
54
  <div id="icon-tools" class="icon32"></div>
55
  <h2>Widgets on Pages: Options</h2>
56
  <form method="post" action="options.php">
57
+ <?php
58
+ wp_nonce_field('update-options');
59
+ settings_fields( 'wop_options' );
60
+ $options = get_option('wop_options_field');
61
+ $num_add_sidebars = $options["num_of_wop_sidebars"];
62
+ ?>
63
 
64
  <script language="JavaScript">
65
  function validate(evt) {
81
  <table class="form-table">
82
 
83
  <tr valign="top">
84
+ <th scope="row">Number of additional sidebars</th>
85
+ <td><input type='text' name="wop_options_field[num_of_wop_sidebars]" size='3' value="<?php echo $num_add_sidebars;?>" onkeypress='validate(event)' /></td>
86
+ </tr>
87
+
88
+ <tr><td></td><td>
89
+ <p class="submit">
90
+ <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
91
+ </p>
92
+ </td></tr>
93
+ <tr><td><h3>Optional Sidebar Names</h3></td><td></td></tr>
94
+ <?
95
+ for ($sidebar = 1; $sidebar <= ($num_add_sidebars + 1); $sidebar++) {
96
+ $option_id = 'wop_name_' . $sidebar;
97
+ ?>
98
+ <tr valign="top">
99
+ <th scope="row">WoP sidebar <? echo $sidebar;?> name:</th>
100
+ <td><input type='text' name="wop_options_field[<? echo $option_id;?>]" size='35' value="<?php echo $options[$option_id];?>" /></td>
101
+ </tr>
102
+ <?
103
+ }
104
+ ?>
105
+ <tr><td></td><td>
106
+ <p class="submit">
107
  <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
108
+ </p>
109
+ </td></tr>
110
+ <input type="hidden" name="action" value="update" />
111
  </form>
112
  </div>
113
  <?php
115
 
116
 
117
 
118
+ /* ===============================
119
+ I N S T A L L / U P G R A D E
120
+ ================================*/
121
+
122
+ function wop_install() {
123
+ if (get_option('num_of_wop_sidebars')) {
124
+ // older version sub run upgrade
125
+ $num_of_sidebars = get_option('num_of_wop_sidebars');
126
+ $wop_options = array(num_of_wop_sidebars => $num_of_sidebars);
127
+ update_option('wop_options_field', $wop_options);
128
+ delete_option('num_of_wop_sidebars');
129
+ update_option('wop_version', "0.0.6");
130
+ }
131
+ }
132
+
133
+
134
 
135
  /* ===============================
136
  C O R E C O D E
140
  function widgets_on_page($atts){
141
  reg_wop_sidebar();
142
  extract(shortcode_atts( array('id' => '1'), $atts));
143
+ if (is_numeric($id)) :
144
+ $sidebar_name = 'Widgets on Pages ' . $id;
145
+ else :
146
+ $sidebar_name = $id;
147
+ endif;
148
  $str = "<div id='widgets_on_page'>
149
  <ul>";
150
  ob_start();
151
+ if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar($sidebar_name) ) :
152
  endif;
153
  $myStr = ob_get_contents();
154
  ob_end_clean();
161
 
162
 
163
  function reg_wop_sidebar() {
164
+ $options = get_option('wop_options_field');
165
+ $num_sidebars = $options["num_of_wop_sidebars"] + 1;
166
  // register the main sidebar
167
+ if ( function_exists('register_sidebar') )
168
+ if ($options['wop_name_1'] != "") :
169
+ $name = $options['wop_name_1'];
170
+ $sidebar_id = ' id="' .$name . '"';
171
+ else :
172
+ $name = 'Widgets on Pages 1';
173
+ $sidebar_id = "";
174
+ endif;
175
+ $id = 'wop_1';
176
+ $desc = '#1 Widgets on Pages sidebar.
177
+ Use shortcode
178
+ "[widgets_on_pages' . $sidebar_id .']"';
179
+ register_sidebar(array(
180
+ 'name' => __( $name, 'wop' ),
181
+ 'description' => __( $desc, 'wop' ),
182
+ 'before_widget' => '<li id="%1$s" class="widget %2$s">',
183
+ 'after_widget' => '</li>',
184
+ 'before_title' => '<h2 class="widgettitle">',
185
+ 'after_title' => '</h2>',
186
  ));
187
 
188
  // register any other additional sidebars
 
189
  if ($num_sidebars > 1) :
190
  for ( $sidebar = 2; $sidebar <= $num_sidebars; $sidebar++){
191
+ if ( function_exists('register_sidebar') )
192
+ $option_id = 'wop_name_' . $sidebar;
193
+ if ($options[$option_id] != "") :
194
+ $name = $options[$option_id];
195
+ $sidebar_id = ' id="' . $name . '"';
196
+ else :
197
+ $name = 'Widgets on Pages ' . $sidebar;
198
+ $sidebar_id = ' id=' . $sidebar;
199
+ endif;
200
+ $id = 'wop_' . $sidebar;
201
+ $desc = '#' . $sidebar . 'Widgets on Pages sidebar.
202
+ Use shortcode
203
+ "[widgets_on_pages' . $sidebar_id .']"';
204
+ register_sidebar(array(
205
+ 'name' => __( $name, 'wop' ),
206
+ 'description' => __( $desc, 'wop' ),
207
  'before_widget' => '<li id="%1$s" class="widget %2$s">',
208
  'after_widget' => '</li>',
209
  'before_title' => '<h2 class="widgettitle">',
213
  endif;
214
  }
215
 
216
+
217
+ register_activation_hook(__FILE__,'wop_install');
218
+
219
  add_action('admin_init', 'reg_wop_sidebar');
220
  add_shortcode('widgets_on_pages', 'widgets_on_page');
221