amr shortcode any widget - Version 2.3

Version Description

Download this release

Release Info

Developer anmari
Plugin Icon wp plugin amr shortcode any widget
Version 2.3
Comparing to
See all releases

Code changes from version 2.2 to 2.3

Files changed (2) hide show
  1. amr-shortcode-any-widget.php +26 -9
  2. readme.txt +118 -37
amr-shortcode-any-widget.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: amr shortcode any widget
4
  Plugin URI: http://webdesign.anmari.com/shortcode-any-widget/
5
  Description: Include any widget in a page for any theme. [do_widget widgetname ] or [do_widget "widget name" ] or include a whole widget area [do_widget_area]. If upgrading see changelog. Can be very powerful eg: with queryposts widget it can become a templater.
6
  Author: anmari
7
- Version: 2.2
8
  Author URI: http://webdesign.anmari.com
9
 
10
  */
@@ -30,26 +30,40 @@ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
30
 
31
  extract(shortcode_atts(array(
32
  'widget_area' => 'widgets_for_shortcodes',
33
- 'class' => 'amr_widget_area', /* the widget class is picked up automatically. If we want to add an additional class at the wrap level to try to match a theme, use this */
34
  'widget_area_class' => '', /* option to disassociate from themes widget styling use =none*/
35
  'widget_classes' => '' /* option to disassociate from themes widget styling */
36
 
37
  ), $atts));
38
 
39
- $class = 'class="amr-widget-area ';
40
- if (empty($widget_area_class) or !($widget_area_class=='none'))
41
- $class .= ' widget-area"';
42
- $output = PHP_EOL.'<div id="'.$widget_area.'" '.$class. '>';
 
 
43
 
 
 
 
 
 
 
 
 
 
 
44
  if (!empty($widget_classes) and ($widget_classes=='none'))
45
  add_filter('dynamic_sidebar_params','amr_remove_widget_class');
46
 
47
  ob_start(); /* catch the echo output, so we can control where it appears in the text */
48
  dynamic_sidebar($widget_area);
49
- $output .= ob_get_clean();
50
  remove_filter('dynamic_sidebar_params','amr_remove_widget_class');
51
-
52
- $output .= '</div>'.PHP_EOL;
 
 
53
 
54
  return ($output);
55
  }
@@ -108,6 +122,9 @@ if it is in, then get the instance data and use that */
108
  }
109
  }
110
 
 
 
 
111
  if (empty ($widget_ids)) {
112
  echo '<br /><a href="" title="Error: Your Requested widget '.$widget.' '.$id.' is not in the widget list. Typo maybe?">!</a><br />';
113
  amr_show_widget_debug('empty', $atts);
4
  Plugin URI: http://webdesign.anmari.com/shortcode-any-widget/
5
  Description: Include any widget in a page for any theme. [do_widget widgetname ] or [do_widget "widget name" ] or include a whole widget area [do_widget_area]. If upgrading see changelog. Can be very powerful eg: with queryposts widget it can become a templater.
6
  Author: anmari
7
+ Version: 2.3
8
  Author URI: http://webdesign.anmari.com
9
 
10
  */
30
 
31
  extract(shortcode_atts(array(
32
  'widget_area' => 'widgets_for_shortcodes',
33
+ 'class' => 'amr-widget-area', /* the widget class is picked up automatically. If we want to add an additional class at the wrap level to try to match a theme, use this */
34
  'widget_area_class' => '', /* option to disassociate from themes widget styling use =none*/
35
  'widget_classes' => '' /* option to disassociate from themes widget styling */
36
 
37
  ), $atts));
38
 
39
+
40
+ if (empty ($wp_registered_sidebars[$widget_area])) {
41
+ echo '<br/>Widget area "'.$widget_area.'" not found. Registered widget areas (sidebars) are: <br/>';
42
+ foreach ($wp_registered_sidebars as $area=> $sidebar) echo $area.'<br />';
43
+ }
44
+ if (isset($_REQUEST['do_widget_debug']) and current_user_can('administrator')) var_dump( $wp_registered_sidebars); /**/
45
 
46
+ if ($widget_area_class=='none')
47
+ $class = '';
48
+ else {
49
+
50
+ if (!empty($widget_area_class)) //2014 08
51
+ $class .= 'class="'.$class.' '.$widget_area_class.'"';
52
+ else
53
+ $class = 'class="'.$class.'"';
54
+ }
55
+
56
  if (!empty($widget_classes) and ($widget_classes=='none'))
57
  add_filter('dynamic_sidebar_params','amr_remove_widget_class');
58
 
59
  ob_start(); /* catch the echo output, so we can control where it appears in the text */
60
  dynamic_sidebar($widget_area);
61
+ $output = ob_get_clean();
62
  remove_filter('dynamic_sidebar_params','amr_remove_widget_class');
63
+
64
+ $output = PHP_EOL.'<div id="'.$widget_area.'" '.$class. '>'
65
+ .$output
66
+ .'</div>'.PHP_EOL;
67
 
68
  return ($output);
69
  }
122
  }
123
  }
124
 
125
+ if (empty($widget)) $widget = '';
126
+ if (empty($id)) $id = '';
127
+
128
  if (empty ($widget_ids)) {
129
  echo '<br /><a href="" title="Error: Your Requested widget '.$widget.' '.$id.' is not in the widget list. Typo maybe?">!</a><br />';
130
  amr_show_widget_debug('empty', $atts);
readme.txt CHANGED
@@ -1,16 +1,16 @@
1
  === amr shortcode any widget ===
2
  Contributors: anmari
3
  Tags: shortcode, widget, page, templates, page template, widget_area, sidebar
4
- Tested up to: 3.8.1
5
- Version: 2.2
6
  Stable tag: trunk
7
 
8
  == Description ==
9
- Insert separate widgets or a entire widget area (sidebar) into a page using a shortcode.
10
 
11
- The Widgets settings are specified in a specially created "widgets for shortcode" sidebar, just like you normally setuop a widget.
12
 
13
- The Plugin will call that widget instance from the do_widget shortcode, or the chosen sidebar from the do_widget_area shortcode.
14
 
15
  For example: You could use the query posts widget in the page to create a archive within a page, or the rss widget to list feed content from other sites. For more details see [anmari.com](http://webdesign.anmari.com/category/plugins/shortcode-any-widget/)
16
 
@@ -31,20 +31,20 @@ Change your theme? No problem, the plugin will save and restore the widgets_for_
31
 
32
  [do_widget widgetname] eg: [do_widget calendar]
33
  [do_widget "widget name"]. eg: [do_widget "tag cloud"]
34
- [do_widget id=widgetid]
35
 
36
  [do_widget_area] (will use the "widgets in shortcodes" widget area / sidebar
37
  [do_widget_area sidebarname] for another sidebar or widget area - eg: to maximise likelihood of getting your theme's widget css to apply.
38
 
39
-
40
 
41
  7. If the plugin cannot work out what you want and you are logged in as an administrator, it will show a debug prompt to you, the logged in admin only.
42
- Click on the link 'Try debug'. It will produce a bunch of info. Look for the id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug info). Try using the widget id. Sometimes the widget name that wordpress calls it internally is not the same as what you see on the screen and you will need the 'debug' to find the id.
43
 
44
  **[do_widget ...] Parameters:**
45
 
46
  * *nameofwidget* or name="*nameofwidget*" This is NOT the title of the widget. THis is the name that you see in the widgets menu page even when unassigned to a sidebar. For existing users , you can also use just the name of the widget without name=. It must bethe first parameter then.
47
- * id=*wordpress assigned id of widget*
48
  * title=false to hide the widgets title OR to override your themes first sidebar html settings for widget titles, use title=*htmltag* where *htmltag* is one of h1,h2,h3,h4,h5,header,strong,em. If not entered plugin will use the same title html that your themes first sidebar uses - yes even if you change themes, it will switch to the new themes html.
49
  * wrap=*htmltag* where *htmltag* is one of div,p,main,aside,section. This will override your themes first sidebar html settings for widget wrapping html.
50
  * widget_classes=none This will remove the class "widget" from the wrapping html and the class "widget_title" from the title html. This may be enough to remove any unwanted css styling from your theme.
@@ -56,7 +56,7 @@ Click on the link 'Try debug'. It will produce a bunch of info. Look for the id
56
  * widget_area=*yourwidgetarea* defaults to 'widgets_for_shortcodes' if nothing entered
57
  * widget_area_class=none /* option to remove theme styling by removing the widget_area class from the sidebar html */
58
  * widget_classes=none /* option to remove the widget class from the widget wrappinghtml
59
- * class=*yourclassname* default is amr_widget_area'
60
 
61
 
62
  See the settings page for links to help your create the shortcodes in a page.
@@ -72,9 +72,114 @@ If you liked this plugin, you might also like my other plugins:
72
  [icalevents.com](http://icalevents.com) - a ics compliant events plugin fully integrated with wordpress, so it will work with many other plugins (seo, maps, social)
73
  [wpusersplugin.com](http://wpusersplugin.com) - a suite of plugins to help with membership sites. Major plugin is [amr users](http://wordpress.org/extend/plugins/amr-users/)
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
 
77
  == Changelog ==
 
 
 
 
 
 
78
  = Version 2.2 =
79
  * Attempt to add more styling control.
80
  * Add widget_classes=none to reverse out widget type class. NOte to totally override wordpress widget
@@ -131,39 +236,15 @@ If you liked this plugin, you might also like my other plugins:
131
  1. Goto Appearance > widgets and find "shortcode" sidebar
132
  1. Drag chosen widgets to shortcodes sidebar. Save. (note the names)
133
  2. Add [do_widget widgetname] in a page or post or [do_widget_area]
134
- 3. If it fails, click on the debug prompt and look for the id of your widget, use that.
 
135
 
136
  Or can use [do_widget widgetname] within the text in the page and save. If the widget name has a space in it, use [do_widget "widget name"].
137
 
138
  If you use a widget more than once for different shortcodes, you can use the widget id to isolate which widget instance (and of course associated settings to use). ie: [do_widget id=categories-6]
 
139
 
140
- do_widget parameters:
141
-
142
- * title=false to hide a title
143
- * title= one of h1,h2,h3,h4,h5,strong,em
144
- * class=yourclassname (else it will add amr_widget)
145
- * wrap=one of div, section, p, aside
146
- * widget_classes=none (will take the widget class out and the widget-title class out)
147
-
148
- do_widget_area parameters:
149
-
150
- * widget_classes=none (will take the 'widget' class out and the widget-title class out)
151
- * widget_area_class=none (will take out the 'widget_area' class )
152
-
153
- **Styling**
154
-
155
- Check your styling. The effects are very dependent on how your theme has specified the css that may apply to widgets and sidebars/widget areas. It may work beautifully and have the content looking like it belongs with your theme.
156
- You may have undesired effects applying that do not work in the main content area.
157
- You may have desired effects not applying because the css is specific to a themes sidebar.
158
 
159
- Via the plugin you can do the following to affect styling:
160
- * Remove the general wordpress 'widget' class from the widgets wrapping html and the 'widget_title' from the title html. ([do_widget *widgetname* widget_classes=none]
161
- * Hardcode away from your themes html for widgets and widget title. EG: if your theme uses aside and h2, you could specify: [do_widget *widgetname* widget_classes=none wrap=div title=h3]. By default the plugin will use whatever your first sidebar uses. This will change if you change themes, but only if you have NOT overridden the html with wrap and title.
162
- * Apply an existing class in your theme. Use [do_widget *widgetname* class=*yourclass*].
163
- * Use the addition class 'amr-widget' provided to specify alternate css in your themes stylesheet or with something like wordpress custom css.
164
-
165
-
166
-
167
 
168
  == Screenshots ==
169
 
1
  === amr shortcode any widget ===
2
  Contributors: anmari
3
  Tags: shortcode, widget, page, templates, page template, widget_area, sidebar
4
+ Tested up to: 4.0
5
+ Version: 2.3
6
  Stable tag: trunk
7
 
8
  == Description ==
9
+ Insert a widget or multiple widgets or a entire widget area (sidebar) into a page using a shortcode.
10
 
11
+ The Widget settings are specified in a specially created sidebar called "widgets for shortcode". This means you have the full widget settings avaiabled just like you normally setup a widget.. Setup the widget first in a normal sidebar, then drag it into the widgets sidebar. These settings will be saved even if you change your theme. The widgets for shortcode sidebar will remember it self and recreate itself if you change themes.
12
 
13
+ You can reference a specific widget instance from the do_widget shortcode, or the chosen sidebar from the do_widget_area shortcode.
14
 
15
  For example: You could use the query posts widget in the page to create a archive within a page, or the rss widget to list feed content from other sites. For more details see [anmari.com](http://webdesign.anmari.com/category/plugins/shortcode-any-widget/)
16
 
31
 
32
  [do_widget widgetname] eg: [do_widget calendar]
33
  [do_widget "widget name"]. eg: [do_widget "tag cloud"]
34
+ [do_widget id=widgetid] . eg: [do_widget id=tag-cloud-3]
35
 
36
  [do_widget_area] (will use the "widgets in shortcodes" widget area / sidebar
37
  [do_widget_area sidebarname] for another sidebar or widget area - eg: to maximise likelihood of getting your theme's widget css to apply.
38
 
39
+ WARNING: using do_widget_area with a widget area other than the shortcode one means that if you changes themes and the new theme has different sidebars, then this shortcode with a named widgete area will not work. Go that ?
40
 
41
  7. If the plugin cannot work out what you want and you are logged in as an administrator, it will show a debug prompt to you, the logged in admin only.
42
+ Click on the link 'Try debug'. It will produce a bunch of info. Look for the id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug info). Try using the widget id - ie [do_widget id=somename-n]. Examples are tag-cloud-3, meta-2 etc. Sometimes the widget name that wordpress calls it internally is not the same as what you see on the screen and you will need the 'debug' to find the id.
43
 
44
  **[do_widget ...] Parameters:**
45
 
46
  * *nameofwidget* or name="*nameofwidget*" This is NOT the title of the widget. THis is the name that you see in the widgets menu page even when unassigned to a sidebar. For existing users , you can also use just the name of the widget without name=. It must bethe first parameter then.
47
+ * id=*wordpress assigned id of widget*. Examples: meta-3, tag-cloud-9 etc
48
  * title=false to hide the widgets title OR to override your themes first sidebar html settings for widget titles, use title=*htmltag* where *htmltag* is one of h1,h2,h3,h4,h5,header,strong,em. If not entered plugin will use the same title html that your themes first sidebar uses - yes even if you change themes, it will switch to the new themes html.
49
  * wrap=*htmltag* where *htmltag* is one of div,p,main,aside,section. This will override your themes first sidebar html settings for widget wrapping html.
50
  * widget_classes=none This will remove the class "widget" from the wrapping html and the class "widget_title" from the title html. This may be enough to remove any unwanted css styling from your theme.
56
  * widget_area=*yourwidgetarea* defaults to 'widgets_for_shortcodes' if nothing entered
57
  * widget_area_class=none /* option to remove theme styling by removing the widget_area class from the sidebar html */
58
  * widget_classes=none /* option to remove the widget class from the widget wrappinghtml
59
+ * class=*yourclassname* default is amr_widget_area. This will affect the widget area NOT the individual widgets. At the moment can only remove the widget classes, not replace them when using do_widget_area.
60
 
61
 
62
  See the settings page for links to help your create the shortcodes in a page.
72
  [icalevents.com](http://icalevents.com) - a ics compliant events plugin fully integrated with wordpress, so it will work with many other plugins (seo, maps, social)
73
  [wpusersplugin.com](http://wpusersplugin.com) - a suite of plugins to help with membership sites. Major plugin is [amr users](http://wordpress.org/extend/plugins/amr-users/)
74
 
75
+ == Frequently Asked Questions ==
76
+
77
+ **Widget help, the widget is doing this, when it should do that**
78
+
79
+ Please see
80
+ http://wordpress.org/support/topic/widget-help-settings-functioning-etc?replies=1
81
+
82
+
83
+ **How to identify widget**
84
+
85
+ To identify your widget in the shortcode, use a safe constant identfier like the NAME or the ID.
86
+
87
+ The name is the generic NAME like "tag cloud". It is NOT your unique title eg: "Amazing Cloud Of Keywords" which you might change one day while procrastinating about doing real work, idly decide looks a bit twee and change to "Cloud of tags". That would break the do_widget shortcode and it would not find your widget (if that was the way it worked).
88
+
89
+ For this reason the plugin deliberately does not allow identification by 'title'. It is not necessary - for simple usage the name is perfectly adequate, for more complicated multi-instance usage, the ID is safer all around.
90
+
91
+ Also the parameter 'title=' is being used to allow you to change the html tag used around the title (or hide the title), so it would be a tad confusing anyway to offer it and not necessary.
92
+
93
+ Need more instruction: As per step 7 on the front page: To find the id of your chosen widget you can either
94
+
95
+ 1)
96
+ enter some garbage in the shortcode [do_widget wtf] and the plugin will offer you a try debug (if you are admin and logged in that is)
97
+ Click on the "try debug"
98
+
99
+ 2) else add ?do_widget_debug=1 to the url of the page where the [do_widget] shortcode is
100
+
101
+ either way you should see a list of stuff. It will say something like the widgets in "widgets for shortcode" are:
102
+ xxx-n
103
+ xxxxxx-n
104
+ xxx-xxxxx-n
105
+
106
+ and it will list the ids of your widget - the n's are numbers that distinguish multiple instanaces of the same widget. xxx's are the abbreviated names of the widgets.
107
+
108
+ as per screenshot 5
109
+ http://s.w.org/plugins/amr-shortcode-any-widget/screenshot-5.png?r=884849
110
+
111
+ Those are the ids you should use. They look like this:
112
+
113
+ meta-3
114
+ tag-cloud-2
115
+
116
+
117
+ More info here: http://wordpress.org/support/topic/ids-and-multiple-instances-of-widget?replies=2
118
+
119
+
120
+ **Styling, your theme, css, overriding**
121
+
122
+ Check your styling. The effects are very dependent on how your theme has specified the css that may apply to widgets and sidebars/widget areas. It may work beautifully and have the content looking like it belongs with your theme.
123
+ You may have undesired effects applying that do not work in the main content area.
124
+ You may have desired effects not applying because the css is specific to a themes sidebar.
125
+
126
+ Via the plugin you can do the following to affect styling:
127
+ * Remove the general wordpress 'widget' class from the widgets wrapping html and the 'widget_title' from the title html. ([do_widget *widgetname* widget_classes=none]
128
+ * Hardcode away from your themes html for widgets and widget title. EG: if your theme uses aside and h2, you could specify: [do_widget *widgetname* widget_classes=none wrap=div title=h3]. By default the plugin will use whatever your first sidebar uses. This will change if you change themes, but only if you have NOT overridden the html with wrap and title.
129
+ * Apply an existing class in your theme. Use [do_widget *widgetname* class=*yourclass*].
130
+ * Use the addition class 'amr-widget' provided to specify alternate css in your themes stylesheet or with something like wordpress custom css.
131
+
132
+ One of the new features is as a default setting is that the plugin will try have your current themes first sidebar styling apply to the widgets inserted into a page via the shortcode.
133
+
134
+ Many folks requested this, insisting that absolutely this is what should be happening and why didn't it? Well..This could be great - Imagine: a plugin that can pick up the theme styling and change it as your theme changes.
135
+
136
+ The success of this depends very much on how your theme specifies it's css. Does it always use classes ? - more css will apply. Does it lock the css down by sidebar-id: that css will not apply.
137
+
138
+ It also depends on what the original widget plugin does with css and js. It may have done something thinking that the widget will always be inside a sidebar and not anticipated being in a page. This the shortcde-any-widget plugin has no control over.
139
+
140
+ For example: An unwanted effect could be white text on a white background as in the twenty fourteen theme.
141
+
142
+ If you have an undesired effect with the default setings:
143
+
144
+ You need to learn the joys of the 'inspect element' tools in various browsers or browser web developer, firebug add-ons, so you can see what css is applying to what html. Then you can either change some of the html or override or change the css.
145
+
146
+ Options if you don't like the default result:
147
+
148
+ Use the 'amr-widget' class that has been added to the widget wrapping html to override any css.
149
+
150
+ eg:
151
+ .amr-widget [
152
+ color: #000000;
153
+ }
154
+
155
+ Tap into a class you already have in your theme:
156
+
157
+ [do_widget class=yourclass]
158
+
159
+ Change the html that the shortcode-any-widget plugin will use.
160
+
161
+ eg: don't like the h3.widget-title styling ? change the title html to h2 in the shotcode parameters
162
+
163
+ [do_widget title=h2]
164
+
165
+ eg: don't like the 'aside' wrapping html styling? change the wrapping html:
166
+
167
+ [do_widget wrap=div]
168
+
169
+ If you only using widget, maybe inserting the whole sidebar or widgertarea would give an interesting effect. Sidebar background css may apply.
170
+
171
+ [do_widget_area]
172
+ More info on background: http://wordpress.org/support/topic/your-theme-your-sidebars-and-the-plugin-overriding?replies=10
173
+
174
 
175
 
176
  == Changelog ==
177
+ = Version 2.3 =
178
+ * Fixed some widget area class options that were not working.
179
+ * Added a widget area debug option to make it easier to find how your theme has stored it's widget area / sidebar ids. They are not always easy to find.
180
+ * Tested on 3.9.1
181
+ * Updated readme
182
+
183
  = Version 2.2 =
184
  * Attempt to add more styling control.
185
  * Add widget_classes=none to reverse out widget type class. NOte to totally override wordpress widget
236
  1. Goto Appearance > widgets and find "shortcode" sidebar
237
  1. Drag chosen widgets to shortcodes sidebar. Save. (note the names)
238
  2. Add [do_widget widgetname] in a page or post or [do_widget_area]
239
+ 3. If it fails, it will offer a debug prompt to logged-in admin, click on the debug prompt and look for the id of your widget, use that.
240
+ 4. To force a debug anyway without waiting for an error, then be logged in as admin and on the page where you have a [do_widget something] shortcode, add ?do_widget_debug=1 to the url , hit enter and look for the list of widget ids that are in the widgets_for_shortcode sidebar.
241
 
242
  Or can use [do_widget widgetname] within the text in the page and save. If the widget name has a space in it, use [do_widget "widget name"].
243
 
244
  If you use a widget more than once for different shortcodes, you can use the widget id to isolate which widget instance (and of course associated settings to use). ie: [do_widget id=categories-6]
245
+ For detailed instructions on shortcodes and their parameters, see the [home page](http://wordpress.org/plugins/amr-shortcode-any-widget/)
246
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
 
 
 
 
 
 
 
 
 
248
 
249
  == Screenshots ==
250