amr shortcode any widget - Version 2.5

Version Description

Download this release

Release Info

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

Code changes from version 2.4 to 2.5

Files changed (155) hide show
  1. assets/banner-772x250.jpg +0 -0
  2. screenshot-1.png → assets/screenshot-1.png +0 -0
  3. screenshot-2.jpg → assets/screenshot-2.jpg +0 -0
  4. screenshot-3.jpg → assets/screenshot-3.jpg +0 -0
  5. screenshot-4.png → assets/screenshot-4.png +0 -0
  6. assets/screenshot-5.jpg +0 -0
  7. assets/screenshot-6.jpg +0 -0
  8. assets/screenshot-7.jpg +0 -0
  9. assets/screenshot-8.jpg +0 -0
  10. tags/1.0/amr_shortcode_any_widget.php +175 -0
  11. tags/1.0/readme.txt +37 -0
  12. screenshot-6.png → tags/1.0/screenshot-1.png +0 -0
  13. tags/1.0/screenshot-2.png +0 -0
  14. tags/1.0/screenshot-3.png +0 -0
  15. tags/1.3/amr_shortcode_any_widget.php +280 -0
  16. tags/1.3/readme.txt +45 -0
  17. tags/1.3/screenshot-1.png +0 -0
  18. tags/1.3/screenshot-2.png +0 -0
  19. tags/1.3/screenshot-3.png +0 -0
  20. tags/1.4/amr_shortcode_any_widget.php +282 -0
  21. tags/1.4/readme.txt +72 -0
  22. tags/1.4/screenshot-1.jpg +0 -0
  23. tags/1.4/screenshot-2.jpg +0 -0
  24. tags/1.4/screenshot-3.jpg +0 -0
  25. screenshot-7.jpg → tags/1.4/screenshot-4.jpg +0 -0
  26. tags/1.4/screenshot-5.png +0 -0
  27. tags/1.4/screenshot-6.png +0 -0
  28. tags/1.4/screenshot-7.png +0 -0
  29. tags/1.4/screenshot-8.jpg +0 -0
  30. tags/1.4/screenshot-9.jpg +0 -0
  31. tags/1.5/amr_shortcode_any_widget.php +282 -0
  32. tags/1.5/readme.txt +79 -0
  33. tags/1.5/screenshot-1.jpg +0 -0
  34. tags/1.5/screenshot-2.jpg +0 -0
  35. tags/1.5/screenshot-3.jpg +0 -0
  36. tags/1.5/screenshot-4.jpg +0 -0
  37. tags/1.5/screenshot-5.png +0 -0
  38. tags/1.5/screenshot-6.png +0 -0
  39. tags/1.5/screenshot-7.png +0 -0
  40. tags/1.5/screenshot-8.jpg +0 -0
  41. tags/1.5/screenshot-9.jpg +0 -0
  42. tags/1.6/amr-admin-form-html.php +214 -0
  43. tags/1.6/amr_shortcode_any_widget.php +300 -0
  44. tags/1.6/readme.txt +83 -0
  45. tags/1.6/screenshot-1.jpg +0 -0
  46. tags/1.6/screenshot-2.jpg +0 -0
  47. tags/1.6/screenshot-3.jpg +0 -0
  48. tags/1.6/screenshot-4.jpg +0 -0
  49. tags/1.6/screenshot-5.png +0 -0
  50. tags/1.6/screenshot-6.png +0 -0
  51. tags/1.6/screenshot-7.png +0 -0
  52. tags/1.6/screenshot-8.jpg +0 -0
  53. tags/1.6/screenshot-9.jpg +0 -0
  54. tags/1.7/amr-admin-form-html.php +214 -0
  55. tags/1.7/amr-shortcode-any-widget.php +316 -0
  56. tags/1.7/amr_shortcode_any_widget.php +300 -0
  57. tags/1.7/readme.txt +88 -0
  58. tags/1.7/screenshot-1.jpg +0 -0
  59. tags/1.7/screenshot-2.jpg +0 -0
  60. tags/1.7/screenshot-3.jpg +0 -0
  61. tags/1.7/screenshot-4.jpg +0 -0
  62. tags/1.7/screenshot-5.png +0 -0
  63. tags/1.7/screenshot-6.png +0 -0
  64. tags/1.7/screenshot-7.png +0 -0
  65. tags/1.7/screenshot-8.jpg +0 -0
  66. tags/1.7/screenshot-9.jpg +0 -0
  67. tags/1.8/amr-admin-form-html.php +214 -0
  68. tags/1.8/amr-shortcode-any-widget.php +316 -0
  69. tags/1.8/readme.txt +90 -0
  70. tags/1.8/screenshot-1.jpg +0 -0
  71. tags/1.8/screenshot-2.jpg +0 -0
  72. tags/1.8/screenshot-3.jpg +0 -0
  73. tags/1.8/screenshot-4.jpg +0 -0
  74. tags/1.8/screenshot-5.png +0 -0
  75. tags/1.8/screenshot-6.png +0 -0
  76. tags/1.8/screenshot-7.png +0 -0
  77. tags/1.8/screenshot-8.jpg +0 -0
  78. tags/1.8/screenshot-9.jpg +0 -0
  79. tags/2.0/amr-admin-form-html.php +175 -0
  80. tags/2.0/amr-shortcode-any-widget.php +283 -0
  81. amr-utilities.php → tags/2.0/amr-utilities.php +0 -0
  82. tags/2.0/readme.txt +119 -0
  83. tags/2.0/screenshot-1.jpg +0 -0
  84. tags/2.0/screenshot-2.jpg +0 -0
  85. tags/2.0/screenshot-3.jpg +0 -0
  86. tags/2.0/screenshot-4.jpg +0 -0
  87. tags/2.0/screenshot-5.png +0 -0
  88. tags/2.0/screenshot-6.png +0 -0
  89. tags/2.0/screenshot-7.png +0 -0
  90. tags/2.0/screenshot-8.jpg +0 -0
  91. tags/2.0/screenshot-9.jpg +0 -0
  92. tags/2.1/amr-admin-form-html.php +175 -0
  93. tags/2.1/amr-shortcode-any-widget.php +282 -0
  94. tags/2.1/amr-utilities.php +141 -0
  95. tags/2.1/readme.txt +125 -0
  96. tags/2.1/screenshot-1.jpg +0 -0
  97. tags/2.1/screenshot-2.jpg +0 -0
  98. tags/2.1/screenshot-3.jpg +0 -0
  99. tags/2.1/screenshot-4.jpg +0 -0
  100. tags/2.1/screenshot-5.png +0 -0
  101. tags/2.1/screenshot-6.png +0 -0
  102. tags/2.1/screenshot-7.png +0 -0
  103. tags/2.1/screenshot-8.jpg +0 -0
  104. tags/2.1/screenshot-9.jpg +0 -0
  105. tags/2.2/amr-admin-form-html.php +189 -0
  106. tags/2.2/amr-shortcode-any-widget.php +326 -0
  107. tags/2.2/amr-utilities.php +141 -0
  108. index.php → tags/2.2/index.php +0 -0
  109. tags/2.2/readme.txt +180 -0
  110. tags/2.2/screenshot-1.png +0 -0
  111. tags/2.2/screenshot-2.jpg +0 -0
  112. tags/2.2/screenshot-3.jpg +0 -0
  113. tags/2.2/screenshot-4.png +0 -0
  114. screenshot-5.png → tags/2.2/screenshot-5.png +0 -0
  115. tags/2.2/screenshot-6.png +0 -0
  116. tags/2.2/screenshot-7.jpg +0 -0
  117. tags/2.3/amr-admin-form-html.php +189 -0
  118. tags/2.3/amr-shortcode-any-widget.php +343 -0
  119. tags/2.3/amr-utilities.php +141 -0
  120. tags/2.3/index.php +3 -0
  121. tags/2.3/readme.txt +261 -0
  122. tags/2.3/screenshot-1.png +0 -0
  123. tags/2.3/screenshot-2.jpg +0 -0
  124. tags/2.3/screenshot-3.jpg +0 -0
  125. tags/2.3/screenshot-4.png +0 -0
  126. tags/2.3/screenshot-5.png +0 -0
  127. tags/2.3/screenshot-6.png +0 -0
  128. tags/2.3/screenshot-7.jpg +0 -0
  129. amr-admin-form-html.php → tags/2.4/amr-admin-form-html.php +0 -0
  130. amr-shortcode-any-widget.php → tags/2.4/amr-shortcode-any-widget.php +0 -0
  131. tags/2.4/amr-utilities.php +141 -0
  132. tags/2.4/index.php +3 -0
  133. {languages → tags/2.4/languages}/amr-shortcode-any-widget-en_AU.mo +0 -0
  134. {languages → tags/2.4/languages}/amr-shortcode-any-widget-en_AU.po +0 -0
  135. {languages → tags/2.4/languages}/amr-shortcode-any-widget-sr_RS.mo +0 -0
  136. {languages → tags/2.4/languages}/amr-shortcode-any-widget-sr_RS.po +0 -0
  137. {languages → tags/2.4/languages}/amr-shortcode-any-widget.pot +0 -0
  138. readme.txt → tags/2.4/readme.txt +0 -0
  139. tags/2.4/screenshot-1.png +0 -0
  140. tags/2.4/screenshot-2.jpg +0 -0
  141. tags/2.4/screenshot-3.jpg +0 -0
  142. tags/2.4/screenshot-4.png +0 -0
  143. tags/2.4/screenshot-5.png +0 -0
  144. tags/2.4/screenshot-6.png +0 -0
  145. tags/2.4/screenshot-7.jpg +0 -0
  146. trunk/amr-admin-form-html.php +200 -0
  147. trunk/amr-shortcode-any-widget.php +359 -0
  148. trunk/amr-utilities.php +141 -0
  149. trunk/index.php +3 -0
  150. trunk/languages/amr-shortcode-any-widget-en_AU.mo +0 -0
  151. trunk/languages/amr-shortcode-any-widget-en_AU.po +118 -0
  152. trunk/languages/amr-shortcode-any-widget-sr_RS.mo +0 -0
  153. trunk/languages/amr-shortcode-any-widget-sr_RS.po +113 -0
  154. trunk/languages/amr-shortcode-any-widget.pot +118 -0
  155. trunk/readme.txt +273 -0
assets/banner-772x250.jpg ADDED
Binary file
screenshot-1.png → assets/screenshot-1.png RENAMED
File without changes
screenshot-2.jpg → assets/screenshot-2.jpg RENAMED
File without changes
screenshot-3.jpg → assets/screenshot-3.jpg RENAMED
File without changes
screenshot-4.png → assets/screenshot-4.png RENAMED
File without changes
assets/screenshot-5.jpg ADDED
Binary file
assets/screenshot-6.jpg ADDED
Binary file
assets/screenshot-7.jpg ADDED
Binary file
assets/screenshot-8.jpg ADDED
Binary file
tags/1.0/amr_shortcode_any_widget.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: amr shortcode any widget
4
+ Plugin URI: http://webdesign.anmari.com/shortcode-any-widget/
5
+ Description: Allows inclusion of any widget within a page for any theme. [do_widget widgetname ] or [do_widget "widget name" ]
6
+ Author: Anna-marie Redpath
7
+ Version: 1.0 alpha
8
+ Author URI: http://webdesign.anmari.com
9
+
10
+ */
11
+
12
+
13
+ /*-----------------------------------*/
14
+ function do_widget($atts) {
15
+
16
+ global $wp_registered_widgets,$_wp_sidebars_widgets;
17
+
18
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
19
+ if it is in, then get the instance data and use that */
20
+ if (isset($_REQUEST['debug'])) $debug=true;
21
+
22
+ extract(shortcode_atts(array(
23
+ 'sidebar' => 'Shortcode',
24
+ 'id' => '',
25
+ 'title' => 'true' /* do the default title unless they ask us not to - use string here not boolean */
26
+ ), $atts));
27
+
28
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
29
+ if (!empty($atts[0])) {
30
+ $widget = $atts[0];
31
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
32
+ if ($w['name'] === $widget) $widget_ids[] = $i;
33
+ }
34
+ }
35
+ else { /* check for id */
36
+ if (!empty($id)) { /* if a specific id has been specified */
37
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
38
+ if ($debug) { echo '<br> id = '.$id.' - '.$w['id'] ;}
39
+ if ($w['id'] === $id) $widget_ids[] = $i;
40
+ }
41
+ }
42
+ else {
43
+ if ($debug) { echo 'No valid widget name or id given';}
44
+ return (false);
45
+
46
+ }
47
+ }
48
+ if (empty ($widget_ids)) {
49
+ if ($debug) { echo '<h2>Widget not found in widget list </h2>'; print_r($wp_registered_widgets);}
50
+ return ;
51
+ }
52
+ if ($title=='false') $title = false;
53
+ else $title = true;
54
+
55
+ $sidebarid = get_sidebar_id ($sidebar); /* get the official sidebar id - will take the first one */
56
+
57
+ if ($debug) { echo '<hr><h2>Looking for widget:'.$widget.' </h2>'; echo 'found instances:'; print_r ($widget_ids); }
58
+ $content = '';
59
+ /* if the widget is in our chosen sidebar, then use the otions stored for that */
60
+ if (isset($_wp_sidebars_widgets) ) {
61
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
62
+ if ($debug) {
63
+ echo '<h2>Widget ids in sidebar in sidebar '.$sidebar.' with id:'.$sidebarid .'</h2>';
64
+ print_r($_wp_sidebars_widgets[$sidebarid]);
65
+ }
66
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
67
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
68
+ if ($debug) { echo '<br />Chosen Widget ids in Chosen sidebar';print_r($wid);}
69
+ }
70
+ else { /* the sidebar is not defined */
71
+ if ($debug) {echo '<br />Sidebar '.$sidebar.' empty or not defined.'; }
72
+ }
73
+ }
74
+ else { if ($debug) {echo '<br />No widgets defined'; }
75
+ return (false);
76
+ }
77
+ if (empty ($wid)) {
78
+ unset($sidebar); unset($sidebarid);
79
+ if ($debug) { echo '<h2>No Widget ids in sidebar '.$sidebarid.' with name '.$sidebar.' Try defaults </h2>';}
80
+ }
81
+ else
82
+ /* There may only be one but if we have two in our chosen widget then it will do both */
83
+ foreach ($wid as $i=>$widget_instance) {
84
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
85
+ shortcode_sidebar($widget_instance, $sidebar, $title);
86
+ $output .= ob_get_clean();
87
+ }
88
+ return ($output);
89
+ }
90
+
91
+ /*-----------------------------------*/
92
+ function get_sidebar_id ($name) { /* dont need anymore ? or at least temporarily */
93
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
94
+ global $wp_registered_sidebars;
95
+ foreach ($wp_registered_sidebars as $i => $a) {
96
+ if ((isset ($a['name'])) and ( $a['name'] === $name)) return ($i);
97
+ }
98
+ return (false);
99
+ }
100
+ /* -------------------------------------------------------------------------*/
101
+ function shortcode_sidebar( $id, $index=1, $title=true) { /* This is basically the wordpress code, slightly modified */
102
+ global $wp_registered_sidebars, $wp_registered_widgets;
103
+
104
+ if ( is_int($index) ) {
105
+ $index = "sidebar-$index";
106
+ } else {
107
+ $index = sanitize_title($index);
108
+ foreach ( (array) $wp_registered_sidebars as $key => $value ) {
109
+ if ( sanitize_title($value['name']) == $index ) {
110
+ $index = $key;
111
+ break;
112
+ }
113
+ }
114
+ }
115
+
116
+ $sidebars_widgets = wp_get_sidebars_widgets();
117
+ /* if there are no active widgets */
118
+ if ( empty($wp_registered_sidebars[$index]) ||
119
+ !array_key_exists($index, $sidebars_widgets) ||
120
+ !is_array($sidebars_widgets[$index])
121
+ || empty($sidebars_widgets[$index]) )
122
+ return false;
123
+
124
+ $sidebar = $wp_registered_sidebars[$index];
125
+ // $sidebar = array('wp_inactive_widgets');
126
+ $did_one = false;
127
+
128
+ // foreach ( (array) $sidebars_widgets[$index] as $id ) { /* lifted from wordpress code, keep as similar as possible for now */
129
+
130
+ if ( !isset($wp_registered_widgets[$id]) ) continue;
131
+
132
+ $params = array_merge(
133
+ array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
134
+ (array) $wp_registered_widgets[$id]['params']
135
+ );
136
+
137
+ // Substitute HTML id and class attributes into before_widget
138
+ $classname_ = '';
139
+ foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
140
+ if ( is_string($cn) )
141
+ $classname_ .= '_' . $cn;
142
+ elseif ( is_object($cn) )
143
+ $classname_ .= '_' . get_class($cn);
144
+ }
145
+ $classname_ = ltrim($classname_, '_');
146
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
147
+
148
+ $params = apply_filters( 'dynamic_sidebar_params', $params );
149
+
150
+ if (!$title) { /* amr switch off the title html, still need to get rid of title separately */
151
+ $params[0]['before_title'] = '<span style="display: none">';
152
+ $params[0]['after_title'] = '</span>';
153
+ }
154
+
155
+ $callback = $wp_registered_widgets[$id]['callback'];
156
+ if ( is_callable($callback) ) {
157
+ call_user_func_array($callback, $params);
158
+ $did_one = true;
159
+ }
160
+ // }
161
+ return $did_one;
162
+ }
163
+
164
+ /* -------------------------------------------------------------------------------------------------------------*/
165
+ add_shortcode('do_widget', 'do_widget');
166
+ /* Create a sidebar that will not appear in any theme, but can be used to customise widget settings if default settings not suitable */
167
+ if ( function_exists('register_sidebar') )
168
+ register_sidebar(array('name'=>'Shortcode',
169
+ 'id' => 'sidebar-shortcode',
170
+ 'before_widget' => '<div id="%1$s" class="widget %2$s clearfix">',
171
+ 'after_widget' => '</div>',
172
+ 'before_title' => '<h2 class="widgettitle">',
173
+ 'after_title' => '</h2>' ));
174
+
175
+ ?>
tags/1.0/readme.txt ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === AmR shortcode any widget ===
2
+ Contributors: Anmari
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=anmari%40anmari%2ecom&item_name=Shortcode widget Plugin Support&no_shipping=1&no_note=1&cn=Optional%20Notes&tax=0&currency_code=USD&bn=PP%2dDonationsBF&charset=UTF%2d8">Donate</a>
4
+ Tags: shortcode widget page
5
+ Tested up to: 2.8.4
6
+ Version: 1.0 alpha
7
+ Stable tag: trunk
8
+
9
+ == Description ==
10
+ This simple 'utility' plugin allows one to have any widget used in a page shortcode in any theme - no need to use the hybrid theme or create a special template.
11
+
12
+ If you found the plugin useful, please <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=anmari%40anmari%2ecom&item_name=Shortcode widget Support&no_shipping=1&no_note=1&cn=Optional%20Notes&tax=0&currency_code=USD&bn=PP%2dDonationsBF&charset=UTF%2d8">Donate</a>
13
+
14
+ == Changelog ==
15
+ = 1.0 =
16
+ * Launch of the plugin
17
+
18
+
19
+ == Installation ==
20
+
21
+ 1. In the wordpress admin plugin section of your site, click "Add New" or download and Unzip the file into your wordpress plugins folder.
22
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
23
+ 3. Activate the widget plugin that you want to use.
24
+ 4. Go to the widgets menu and drag an instance of the widget to the shortcodes sidebar, and set the widget options.
25
+ 5. Create or edit the page or post in which you wish to use the widget, enter [do_widget widgetname] within the text in the page and save.
26
+
27
+ Other variations:
28
+ 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 assocaied settings to use).
29
+
30
+
31
+
32
+ == Screenshots ==
33
+
34
+ 1. Demonstration of two widgets being used via the do_widget short code.
35
+ 2. The Page or post with the do_widget shortcodes
36
+ 3. The shortcode sidebar. The widget's user interface (UI) is used to provide a UI for the do_widget shortcode.
37
+
screenshot-6.png → tags/1.0/screenshot-1.png RENAMED
File without changes
tags/1.0/screenshot-2.png ADDED
Binary file
tags/1.0/screenshot-3.png ADDED
Binary file
tags/1.3/amr_shortcode_any_widget.php ADDED
@@ -0,0 +1,280 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: amr shortcode any widget
4
+ Plugin URI: http://webdesign.anmari.com/shortcode-any-widget/
5
+ Description: Allows inclusion of any widget within a page for any theme. [do_widget widgetname ] or [do_widget "widget name" ]. Warning if upgraded from 1.1 t- Don't panic, please see changelog about the shortcodes sidebar. Add ?do_widget_debug to see list of widget ids that can be used.
6
+ Author: anmari
7
+ Version: 1.3
8
+ Author URI: http://webdesign.anmari.com
9
+
10
+ */
11
+
12
+
13
+ /*-----------------------------------*/
14
+ function do_widget($atts) {
15
+
16
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
17
+
18
+
19
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
20
+ if it is in, then get the instance data and use that */
21
+ if (isset($_REQUEST['do_widget_debug'])) $debug=true;
22
+ else $debug = false;
23
+
24
+ if (isset($_wp_sidebars_widgets) ) {
25
+ if ($debug) {
26
+ echo '<br />Attributes entered:<br />';
27
+ var_dump($atts);
28
+ echo '<br />Available sidebars and widgets<br />';
29
+ foreach ($_wp_sidebars_widgets as $i=> $w) {
30
+ echo 'Sidebar:&nbsp;<b>'.$i.': '.get_sidebar_name($i).'</b><br />';
31
+ if (is_array($w)) {
32
+ sort ($w);
33
+ foreach ($w as $i2=> $w2) {
34
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$w2.' <br />';
35
+ };
36
+ }
37
+ echo '<br />';
38
+ };
39
+ }
40
+ }
41
+ else { if ($debug) {echo '<br />No widgets defined'; }
42
+ return (false);
43
+ }
44
+
45
+ extract(shortcode_atts(array(
46
+ 'sidebar' => 'Shortcodes',
47
+ 'id' => '',
48
+ 'title' => 'true' /* do the default title unless they ask us not to - use string here not boolean */
49
+ ), $atts));
50
+
51
+
52
+
53
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
54
+ if (!empty($atts[0])) {
55
+ if ($debug) {
56
+ echo 'We have a name';
57
+ print_r($atts[0]);
58
+ //var_dump($wp_registered_widgets);
59
+ }
60
+ $widget = $atts[0];
61
+
62
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
63
+ if (strtolower($w['name']) === strtolower($widget)) $widget_ids[] = $i;
64
+ if ($debug) {echo '<br /> Check: '.$w['name'];}
65
+ }
66
+
67
+
68
+ }
69
+ else { /* check for id if we do not have a name */
70
+ if (!empty($id)) { /* if a specific id has been specified */
71
+
72
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
73
+ if ($w['id'] === $id) $widget_ids[] = $id;
74
+ }
75
+ if ($debug) {echo '<h2>We have an id: '.$id.'</h2>'; var_dump($widget_ids);}
76
+ }
77
+ else {
78
+ if ($debug) { echo 'No valid widget name or id given';}
79
+ return (false);
80
+
81
+ }
82
+ }
83
+
84
+ if (empty ($widget_ids)) {
85
+
86
+ echo '<p><b>Widget not found in widget list.'
87
+ .' <a href="'.add_query_arg('do_widget_debug','1').'">Try debug</a></b></p>';
88
+ if ($debug) {
89
+ echo '<h2>As a last resort, dump the wp variables </h2>';
90
+ $sidebars_widgets = wp_get_sidebars_widgets();
91
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
92
+ foreach ($sidebars_widgets as $i=>$w) {
93
+ echo '<br/>'.$i; var_dump($w);
94
+ };
95
+
96
+ echo '<h3>$_wp_sidebars_widgets:</h3>';
97
+ var_dump($_wp_sidebars_widgets);
98
+ echo '<br /><h3>$wp_registered_widgets:</h3>';
99
+ var_dump($wp_registered_widgets);
100
+ }
101
+ return (false) ;
102
+ }
103
+
104
+ if ($title == 'false') $title = false; /* If ask not to display title, then do not */
105
+ else $title = true;
106
+
107
+ if (!($sidebarid = get_sidebar_id ($sidebar))) $sidebarid=$sidebar; /* get the official sidebar id - will take the first one */
108
+
109
+ if ($debug) {
110
+ echo '<hr>Looking for widget with name:'.$widget.' or id='.$id.' Found instances:'.' <br />';
111
+ foreach ($widget_ids as $i=> $w) {
112
+ echo $w.'<br />';
113
+ };
114
+ }
115
+ $content = '';
116
+ /* if the widget is in our chosen sidebar, then use the otions stored for that */
117
+
118
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
119
+ if ($debug) {
120
+ echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
121
+ sort ($_wp_sidebars_widgets[$sidebarid]);
122
+ foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
123
+ echo $i.' '.$w.'<br />';
124
+ };
125
+ }
126
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
127
+
128
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
129
+ if ($debug) { echo '<br />Will use widget ids'.'<br />';
130
+ foreach ($widget_ids as $i=> $w) {
131
+ echo '&nbsp;&nbsp;&nbsp;'.$w.'<br />';
132
+ };
133
+ }
134
+ }
135
+ else { /* the sidebar is not defined */
136
+ if ($debug) {echo '<br />Sidebar '.$sidebar.'with sidebarid '.$sidebarid.' empty or not defined.'; }
137
+ }
138
+
139
+
140
+ if (empty ($wid)) {
141
+ if ($debug) { echo '<h2>No Widget ids in sidebar '.$sidebarid.' with name '.$sidebar.' Try defaults </h2>';}
142
+ unset($sidebar); unset($sidebarid);
143
+
144
+ }
145
+ else
146
+ /* There may only be one but if we have two in our chosen widget then it will do both */
147
+ $output = '';
148
+ foreach ($wid as $i=>$widget_instance) {
149
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
150
+ shortcode_sidebar($widget_instance, $sidebar, $title);
151
+ $output .= ob_get_clean();
152
+ }
153
+
154
+
155
+
156
+ return ($output);
157
+ }
158
+ /*-----------------------------------*/
159
+ function get_sidebar_name ($id) { /* dont need anymore ? or at least temporarily */
160
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
161
+ global $wp_registered_sidebars;
162
+ foreach ($wp_registered_sidebars as $i => $a) {
163
+ if ((isset ($a['id'])) and ( $a['id'] === $id)) {
164
+ if (isset($a['name'])) return ($a['name']);
165
+ else return ($id);
166
+ }
167
+ }
168
+ return (false);
169
+ }
170
+ /*-----------------------------------*/
171
+ function get_sidebar_id ($name) { /* dont need anymore ? or at least temporarily */
172
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
173
+ global $wp_registered_sidebars;
174
+ foreach ($wp_registered_sidebars as $i => $a) {
175
+ if ((isset ($a['name'])) and ( $a['name'] === $name)) return ($i);
176
+ }
177
+ return (false);
178
+ }
179
+ /* -------------------------------------------------------------------------*/
180
+ function shortcode_sidebar( $id, $index=1, $title=true) { /* This is basically the wordpress code, slightly modified */
181
+ global $wp_registered_sidebars, $wp_registered_widgets;
182
+
183
+ if (isset($_REQUEST['do_widget_debug'])) $debug=true;
184
+ else $debug = false;
185
+
186
+ if ( is_int($index) ) {
187
+ $index = "sidebar-$index";
188
+ } else {
189
+ $index = sanitize_title($index);
190
+ foreach ( (array) $wp_registered_sidebars as $key => $value ) {
191
+ if ( sanitize_title($value['name']) == $index ) {
192
+ $index = $key;
193
+ break;
194
+ }
195
+ }
196
+ }
197
+
198
+ $sidebars_widgets = wp_get_sidebars_widgets();
199
+
200
+ if ($debug) {
201
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
202
+ foreach ($sidebars_widgets as $i=>$w) {
203
+ echo '<br />'.$w['name'].' '.$w['id'];
204
+ };
205
+ }
206
+
207
+
208
+ /* DONT NEED TO BE ACTIVE ? if there are no active widgets */
209
+ // if ( empty($wp_registered_sidebars[$index]) ||
210
+ // !array_key_exists($index, $sidebars_widgets) ||
211
+ // !is_array($sidebars_widgets[$index])
212
+ // || empty($sidebars_widgets[$index]) ) {
213
+ // echo '<br />'.'No active widgets for '.$index;
214
+ // return false;
215
+ // }
216
+
217
+ // $sidebar = $wp_registered_sidebars[$index];
218
+ $sidebar = array('wp_inactive_widgets');
219
+ $did_one = false;
220
+
221
+ // foreach ( (array) $sidebars_widgets[$index] as $id ) { /* lifted from wordpress code, keep as similar as possible for now */
222
+
223
+ if ( !isset($wp_registered_widgets[$id]) ) continue;
224
+
225
+ $params = array_merge(
226
+ array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
227
+ (array) $wp_registered_widgets[$id]['params']
228
+ );
229
+
230
+ // Substitute HTML id and class attributes into before_widget
231
+ $classname_ = '';
232
+ foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
233
+ if ( is_string($cn) )
234
+ $classname_ .= '_' . $cn;
235
+ elseif ( is_object($cn) )
236
+ $classname_ .= '_' . get_class($cn);
237
+ }
238
+ $classname_ = ltrim($classname_, '_');
239
+ if (!empty($params[0]['before_widget']))
240
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
241
+ else $params[0]['before_widget'] = '';
242
+ if (empty($params[0]['after_widget'])) $params[0]['after_widget'] = '';
243
+
244
+ $params = apply_filters( 'dynamic_sidebar_params', $params );
245
+
246
+ if (!$title) { /* amr switch off the title html, still need to get rid of title separately */
247
+ $params[0]['before_title'] = '<span style="display: none">';
248
+ $params[0]['after_title'] = '</span>';
249
+ }
250
+ else {
251
+ $params[0]['before_title'] = '<h2>';
252
+ $params[0]['after_title'] = '</h2>';
253
+ }
254
+
255
+ $callback = $wp_registered_widgets[$id]['callback'];
256
+ if ( is_callable($callback) ) {
257
+ call_user_func_array($callback, $params);
258
+ $did_one = true;
259
+ }
260
+ // }
261
+ return $did_one;
262
+ }
263
+ /* -------------------------------------------------------------------------------------------------------------*/
264
+ function amr_reg_sidebar() {
265
+ if ( function_exists('register_sidebar') )
266
+ register_sidebar(array('name'=>'Shortcodes',
267
+ 'id' => 'Shortcodes',
268
+ 'before_widget' => '<div id="%1$s" class="widget %2$s clearfix">',
269
+ 'after_widget' => '</div>',
270
+ 'before_title' => '<h2 class="widgettitle">',
271
+ 'after_title' => '</h2>' ));
272
+ }
273
+ /* -------------------------------------------------------------------------------------------------------------*/
274
+
275
+ add_action('admin_init', 'amr_reg_sidebar');
276
+ add_shortcode('do_widget', 'do_widget');
277
+
278
+ require_once(ABSPATH . 'wp-includes/widgets.php');
279
+
280
+ ?>
tags/1.3/readme.txt ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === amr shortcode any widget ===
2
+ Contributors: anmari
3
+ Tags: shortcode widget page
4
+ Tested up to: 3.2.1
5
+ Version: 1.3
6
+ Stable tag: trunk
7
+
8
+ == Description ==
9
+ This simple 'utility' plugin allows one to have any widget used in a page shortcode in any theme - no need to use the hybrid theme or create a special template. For more details see [anmari.com](http://webdesign.anmari.com/category/plugins/shortcode-any-widget/)
10
+
11
+
12
+ == Changelog ==
13
+ = Version 1.3 =
14
+ * Added debug link and retested. Added readme.
15
+
16
+ = 1.12=
17
+ * Changed dummy shortcode sidebar so it appears after the theme sidebars to avoid taking over their widgets (this happened in numbered sidebars) PLEASE note if you have upgraded, you may appear to have "lost" your widgets due to this sidebar change. You have not - they will be in your "inactive widgets" - please drag them to the new sidebar. You may also find that you have 2 versions of the plugin, with slightly different folder names. This will allow you to go back to the previous one to check what you had there if you need to. Deactivate the old one and activate the new one. Move your widgets back in. Test then Delete the old one. In one theme it also appeared that somehow due to this change, one of the sidebar widgets "moved" down to another sidebar. I think that this may have had something to do with the fact that sidebars can be numbered or named, so please check all your sidebars before continuing. As always make sure thath you know how to restore from a backup before doing any upgrades of any kind.
18
+ * Tested in 2.9.2, can still use either the widget name "Categories" or id=categories-6. Note widget must have been created in the dummy shortcode sidebar.
19
+
20
+ = 1.1 =
21
+
22
+ * Allow for lowercase use of widget names for the those challenged by attention to detail!
23
+ * Cleaned up debug mode to make it easier for people to identify which instance of a widget they are using. Add &do_widget_debug to url string.
24
+
25
+ = 1.0 =
26
+ * Launch of the plugin
27
+
28
+ == Installation ==
29
+
30
+ 0. Activate plugin
31
+ 1. Drag widgets to shortcodes sidebar. Save.
32
+ 2. Add [do_widget id=widgetid] in a page or post
33
+ 3. If it fails, click on the debug prompt and look for the id of your widget, use that.
34
+
35
+ 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"].
36
+
37
+ 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]
38
+
39
+
40
+ == Screenshots ==
41
+
42
+ 1. Demonstration of two widgets being used via the do_widget short code.
43
+ 2. The Page or post with the do_widget shortcodes
44
+ 3. The shortcode sidebar. The widget's user interface (UI) is used to provide a UI for the do_widget shortcode.
45
+
tags/1.3/screenshot-1.png ADDED
Binary file
tags/1.3/screenshot-2.png ADDED
Binary file
tags/1.3/screenshot-3.png ADDED
Binary file
tags/1.4/amr_shortcode_any_widget.php ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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" ]. If upgrading see changelog. Can be very powerful eg: with queryposts widget it can bceome a templater.
6
+ Author: anmari
7
+ Version: 1.4
8
+ Author URI: http://webdesign.anmari.com
9
+
10
+ */
11
+
12
+
13
+ /*-----------------------------------*/
14
+ function do_widget($atts) {
15
+
16
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
17
+
18
+
19
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
20
+ if it is in, then get the instance data and use that */
21
+ if (isset($_REQUEST['do_widget_debug'])) $debug=true;
22
+ else $debug = false;
23
+
24
+ if (isset($_wp_sidebars_widgets) ) {
25
+ if ($debug) {
26
+ echo '<h3>DEBUG on: Please scroll down till you find the shortcodes sidebar.</h3>';
27
+ echo '<br />Attributes entered:<br />';
28
+ var_dump($atts);
29
+ echo '<br />Available sidebars and widgets<br />';
30
+ foreach ($_wp_sidebars_widgets as $i=> $w) {
31
+ echo 'Sidebar:&nbsp;<b>'.$i.': '.get_sidebar_name($i).'</b><br />';
32
+ if (is_array($w)) {
33
+ sort ($w);
34
+ foreach ($w as $i2=> $w2) {
35
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$w2.' <br />';
36
+ };
37
+ }
38
+ echo '<br />';
39
+ };
40
+ }
41
+ }
42
+ else { if ($debug) {echo '<br />No widgets defined'; }
43
+ return (false);
44
+ }
45
+
46
+ extract(shortcode_atts(array(
47
+ 'sidebar' => 'Shortcodes',
48
+ 'id' => '',
49
+ 'title' => 'true' /* do the default title unless they ask us not to - use string here not boolean */
50
+ ), $atts));
51
+
52
+
53
+
54
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
55
+ if (!empty($atts[0])) {
56
+ if ($debug) {
57
+ echo 'We have a name';
58
+ print_r($atts[0]);
59
+ //var_dump($wp_registered_widgets);
60
+ }
61
+ $widget = $atts[0];
62
+
63
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
64
+ if (strtolower($w['name']) === strtolower($widget)) $widget_ids[] = $i;
65
+ if ($debug) {echo '<br /> Check: '.$w['name'];}
66
+ }
67
+
68
+
69
+ }
70
+ else { /* check for id if we do not have a name */
71
+ if (!empty($id)) { /* if a specific id has been specified */
72
+
73
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
74
+ if ($w['id'] === $id) $widget_ids[] = $id;
75
+ }
76
+ if ($debug) {echo '<h2>We have an id: '.$id.'</h2>'; if (!empty($widget_ids)) var_dump($widget_ids);}
77
+ }
78
+ else {
79
+ if ($debug) { echo 'No valid widget name or id given';}
80
+ return (false);
81
+
82
+ }
83
+ }
84
+
85
+ if (empty ($widget_ids)) {
86
+
87
+ echo '<p><b>Widget not found in widget list.'
88
+ .' <a href="'.add_query_arg('do_widget_debug','1').'">Try debug</a></b></p>';
89
+ if ($debug) {
90
+ echo '<h2>As a last resort, dump the wp variables </h2>';
91
+ $sidebars_widgets = wp_get_sidebars_widgets();
92
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
93
+ foreach ($sidebars_widgets as $i=>$w) {
94
+ echo '<br/>'.$i; var_dump($w);
95
+ };
96
+
97
+ echo '<h3>$_wp_sidebars_widgets:</h3>';
98
+ var_dump($_wp_sidebars_widgets);
99
+ echo '<br /><h3>$wp_registered_widgets:</h3>';
100
+ var_dump($wp_registered_widgets);
101
+ }
102
+ return (false) ;
103
+ }
104
+
105
+ if ($title == 'false') $title = false; /* If ask not to display title, then do not */
106
+ else $title = true;
107
+
108
+ if (!($sidebarid = get_sidebar_id ($sidebar))) $sidebarid=$sidebar; /* get the official sidebar id - will take the first one */
109
+
110
+ if ($debug) {
111
+ if (empty($widget)) $widget = '';
112
+ echo '<hr>Looking for widget with name:'.$widget.' or id='.$id.' Found instances:'.' <br />';
113
+ if (!empty($widget_ids)) foreach ($widget_ids as $i=> $w) {
114
+ echo $w.'<br />';
115
+ };
116
+ }
117
+ $content = '';
118
+ /* if the widget is in our chosen sidebar, then use the otions stored for that */
119
+
120
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
121
+ if ($debug) {
122
+ echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
123
+ sort ($_wp_sidebars_widgets[$sidebarid]);
124
+ foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
125
+ echo $i.' '.$w.'<br />';
126
+ };
127
+ }
128
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
129
+
130
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
131
+ if ($debug) { echo '<br />Will use widget ids'.'<br />';
132
+ foreach ($widget_ids as $i=> $w) {
133
+ echo '&nbsp;&nbsp;&nbsp;'.$w.'<br />';
134
+ };
135
+ }
136
+ }
137
+ else { /* the sidebar is not defined */
138
+ if ($debug) {echo '<br />Sidebar '.$sidebar.'with sidebarid '.$sidebarid.' empty or not defined.'; }
139
+ }
140
+
141
+ $output = '';
142
+ if (empty ($wid)) {
143
+ if ($debug) { echo '<h2>No Widget ids in sidebar '.$sidebarid.' with name '.$sidebar.' Try defaults </h2>';}
144
+ unset($sidebar); unset($sidebarid);
145
+
146
+ }
147
+ else
148
+ /* There may only be one but if we have two in our chosen widget then it will do both */
149
+ $output = '';
150
+ foreach ($wid as $i=>$widget_instance) {
151
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
152
+ shortcode_sidebar($widget_instance, $sidebar, $title);
153
+ $output .= ob_get_clean();
154
+ }
155
+
156
+
157
+
158
+ return ($output);
159
+ }
160
+ /*-----------------------------------*/
161
+ function get_sidebar_name ($id) { /* dont need anymore ? or at least temporarily */
162
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
163
+ global $wp_registered_sidebars;
164
+ foreach ($wp_registered_sidebars as $i => $a) {
165
+ if ((isset ($a['id'])) and ( $a['id'] === $id)) {
166
+ if (isset($a['name'])) return ($a['name']);
167
+ else return ($id);
168
+ }
169
+ }
170
+ return (false);
171
+ }
172
+ /*-----------------------------------*/
173
+ function get_sidebar_id ($name) { /* dont need anymore ? or at least temporarily */
174
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
175
+ global $wp_registered_sidebars;
176
+ foreach ($wp_registered_sidebars as $i => $a) {
177
+ if ((isset ($a['name'])) and ( $a['name'] === $name)) return ($i);
178
+ }
179
+ return (false);
180
+ }
181
+ /* -------------------------------------------------------------------------*/
182
+ function shortcode_sidebar( $id, $index=1, $title=true) { /* This is basically the wordpress code, slightly modified */
183
+ global $wp_registered_sidebars, $wp_registered_widgets;
184
+
185
+ if (isset($_REQUEST['do_widget_debug'])) $debug=true;
186
+ else $debug = false;
187
+
188
+ if ( is_int($index) ) {
189
+ $index = "sidebar-$index";
190
+ } else {
191
+ $index = sanitize_title($index);
192
+ foreach ( (array) $wp_registered_sidebars as $key => $value ) {
193
+ if ( sanitize_title($value['name']) == $index ) {
194
+ $index = $key;
195
+ break;
196
+ }
197
+ }
198
+ }
199
+
200
+ $sidebars_widgets = wp_get_sidebars_widgets();
201
+
202
+ if ($debug) {
203
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
204
+ foreach ($sidebars_widgets as $i=>$w) {
205
+ echo '<br />'.$w['name'].' '.$w['id'];
206
+ };
207
+ }
208
+
209
+
210
+ /* DONT NEED TO BE ACTIVE ? if there are no active widgets */
211
+ // if ( empty($wp_registered_sidebars[$index]) ||
212
+ // !array_key_exists($index, $sidebars_widgets) ||
213
+ // !is_array($sidebars_widgets[$index])
214
+ // || empty($sidebars_widgets[$index]) ) {
215
+ // echo '<br />'.'No active widgets for '.$index;
216
+ // return false;
217
+ // }
218
+
219
+ // $sidebar = $wp_registered_sidebars[$index];
220
+ $sidebar = array('wp_inactive_widgets');
221
+ $did_one = false;
222
+
223
+ // foreach ( (array) $sidebars_widgets[$index] as $id ) { /* lifted from wordpress code, keep as similar as possible for now */
224
+
225
+ if ( !isset($wp_registered_widgets[$id]) ) continue;
226
+
227
+ $params = array_merge(
228
+ array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
229
+ (array) $wp_registered_widgets[$id]['params']
230
+ );
231
+
232
+ // Substitute HTML id and class attributes into before_widget
233
+ $classname_ = '';
234
+ foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
235
+ if ( is_string($cn) )
236
+ $classname_ .= '_' . $cn;
237
+ elseif ( is_object($cn) )
238
+ $classname_ .= '_' . get_class($cn);
239
+ }
240
+ $classname_ = ltrim($classname_, '_');
241
+ if (!empty($params[0]['before_widget']))
242
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
243
+ else $params[0]['before_widget'] = '';
244
+ if (empty($params[0]['after_widget'])) $params[0]['after_widget'] = '';
245
+
246
+ $params = apply_filters( 'dynamic_sidebar_params', $params );
247
+
248
+ if (!$title) { /* amr switch off the title html, still need to get rid of title separately */
249
+ $params[0]['before_title'] = '<span style="display: none">';
250
+ $params[0]['after_title'] = '</span>';
251
+ }
252
+ else {
253
+ $params[0]['before_title'] = '<h2>';
254
+ $params[0]['after_title'] = '</h2>';
255
+ }
256
+
257
+ $callback = $wp_registered_widgets[$id]['callback'];
258
+ if ( is_callable($callback) ) {
259
+ call_user_func_array($callback, $params);
260
+ $did_one = true;
261
+ }
262
+ // }
263
+ return $did_one;
264
+ }
265
+ /* -------------------------------------------------------------------------------------------------------------*/
266
+ function amr_reg_sidebar() {
267
+ if ( function_exists('register_sidebar') )
268
+ register_sidebar(array('name'=>'Shortcodes',
269
+ 'id' => 'Shortcodes',
270
+ 'before_widget' => '<div id="%1$s" class="widget %2$s clearfix">',
271
+ 'after_widget' => '</div>',
272
+ 'before_title' => '<h2 class="widgettitle">',
273
+ 'after_title' => '</h2>' ));
274
+ }
275
+ /* -------------------------------------------------------------------------------------------------------------*/
276
+
277
+ add_action('admin_init', 'amr_reg_sidebar');
278
+ add_shortcode('do_widget', 'do_widget');
279
+
280
+ require_once(ABSPATH . 'wp-includes/widgets.php');
281
+
282
+ ?>
tags/1.4/readme.txt ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === amr shortcode any widget ===
2
+ Contributors: anmari
3
+ Tags: shortcode, widget, page, templates, page template
4
+ Tested up to: 3.3.1
5
+ Version: 1.4
6
+ Stable tag: trunk
7
+
8
+ == Description ==
9
+ This simple 'utility' plugin allows one to have any widget used in a page shortcode in any theme - no need to use the hybrid theme or create a special template. 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/)
10
+
11
+ 1. Test chosen widget works in normal sidebar first.
12
+ 2. Activate this plugin
13
+ 3. Go to Appearance > widgets and find "shortcode" sidebar
14
+ 4. Drag chosen widgets from configured sidebar to shortcodes sidebar. Save.
15
+ 5. Go to page where you want configured widget to appear
16
+ 6. enter one of:
17
+ [do_widget widgetname] eg: [do_widget calendar]
18
+ [do_widget "widget name"]. eg: [do_widget "tag cloud"]
19
+ [do_widget id=widgetid] in a page or post
20
+ 7. If the plugin cannot work out what you want, it will show a debug prompt
21
+ , click on the debug prompt and look for the id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug nfo). Try with the id. Sometimes the widget name that wordpress calls it internally is not the same as what you see on the screen and you willneed the 'debug' to find the id.
22
+
23
+ Plugin has been tested with most standard widgets (rss feeds, tag cloud, pages, meta, search, and of course my own plugins widgets - upcoming events list, calendar and user lists.
24
+
25
+ If you use a widget more than once for different reasons, you may need to use the widget id to isolate which widget instance and it's settings to use. ie: [do_widget id=categories-6] . If you just use the name, it will display all widgets in the shortcode sidebar with that name (all instances).
26
+
27
+
28
+ == Changelog ==
29
+ = Version 1.4 =
30
+ * Updated readme - made very detailed steps and added some screen shots.
31
+ * Tested on wp 3.3.1 and fixed some notices when bad parameters entered.
32
+
33
+ = Version 1.3 =
34
+ * Added debug link and retested. Added readme.
35
+
36
+ = 1.12=
37
+ * Changed dummy shortcode sidebar so it appears after the theme sidebars to avoid taking over their widgets (this happened in numbered sidebars) PLEASE note if you have upgraded, you may appear to have "lost" your widgets due to this sidebar change. You have not - they will be in your "inactive widgets" - please drag them to the new sidebar. You may also find that you have 2 versions of the plugin, with slightly different folder names. This will allow you to go back to the previous one to check what you had there if you need to. Deactivate the old one and activate the new one. Move your widgets back in. Test then Delete the old one. In one theme it also appeared that somehow due to this change, one of the sidebar widgets "moved" down to another sidebar. I think that this may have had something to do with the fact that sidebars can be numbered or named, so please check all your sidebars before continuing. As always make sure thath you know how to restore from a backup before doing any upgrades of any kind.
38
+ * Tested in 2.9.2, can still use either the widget name "Categories" or id=categories-6. Note widget must have been created in the dummy shortcode sidebar.
39
+
40
+ = 1.1 =
41
+
42
+ * Allow for lowercase use of widget names for the those challenged by attention to detail!
43
+ * Cleaned up debug mode to make it easier for people to identify which instance of a widget they are using. Add &do_widget_debug to url string.
44
+
45
+ = 1.0 =
46
+ * Launch of the plugin
47
+
48
+ == Installation ==
49
+
50
+ 0. Activate plugin
51
+ 1. Goto Appearance > widgets and find "shortcode" sidebar
52
+ 1. Drag chosen widgets to shortcodes sidebar. Save. (note the names)
53
+ 2. Add [do_widget id=widgetid] in a page or post
54
+ 3. If it fails, click on the debug prompt and look for the id of your widget, use that.
55
+
56
+ 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"].
57
+
58
+ 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]
59
+
60
+
61
+ == Screenshots ==
62
+
63
+ 1. setting up widgets in page (must be in the shortcode sidebar)
64
+ 2. widgets in a page
65
+ 3. setting up widgets in the shortcode sidebar
66
+ 4. two rss feed widgets in shortcode sidebar - both will show if just name used
67
+ 5. Demonstration of two widgets being used via the do_widget short code.
68
+ 6. The Page or post with the do_widget shortcodes
69
+ 7. The shortcode sidebar. The widget's user interface (UI) is used to provide a UI for the do_widget shortcode.
70
+ 8. Debug prompt if one enters something like id=junk
71
+ 9. Debug messages - scroll down till you see the shortcodes sidebar - the widgets and their ids will be listed. Use the id of the widet you want.
72
+
tags/1.4/screenshot-1.jpg ADDED
Binary file
tags/1.4/screenshot-2.jpg ADDED
Binary file
tags/1.4/screenshot-3.jpg ADDED
Binary file
screenshot-7.jpg → tags/1.4/screenshot-4.jpg RENAMED
File without changes
tags/1.4/screenshot-5.png ADDED
Binary file
tags/1.4/screenshot-6.png ADDED
Binary file
tags/1.4/screenshot-7.png ADDED
Binary file
tags/1.4/screenshot-8.jpg ADDED
Binary file
tags/1.4/screenshot-9.jpg ADDED
Binary file
tags/1.5/amr_shortcode_any_widget.php ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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" ]. If upgrading see changelog. Can be very powerful eg: with queryposts widget it can bceome a templater.
6
+ Author: anmari
7
+ Version: 1.5
8
+ Author URI: http://webdesign.anmari.com
9
+
10
+ */
11
+
12
+
13
+ /*-----------------------------------*/
14
+ function do_widget($atts) {
15
+
16
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
17
+
18
+
19
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
20
+ if it is in, then get the instance data and use that */
21
+ if (isset($_REQUEST['do_widget_debug'])) $debug=true;
22
+ else $debug = false;
23
+
24
+ if (isset($_wp_sidebars_widgets) ) {
25
+ if ($debug) {
26
+ echo '<h3>DEBUG on: Please scroll down till you find the shortcodes sidebar.</h3>';
27
+ echo '<br />Attributes entered:<br />';
28
+ var_dump($atts);
29
+ echo '<br />Available sidebars and widgets<br />';
30
+ foreach ($_wp_sidebars_widgets as $i=> $w) {
31
+ echo 'Sidebar:&nbsp;<b>'.$i.': '.get_sidebar_name($i).'</b><br />';
32
+ if (is_array($w)) {
33
+ sort ($w);
34
+ foreach ($w as $i2=> $w2) {
35
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$w2.' <br />';
36
+ };
37
+ }
38
+ echo '<br />';
39
+ };
40
+ }
41
+ }
42
+ else { if ($debug) {echo '<br />No widgets defined'; }
43
+ return (false);
44
+ }
45
+
46
+ extract(shortcode_atts(array(
47
+ 'sidebar' => 'Shortcodes',
48
+ 'id' => '',
49
+ 'title' => 'true' /* do the default title unless they ask us not to - use string here not boolean */
50
+ ), $atts));
51
+
52
+
53
+
54
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
55
+ if (!empty($atts[0])) {
56
+ if ($debug) {
57
+ echo 'We have a name';
58
+ print_r($atts[0]);
59
+ //var_dump($wp_registered_widgets);
60
+ }
61
+ $widget = $atts[0];
62
+
63
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
64
+ if (strtolower($w['name']) === strtolower($widget)) $widget_ids[] = $i;
65
+ if ($debug) {echo '<br /> Check: '.$w['name'];}
66
+ }
67
+
68
+
69
+ }
70
+ else { /* check for id if we do not have a name */
71
+ if (!empty($id)) { /* if a specific id has been specified */
72
+
73
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
74
+ if ($w['id'] === $id) $widget_ids[] = $id;
75
+ }
76
+ if ($debug) {echo '<h2>We have an id: '.$id.'</h2>'; if (!empty($widget_ids)) var_dump($widget_ids);}
77
+ }
78
+ else {
79
+ if ($debug) { echo 'No valid widget name or id given';}
80
+ return (false);
81
+
82
+ }
83
+ }
84
+
85
+ if (empty ($widget_ids)) {
86
+
87
+ echo '<p><b>Widget not found in widget list.'
88
+ .' <a href="'.add_query_arg('do_widget_debug','1').'">Try debug</a></b></p>';
89
+ if ($debug) {
90
+ echo '<h2>As a last resort, dump the wp variables </h2>';
91
+ $sidebars_widgets = wp_get_sidebars_widgets();
92
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
93
+ foreach ($sidebars_widgets as $i=>$w) {
94
+ echo '<br/>'.$i; var_dump($w);
95
+ };
96
+
97
+ echo '<h3>$_wp_sidebars_widgets:</h3>';
98
+ var_dump($_wp_sidebars_widgets);
99
+ echo '<br /><h3>$wp_registered_widgets:</h3>';
100
+ var_dump($wp_registered_widgets);
101
+ }
102
+ return (false) ;
103
+ }
104
+
105
+ if ($title == 'false') $title = false; /* If ask not to display title, then do not */
106
+ else $title = true;
107
+
108
+ if (!($sidebarid = get_sidebar_id ($sidebar))) $sidebarid=$sidebar; /* get the official sidebar id - will take the first one */
109
+
110
+ if ($debug) {
111
+ if (empty($widget)) $widget = '';
112
+ echo '<hr>Looking for widget with name:'.$widget.' or id='.$id.' Found instances:'.' <br />';
113
+ if (!empty($widget_ids)) foreach ($widget_ids as $i=> $w) {
114
+ echo $w.'<br />';
115
+ };
116
+ }
117
+ $content = '';
118
+ /* if the widget is in our chosen sidebar, then use the otions stored for that */
119
+
120
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
121
+ if ($debug) {
122
+ echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
123
+ sort ($_wp_sidebars_widgets[$sidebarid]);
124
+ foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
125
+ echo $i.' '.$w.'<br />';
126
+ };
127
+ }
128
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
129
+
130
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
131
+ if ($debug) { echo '<br />Will use widget ids'.'<br />';
132
+ foreach ($widget_ids as $i=> $w) {
133
+ echo '&nbsp;&nbsp;&nbsp;'.$w.'<br />';
134
+ };
135
+ }
136
+ }
137
+ else { /* the sidebar is not defined */
138
+ if ($debug) {echo '<br />Sidebar '.$sidebar.'with sidebarid '.$sidebarid.' empty or not defined.'; }
139
+ }
140
+
141
+ $output = '';
142
+ if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
143
+ if ($debug) { echo '<h2>No Widget ids in sidebar '.$sidebarid.' with name '.$sidebar.' Try defaults </h2>';}
144
+ unset($sidebar); unset($sidebarid);
145
+
146
+ }
147
+ else {
148
+ /* There may only be one but if we have two in our chosen widget then it will do both */
149
+ $output = '';
150
+ foreach ($wid as $i=>$widget_instance) {
151
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
152
+ shortcode_sidebar($widget_instance, $sidebar, $title);
153
+ $output .= ob_get_clean();
154
+ }
155
+
156
+ }
157
+
158
+ return ($output);
159
+ }
160
+ /*-----------------------------------*/
161
+ function get_sidebar_name ($id) { /* dont need anymore ? or at least temporarily */
162
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
163
+ global $wp_registered_sidebars;
164
+ foreach ($wp_registered_sidebars as $i => $a) {
165
+ if ((isset ($a['id'])) and ( $a['id'] === $id)) {
166
+ if (isset($a['name'])) return ($a['name']);
167
+ else return ($id);
168
+ }
169
+ }
170
+ return (false);
171
+ }
172
+ /*-----------------------------------*/
173
+ function get_sidebar_id ($name) { /* dont need anymore ? or at least temporarily */
174
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
175
+ global $wp_registered_sidebars;
176
+ foreach ($wp_registered_sidebars as $i => $a) {
177
+ if ((isset ($a['name'])) and ( $a['name'] === $name)) return ($i);
178
+ }
179
+ return (false);
180
+ }
181
+ /* -------------------------------------------------------------------------*/
182
+ function shortcode_sidebar( $id, $index=1, $title=true) { /* This is basically the wordpress code, slightly modified */
183
+ global $wp_registered_sidebars, $wp_registered_widgets;
184
+
185
+ if (isset($_REQUEST['do_widget_debug'])) $debug=true;
186
+ else $debug = false;
187
+
188
+ if ( is_int($index) ) {
189
+ $index = "sidebar-$index";
190
+ } else {
191
+ $index = sanitize_title($index);
192
+ foreach ( (array) $wp_registered_sidebars as $key => $value ) {
193
+ if ( sanitize_title($value['name']) == $index ) {
194
+ $index = $key;
195
+ break;
196
+ }
197
+ }
198
+ }
199
+
200
+ $sidebars_widgets = wp_get_sidebars_widgets();
201
+
202
+ if ($debug) {
203
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
204
+ foreach ($sidebars_widgets as $i=>$w) {
205
+ echo '<br />'.$w['name'].' '.$w['id'];
206
+ };
207
+ }
208
+
209
+
210
+ /* DONT NEED TO BE ACTIVE ? if there are no active widgets */
211
+ // if ( empty($wp_registered_sidebars[$index]) ||
212
+ // !array_key_exists($index, $sidebars_widgets) ||
213
+ // !is_array($sidebars_widgets[$index])
214
+ // || empty($sidebars_widgets[$index]) ) {
215
+ // echo '<br />'.'No active widgets for '.$index;
216
+ // return false;
217
+ // }
218
+
219
+ // $sidebar = $wp_registered_sidebars[$index];
220
+ $sidebar = array('wp_inactive_widgets');
221
+ $did_one = false;
222
+
223
+ // foreach ( (array) $sidebars_widgets[$index] as $id ) { /* lifted from wordpress code, keep as similar as possible for now */
224
+
225
+ if ( !isset($wp_registered_widgets[$id]) ) continue;
226
+
227
+ $params = array_merge(
228
+ array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
229
+ (array) $wp_registered_widgets[$id]['params']
230
+ );
231
+
232
+ // Substitute HTML id and class attributes into before_widget
233
+ $classname_ = '';
234
+ foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
235
+ if ( is_string($cn) )
236
+ $classname_ .= '_' . $cn;
237
+ elseif ( is_object($cn) )
238
+ $classname_ .= '_' . get_class($cn);
239
+ }
240
+ $classname_ = ltrim($classname_, '_');
241
+ if (!empty($params[0]['before_widget']))
242
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
243
+ else $params[0]['before_widget'] = '';
244
+ if (empty($params[0]['after_widget'])) $params[0]['after_widget'] = '';
245
+
246
+ $params = apply_filters( 'dynamic_sidebar_params', $params );
247
+
248
+ if (!$title) { /* amr switch off the title html, still need to get rid of title separately */
249
+ $params[0]['before_title'] = '<span style="display: none">';
250
+ $params[0]['after_title'] = '</span>';
251
+ }
252
+ else {
253
+ $params[0]['before_title'] = '<h2>';
254
+ $params[0]['after_title'] = '</h2>';
255
+ }
256
+
257
+ $callback = $wp_registered_widgets[$id]['callback'];
258
+ if ( is_callable($callback) ) {
259
+ call_user_func_array($callback, $params);
260
+ $did_one = true;
261
+ }
262
+ // }
263
+ return $did_one;
264
+ }
265
+ /* -------------------------------------------------------------------------------------------------------------*/
266
+ function amr_reg_sidebar() {
267
+ if ( function_exists('register_sidebar') )
268
+ register_sidebar(array('name'=>'Shortcodes',
269
+ 'id' => 'Shortcodes',
270
+ 'before_widget' => '<div id="%1$s" class="widget %2$s clearfix">',
271
+ 'after_widget' => '</div>',
272
+ 'before_title' => '<h2 class="widgettitle">',
273
+ 'after_title' => '</h2>' ));
274
+ }
275
+ /* -------------------------------------------------------------------------------------------------------------*/
276
+
277
+ add_action('admin_init', 'amr_reg_sidebar');
278
+ add_shortcode('do_widget', 'do_widget');
279
+
280
+ require_once(ABSPATH . 'wp-includes/widgets.php');
281
+
282
+ ?>
tags/1.5/readme.txt ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === amr shortcode any widget ===
2
+ Contributors: anmari
3
+ Tags: shortcode, widget, page, templates, page template
4
+ Tested up to: 3.3.1
5
+ Version: 1.5
6
+ Stable tag: trunk
7
+
8
+ == Description ==
9
+ This simple 'utility' plugin allows one to have any widget used in a page shortcode in any theme - no need to use the hybrid theme or create a special template. 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/)
10
+
11
+ 1. Test chosen widget works in normal sidebar first.
12
+ 2. Activate this plugin
13
+ 3. Go to Appearance > widgets and find "shortcode" sidebar
14
+ 4. Drag chosen widgets from configured sidebar to shortcodes sidebar. Save.
15
+ 5. Go to page where you want configured widget to appear
16
+ 6. enter one of:
17
+ [do_widget widgetname] eg: [do_widget calendar]
18
+ [do_widget "widget name"]. eg: [do_widget "tag cloud"]
19
+ [do_widget id=widgetid] in a page or post
20
+ 7. If the plugin cannot work out what you want, it will show a debug prompt
21
+ , click on the debug prompt and look for the id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug nfo). Try with the 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.
22
+
23
+ Plugin has been tested with most standard widgets (rss feeds, tag cloud, pages, meta, search, and of course my own plugins widgets - upcoming events list, calendar and user lists.
24
+
25
+ If you use a widget more than once for different reasons, you may need to use the widget id to isolate which widget instance and it's settings to use. ie: [do_widget id=categories-6] . If you just use the name, it will display all widgets in the shortcode sidebar with that name (all instances).
26
+
27
+ If you liked this plugin, you might also like my other plugins:
28
+ [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)
29
+ [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/)
30
+
31
+
32
+ == Changelog ==
33
+ = Version 1.5 =
34
+ * Fixed: a small bug which caused a warning if you had not saved the widgets in your shortcode sidebar
35
+
36
+ = Version 1.4 =
37
+ * Updated readme - made very detailed steps and added some screen shots.
38
+ * Tested on wp 3.3.1 and fixed some notices when bad parameters entered.
39
+
40
+ = Version 1.3 =
41
+ * Added debug link and retested. Added readme.
42
+
43
+ = 1.12=
44
+ * Changed dummy shortcode sidebar so it appears after the theme sidebars to avoid taking over their widgets (this happened in numbered sidebars) PLEASE note if you have upgraded, you may appear to have "lost" your widgets due to this sidebar change. You have not - they will be in your "inactive widgets" - please drag them to the new sidebar. You may also find that you have 2 versions of the plugin, with slightly different folder names. This will allow you to go back to the previous one to check what you had there if you need to. Deactivate the old one and activate the new one. Move your widgets back in. Test then Delete the old one. In one theme it also appeared that somehow due to this change, one of the sidebar widgets "moved" down to another sidebar. I think that this may have had something to do with the fact that sidebars can be numbered or named, so please check all your sidebars before continuing. As always make sure thath you know how to restore from a backup before doing any upgrades of any kind.
45
+ * Tested in 2.9.2, can still use either the widget name "Categories" or id=categories-6. Note widget must have been created in the dummy shortcode sidebar.
46
+
47
+ = 1.1 =
48
+
49
+ * Allow for lowercase use of widget names for the those challenged by attention to detail!
50
+ * Cleaned up debug mode to make it easier for people to identify which instance of a widget they are using. Add &do_widget_debug to url string.
51
+
52
+ = 1.0 =
53
+ * Launch of the plugin
54
+
55
+ == Installation ==
56
+
57
+ 0. Activate plugin
58
+ 1. Goto Appearance > widgets and find "shortcode" sidebar
59
+ 1. Drag chosen widgets to shortcodes sidebar. Save. (note the names)
60
+ 2. Add [do_widget id=widgetid] in a page or post
61
+ 3. If it fails, click on the debug prompt and look for the id of your widget, use that.
62
+
63
+ 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"].
64
+
65
+ 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]
66
+
67
+
68
+ == Screenshots ==
69
+
70
+ 1. setting up widgets in page (must be in the shortcode sidebar)
71
+ 2. widgets in a page
72
+ 3. setting up widgets in the shortcode sidebar
73
+ 4. two rss feed widgets in shortcode sidebar - both will show if just name used
74
+ 5. Demonstration of two widgets being used via the do_widget short code.
75
+ 6. The Page or post with the do_widget shortcodes
76
+ 7. The shortcode sidebar. The widget's user interface (UI) is used to provide a UI for the do_widget shortcode.
77
+ 8. Debug prompt if one enters something like id=junk
78
+ 9. Debug messages - scroll down till you see the shortcodes sidebar - the widgets and their ids will be listed. Use the id of the widet you want.
79
+
tags/1.5/screenshot-1.jpg ADDED
Binary file
tags/1.5/screenshot-2.jpg ADDED
Binary file
tags/1.5/screenshot-3.jpg ADDED
Binary file
tags/1.5/screenshot-4.jpg ADDED
Binary file
tags/1.5/screenshot-5.png ADDED
Binary file
tags/1.5/screenshot-6.png ADDED
Binary file
tags/1.5/screenshot-7.png ADDED
Binary file
tags/1.5/screenshot-8.jpg ADDED
Binary file
tags/1.5/screenshot-9.jpg ADDED
Binary file
tags/1.6/amr-admin-form-html.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Backend Class for use in all amr plugins
4
+ * Version 0.1
5
+ */
6
+
7
+ //------------------------------------------------------------------------------------------------------------------
8
+ if (!class_exists('amr_saw_plugin_admin')) {
9
+ class amr_saw_plugin_admin {
10
+ var $hook = 'amr_saw';
11
+ var $filename = 'amr_shortcode_any_widget/amr_shortcode_any_widget.php';
12
+ var $longname = 'Shortcode any widget';
13
+ var $shortname = 'Shortcode any widget';
14
+ var $optionname = '';
15
+ var $homepage = '';
16
+ var $parent_slug = 'plugin_listings_menu';
17
+ var $accesslvl = 'manage_options';
18
+
19
+ function amr_saw_plugin_admin() {
20
+ add_action('admin_menu', array(&$this, 'register_settings_page') );
21
+ add_filter('plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
22
+ }
23
+ function register_settings_page() {
24
+ add_options_page( $this->longname, $this->shortname, $this->accesslvl, $this->hook, array(&$this,'config_page'));
25
+ }
26
+ function plugin_options_url() {
27
+ return admin_url( 'options-general.php?page='.$this->hook );
28
+ }
29
+ /**
30
+ * Add a link to the settings page to the plugins list
31
+ */
32
+ function add_action_link( $links, $file ) {
33
+ static $this_plugin;
34
+ if( empty($this_plugin) )
35
+ $this_plugin = $this->filename;
36
+ if ( $file == $this_plugin ) {
37
+ $settings_link = '<a href="' . $this->plugin_options_url() . '">' . __('Settings') . '</a>';
38
+ array_unshift( $links, $settings_link );
39
+ }
40
+ return $links;
41
+ }
42
+
43
+ function admin_heading($title) {
44
+ echo '<div class="wrap" >
45
+ <div id="icon-options-general" class="icon32"><br />
46
+ </div>
47
+ <h2>'.$title.' </h2>';
48
+ // <form method="post" action="'
49
+ // .esc_url($_SERVER['PHP_SELF'])
50
+ // .'">';
51
+ // wp_nonce_field($this->hook); /* outputs hidden field */
52
+ // ;
53
+ }
54
+
55
+ function admin_subheading($title) {
56
+ echo '<h2>'.$title.'</h2>';
57
+ }
58
+ function config_page() {
59
+ $this->admin_heading($this->longname);
60
+ echo '<ul>';
61
+ echo '<li>';
62
+ _e('Drag the widgets you want to use to the shortcodes sidebar.');
63
+
64
+ echo '</li>';
65
+ echo '<li>';
66
+ _e('Set the widgets parameters if there are any.');
67
+ echo '</li>';
68
+ echo '<li>';
69
+ _e('You could test them out in a displayable sidebar, then drag them to the shortcodes sidebar.');
70
+
71
+ echo '</li>';
72
+ echo '<li>';
73
+ echo '<a title="Go to widget area" href="'.get_admin_url('','widgets.php').'"> ';
74
+ _e('Go to widgets');
75
+ echo '</a>';
76
+ echo '</li>';
77
+ echo '<li>';
78
+ _e('Then add the shortcode [do_widget widgetname] to a page.');
79
+ echo '</li>';
80
+ echo '<li>';
81
+ _e('Examples:[do_widget "tag cloud"] or [do_widget id=widgetid]');
82
+ echo '</li>';
83
+ echo '<li>';
84
+ echo '<a title="Create a page" href="'
85
+ .add_query_arg('content','[do_widget Archives]', get_admin_url('','post-new.php?post_type=page'))
86
+ .'"> ';
87
+ _e('Create the page');
88
+ echo '</a>';
89
+ echo '</li>';
90
+ echo '<li>';
91
+ echo 'You can add as many of these on one page as you like. Use title=false to switch off the title.';
92
+ echo '</li>';
93
+ echo '<li>';
94
+ echo '[do_widget pages title=false]';
95
+ echo '</li>';
96
+ echo '<li>';
97
+ echo '[do_widget categories]';
98
+ echo '</li>';
99
+ echo '<li>';
100
+ echo '[do_widget "tag cloud"]';
101
+ echo '</li>';
102
+ echo '<li>';
103
+ echo '[do_widget "recent posts"]';
104
+ echo '</li>';
105
+ echo '<li>';
106
+ echo '<li>';
107
+ echo 'If the plugin cannot work out what you want, it will show a debug prompt
108
+ , click on the debug prompt and look for the name or id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug info). If the name does not work, try with the 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.';
109
+ echo '</li>';
110
+ echo '<li>';
111
+ echo '</ul>';
112
+ }
113
+
114
+
115
+
116
+ /**
117
+ * Create a Checkbox input field
118
+ */
119
+ function radiobutton($id, $label, $value, $selected) {
120
+ $sel = checked($value,$selected, false);
121
+ return "<input type='radio' id='".$id."' name='".$id."' value='".$value."'"
122
+ . $sel."/>&nbsp;".$label."<br />";
123
+ }
124
+ /**
125
+ * Create a Checkbox input field
126
+ */
127
+ function checkbox($id, $label, $value) {
128
+ return '<input type="checkbox" id="'.$id.'" name="'.$id.'"'. checked($value,true,false).'/>&nbsp;<label for="'.$id.'">'.$label.'</label><br/>';
129
+ }
130
+ /**
131
+ * Create a Dropdown input field
132
+ */
133
+ function dropdown($id, $label, $options, $selected) {
134
+ //
135
+ $html = '<label for="'.$id.'">'.$label.':</label><br/>'
136
+ .'<select id=\''.$id.'\' name=\''.$id.'\'>';
137
+ foreach ($options as $i => $option) {
138
+ //
139
+ $sel = selected($i, $selected, false); //wordpress function returns with single quotes, not double
140
+ $html .= '<OPTION '.$sel.' label=\''.$option.'\' value=\''.$i.'\'>'.$option.'</OPTION>';
141
+ }
142
+ $html .= '</select>';
143
+ return ($html);
144
+ }
145
+ /**
146
+ * Create a Text input field
147
+ */
148
+ function textinput($id, $label, $value, $length='45') {
149
+ return '<label for="'.$id.'">'.$label.':</label><br/><input size="'
150
+ .$length.'" type="text" id="'.$id.'" name="'.$id.'" value="'.$value.'"/><br/><br/>';
151
+ }
152
+ /**
153
+ * Create a Text area field
154
+ */
155
+ function textarea($id, $label, $value, $cols='45', $rows='10') {
156
+ return '<label for="'.$id.'">'.$label.':</label><br/>'
157
+ .'<textarea rows="'.$rows.'" cols="'.$cols
158
+ .'" id="'.$id.'" name="'.$id.'"/>'.$value.'</TEXTAREA><br/><br/>';
159
+ }
160
+ /**
161
+ * Create a postbox widget
162
+ */
163
+ function postbox($id, $title, $content) {
164
+ ?>
165
+ <div id="<?php echo $id; ?>" class="postbox">
166
+ <div class="handlediv" title="Click to toggle"><br /></div>
167
+ <h3 class="hndle"><span><?php echo $title; ?></span></h3>
168
+ <div class="inside">
169
+ <?php echo $content; ?>
170
+ </div>
171
+ </div>
172
+ <?php
173
+ }
174
+ /**
175
+ * Create a form table from an array of rows
176
+ */
177
+ function form_table($rows) { // array of rows () id, label, desc, content
178
+ $content = '<table class="form-table">';
179
+ foreach ($rows as $row) {
180
+ $content .= '<tr><th valign="top" scrope="row">';
181
+ if (isset($row['id']) && $row['id'] != '')
182
+ $content .= '<label for="'.$row['id'].'">'.$row['label'].':</label>';
183
+ else
184
+ $content .= $row['label'];
185
+ if (isset($row['desc']) && $row['desc'] != '')
186
+ $content .= '<br/><small>'.$row['desc'].'</small>';
187
+ $content .= '</th><td valign="top">';
188
+ $content .= $row['content'];
189
+ $content .= '</td></tr>';
190
+ }
191
+ $content .= '</table>';
192
+ return $content;
193
+ }
194
+
195
+ /**
196
+ * Info box with link to the support forums.
197
+ */
198
+ function plugin_support() {
199
+ $content = '<p>'.__('If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the','amrplugin').' <a href="http://wordpress.org/tags/'.$this->hook.'">'.__("Support forums",'amrplugin').'</a>.</p>';
200
+ $this->postbox($this->hook.'support', 'Need support?', $content);
201
+ }
202
+
203
+ function text_limit( $text, $limit, $finish = ' [&hellip;]') {
204
+ if( strlen( $text ) > $limit ) {
205
+ $text = substr( $text, 0, $limit );
206
+ $text = substr( $text, 0, - ( strlen( strrchr( $text,' ') ) ) );
207
+ $text .= $finish;
208
+ }
209
+ return $text;
210
+ }
211
+ }
212
+ }
213
+
214
+ ?>
tags/1.6/amr_shortcode_any_widget.php ADDED
@@ -0,0 +1,300 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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" ]. If upgrading see changelog. Can be very powerful eg: with queryposts widget it can become a templater.
6
+ Author: anmari
7
+ Version: 1.6
8
+ Author URI: http://webdesign.anmari.com
9
+
10
+ */
11
+
12
+
13
+ /*-----------------------------------*/
14
+ function do_widget($atts) {
15
+
16
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
17
+
18
+
19
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
20
+ if it is in, then get the instance data and use that */
21
+ if (isset($_REQUEST['do_widget_debug'])) $debug=true;
22
+ else $debug = false;
23
+
24
+ if (isset($_wp_sidebars_widgets) ) {
25
+ if ($debug) {
26
+ echo '<h3>DEBUG on: Please scroll down till you find the shortcodes sidebar.</h3>';
27
+ echo '<br />Attributes entered:<br />';
28
+ var_dump($atts);
29
+ echo '<br />Available sidebars and widgets<br />';
30
+ foreach ($_wp_sidebars_widgets as $i=> $w) {
31
+ echo 'Sidebar:&nbsp;<b>'.$i.': '.amr_get_sidebar_name($i).'</b><br />';
32
+ if (is_array($w)) {
33
+ sort ($w);
34
+ foreach ($w as $i2=> $w2) {
35
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$w2.' <br />';
36
+ };
37
+ }
38
+ echo '<br />';
39
+ };
40
+ }
41
+ }
42
+ else { //if ($debug) {
43
+ echo '<br />No widgets defined at all';
44
+ //}
45
+ return (false);
46
+ }
47
+
48
+ extract(shortcode_atts(array(
49
+ 'sidebar' => 'Shortcodes',
50
+ 'id' => '',
51
+ 'title' => 'true' /* do the default title unless they ask us not to - use string here not boolean */
52
+ ), $atts));
53
+
54
+
55
+
56
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
57
+ if (!empty($atts[0])) {
58
+ if ($debug) {
59
+ echo 'We have a name';
60
+ print_r($atts[0]);
61
+ //var_dump($wp_registered_widgets);
62
+ }
63
+ $widget = $atts[0];
64
+
65
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
66
+ if (strtolower($w['name']) === strtolower($widget)) $widget_ids[] = $i;
67
+ if ($debug) {echo '<br /> Check: '.$w['name'];}
68
+ }
69
+
70
+
71
+ }
72
+ else { /* check for id if we do not have a name */
73
+ if (!empty($id)) { /* if a specific id has been specified */
74
+
75
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
76
+ if ($w['id'] === $id) $widget_ids[] = $id;
77
+ }
78
+ if ($debug) {
79
+ echo '<h2>We have an id: '.$id.'</h2>';
80
+ if (!empty($widget_ids)) var_dump($widget_ids);
81
+ }
82
+ }
83
+ else {
84
+ if ($debug) { echo 'No valid widget name or id given';}
85
+ return (false);
86
+
87
+ }
88
+ }
89
+
90
+ if (empty ($widget_ids)) {
91
+
92
+ echo '<p><b>Widget not found in widget list.'
93
+ .' <a href="'.add_query_arg('do_widget_debug','1').'">Try debug</a></b></p>';
94
+ if ($debug) {
95
+ echo '<h2>As a last resort, dump the wp variables </h2>';
96
+ $sidebars_widgets = wp_get_sidebars_widgets();
97
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
98
+ foreach ($sidebars_widgets as $i=>$w) {
99
+ echo '<br/>'.$i; var_dump($w);
100
+ };
101
+
102
+ echo '<h3>$_wp_sidebars_widgets:</h3>';
103
+ var_dump($_wp_sidebars_widgets);
104
+ echo '<br /><h3>$wp_registered_widgets:</h3>';
105
+ var_dump($wp_registered_widgets);
106
+ }
107
+ return (false) ;
108
+ }
109
+
110
+ if ($title == 'false')
111
+ $title = false; /* If ask not to display title, then do not */
112
+ else
113
+ $title = true;
114
+
115
+ if (!($sidebarid = get_sidebar_id ($sidebar)))
116
+ $sidebarid=$sidebar; /* get the official sidebar id - will take the first one */
117
+
118
+ if ($debug) {
119
+ if (empty($widget)) $widget = '';
120
+ echo '<hr>Looking for widget with name:'.$widget.' or id='.$id.' Found instances:'.' <br />';
121
+ if (!empty($widget_ids)) foreach ($widget_ids as $i=> $w) {
122
+ echo $w.'<br />';
123
+ };
124
+ }
125
+ $content = '';
126
+ /* if the widget is in our chosen sidebar, then use the otions stored for that */
127
+
128
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
129
+ if ($debug) {
130
+ echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
131
+ sort ($_wp_sidebars_widgets[$sidebarid]);
132
+ foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
133
+ echo $i.' '.$w.'<br />';
134
+ };
135
+ }
136
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
137
+
138
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
139
+ if ($debug) { echo '<br />Will use widget ids'.'<br />';
140
+ foreach ($widget_ids as $i=> $w) {
141
+ echo '&nbsp;&nbsp;&nbsp;'.$w.'<br />';
142
+ };
143
+ }
144
+ }
145
+ else { /* the sidebar is not defined */
146
+ //if ($debug) {
147
+ echo '<br />Sidebar '.$sidebar.'with sidebarid '.$sidebarid.' empty or not defined.';
148
+ //}
149
+ }
150
+
151
+ $output = '';
152
+ if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
153
+ //if ($debug) {
154
+ echo '<h2>Widget '.$widget.' not in sidebar with id '.$sidebarid.' and with name '.$sidebar.'</h2>';
155
+ //}
156
+ unset($sidebar);
157
+ unset($sidebarid);
158
+
159
+ }
160
+ else {
161
+ /* There may only be one but if we have two in our chosen widget then it will do both */
162
+ $output = '';
163
+ foreach ($wid as $i=>$widget_instance) {
164
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
165
+ shortcode_sidebar($widget_instance, $sidebar, $title);
166
+ $output .= ob_get_clean();
167
+ }
168
+
169
+ }
170
+
171
+ return ($output);
172
+ }
173
+ /*-----------------------------------*/
174
+ function amr_get_sidebar_name ($id) { /* dont need anymore ? or at least temporarily */
175
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
176
+ global $wp_registered_sidebars;
177
+ foreach ($wp_registered_sidebars as $i => $a) {
178
+ if ((isset ($a['id'])) and ( $a['id'] === $id)) {
179
+ if (isset($a['name'])) return ($a['name']);
180
+ else return ($id);
181
+ }
182
+ }
183
+ return (false);
184
+ }
185
+ /*-----------------------------------*/
186
+ function get_sidebar_id ($name) { /* dont need anymore ? or at least temporarily */
187
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
188
+ global $wp_registered_sidebars;
189
+ foreach ($wp_registered_sidebars as $i => $a) {
190
+ if ((isset ($a['name'])) and ( $a['name'] === $name)) return ($i);
191
+ }
192
+ return (false);
193
+ }
194
+ /* -------------------------------------------------------------------------*/
195
+ function shortcode_sidebar( $id, $index=1, $title=true) { /* This is basically the wordpress code, slightly modified */
196
+ global $wp_registered_sidebars, $wp_registered_widgets;
197
+
198
+ if (isset($_REQUEST['do_widget_debug']))
199
+ $debug=true;
200
+ else
201
+ $debug = false;
202
+
203
+ if ( is_int($index) ) {
204
+ $index = "sidebar-$index";
205
+ } else {
206
+ $index = sanitize_title($index);
207
+ foreach ( (array) $wp_registered_sidebars as $key => $value ) {
208
+ if ( sanitize_title($value['name']) == $index ) {
209
+ $index = $key;
210
+ break;
211
+ }
212
+ }
213
+ }
214
+
215
+ $sidebars_widgets = wp_get_sidebars_widgets();
216
+
217
+ if ($debug) {
218
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
219
+ foreach ($sidebars_widgets as $i=>$w) {
220
+ echo '<br />'.$w['name'].' '.$w['id'];
221
+ };
222
+ }
223
+
224
+
225
+ /* DONT NEED TO BE ACTIVE ? if there are no active widgets */
226
+ // if ( empty($wp_registered_sidebars[$index]) ||
227
+ // !array_key_exists($index, $sidebars_widgets) ||
228
+ // !is_array($sidebars_widgets[$index])
229
+ // || empty($sidebars_widgets[$index]) ) {
230
+ // echo '<br />'.'No active widgets for '.$index;
231
+ // return false;
232
+ // }
233
+
234
+ // $sidebar = $wp_registered_sidebars[$index];
235
+ $sidebar = array('wp_inactive_widgets');
236
+ $did_one = false;
237
+
238
+ // foreach ( (array) $sidebars_widgets[$index] as $id ) { /* lifted from wordpress code, keep as similar as possible for now */
239
+
240
+ if ( !isset($wp_registered_widgets[$id]) ) continue;
241
+
242
+ $params = array_merge(
243
+ array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
244
+ (array) $wp_registered_widgets[$id]['params']
245
+ );
246
+
247
+ // Substitute HTML id and class attributes into before_widget
248
+ $classname_ = '';
249
+ foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
250
+ if ( is_string($cn) )
251
+ $classname_ .= '_' . $cn;
252
+ elseif ( is_object($cn) )
253
+ $classname_ .= '_' . get_class($cn);
254
+ }
255
+ $classname_ = ltrim($classname_, '_');
256
+ if (!empty($params[0]['before_widget']))
257
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
258
+ else $params[0]['before_widget'] = '';
259
+ if (empty($params[0]['after_widget'])) $params[0]['after_widget'] = '';
260
+
261
+ $params = apply_filters( 'dynamic_sidebar_params', $params );
262
+
263
+ if (!$title) { /* amr switch off the title html, still need to get rid of title separately */
264
+ $params[0]['before_title'] = '<span style="display: none">';
265
+ $params[0]['after_title'] = '</span>';
266
+ }
267
+ else {
268
+ $params[0]['before_title'] = '<h2>';
269
+ $params[0]['after_title'] = '</h2>';
270
+ }
271
+
272
+ $callback = $wp_registered_widgets[$id]['callback'];
273
+ if ( is_callable($callback) ) {
274
+ call_user_func_array($callback, $params);
275
+ $did_one = true;
276
+ }
277
+ // }
278
+ return $did_one;
279
+ }
280
+ /* -------------------------------------------------------------------------------------------------------------*/
281
+ function amr_reg_sidebar() {
282
+ if ( function_exists('register_sidebar') )
283
+ register_sidebar(array('name'=>'Shortcodes',
284
+ 'id' => 'Shortcodes',
285
+ 'before_widget' => '<div id="%1$s" class="widget %2$s clearfix">',
286
+ 'after_widget' => '</div>',
287
+ 'before_title' => '<h2 class="widgettitle">',
288
+ 'after_title' => '</h2>' ));
289
+ }
290
+
291
+ include ('amr-admin-form-html.php');
292
+ if (is_admin() ) $amr_saw_plugin_admin = new amr_saw_plugin_admin();
293
+ add_action('admin_init', 'amr_reg_sidebar');
294
+
295
+ add_shortcode('do_widget', 'do_widget');
296
+
297
+
298
+ require_once(ABSPATH . 'wp-includes/widgets.php');
299
+
300
+ ?>
tags/1.6/readme.txt ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === amr shortcode any widget ===
2
+ Contributors: anmari
3
+ Tags: shortcode, widget, page, templates, page template
4
+ Tested up to: 3.8
5
+ Version: 1.6
6
+ Stable tag: trunk
7
+
8
+ == Description ==
9
+ This simple 'utility' plugin allows one to have any widget used in a page shortcode in any theme - no need to use the hybrid theme or create a special template. 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/)
10
+
11
+ 1. Test chosen widget works in normal sidebar first.
12
+ 2. Activate this plugin
13
+ 3. Go to Appearance > widgets and find "shortcode" sidebar
14
+ 4. Drag chosen widgets from configured sidebar to shortcodes sidebar. Save.
15
+ 5. Go to page where you want configured widget to appear
16
+ 6. enter one of:
17
+ [do_widget widgetname] eg: [do_widget calendar]
18
+ [do_widget "widget name"]. eg: [do_widget "tag cloud"]
19
+ [do_widget id=widgetid] in a page or post
20
+ 7. If the plugin cannot work out what you want, it will show a debug prompt. Click on the link 'Try debug'.
21
+ 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 nfo). Try with the 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.
22
+
23
+ Plugin has been tested with most standard widgets (rss feeds, tag cloud, pages, meta, search, and of course my own plugins widgets - upcoming events list, calendar and user lists.
24
+
25
+ If you use a widget more than once for different reasons, you may need to use the widget id to isolate which widget instance and it's settings to use. ie: [do_widget id=categories-6] . If you just use the name, it will display all widgets in the shortcode sidebar with that name (all instances).
26
+
27
+ If you liked this plugin, you might also like my other plugins:
28
+ [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)
29
+ [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/)
30
+
31
+
32
+ == Changelog ==
33
+ = Version 1.6 =
34
+ * Add: added a settings page to help people out (not really settings)
35
+ * Fix: changed a clashing function name
36
+
37
+ = Version 1.5 =
38
+ * Fixed: a small bug which caused a warning if you had not saved the widgets in your shortcode sidebar
39
+
40
+ = Version 1.4 =
41
+ * Updated readme - made very detailed steps and added some screen shots.
42
+ * Tested on wp 3.3.1 and fixed some notices when bad parameters entered.
43
+
44
+ = Version 1.3 =
45
+ * Added debug link and retested. Added readme.
46
+
47
+ = 1.12=
48
+ * Changed dummy shortcode sidebar so it appears after the theme sidebars to avoid taking over their widgets (this happened in numbered sidebars) PLEASE note if you have upgraded, you may appear to have "lost" your widgets due to this sidebar change. You have not - they will be in your "inactive widgets" - please drag them to the new sidebar. You may also find that you have 2 versions of the plugin, with slightly different folder names. This will allow you to go back to the previous one to check what you had there if you need to. Deactivate the old one and activate the new one. Move your widgets back in. Test then Delete the old one. In one theme it also appeared that somehow due to this change, one of the sidebar widgets "moved" down to another sidebar. I think that this may have had something to do with the fact that sidebars can be numbered or named, so please check all your sidebars before continuing. As always make sure thath you know how to restore from a backup before doing any upgrades of any kind.
49
+ * Tested in 2.9.2, can still use either the widget name "Categories" or id=categories-6. Note widget must have been created in the dummy shortcode sidebar.
50
+
51
+ = 1.1 =
52
+
53
+ * Allow for lowercase use of widget names for the those challenged by attention to detail!
54
+ * Cleaned up debug mode to make it easier for people to identify which instance of a widget they are using. Add &do_widget_debug to url string.
55
+
56
+ = 1.0 =
57
+ * Launch of the plugin
58
+
59
+ == Installation ==
60
+
61
+ 0. Activate plugin
62
+ 1. Goto Appearance > widgets and find "shortcode" sidebar
63
+ 1. Drag chosen widgets to shortcodes sidebar. Save. (note the names)
64
+ 2. Add [do_widget id=widgetid] in a page or post
65
+ 3. If it fails, click on the debug prompt and look for the id of your widget, use that.
66
+
67
+ 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"].
68
+
69
+ 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]
70
+
71
+
72
+ == Screenshots ==
73
+
74
+ 1. setting up widgets in page (must be in the shortcode sidebar)
75
+ 2. widgets in a page
76
+ 3. setting up widgets in the shortcode sidebar
77
+ 4. two rss feed widgets in shortcode sidebar - both will show if just name used
78
+ 5. Demonstration of two widgets being used via the do_widget short code.
79
+ 6. The Page or post with the do_widget shortcodes
80
+ 7. The shortcode sidebar. The widget's user interface (UI) is used to provide a UI for the do_widget shortcode.
81
+ 8. Debug prompt if one enters something like id=junk
82
+ 9. Debug messages - scroll down till you see the shortcodes sidebar - the widgets and their ids will be listed. Use the id of the widet you want.
83
+
tags/1.6/screenshot-1.jpg ADDED
Binary file
tags/1.6/screenshot-2.jpg ADDED
Binary file
tags/1.6/screenshot-3.jpg ADDED
Binary file
tags/1.6/screenshot-4.jpg ADDED
Binary file
tags/1.6/screenshot-5.png ADDED
Binary file
tags/1.6/screenshot-6.png ADDED
Binary file
tags/1.6/screenshot-7.png ADDED
Binary file
tags/1.6/screenshot-8.jpg ADDED
Binary file
tags/1.6/screenshot-9.jpg ADDED
Binary file
tags/1.7/amr-admin-form-html.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Backend Class for use in all amr plugins
4
+ * Version 0.1
5
+ */
6
+
7
+ //------------------------------------------------------------------------------------------------------------------
8
+ if (!class_exists('amr_saw_plugin_admin')) {
9
+ class amr_saw_plugin_admin {
10
+ var $hook = 'amr_saw';
11
+ var $filename = 'amr_shortcode_any_widget/amr_shortcode_any_widget.php';
12
+ var $longname = 'Shortcode any widget';
13
+ var $shortname = 'Shortcode any widget';
14
+ var $optionname = '';
15
+ var $homepage = '';
16
+ var $parent_slug = 'plugin_listings_menu';
17
+ var $accesslvl = 'manage_options';
18
+
19
+ function amr_saw_plugin_admin() {
20
+ add_action('admin_menu', array(&$this, 'register_settings_page') );
21
+ add_filter('plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
22
+ }
23
+ function register_settings_page() {
24
+ add_options_page( $this->longname, $this->shortname, $this->accesslvl, $this->hook, array(&$this,'config_page'));
25
+ }
26
+ function plugin_options_url() {
27
+ return admin_url( 'options-general.php?page='.$this->hook );
28
+ }
29
+ /**
30
+ * Add a link to the settings page to the plugins list
31
+ */
32
+ function add_action_link( $links, $file ) {
33
+ static $this_plugin;
34
+ if( empty($this_plugin) )
35
+ $this_plugin = $this->filename;
36
+ if ( $file == $this_plugin ) {
37
+ $settings_link = '<a href="' . $this->plugin_options_url() . '">' . __('Settings') . '</a>';
38
+ array_unshift( $links, $settings_link );
39
+ }
40
+ return $links;
41
+ }
42
+
43
+ function admin_heading($title) {
44
+ echo '<div class="wrap" >
45
+ <div id="icon-options-general" class="icon32"><br />
46
+ </div>
47
+ <h2>'.$title.' </h2>';
48
+ // <form method="post" action="'
49
+ // .esc_url($_SERVER['PHP_SELF'])
50
+ // .'">';
51
+ // wp_nonce_field($this->hook); /* outputs hidden field */
52
+ // ;
53
+ }
54
+
55
+ function admin_subheading($title) {
56
+ echo '<h2>'.$title.'</h2>';
57
+ }
58
+ function config_page() {
59
+ $this->admin_heading($this->longname);
60
+ echo '<ul>';
61
+ echo '<li>';
62
+ _e('Drag the widgets you want to use to the shortcodes sidebar.');
63
+
64
+ echo '</li>';
65
+ echo '<li>';
66
+ _e('Set the widgets parameters if there are any.');
67
+ echo '</li>';
68
+ echo '<li>';
69
+ _e('You could test them out in a displayable sidebar, then drag them to the shortcodes sidebar.');
70
+
71
+ echo '</li>';
72
+ echo '<li>';
73
+ echo '<a title="Go to widget area" href="'.get_admin_url('','widgets.php').'"> ';
74
+ _e('Go to widgets');
75
+ echo '</a>';
76
+ echo '</li>';
77
+ echo '<li>';
78
+ _e('Then add the shortcode [do_widget widgetname] to a page.');
79
+ echo '</li>';
80
+ echo '<li>';
81
+ _e('Examples:[do_widget "tag cloud"] or [do_widget id=widgetid]');
82
+ echo '</li>';
83
+ echo '<li>';
84
+ echo '<a title="Create a page" href="'
85
+ .add_query_arg('content','[do_widget Archives]', get_admin_url('','post-new.php?post_type=page'))
86
+ .'"> ';
87
+ _e('Create the page');
88
+ echo '</a>';
89
+ echo '</li>';
90
+ echo '<li>';
91
+ echo 'You can add as many of these on one page as you like. Use title=false to switch off the title.';
92
+ echo '</li>';
93
+ echo '<li>';
94
+ echo '[do_widget pages title=false]';
95
+ echo '</li>';
96
+ echo '<li>';
97
+ echo '[do_widget categories]';
98
+ echo '</li>';
99
+ echo '<li>';
100
+ echo '[do_widget "tag cloud"]';
101
+ echo '</li>';
102
+ echo '<li>';
103
+ echo '[do_widget "recent posts"]';
104
+ echo '</li>';
105
+ echo '<li>';
106
+ echo '<li>';
107
+ echo 'If the plugin cannot work out what you want, it will show a debug prompt
108
+ , click on the debug prompt and look for the name or id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug info). If the name does not work, try with the 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.';
109
+ echo '</li>';
110
+ echo '<li>';
111
+ echo '</ul>';
112
+ }
113
+
114
+
115
+
116
+ /**
117
+ * Create a Checkbox input field
118
+ */
119
+ function radiobutton($id, $label, $value, $selected) {
120
+ $sel = checked($value,$selected, false);
121
+ return "<input type='radio' id='".$id."' name='".$id."' value='".$value."'"
122
+ . $sel."/>&nbsp;".$label."<br />";
123
+ }
124
+ /**
125
+ * Create a Checkbox input field
126
+ */
127
+ function checkbox($id, $label, $value) {
128
+ return '<input type="checkbox" id="'.$id.'" name="'.$id.'"'. checked($value,true,false).'/>&nbsp;<label for="'.$id.'">'.$label.'</label><br/>';
129
+ }
130
+ /**
131
+ * Create a Dropdown input field
132
+ */
133
+ function dropdown($id, $label, $options, $selected) {
134
+ //
135
+ $html = '<label for="'.$id.'">'.$label.':</label><br/>'
136
+ .'<select id=\''.$id.'\' name=\''.$id.'\'>';
137
+ foreach ($options as $i => $option) {
138
+ //
139
+ $sel = selected($i, $selected, false); //wordpress function returns with single quotes, not double
140
+ $html .= '<OPTION '.$sel.' label=\''.$option.'\' value=\''.$i.'\'>'.$option.'</OPTION>';
141
+ }
142
+ $html .= '</select>';
143
+ return ($html);
144
+ }
145
+ /**
146
+ * Create a Text input field
147
+ */
148
+ function textinput($id, $label, $value, $length='45') {
149
+ return '<label for="'.$id.'">'.$label.':</label><br/><input size="'
150
+ .$length.'" type="text" id="'.$id.'" name="'.$id.'" value="'.$value.'"/><br/><br/>';
151
+ }
152
+ /**
153
+ * Create a Text area field
154
+ */
155
+ function textarea($id, $label, $value, $cols='45', $rows='10') {
156
+ return '<label for="'.$id.'">'.$label.':</label><br/>'
157
+ .'<textarea rows="'.$rows.'" cols="'.$cols
158
+ .'" id="'.$id.'" name="'.$id.'"/>'.$value.'</TEXTAREA><br/><br/>';
159
+ }
160
+ /**
161
+ * Create a postbox widget
162
+ */
163
+ function postbox($id, $title, $content) {
164
+ ?>
165
+ <div id="<?php echo $id; ?>" class="postbox">
166
+ <div class="handlediv" title="Click to toggle"><br /></div>
167
+ <h3 class="hndle"><span><?php echo $title; ?></span></h3>
168
+ <div class="inside">
169
+ <?php echo $content; ?>
170
+ </div>
171
+ </div>
172
+ <?php
173
+ }
174
+ /**
175
+ * Create a form table from an array of rows
176
+ */
177
+ function form_table($rows) { // array of rows () id, label, desc, content
178
+ $content = '<table class="form-table">';
179
+ foreach ($rows as $row) {
180
+ $content .= '<tr><th valign="top" scrope="row">';
181
+ if (isset($row['id']) && $row['id'] != '')
182
+ $content .= '<label for="'.$row['id'].'">'.$row['label'].':</label>';
183
+ else
184
+ $content .= $row['label'];
185
+ if (isset($row['desc']) && $row['desc'] != '')
186
+ $content .= '<br/><small>'.$row['desc'].'</small>';
187
+ $content .= '</th><td valign="top">';
188
+ $content .= $row['content'];
189
+ $content .= '</td></tr>';
190
+ }
191
+ $content .= '</table>';
192
+ return $content;
193
+ }
194
+
195
+ /**
196
+ * Info box with link to the support forums.
197
+ */
198
+ function plugin_support() {
199
+ $content = '<p>'.__('If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the','amrplugin').' <a href="http://wordpress.org/tags/'.$this->hook.'">'.__("Support forums",'amrplugin').'</a>.</p>';
200
+ $this->postbox($this->hook.'support', 'Need support?', $content);
201
+ }
202
+
203
+ function text_limit( $text, $limit, $finish = ' [&hellip;]') {
204
+ if( strlen( $text ) > $limit ) {
205
+ $text = substr( $text, 0, $limit );
206
+ $text = substr( $text, 0, - ( strlen( strrchr( $text,' ') ) ) );
207
+ $text .= $finish;
208
+ }
209
+ return $text;
210
+ }
211
+ }
212
+ }
213
+
214
+ ?>
tags/1.7/amr-shortcode-any-widget.php ADDED
@@ -0,0 +1,316 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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" ]. If upgrading see changelog. Can be very powerful eg: with queryposts widget it can become a templater.
6
+ Author: anmari
7
+ Version: 1.7
8
+ Author URI: http://webdesign.anmari.com
9
+
10
+ */
11
+
12
+ /*-----------------------------------*/
13
+ function do_widget($atts) {
14
+
15
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
16
+
17
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
18
+ if it is in, then get the instance data and use that */
19
+
20
+ if (isset($_wp_sidebars_widgets) ) {
21
+ amr_show_widget_debug('which one'); //check for debug prompt and show widgets in shortcode sidebar if requested and logged in etc
22
+ }
23
+ else {
24
+ echo '<br />No widgets defined at all in any sidebar!';
25
+ return (false);
26
+ }
27
+
28
+ extract(shortcode_atts(array(
29
+ 'sidebar' => 'Shortcodes',
30
+ 'id' => '',
31
+ 'title' => 'true' /* do the default title unless they ask us not to - use string here not boolean */
32
+ ), $atts));
33
+
34
+
35
+
36
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
37
+ if (!empty($atts[0])) { // we have a name
38
+ $widget = $atts[0];
39
+
40
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
41
+ if (strtolower($w['name']) === strtolower($widget)) $widget_ids[] = $i;
42
+ //if ($debug) {echo '<br /> Check: '.$w['name'];}
43
+ }
44
+
45
+ }
46
+ else { /* check for id if we do not have a name */
47
+ if (!empty($id)) { /* if a specific id has been specified */
48
+
49
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
50
+ if ($w['id'] === $id) $widget_ids[] = $id;
51
+ }
52
+ //if ($debug) { echo '<h2>We have an id: '.$id.'</h2>'; if (!empty($widget_ids)) var_dump($widget_ids); }
53
+ }
54
+ else {
55
+ echo '<br />No valid widget name or id given in shortcode parameters';
56
+ return (false);
57
+ }
58
+ }
59
+
60
+ if (empty ($widget_ids)) {
61
+ echo '<p><b>Requested widget not found in widget list.';
62
+ amr_show_widget_debug('empty', $atts);
63
+ return (false) ;
64
+ }
65
+
66
+ if ($title == 'false')
67
+ $title = false; /* If ask not to display title, then do not */
68
+ else
69
+ $title = true;
70
+
71
+ if (!($sidebarid = get_sidebar_id ($sidebar)))
72
+ $sidebarid=$sidebar; /* get the official sidebar id - will take the first one */
73
+
74
+ if (empty($widget))
75
+ $widget = '';
76
+ /* if ($debug) {
77
+ echo '<hr>Looking for widget with name:'.$widget.' or id='.$id.' Found instances:'.' <br />';
78
+ if (!empty($widget_ids)) foreach ($widget_ids as $i=> $w) {
79
+ echo $w.'<br />';
80
+ };
81
+ }
82
+ */
83
+ $content = '';
84
+ /* if the widget is in our chosen sidebar, then use the options stored for that */
85
+
86
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
87
+ /* if ($debug) {
88
+ echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
89
+ sort ($_wp_sidebars_widgets[$sidebarid]);
90
+ foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
91
+ echo $i.' '.$w.'<br />';
92
+ };
93
+ }
94
+ */
95
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
96
+
97
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
98
+ /* if ($debug) { echo '<br />Will use widget ids'.'<br />';
99
+ foreach ($widget_ids as $i=> $w) {
100
+ echo '&nbsp;&nbsp;&nbsp;'.$w.'<br />';
101
+ };
102
+ }
103
+ */
104
+ }
105
+ else { /* the sidebar is not defined */
106
+ //if ($debug) {
107
+ echo '<br />Sidebar '.$sidebar.'with sidebarid '.$sidebarid.' is empty or not defined.';
108
+ //}
109
+ }
110
+
111
+ $output = '';
112
+ if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
113
+ //if ($debug) {
114
+ echo '<h2>Widget '.$widget.' not in sidebar with id '.$sidebarid.' and with name '.$sidebar.'</h2>';
115
+ //}
116
+ unset($sidebar);
117
+ unset($sidebarid);
118
+
119
+ }
120
+ else {
121
+ /* There may only be one but if we have two in our chosen widget then it will do both */
122
+ $output = '';
123
+ foreach ($wid as $i=>$widget_instance) {
124
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
125
+ shortcode_sidebar($widget_instance, $sidebar, $title);
126
+ $output .= ob_get_clean();
127
+ }
128
+
129
+ }
130
+
131
+ return ($output);
132
+ }
133
+ /*-----------------------------------*/
134
+ function amr_get_sidebar_name ($id) { /* dont need anymore ? or at least temporarily */
135
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
136
+ global $wp_registered_sidebars;
137
+ foreach ($wp_registered_sidebars as $i => $a) {
138
+ if ((isset ($a['id'])) and ( $a['id'] === $id)) {
139
+ if (isset($a['name'])) return ($a['name']);
140
+ else return ($id);
141
+ }
142
+ }
143
+ return (false);
144
+ }
145
+ /*-----------------------------------*/
146
+ function get_sidebar_id ($name) { /* dont need anymore ? or at least temporarily */
147
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
148
+ global $wp_registered_sidebars;
149
+ foreach ($wp_registered_sidebars as $i => $a) {
150
+ if ((isset ($a['name'])) and ( $a['name'] === $name)) return ($i);
151
+ }
152
+ return (false);
153
+ }
154
+ /* -------------------------------------------------------------------------*/
155
+ function shortcode_sidebar( $id, $index=1, $title=true) { /* This is basically the wordpress code, slightly modified */
156
+ global $wp_registered_sidebars, $wp_registered_widgets;
157
+
158
+ $debug = amr_check_if_widget_debug();
159
+
160
+ if ( is_int($index) ) {
161
+ $index = "sidebar-$index";
162
+ } else {
163
+ $index = sanitize_title($index);
164
+ foreach ( (array) $wp_registered_sidebars as $key => $value ) {
165
+ if ( sanitize_title($value['name']) == $index ) {
166
+ $index = $key;
167
+ break;
168
+ }
169
+ }
170
+ }
171
+
172
+ $sidebars_widgets = wp_get_sidebars_widgets();
173
+
174
+ /* if ($debug) {
175
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
176
+ foreach ($sidebars_widgets as $i=>$w) {
177
+ echo '<br />'.$w['name'].' '.$w['id'];
178
+ };
179
+ }
180
+ */
181
+
182
+ /* DONT NEED TO BE ACTIVE ? if there are no active widgets */
183
+ // if ( empty($wp_registered_sidebars[$index]) ||
184
+ // !array_key_exists($index, $sidebars_widgets) ||
185
+ // !is_array($sidebars_widgets[$index])
186
+ // || empty($sidebars_widgets[$index]) ) {
187
+ // echo '<br />'.'No active widgets for '.$index;
188
+ // return false;
189
+ // }
190
+
191
+ // $sidebar = $wp_registered_sidebars[$index];
192
+ $sidebar = array('wp_inactive_widgets');
193
+ $did_one = false;
194
+
195
+ // foreach ( (array) $sidebars_widgets[$index] as $id ) { /* lifted from wordpress code, keep as similar as possible for now */
196
+
197
+ if ( !isset($wp_registered_widgets[$id]) ) continue;
198
+
199
+ $params = array_merge(
200
+ array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
201
+ (array) $wp_registered_widgets[$id]['params']
202
+ );
203
+
204
+ // Substitute HTML id and class attributes into before_widget
205
+ $classname_ = '';
206
+ foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
207
+ if ( is_string($cn) )
208
+ $classname_ .= '_' . $cn;
209
+ elseif ( is_object($cn) )
210
+ $classname_ .= '_' . get_class($cn);
211
+ }
212
+ $classname_ = ltrim($classname_, '_');
213
+ if (!empty($params[0]['before_widget']))
214
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
215
+ else $params[0]['before_widget'] = '';
216
+ if (empty($params[0]['after_widget'])) $params[0]['after_widget'] = '';
217
+
218
+ $params = apply_filters( 'dynamic_sidebar_params', $params );
219
+
220
+ if (!$title) { /* amr switch off the title html, still need to get rid of title separately */
221
+ $params[0]['before_title'] = '<span style="display: none">';
222
+ $params[0]['after_title'] = '</span>';
223
+ }
224
+ else {
225
+ $params[0]['before_title'] = '<h2>';
226
+ $params[0]['after_title'] = '</h2>';
227
+ }
228
+
229
+ $callback = $wp_registered_widgets[$id]['callback'];
230
+ if ( is_callable($callback) ) {
231
+ call_user_func_array($callback, $params);
232
+ $did_one = true;
233
+ }
234
+ // }
235
+ return $did_one;
236
+ }
237
+ /* -------------------------------------------------------------------------------------------------------------*/
238
+ function amr_reg_sidebar() {
239
+ if ( function_exists('register_sidebar') )
240
+ register_sidebar(array('name'=>'Shortcodes',
241
+ 'id' => 'Shortcodes',
242
+ 'before_widget' => '<div id="%1$s" class="widget %2$s clearfix">',
243
+ 'after_widget' => '</div>',
244
+ 'before_title' => '<h2 class="widgettitle">',
245
+ 'after_title' => '</h2>' ));
246
+ }
247
+ /*-----------------------------------*/
248
+ function amr_check_if_widget_debug() {
249
+ // only do these debug if we are logged in and are the administrator
250
+
251
+ if ((!is_user_logged_in()) or (!current_user_can('administrator')))
252
+ return false;
253
+
254
+ if (isset($_REQUEST['do_widget_debug'])) {
255
+ echo '<br/>Note: Debugs only shown to a Logged in Administrator.<br />';
256
+ return true;
257
+ }
258
+ else
259
+ return false;
260
+ }
261
+ /*-----------------------------------*/
262
+ function amr_show_widget_debug($type='', $atts=array()) {
263
+ global $wp_registered_sidebars, $wp_registered_widgets,$_wp_sidebars_widgets;
264
+ // only do these debug if we are logged in and are the administrator
265
+
266
+ $debug = amr_check_if_widget_debug();
267
+
268
+ if ($type=='empty') {
269
+ if (current_user_can('administrator')) echo '<br />You are admin: <a href="'.add_query_arg('do_widget_debug','1').'">Try debug</a></b></p>';
270
+
271
+ if ($debug) {
272
+
273
+ echo '<h2>As a last resort, dump the wp variables </h2>';
274
+ $sidebars_widgets = wp_get_sidebars_widgets();
275
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
276
+ foreach ($sidebars_widgets as $i=>$w) {
277
+ echo '<br/>'.$i; var_dump($w);
278
+ };
279
+
280
+ echo '<h3>$_wp_sidebars_widgets:</h3>';
281
+ var_dump($_wp_sidebars_widgets);
282
+ echo '<br /><h3>$wp_registered_widgets:</h3>';
283
+ var_dump($wp_registered_widgets);
284
+ }
285
+ }
286
+
287
+ if (($type=='which one') and ($debug)) {
288
+ echo '<h3>DEBUG on: Please scroll down till you find the shortcodes sidebar.</h3>';
289
+ echo '<br />Attributes entered:<br />';
290
+ var_dump($atts);
291
+ echo '<br />Shortcode sidebar and widgets<br />';
292
+ foreach ($_wp_sidebars_widgets as $i=> $w) {
293
+ if (($i == "Shortcodes")) {
294
+ echo 'Sidebar:&nbsp;<b>'.$i.': '.amr_get_sidebar_name($i).'</b><br />';
295
+ if (is_array($w)) {
296
+ sort ($w);
297
+ foreach ($w as $i2=> $w2) {
298
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$w2.' <br />';
299
+ };
300
+ }
301
+ echo '<br />';
302
+ }
303
+ };
304
+ }
305
+ }
306
+ /*-----------------------------------*/
307
+ include ('amr-admin-form-html.php');
308
+ if (is_admin() ) $amr_saw_plugin_admin = new amr_saw_plugin_admin();
309
+ add_action('admin_init', 'amr_reg_sidebar');
310
+
311
+ add_shortcode('do_widget', 'do_widget');
312
+
313
+
314
+ require_once(ABSPATH . 'wp-includes/widgets.php');
315
+
316
+ ?>
tags/1.7/amr_shortcode_any_widget.php ADDED
@@ -0,0 +1,300 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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" ]. If upgrading see changelog. Can be very powerful eg: with queryposts widget it can become a templater.
6
+ Author: anmari
7
+ Version: 1.6
8
+ Author URI: http://webdesign.anmari.com
9
+
10
+ */
11
+
12
+
13
+ /*-----------------------------------*/
14
+ function do_widget($atts) {
15
+
16
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
17
+
18
+
19
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
20
+ if it is in, then get the instance data and use that */
21
+ if (isset($_REQUEST['do_widget_debug'])) $debug=true;
22
+ else $debug = false;
23
+
24
+ if (isset($_wp_sidebars_widgets) ) {
25
+ if ($debug) {
26
+ echo '<h3>DEBUG on: Please scroll down till you find the shortcodes sidebar.</h3>';
27
+ echo '<br />Attributes entered:<br />';
28
+ var_dump($atts);
29
+ echo '<br />Available sidebars and widgets<br />';
30
+ foreach ($_wp_sidebars_widgets as $i=> $w) {
31
+ echo 'Sidebar:&nbsp;<b>'.$i.': '.amr_get_sidebar_name($i).'</b><br />';
32
+ if (is_array($w)) {
33
+ sort ($w);
34
+ foreach ($w as $i2=> $w2) {
35
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$w2.' <br />';
36
+ };
37
+ }
38
+ echo '<br />';
39
+ };
40
+ }
41
+ }
42
+ else { //if ($debug) {
43
+ echo '<br />No widgets defined at all';
44
+ //}
45
+ return (false);
46
+ }
47
+
48
+ extract(shortcode_atts(array(
49
+ 'sidebar' => 'Shortcodes',
50
+ 'id' => '',
51
+ 'title' => 'true' /* do the default title unless they ask us not to - use string here not boolean */
52
+ ), $atts));
53
+
54
+
55
+
56
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
57
+ if (!empty($atts[0])) {
58
+ if ($debug) {
59
+ echo 'We have a name';
60
+ print_r($atts[0]);
61
+ //var_dump($wp_registered_widgets);
62
+ }
63
+ $widget = $atts[0];
64
+
65
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
66
+ if (strtolower($w['name']) === strtolower($widget)) $widget_ids[] = $i;
67
+ if ($debug) {echo '<br /> Check: '.$w['name'];}
68
+ }
69
+
70
+
71
+ }
72
+ else { /* check for id if we do not have a name */
73
+ if (!empty($id)) { /* if a specific id has been specified */
74
+
75
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
76
+ if ($w['id'] === $id) $widget_ids[] = $id;
77
+ }
78
+ if ($debug) {
79
+ echo '<h2>We have an id: '.$id.'</h2>';
80
+ if (!empty($widget_ids)) var_dump($widget_ids);
81
+ }
82
+ }
83
+ else {
84
+ if ($debug) { echo 'No valid widget name or id given';}
85
+ return (false);
86
+
87
+ }
88
+ }
89
+
90
+ if (empty ($widget_ids)) {
91
+
92
+ echo '<p><b>Widget not found in widget list.'
93
+ .' <a href="'.add_query_arg('do_widget_debug','1').'">Try debug</a></b></p>';
94
+ if ($debug) {
95
+ echo '<h2>As a last resort, dump the wp variables </h2>';
96
+ $sidebars_widgets = wp_get_sidebars_widgets();
97
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
98
+ foreach ($sidebars_widgets as $i=>$w) {
99
+ echo '<br/>'.$i; var_dump($w);
100
+ };
101
+
102
+ echo '<h3>$_wp_sidebars_widgets:</h3>';
103
+ var_dump($_wp_sidebars_widgets);
104
+ echo '<br /><h3>$wp_registered_widgets:</h3>';
105
+ var_dump($wp_registered_widgets);
106
+ }
107
+ return (false) ;
108
+ }
109
+
110
+ if ($title == 'false')
111
+ $title = false; /* If ask not to display title, then do not */
112
+ else
113
+ $title = true;
114
+
115
+ if (!($sidebarid = get_sidebar_id ($sidebar)))
116
+ $sidebarid=$sidebar; /* get the official sidebar id - will take the first one */
117
+
118
+ if ($debug) {
119
+ if (empty($widget)) $widget = '';
120
+ echo '<hr>Looking for widget with name:'.$widget.' or id='.$id.' Found instances:'.' <br />';
121
+ if (!empty($widget_ids)) foreach ($widget_ids as $i=> $w) {
122
+ echo $w.'<br />';
123
+ };
124
+ }
125
+ $content = '';
126
+ /* if the widget is in our chosen sidebar, then use the otions stored for that */
127
+
128
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
129
+ if ($debug) {
130
+ echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
131
+ sort ($_wp_sidebars_widgets[$sidebarid]);
132
+ foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
133
+ echo $i.' '.$w.'<br />';
134
+ };
135
+ }
136
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
137
+
138
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
139
+ if ($debug) { echo '<br />Will use widget ids'.'<br />';
140
+ foreach ($widget_ids as $i=> $w) {
141
+ echo '&nbsp;&nbsp;&nbsp;'.$w.'<br />';
142
+ };
143
+ }
144
+ }
145
+ else { /* the sidebar is not defined */
146
+ //if ($debug) {
147
+ echo '<br />Sidebar '.$sidebar.'with sidebarid '.$sidebarid.' empty or not defined.';
148
+ //}
149
+ }
150
+
151
+ $output = '';
152
+ if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
153
+ //if ($debug) {
154
+ echo '<h2>Widget '.$widget.' not in sidebar with id '.$sidebarid.' and with name '.$sidebar.'</h2>';
155
+ //}
156
+ unset($sidebar);
157
+ unset($sidebarid);
158
+
159
+ }
160
+ else {
161
+ /* There may only be one but if we have two in our chosen widget then it will do both */
162
+ $output = '';
163
+ foreach ($wid as $i=>$widget_instance) {
164
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
165
+ shortcode_sidebar($widget_instance, $sidebar, $title);
166
+ $output .= ob_get_clean();
167
+ }
168
+
169
+ }
170
+
171
+ return ($output);
172
+ }
173
+ /*-----------------------------------*/
174
+ function amr_get_sidebar_name ($id) { /* dont need anymore ? or at least temporarily */
175
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
176
+ global $wp_registered_sidebars;
177
+ foreach ($wp_registered_sidebars as $i => $a) {
178
+ if ((isset ($a['id'])) and ( $a['id'] === $id)) {
179
+ if (isset($a['name'])) return ($a['name']);
180
+ else return ($id);
181
+ }
182
+ }
183
+ return (false);
184
+ }
185
+ /*-----------------------------------*/
186
+ function get_sidebar_id ($name) { /* dont need anymore ? or at least temporarily */
187
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
188
+ global $wp_registered_sidebars;
189
+ foreach ($wp_registered_sidebars as $i => $a) {
190
+ if ((isset ($a['name'])) and ( $a['name'] === $name)) return ($i);
191
+ }
192
+ return (false);
193
+ }
194
+ /* -------------------------------------------------------------------------*/
195
+ function shortcode_sidebar( $id, $index=1, $title=true) { /* This is basically the wordpress code, slightly modified */
196
+ global $wp_registered_sidebars, $wp_registered_widgets;
197
+
198
+ if (isset($_REQUEST['do_widget_debug']))
199
+ $debug=true;
200
+ else
201
+ $debug = false;
202
+
203
+ if ( is_int($index) ) {
204
+ $index = "sidebar-$index";
205
+ } else {
206
+ $index = sanitize_title($index);
207
+ foreach ( (array) $wp_registered_sidebars as $key => $value ) {
208
+ if ( sanitize_title($value['name']) == $index ) {
209
+ $index = $key;
210
+ break;
211
+ }
212
+ }
213
+ }
214
+
215
+ $sidebars_widgets = wp_get_sidebars_widgets();
216
+
217
+ if ($debug) {
218
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
219
+ foreach ($sidebars_widgets as $i=>$w) {
220
+ echo '<br />'.$w['name'].' '.$w['id'];
221
+ };
222
+ }
223
+
224
+
225
+ /* DONT NEED TO BE ACTIVE ? if there are no active widgets */
226
+ // if ( empty($wp_registered_sidebars[$index]) ||
227
+ // !array_key_exists($index, $sidebars_widgets) ||
228
+ // !is_array($sidebars_widgets[$index])
229
+ // || empty($sidebars_widgets[$index]) ) {
230
+ // echo '<br />'.'No active widgets for '.$index;
231
+ // return false;
232
+ // }
233
+
234
+ // $sidebar = $wp_registered_sidebars[$index];
235
+ $sidebar = array('wp_inactive_widgets');
236
+ $did_one = false;
237
+
238
+ // foreach ( (array) $sidebars_widgets[$index] as $id ) { /* lifted from wordpress code, keep as similar as possible for now */
239
+
240
+ if ( !isset($wp_registered_widgets[$id]) ) continue;
241
+
242
+ $params = array_merge(
243
+ array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
244
+ (array) $wp_registered_widgets[$id]['params']
245
+ );
246
+
247
+ // Substitute HTML id and class attributes into before_widget
248
+ $classname_ = '';
249
+ foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
250
+ if ( is_string($cn) )
251
+ $classname_ .= '_' . $cn;
252
+ elseif ( is_object($cn) )
253
+ $classname_ .= '_' . get_class($cn);
254
+ }
255
+ $classname_ = ltrim($classname_, '_');
256
+ if (!empty($params[0]['before_widget']))
257
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
258
+ else $params[0]['before_widget'] = '';
259
+ if (empty($params[0]['after_widget'])) $params[0]['after_widget'] = '';
260
+
261
+ $params = apply_filters( 'dynamic_sidebar_params', $params );
262
+
263
+ if (!$title) { /* amr switch off the title html, still need to get rid of title separately */
264
+ $params[0]['before_title'] = '<span style="display: none">';
265
+ $params[0]['after_title'] = '</span>';
266
+ }
267
+ else {
268
+ $params[0]['before_title'] = '<h2>';
269
+ $params[0]['after_title'] = '</h2>';
270
+ }
271
+
272
+ $callback = $wp_registered_widgets[$id]['callback'];
273
+ if ( is_callable($callback) ) {
274
+ call_user_func_array($callback, $params);
275
+ $did_one = true;
276
+ }
277
+ // }
278
+ return $did_one;
279
+ }
280
+ /* -------------------------------------------------------------------------------------------------------------*/
281
+ function amr_reg_sidebar() {
282
+ if ( function_exists('register_sidebar') )
283
+ register_sidebar(array('name'=>'Shortcodes',
284
+ 'id' => 'Shortcodes',
285
+ 'before_widget' => '<div id="%1$s" class="widget %2$s clearfix">',
286
+ 'after_widget' => '</div>',
287
+ 'before_title' => '<h2 class="widgettitle">',
288
+ 'after_title' => '</h2>' ));
289
+ }
290
+
291
+ include ('amr-admin-form-html.php');
292
+ if (is_admin() ) $amr_saw_plugin_admin = new amr_saw_plugin_admin();
293
+ add_action('admin_init', 'amr_reg_sidebar');
294
+
295
+ add_shortcode('do_widget', 'do_widget');
296
+
297
+
298
+ require_once(ABSPATH . 'wp-includes/widgets.php');
299
+
300
+ ?>
tags/1.7/readme.txt ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === amr shortcode any widget ===
2
+ Contributors: anmari
3
+ Tags: shortcode, widget, page, templates, page template
4
+ Tested up to: 3.8.1
5
+ Version: 1.7
6
+ Stable tag: trunk
7
+
8
+ == Description ==
9
+ This simple 'utility' plugin allows one to have any widget used in a page shortcode in any theme - no need to use the hybrid theme or create a special template. 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/)
10
+
11
+ 1. Test chosen widget works in normal sidebar first.
12
+ 2. Activate this plugin
13
+ 3. Go to Appearance > widgets and find "shortcode" sidebar
14
+ 4. Drag chosen widgets from configured sidebar to shortcodes sidebar. Save.
15
+ 5. Go to page where you want configured widget to appear
16
+ 6. enter one of:
17
+ [do_widget widgetname] eg: [do_widget calendar]
18
+ [do_widget "widget name"]. eg: [do_widget "tag cloud"]
19
+ [do_widget id=widgetid] in a page or post
20
+ 7. If the plugin cannot work out what you want and you are logged in as an adminsitrator, it will show a debug prompt to you only.
21
+ Click on the link 'Try debug'.
22
+ 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 wusing 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.
23
+
24
+ Plugin has been tested with most standard widgets (rss feeds, tag cloud, pages, meta, search, and of course my own plugins widgets - upcoming events list, calendar and user lists.
25
+
26
+ If you use a widget more than once for different reasons, you may need to use the widget id to isolate which widget instance and it's settings to use. ie: [do_widget id=categories-6] . If you just use the name, it will display all widgets in the shortcode sidebar with that name (all instances).
27
+
28
+ If you liked this plugin, you might also like my other plugins:
29
+ [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)
30
+ [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/)
31
+
32
+
33
+ == Changelog ==
34
+ = Version 1.7 =
35
+ * Change: Changed so that debugs and debug prompt will only show to a logged in administrator.
36
+
37
+
38
+ = Version 1.6 =
39
+ * Add: added a settings page to help people out (not really settings)
40
+ * Fix: changed a clashing function name
41
+
42
+ = Version 1.5 =
43
+ * Fixed: a small bug which caused a warning if you had not saved the widgets in your shortcode sidebar
44
+
45
+ = Version 1.4 =
46
+ * Updated readme - made very detailed steps and added some screen shots.
47
+ * Tested on wp 3.3.1 and fixed some notices when bad parameters entered.
48
+
49
+ = Version 1.3 =
50
+ * Added debug link and retested. Added readme.
51
+
52
+ = 1.12=
53
+ * Changed dummy shortcode sidebar so it appears after the theme sidebars to avoid taking over their widgets (this happened in numbered sidebars) PLEASE note if you have upgraded, you may appear to have "lost" your widgets due to this sidebar change. You have not - they will be in your "inactive widgets" - please drag them to the new sidebar. You may also find that you have 2 versions of the plugin, with slightly different folder names. This will allow you to go back to the previous one to check what you had there if you need to. Deactivate the old one and activate the new one. Move your widgets back in. Test then Delete the old one. In one theme it also appeared that somehow due to this change, one of the sidebar widgets "moved" down to another sidebar. I think that this may have had something to do with the fact that sidebars can be numbered or named, so please check all your sidebars before continuing. As always make sure thath you know how to restore from a backup before doing any upgrades of any kind.
54
+ * Tested in 2.9.2, can still use either the widget name "Categories" or id=categories-6. Note widget must have been created in the dummy shortcode sidebar.
55
+
56
+ = 1.1 =
57
+
58
+ * Allow for lowercase use of widget names for the those challenged by attention to detail!
59
+ * Cleaned up debug mode to make it easier for people to identify which instance of a widget they are using. Add &do_widget_debug to url string.
60
+
61
+ = 1.0 =
62
+ * Launch of the plugin
63
+
64
+ == Installation ==
65
+
66
+ 0. Activate plugin
67
+ 1. Goto Appearance > widgets and find "shortcode" sidebar
68
+ 1. Drag chosen widgets to shortcodes sidebar. Save. (note the names)
69
+ 2. Add [do_widget id=widgetid] in a page or post
70
+ 3. If it fails, click on the debug prompt and look for the id of your widget, use that.
71
+
72
+ 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"].
73
+
74
+ 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]
75
+
76
+
77
+ == Screenshots ==
78
+
79
+ 1. setting up widgets in page (must be in the shortcode sidebar)
80
+ 2. widgets in a page
81
+ 3. setting up widgets in the shortcode sidebar
82
+ 4. two rss feed widgets in shortcode sidebar - both will show if just name used
83
+ 5. Demonstration of two widgets being used via the do_widget short code.
84
+ 6. The Page or post with the do_widget shortcodes
85
+ 7. The shortcode sidebar. The widget's user interface (UI) is used to provide a UI for the do_widget shortcode.
86
+ 8. Debug prompt if one enters something like id=junk
87
+ 9. Debug messages - scroll down till you see the shortcodes sidebar - the widgets and their ids will be listed. Use the id of the widet you want.
88
+
tags/1.7/screenshot-1.jpg ADDED
Binary file
tags/1.7/screenshot-2.jpg ADDED
Binary file
tags/1.7/screenshot-3.jpg ADDED
Binary file
tags/1.7/screenshot-4.jpg ADDED
Binary file
tags/1.7/screenshot-5.png ADDED
Binary file
tags/1.7/screenshot-6.png ADDED
Binary file
tags/1.7/screenshot-7.png ADDED
Binary file
tags/1.7/screenshot-8.jpg ADDED
Binary file
tags/1.7/screenshot-9.jpg ADDED
Binary file
tags/1.8/amr-admin-form-html.php ADDED
@@ -0,0 +1,214 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Backend Class for use in all amr plugins
4
+ * Version 0.1
5
+ */
6
+
7
+ //------------------------------------------------------------------------------------------------------------------
8
+ if (!class_exists('amr_saw_plugin_admin')) {
9
+ class amr_saw_plugin_admin {
10
+ var $hook = 'amr_saw';
11
+ var $filename = 'amr_shortcode_any_widget/amr_shortcode_any_widget.php';
12
+ var $longname = 'Shortcode any widget';
13
+ var $shortname = 'Shortcode any widget';
14
+ var $optionname = '';
15
+ var $homepage = '';
16
+ var $parent_slug = 'plugin_listings_menu';
17
+ var $accesslvl = 'manage_options';
18
+
19
+ function amr_saw_plugin_admin() {
20
+ add_action('admin_menu', array(&$this, 'register_settings_page') );
21
+ add_filter('plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
22
+ }
23
+ function register_settings_page() {
24
+ add_options_page( $this->longname, $this->shortname, $this->accesslvl, $this->hook, array(&$this,'config_page'));
25
+ }
26
+ function plugin_options_url() {
27
+ return admin_url( 'options-general.php?page='.$this->hook );
28
+ }
29
+ /**
30
+ * Add a link to the settings page to the plugins list
31
+ */
32
+ function add_action_link( $links, $file ) {
33
+ static $this_plugin;
34
+ if( empty($this_plugin) )
35
+ $this_plugin = $this->filename;
36
+ if ( $file == $this_plugin ) {
37
+ $settings_link = '<a href="' . $this->plugin_options_url() . '">' . __('Settings') . '</a>';
38
+ array_unshift( $links, $settings_link );
39
+ }
40
+ return $links;
41
+ }
42
+
43
+ function admin_heading($title) {
44
+ echo '<div class="wrap" >
45
+ <div id="icon-options-general" class="icon32"><br />
46
+ </div>
47
+ <h2>'.$title.' </h2>';
48
+ // <form method="post" action="'
49
+ // .esc_url($_SERVER['PHP_SELF'])
50
+ // .'">';
51
+ // wp_nonce_field($this->hook); /* outputs hidden field */
52
+ // ;
53
+ }
54
+
55
+ function admin_subheading($title) {
56
+ echo '<h2>'.$title.'</h2>';
57
+ }
58
+ function config_page() {
59
+ $this->admin_heading($this->longname);
60
+ echo '<ul>';
61
+ echo '<li>';
62
+ _e('Drag the widgets you want to use to the shortcodes sidebar.');
63
+
64
+ echo '</li>';
65
+ echo '<li>';
66
+ _e('Set the widgets parameters if there are any.');
67
+ echo '</li>';
68
+ echo '<li>';
69
+ _e('You could test them out in a displayable sidebar, then drag them to the shortcodes sidebar.');
70
+
71
+ echo '</li>';
72
+ echo '<li>';
73
+ echo '<a title="Go to widget area" href="'.get_admin_url('','widgets.php').'"> ';
74
+ _e('Go to widgets');
75
+ echo '</a>';
76
+ echo '</li>';
77
+ echo '<li>';
78
+ _e('Then add the shortcode [do_widget widgetname] to a page.');
79
+ echo '</li>';
80
+ echo '<li>';
81
+ _e('Examples:[do_widget "tag cloud"] or [do_widget id=widgetid]');
82
+ echo '</li>';
83
+ echo '<li>';
84
+ echo '<a title="Create a page" href="'
85
+ .add_query_arg('content','[do_widget Archives]', get_admin_url('','post-new.php?post_type=page'))
86
+ .'"> ';
87
+ _e('Create the page');
88
+ echo '</a>';
89
+ echo '</li>';
90
+ echo '<li>';
91
+ echo 'You can add as many of these on one page as you like. Use title=false to switch off the title.';
92
+ echo '</li>';
93
+ echo '<li>';
94
+ echo '[do_widget pages title=false]';
95
+ echo '</li>';
96
+ echo '<li>';
97
+ echo '[do_widget categories]';
98
+ echo '</li>';
99
+ echo '<li>';
100
+ echo '[do_widget "tag cloud"]';
101
+ echo '</li>';
102
+ echo '<li>';
103
+ echo '[do_widget "recent posts"]';
104
+ echo '</li>';
105
+ echo '<li>';
106
+ echo '<li>';
107
+ echo 'If the plugin cannot work out what you want, it will show a debug prompt
108
+ , click on the debug prompt and look for the name or id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug info). If the name does not work, try with the 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.';
109
+ echo '</li>';
110
+ echo '<li>';
111
+ echo '</ul>';
112
+ }
113
+
114
+
115
+
116
+ /**
117
+ * Create a Checkbox input field
118
+ */
119
+ function radiobutton($id, $label, $value, $selected) {
120
+ $sel = checked($value,$selected, false);
121
+ return "<input type='radio' id='".$id."' name='".$id."' value='".$value."'"
122
+ . $sel."/>&nbsp;".$label."<br />";
123
+ }
124
+ /**
125
+ * Create a Checkbox input field
126
+ */
127
+ function checkbox($id, $label, $value) {
128
+ return '<input type="checkbox" id="'.$id.'" name="'.$id.'"'. checked($value,true,false).'/>&nbsp;<label for="'.$id.'">'.$label.'</label><br/>';
129
+ }
130
+ /**
131
+ * Create a Dropdown input field
132
+ */
133
+ function dropdown($id, $label, $options, $selected) {
134
+ //
135
+ $html = '<label for="'.$id.'">'.$label.':</label><br/>'
136
+ .'<select id=\''.$id.'\' name=\''.$id.'\'>';
137
+ foreach ($options as $i => $option) {
138
+ //
139
+ $sel = selected($i, $selected, false); //wordpress function returns with single quotes, not double
140
+ $html .= '<OPTION '.$sel.' label=\''.$option.'\' value=\''.$i.'\'>'.$option.'</OPTION>';
141
+ }
142
+ $html .= '</select>';
143
+ return ($html);
144
+ }
145
+ /**
146
+ * Create a Text input field
147
+ */
148
+ function textinput($id, $label, $value, $length='45') {
149
+ return '<label for="'.$id.'">'.$label.':</label><br/><input size="'
150
+ .$length.'" type="text" id="'.$id.'" name="'.$id.'" value="'.$value.'"/><br/><br/>';
151
+ }
152
+ /**
153
+ * Create a Text area field
154
+ */
155
+ function textarea($id, $label, $value, $cols='45', $rows='10') {
156
+ return '<label for="'.$id.'">'.$label.':</label><br/>'
157
+ .'<textarea rows="'.$rows.'" cols="'.$cols
158
+ .'" id="'.$id.'" name="'.$id.'"/>'.$value.'</TEXTAREA><br/><br/>';
159
+ }
160
+ /**
161
+ * Create a postbox widget
162
+ */
163
+ function postbox($id, $title, $content) {
164
+ ?>
165
+ <div id="<?php echo $id; ?>" class="postbox">
166
+ <div class="handlediv" title="Click to toggle"><br /></div>
167
+ <h3 class="hndle"><span><?php echo $title; ?></span></h3>
168
+ <div class="inside">
169
+ <?php echo $content; ?>
170
+ </div>
171
+ </div>
172
+ <?php
173
+ }
174
+ /**
175
+ * Create a form table from an array of rows
176
+ */
177
+ function form_table($rows) { // array of rows () id, label, desc, content
178
+ $content = '<table class="form-table">';
179
+ foreach ($rows as $row) {
180
+ $content .= '<tr><th valign="top" scrope="row">';
181
+ if (isset($row['id']) && $row['id'] != '')
182
+ $content .= '<label for="'.$row['id'].'">'.$row['label'].':</label>';
183
+ else
184
+ $content .= $row['label'];
185
+ if (isset($row['desc']) && $row['desc'] != '')
186
+ $content .= '<br/><small>'.$row['desc'].'</small>';
187
+ $content .= '</th><td valign="top">';
188
+ $content .= $row['content'];
189
+ $content .= '</td></tr>';
190
+ }
191
+ $content .= '</table>';
192
+ return $content;
193
+ }
194
+
195
+ /**
196
+ * Info box with link to the support forums.
197
+ */
198
+ function plugin_support() {
199
+ $content = '<p>'.__('If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the','amrplugin').' <a href="http://wordpress.org/tags/'.$this->hook.'">'.__("Support forums",'amrplugin').'</a>.</p>';
200
+ $this->postbox($this->hook.'support', 'Need support?', $content);
201
+ }
202
+
203
+ function text_limit( $text, $limit, $finish = ' [&hellip;]') {
204
+ if( strlen( $text ) > $limit ) {
205
+ $text = substr( $text, 0, $limit );
206
+ $text = substr( $text, 0, - ( strlen( strrchr( $text,' ') ) ) );
207
+ $text .= $finish;
208
+ }
209
+ return $text;
210
+ }
211
+ }
212
+ }
213
+
214
+ ?>
tags/1.8/amr-shortcode-any-widget.php ADDED
@@ -0,0 +1,316 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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" ]. If upgrading see changelog. Can be very powerful eg: with queryposts widget it can become a templater.
6
+ Author: anmari
7
+ Version: 1.8
8
+ Author URI: http://webdesign.anmari.com
9
+
10
+ */
11
+
12
+ /*-----------------------------------*/
13
+ function do_widget($atts) {
14
+
15
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
16
+
17
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
18
+ if it is in, then get the instance data and use that */
19
+
20
+ if (isset($_wp_sidebars_widgets) ) {
21
+ amr_show_widget_debug('which one'); //check for debug prompt and show widgets in shortcode sidebar if requested and logged in etc
22
+ }
23
+ else {
24
+ echo '<br />No widgets defined at all in any sidebar!';
25
+ return (false);
26
+ }
27
+
28
+ extract(shortcode_atts(array(
29
+ 'sidebar' => 'Shortcodes',
30
+ 'id' => '',
31
+ 'title' => 'true' /* do the default title unless they ask us not to - use string here not boolean */
32
+ ), $atts));
33
+
34
+
35
+
36
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
37
+ if (!empty($atts[0])) { // we have a name
38
+ $widget = $atts[0];
39
+
40
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
41
+ if (strtolower($w['name']) === strtolower($widget)) $widget_ids[] = $i;
42
+ //if ($debug) {echo '<br /> Check: '.$w['name'];}
43
+ }
44
+
45
+ }
46
+ else { /* check for id if we do not have a name */
47
+ if (!empty($id)) { /* if a specific id has been specified */
48
+
49
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
50
+ if ($w['id'] === $id) $widget_ids[] = $id;
51
+ }
52
+ //if ($debug) { echo '<h2>We have an id: '.$id.'</h2>'; if (!empty($widget_ids)) var_dump($widget_ids); }
53
+ }
54
+ else {
55
+ echo '<br />No valid widget name or id given in shortcode parameters';
56
+ return (false);
57
+ }
58
+ }
59
+
60
+ if (empty ($widget_ids)) {
61
+ echo '<p><b>Requested widget not found in widget list.';
62
+ amr_show_widget_debug('empty', $atts);
63
+ return (false) ;
64
+ }
65
+
66
+ if ($title == 'false')
67
+ $title = false; /* If ask not to display title, then do not */
68
+ else
69
+ $title = true;
70
+
71
+ if (!($sidebarid = get_sidebar_id ($sidebar)))
72
+ $sidebarid=$sidebar; /* get the official sidebar id - will take the first one */
73
+
74
+ if (empty($widget))
75
+ $widget = '';
76
+ /* if ($debug) {
77
+ echo '<hr>Looking for widget with name:'.$widget.' or id='.$id.' Found instances:'.' <br />';
78
+ if (!empty($widget_ids)) foreach ($widget_ids as $i=> $w) {
79
+ echo $w.'<br />';
80
+ };
81
+ }
82
+ */
83
+ $content = '';
84
+ /* if the widget is in our chosen sidebar, then use the options stored for that */
85
+
86
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
87
+ /* if ($debug) {
88
+ echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
89
+ sort ($_wp_sidebars_widgets[$sidebarid]);
90
+ foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
91
+ echo $i.' '.$w.'<br />';
92
+ };
93
+ }
94
+ */
95
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
96
+
97
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
98
+ /* if ($debug) { echo '<br />Will use widget ids'.'<br />';
99
+ foreach ($widget_ids as $i=> $w) {
100
+ echo '&nbsp;&nbsp;&nbsp;'.$w.'<br />';
101
+ };
102
+ }
103
+ */
104
+ }
105
+ else { /* the sidebar is not defined */
106
+ //if ($debug) {
107
+ echo '<br />Sidebar '.$sidebar.'with sidebarid '.$sidebarid.' is empty or not defined.';
108
+ //}
109
+ }
110
+
111
+ $output = '';
112
+ if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
113
+ //if ($debug) {
114
+ echo '<h2>Widget '.$widget.' not in sidebar with id '.$sidebarid.' and with name '.$sidebar.'</h2>';
115
+ //}
116
+ unset($sidebar);
117
+ unset($sidebarid);
118
+
119
+ }
120
+ else {
121
+ /* There may only be one but if we have two in our chosen widget then it will do both */
122
+ $output = '';
123
+ foreach ($wid as $i=>$widget_instance) {
124
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
125
+ shortcode_sidebar($widget_instance, $sidebar, $title);
126
+ $output .= ob_get_clean();
127
+ }
128
+
129
+ }
130
+
131
+ return ($output);
132
+ }
133
+ /*-----------------------------------*/
134
+ function amr_get_sidebar_name ($id) { /* dont need anymore ? or at least temporarily */
135
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
136
+ global $wp_registered_sidebars;
137
+ foreach ($wp_registered_sidebars as $i => $a) {
138
+ if ((isset ($a['id'])) and ( $a['id'] === $id)) {
139
+ if (isset($a['name'])) return ($a['name']);
140
+ else return ($id);
141
+ }
142
+ }
143
+ return (false);
144
+ }
145
+ /*-----------------------------------*/
146
+ function get_sidebar_id ($name) { /* dont need anymore ? or at least temporarily */
147
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
148
+ global $wp_registered_sidebars;
149
+ foreach ($wp_registered_sidebars as $i => $a) {
150
+ if ((isset ($a['name'])) and ( $a['name'] === $name)) return ($i);
151
+ }
152
+ return (false);
153
+ }
154
+ /* -------------------------------------------------------------------------*/
155
+ function shortcode_sidebar( $id, $index=1, $title=true) { /* This is basically the wordpress code, slightly modified */
156
+ global $wp_registered_sidebars, $wp_registered_widgets;
157
+
158
+ $debug = amr_check_if_widget_debug();
159
+
160
+ if ( is_int($index) ) {
161
+ $index = "sidebar-$index";
162
+ } else {
163
+ $index = sanitize_title($index);
164
+ foreach ( (array) $wp_registered_sidebars as $key => $value ) {
165
+ if ( sanitize_title($value['name']) == $index ) {
166
+ $index = $key;
167
+ break;
168
+ }
169
+ }
170
+ }
171
+
172
+ $sidebars_widgets = wp_get_sidebars_widgets();
173
+
174
+ /* if ($debug) {
175
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
176
+ foreach ($sidebars_widgets as $i=>$w) {
177
+ echo '<br />'.$w['name'].' '.$w['id'];
178
+ };
179
+ }
180
+ */
181
+
182
+ /* DONT NEED TO BE ACTIVE ? if there are no active widgets */
183
+ // if ( empty($wp_registered_sidebars[$index]) ||
184
+ // !array_key_exists($index, $sidebars_widgets) ||
185
+ // !is_array($sidebars_widgets[$index])
186
+ // || empty($sidebars_widgets[$index]) ) {
187
+ // echo '<br />'.'No active widgets for '.$index;
188
+ // return false;
189
+ // }
190
+
191
+ // $sidebar = $wp_registered_sidebars[$index];
192
+ $sidebar = array('wp_inactive_widgets');
193
+ $did_one = false;
194
+
195
+ // foreach ( (array) $sidebars_widgets[$index] as $id ) { /* lifted from wordpress code, keep as similar as possible for now */
196
+
197
+ if ( !isset($wp_registered_widgets[$id]) ) continue;
198
+
199
+ $params = array_merge(
200
+ array( array_merge( $sidebar, array('widget_id' => $id, 'widget_name' => $wp_registered_widgets[$id]['name']) ) ),
201
+ (array) $wp_registered_widgets[$id]['params']
202
+ );
203
+
204
+ // Substitute HTML id and class attributes into before_widget
205
+ $classname_ = '';
206
+ foreach ( (array) $wp_registered_widgets[$id]['classname'] as $cn ) {
207
+ if ( is_string($cn) )
208
+ $classname_ .= '_' . $cn;
209
+ elseif ( is_object($cn) )
210
+ $classname_ .= '_' . get_class($cn);
211
+ }
212
+ $classname_ = ltrim($classname_, '_');
213
+ if (!empty($params[0]['before_widget']))
214
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
215
+ else $params[0]['before_widget'] = '';
216
+ if (empty($params[0]['after_widget'])) $params[0]['after_widget'] = '';
217
+
218
+ $params = apply_filters( 'dynamic_sidebar_params', $params );
219
+
220
+ if (!$title) { /* amr switch off the title html, still need to get rid of title separately */
221
+ $params[0]['before_title'] = '<span style="display: none">';
222
+ $params[0]['after_title'] = '</span>';
223
+ }
224
+ else {
225
+ $params[0]['before_title'] = '<h2>';
226
+ $params[0]['after_title'] = '</h2>';
227
+ }
228
+
229
+ $callback = $wp_registered_widgets[$id]['callback'];
230
+ if ( is_callable($callback) ) {
231
+ call_user_func_array($callback, $params);
232
+ $did_one = true;
233
+ }
234
+ // }
235
+ return $did_one;
236
+ }
237
+ /* -------------------------------------------------------------------------------------------------------------*/
238
+ function amr_reg_sidebar() {
239
+ if ( function_exists('register_sidebar') )
240
+ register_sidebar(array('name'=>'Shortcodes',
241
+ 'id' => 'Shortcodes',
242
+ 'before_widget' => '<div id="%1$s" class="widget %2$s clearfix">',
243
+ 'after_widget' => '</div>',
244
+ 'before_title' => '<h2 class="widgettitle">',
245
+ 'after_title' => '</h2>' ));
246
+ }
247
+ /*-----------------------------------*/
248
+ function amr_check_if_widget_debug() {
249
+ // only do these debug if we are logged in and are the administrator
250
+
251
+ if ((!is_user_logged_in()) or (!current_user_can('administrator')))
252
+ return false;
253
+
254
+ if (isset($_REQUEST['do_widget_debug'])) {
255
+ echo '<br/>Note: Debugs only shown to a Logged in Administrator.<br />';
256
+ return true;
257
+ }
258
+ else
259
+ return false;
260
+ }
261
+ /*-----------------------------------*/
262
+ function amr_show_widget_debug($type='', $atts=array()) {
263
+ global $wp_registered_sidebars, $wp_registered_widgets,$_wp_sidebars_widgets;
264
+ // only do these debug if we are logged in and are the administrator
265
+
266
+ $debug = amr_check_if_widget_debug();
267
+
268
+ if ($type=='empty') {
269
+ if (current_user_can('administrator')) echo '<br />You are admin: <a href="'.add_query_arg('do_widget_debug','1').'">Try debug</a></b></p>';
270
+
271
+ if ($debug) {
272
+
273
+ echo '<h2>As a last resort, dump the wp variables </h2>';
274
+ $sidebars_widgets = wp_get_sidebars_widgets();
275
+ echo '<h3> result of wp_get_sidebars_widgets()</h3>';
276
+ foreach ($sidebars_widgets as $i=>$w) {
277
+ echo '<br/>'.$i; var_dump($w);
278
+ };
279
+
280
+ echo '<h3>$_wp_sidebars_widgets:</h3>';
281
+ var_dump($_wp_sidebars_widgets);
282
+ echo '<br /><h3>$wp_registered_widgets:</h3>';
283
+ var_dump($wp_registered_widgets);
284
+ }
285
+ }
286
+
287
+ if (($type=='which one') and ($debug)) {
288
+ echo '<h3>DEBUG on: Please scroll down till you find the shortcodes sidebar.</h3>';
289
+ echo '<br />Attributes entered:<br />';
290
+ var_dump($atts);
291
+ echo '<br />Shortcode sidebar and widgets<br />';
292
+ foreach ($_wp_sidebars_widgets as $i=> $w) {
293
+ if (($i == "Shortcodes")) {
294
+ echo 'Sidebar:&nbsp;<b>'.$i.': '.amr_get_sidebar_name($i).'</b><br />';
295
+ if (is_array($w)) {
296
+ sort ($w);
297
+ foreach ($w as $i2=> $w2) {
298
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$w2.' <br />';
299
+ };
300
+ }
301
+ echo '<br />';
302
+ }
303
+ };
304
+ }
305
+ }
306
+ /*-----------------------------------*/
307
+ include ('amr-admin-form-html.php');
308
+ if (is_admin() ) $amr_saw_plugin_admin = new amr_saw_plugin_admin();
309
+ add_action('admin_init', 'amr_reg_sidebar');
310
+
311
+ add_shortcode('do_widget', 'do_widget');
312
+
313
+
314
+ require_once(ABSPATH . 'wp-includes/widgets.php');
315
+
316
+ ?>
tags/1.8/readme.txt ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === amr shortcode any widget ===
2
+ Contributors: anmari
3
+ Tags: shortcode, widget, page, templates, page template
4
+ Tested up to: 3.8.1
5
+ Version: 1.8
6
+ Stable tag: trunk
7
+
8
+ == Description ==
9
+ This simple 'utility' plugin allows one to have any widget used in a page shortcode in any theme - no need to use the hybrid theme or create a special template. 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/)
10
+
11
+ 1. Test chosen widget works in normal sidebar first.
12
+ 2. Activate this plugin
13
+ 3. Go to Appearance > widgets and find "shortcode" sidebar
14
+ 4. Drag chosen widgets from configured sidebar to shortcodes sidebar. Save.
15
+ 5. Go to page where you want configured widget to appear
16
+ 6. enter one of:
17
+ [do_widget widgetname] eg: [do_widget calendar]
18
+ [do_widget "widget name"]. eg: [do_widget "tag cloud"]
19
+ [do_widget id=widgetid] in a page or post
20
+ 7. If the plugin cannot work out what you want and you are logged in as an adminsitrator, it will show a debug prompt to you only.
21
+ Click on the link 'Try debug'.
22
+ 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 wusing 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.
23
+
24
+ Plugin has been tested with most standard widgets (rss feeds, tag cloud, pages, meta, search, and of course my own plugins widgets - upcoming events list, calendar and user lists.
25
+
26
+ If you use a widget more than once for different reasons, you may need to use the widget id to isolate which widget instance and it's settings to use. ie: [do_widget id=categories-6] . If you just use the name, it will display all widgets in the shortcode sidebar with that name (all instances).
27
+
28
+ If you liked this plugin, you might also like my other plugins:
29
+ [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)
30
+ [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/)
31
+
32
+
33
+ == Changelog ==
34
+ = Version 1.8 =
35
+ * Whoops - had renamed the main file and forgot to delete it from the svn. Forcing a version number change to ensure files get cleaned up for everyone
36
+
37
+ = Version 1.7 =
38
+ * Change: Changed so that debugs and debug prompt will only show to a logged in administrator.
39
+
40
+ = Version 1.6 =
41
+ * Add: added a settings page to help people out (not really settings)
42
+ * Fix: changed a clashing function name
43
+
44
+ = Version 1.5 =
45
+ * Fixed: a small bug which caused a warning if you had not saved the widgets in your shortcode sidebar
46
+
47
+ = Version 1.4 =
48
+ * Updated readme - made very detailed steps and added some screen shots.
49
+ * Tested on wp 3.3.1 and fixed some notices when bad parameters entered.
50
+
51
+ = Version 1.3 =
52
+ * Added debug link and retested. Added readme.
53
+
54
+ = 1.12=
55
+ * Changed dummy shortcode sidebar so it appears after the theme sidebars to avoid taking over their widgets (this happened in numbered sidebars) PLEASE note if you have upgraded, you may appear to have "lost" your widgets due to this sidebar change. You have not - they will be in your "inactive widgets" - please drag them to the new sidebar. You may also find that you have 2 versions of the plugin, with slightly different folder names. This will allow you to go back to the previous one to check what you had there if you need to. Deactivate the old one and activate the new one. Move your widgets back in. Test then Delete the old one. In one theme it also appeared that somehow due to this change, one of the sidebar widgets "moved" down to another sidebar. I think that this may have had something to do with the fact that sidebars can be numbered or named, so please check all your sidebars before continuing. As always make sure thath you know how to restore from a backup before doing any upgrades of any kind.
56
+ * Tested in 2.9.2, can still use either the widget name "Categories" or id=categories-6. Note widget must have been created in the dummy shortcode sidebar.
57
+
58
+ = 1.1 =
59
+
60
+ * Allow for lowercase use of widget names for the those challenged by attention to detail!
61
+ * Cleaned up debug mode to make it easier for people to identify which instance of a widget they are using. Add &do_widget_debug to url string.
62
+
63
+ = 1.0 =
64
+ * Launch of the plugin
65
+
66
+ == Installation ==
67
+
68
+ 0. Activate plugin
69
+ 1. Goto Appearance > widgets and find "shortcode" sidebar
70
+ 1. Drag chosen widgets to shortcodes sidebar. Save. (note the names)
71
+ 2. Add [do_widget id=widgetid] in a page or post
72
+ 3. If it fails, click on the debug prompt and look for the id of your widget, use that.
73
+
74
+ 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"].
75
+
76
+ 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]
77
+
78
+
79
+ == Screenshots ==
80
+
81
+ 1. setting up widgets in page (must be in the shortcode sidebar)
82
+ 2. widgets in a page
83
+ 3. setting up widgets in the shortcode sidebar
84
+ 4. two rss feed widgets in shortcode sidebar - both will show if just name used
85
+ 5. Demonstration of two widgets being used via the do_widget short code.
86
+ 6. The Page or post with the do_widget shortcodes
87
+ 7. The shortcode sidebar. The widget's user interface (UI) is used to provide a UI for the do_widget shortcode.
88
+ 8. Debug prompt if one enters something like id=junk
89
+ 9. Debug messages - scroll down till you see the shortcodes sidebar - the widgets and their ids will be listed. Use the id of the widet you want.
90
+
tags/1.8/screenshot-1.jpg ADDED
Binary file
tags/1.8/screenshot-2.jpg ADDED
Binary file
tags/1.8/screenshot-3.jpg ADDED
Binary file
tags/1.8/screenshot-4.jpg ADDED
Binary file
tags/1.8/screenshot-5.png ADDED
Binary file
tags/1.8/screenshot-6.png ADDED
Binary file
tags/1.8/screenshot-7.png ADDED
Binary file
tags/1.8/screenshot-8.jpg ADDED
Binary file
tags/1.8/screenshot-9.jpg ADDED
Binary file
tags/2.0/amr-admin-form-html.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Backend Class for use in all amr plugins
4
+ * Version 0.1
5
+ */
6
+
7
+ //------------------------------------------------------------------------------------------------------------------
8
+ if (!class_exists('amr_saw_plugin_admin')) {
9
+ class amr_saw_plugin_admin {
10
+ var $hook = 'amr_saw';
11
+ var $filename = 'amr_shortcode_any_widget/amr_shortcode_any_widget.php';
12
+ var $longname = 'Shortcode any widget - insert widgets or widget areas into a page.';
13
+ var $shortname = 'Shortcode any widget';
14
+ var $optionname = '';
15
+ var $homepage = '';
16
+ var $parent_slug = 'plugin_listings_menu';
17
+ var $accesslvl = 'manage_options';
18
+
19
+ function amr_saw_plugin_admin() {
20
+ add_action('admin_menu', array(&$this, 'register_settings_page') );
21
+ add_filter('plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
22
+ }
23
+ function register_settings_page() {
24
+ add_options_page( $this->longname, $this->shortname, $this->accesslvl, $this->hook, array(&$this,'config_page'));
25
+ }
26
+ function plugin_options_url() {
27
+ return admin_url( 'options-general.php?page='.$this->hook );
28
+ }
29
+ /**
30
+ * Add a link to the settings page to the plugins list
31
+ */
32
+ function add_action_link( $links, $file ) {
33
+ static $this_plugin;
34
+ if( empty($this_plugin) )
35
+ $this_plugin = $this->filename;
36
+ if ( $file == $this_plugin ) {
37
+ $settings_link = '<a href="' . $this->plugin_options_url() . '">' . __('Settings') . '</a>';
38
+ array_unshift( $links, $settings_link );
39
+ }
40
+ return $links;
41
+ }
42
+
43
+ function admin_heading($title) {
44
+ echo '<div class="wrap" >
45
+ <div id="icon-options-general" class="icon32"><br />
46
+ </div>
47
+ <h2>'.$title.' </h2>';
48
+ // <form method="post" action="'
49
+ // .esc_url($_SERVER['PHP_SELF'])
50
+ // .'">';
51
+ // wp_nonce_field($this->hook); /* outputs hidden field */
52
+ // ;
53
+ }
54
+
55
+ function admin_subheading($title) {
56
+ echo '<h2>'.$title.'</h2>';
57
+ }
58
+ function config_page() {
59
+ $this->admin_heading($this->longname);
60
+ echo '<ul>';
61
+ echo '<li>';
62
+ _e('Drag the widgets you want to use to the shortcodes sidebar.');
63
+
64
+ echo '</li>';
65
+ echo '<li>';
66
+ _e('Set the widgets parameters if there are any.');
67
+ echo '</li>';
68
+ echo '<li>';
69
+ _e('You could test the widgets out in a displayable widget area (sidebar/footer), then drag them to the widgets_for_shortcodes sidebar.');
70
+
71
+ echo '</li>';
72
+ echo '<li>';
73
+ echo '<a title="Go to widget area" href="'.get_admin_url('','widgets.php').'"> ';
74
+ _e('Go to widgets');
75
+ echo '</a>';
76
+ echo '</li>';
77
+ echo '</ul>';
78
+
79
+ echo '<h2>';
80
+ _e('To add a widget area - all widgets in the widget area:');
81
+
82
+ echo '</h2>';
83
+ echo '<ul>';
84
+ echo '<li>';
85
+ echo '<a title="Create a page" href="'
86
+ .add_query_arg('content','[do_widget_area]', get_admin_url('','post-new.php?post_type=page'))
87
+ .'"> ';
88
+ _e('Create a page with do_widget_area shortcode');
89
+ echo '</a>';
90
+ echo '</li>';
91
+ echo '<li>';
92
+ _e('Examples:');
93
+ echo '</li>';
94
+ echo '<li>';
95
+ _e('[do_widget_area] or [do_widget_area widget_area=sidebar-1]');
96
+ echo '</li>';
97
+ echo '<li>';
98
+ _e('NB: Using something like the twenty-fourteen theme? you might end up with white text on a white background. Be prepared to adjust your css!');
99
+ echo '</li>';
100
+ echo '</ul>';
101
+ echo '<br />';
102
+
103
+ echo '<h2>';
104
+ _e('To add a single widget to a page');
105
+
106
+ echo '</h2>';
107
+ echo '<ul>';
108
+ echo '<li>';
109
+ _e('Add the shortcode [do_widget widgetname] to a page.');
110
+ _e('Examples:');
111
+ echo '</li>';
112
+ echo '<li>';
113
+ _e('[do_widget "tag cloud"] or [do_widget id=widgetid]');
114
+ echo '</li>';
115
+ echo '<li>';
116
+ echo '<a title="Create a page" href="'
117
+ .add_query_arg('content','[do_widget Archives]', get_admin_url('','post-new.php?post_type=page'))
118
+ .'"> ';
119
+ _e('Create a page with do_widget shortcode');
120
+ echo '</a>';
121
+ echo '</li>';
122
+ echo '<li>';
123
+ echo 'Use title=false to hide a widget title. ';
124
+ echo 'Use title=somehtmltag and wrap=somehtmltag to change the html used.';
125
+ echo ' Use class=yourclassname to add a class - maybe to override your themes widget styling?';
126
+ echo '</li>';
127
+ echo '<li>';
128
+ echo '[do_widget pages title=false] will hide the widget title';
129
+ echo '</li>';
130
+ echo '<li>';
131
+ echo '[do_widget pages title=h3] give the title a heading 3 html tag.';
132
+ echo '</li>';
133
+ echo '<li>';
134
+ echo '[do_widget categories] or [do_widget name=categories] will do the same thing: display the categories widget.';
135
+ echo '</li>';
136
+ echo '<li>';
137
+ echo '[do_widget "tag cloud" wrap=aside] will wrap the widget in an "aside" html tag.';
138
+ echo '</li>';
139
+ echo '<li>';
140
+ echo '[do_widget "recent posts"]';
141
+ echo '</li>';
142
+ echo '</ul>';
143
+
144
+ echo '<p>';
145
+ echo 'If the plugin cannot work out what you want, it will show a debug prompt
146
+ , click on the debug prompt and look for the name or id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug info). If the name does not work, try with the 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.';
147
+ echo '</p><p><b>';
148
+ echo "Valid title html tags are : h1, h2, h3, h4, h5, header, strong, em ";
149
+ echo '</b></p><p><b>';
150
+ echo "Valid html wrap tags are : div, p, aside , section";
151
+ echo '</b></p>';
152
+
153
+ }
154
+
155
+
156
+ /**
157
+ * Info box with link to the support forums.
158
+ */
159
+ function plugin_support() {
160
+ $content = '<p>'.__('If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the','amrplugin').' <a href="http://wordpress.org/tags/'.$this->hook.'">'.__("Support forums",'amrplugin').'</a>.</p>';
161
+ $this->postbox($this->hook.'support', 'Need support?', $content);
162
+ }
163
+
164
+ function text_limit( $text, $limit, $finish = ' [&hellip;]') {
165
+ if( strlen( $text ) > $limit ) {
166
+ $text = substr( $text, 0, $limit );
167
+ $text = substr( $text, 0, - ( strlen( strrchr( $text,' ') ) ) );
168
+ $text .= $finish;
169
+ }
170
+ return $text;
171
+ }
172
+ }
173
+ }
174
+
175
+ ?>
tags/2.0/amr-shortcode-any-widget.php ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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.0
8
+ Author URI: http://webdesign.anmari.com
9
+
10
+ */
11
+ /*-----------------------------------*/
12
+ function do_widget_area($atts) {
13
+
14
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
15
+
16
+ extract(shortcode_atts(array(
17
+ 'widget_area' => 'widgets_for_shortcodes'
18
+ ), $atts));
19
+
20
+ $output = PHP_EOL.'<div id="'.$widget_area.'" class="amr-widget-area widget-area">';
21
+
22
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
23
+ dynamic_sidebar($widget_area);
24
+ $output .= ob_get_clean();
25
+
26
+ $output .= '</div>'.PHP_EOL;
27
+
28
+ return ($output);
29
+ }
30
+ /*-----------------------------------*/
31
+ function do_widget($atts) {
32
+
33
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
34
+
35
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
36
+ if it is in, then get the instance data and use that */
37
+
38
+ if (isset($_wp_sidebars_widgets) ) {
39
+ amr_show_widget_debug('which one'); //check for debug prompt and show widgets in shortcode sidebar if requested and logged in etc
40
+ }
41
+ else {
42
+ echo '<br />No widgets defined at all in any sidebar!';
43
+ return (false);
44
+ }
45
+
46
+ extract(shortcode_atts(array(
47
+ // 'sidebar' => 'Shortcodes',
48
+ 'sidebar' => 'Widgets for Shortcodes',
49
+ 'id' => '',
50
+ 'name' => '', /* MKM added explicit 'name' attribute. For existing users we still need to allow prev method, else too many support queries will happen */
51
+ 'title' => '', /* do the default title unless they ask us not to - use string here not boolean */
52
+ 'class' => 'amr_widget', /* 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 */
53
+ 'wrap' => '' /* wrap the whole thing - title plus widget in a div - maybe the themes use a div, maybe not, maybe we want that styling, maybe not */
54
+ ), $atts));
55
+
56
+
57
+
58
+ /* compatibility check - if the name is not entered, then the first parameter is the name */
59
+ if (empty($name) and !empty($atts[0]))
60
+ $name = $atts[0];
61
+
62
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
63
+ if (!empty($name)) { // we have a name
64
+ $widget = $name;
65
+
66
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
67
+ if (strtolower($w['name']) === strtolower($widget)) $widget_ids[] = $i;
68
+ //if ($debug) {echo '<br /> Check: '.$w['name'];}
69
+ }
70
+ }
71
+ else { /* check for id if we do not have a name */
72
+ if (!empty($id)) { /* if a specific id has been specified */
73
+
74
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
75
+ if ($w['id'] === $id) $widget_ids[] = $id;
76
+ }
77
+ //if ($debug) { echo '<h2>We have an id: '.$id.'</h2>'; if (!empty($widget_ids)) var_dump($widget_ids); }
78
+ }
79
+ else {
80
+ echo '<br />No valid widget name or id given in shortcode parameters';
81
+ return (false);
82
+ }
83
+ }
84
+
85
+ if (empty ($widget_ids)) {
86
+ echo '<br /><a href="" title="Error: Your Requested widget '.$widget.' '.$id.' is not in the widget list. Typo maybe?">!</a><br />';
87
+ amr_show_widget_debug('empty', $atts);
88
+ return (false) ;
89
+ }
90
+
91
+ if (!($sidebarid = get_sidebar_id ($sidebar)))
92
+ $sidebarid=$sidebar; /* get the official sidebar id for this widget area - will take the first one */
93
+
94
+ if (empty($widget))
95
+ $widget = '';
96
+
97
+ $content = '';
98
+ /* if the widget is in our chosen sidebar, then use the options stored for that */
99
+
100
+ if ((!isset ($_wp_sidebars_widgets[$sidebarid])) or (empty ($_wp_sidebars_widgets[$sidebarid]))) { // try upgrade
101
+ amr_upgrade_sidebar();
102
+ }
103
+
104
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
105
+ /* if ($debug) {
106
+ echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
107
+ sort ($_wp_sidebars_widgets[$sidebarid]);
108
+ foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
109
+ echo $i.' '.$w.'<br />';
110
+ };
111
+ }
112
+ */
113
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
114
+
115
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
116
+ /* if ($debug) { echo '<br />Will use widget ids'.'<br />';
117
+ foreach ($widget_ids as $i=> $w) {
118
+ echo '&nbsp;&nbsp;&nbsp;'.$w.'<br />';
119
+ };
120
+ }
121
+ */
122
+ }
123
+ else { /* the sidebar is not defined */
124
+ //if ($debug) {
125
+ echo '<br /><a href="" title="Error: Sidebar '.$sidebar.' with sidebarid '.$sidebarid.' is empty (no widgets) or is not defined.">!</a><br />';
126
+ //}
127
+ }
128
+
129
+ $output = '';
130
+ if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
131
+ //if ($debug) {
132
+ echo '<br /><a href="" title="Error: Your requested Widget '.$widget.' is not in the '.$sidebar.' sidebar ">!</a><br />';
133
+ amr_show_widget_debug('empty', $atts);
134
+ //}
135
+ unset($sidebar);
136
+ unset($sidebarid);
137
+
138
+ }
139
+ else {
140
+ /* There may only be one but if we have two in our chosen widget then it will do both */
141
+ $output = '';
142
+ foreach ($wid as $i=>$widget_instance) {
143
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
144
+ shortcode_sidebar($widget_instance, $sidebar, $title, $class, $wrap);
145
+ $output .= ob_get_clean();
146
+ }
147
+ }
148
+
149
+ return ($output);
150
+ }
151
+ /* -------------------------------------------------------------------------*/
152
+ function shortcode_sidebar( $widget_id, $name="widgets_for_shortcode", $title=true, $class='', $wrap='') { /* This is basically the wordpress code, slightly modified */
153
+ global $wp_registered_sidebars, $wp_registered_widgets;
154
+
155
+ $debug = amr_check_if_widget_debug();
156
+
157
+ $sidebarid = get_sidebar_id ($name);
158
+
159
+ $sidebars_widgets = wp_get_sidebars_widgets();
160
+
161
+ $sidebar = $wp_registered_sidebars[$sidebarid]; // has the params etc
162
+
163
+ $did_one = false;
164
+
165
+ /* lifted from wordpress code, keep as similar as possible for now */
166
+
167
+ if ( !isset($wp_registered_widgets[$widget_id]) ) continue;
168
+
169
+ $params = array_merge(
170
+ array(
171
+ array_merge( $sidebar, array('widget_id' => $widget_id, 'widget_name' => $wp_registered_widgets[$widget_id]['name']) ) ),
172
+ (array) $wp_registered_widgets[$widget_id]['params']
173
+ );
174
+
175
+ $validtitletags = array ('h1','h2','h3','h4','h5','header','strong','em');
176
+ $validwraptags = array ('div','p','main','aside','section');
177
+
178
+ if (!empty($wrap)) { /* then folks want to 'wrap' with their own html tag, or wrap = yes */
179
+ if ((!in_array( $wrap, $validwraptags)))
180
+ $wrap = '';
181
+ /* To match a variety of themes, allow for a variety of html tags. */
182
+ /* May not need if our sidebar match attempt has worked */
183
+ }
184
+
185
+ if (!empty ($wrap)) {
186
+ $params[0]['before_widget'] = '<'.$wrap.' id="%1$s" class="%2$s ">';
187
+ $params[0]['after_widget'] = '</'.$wrap.'>';
188
+ }
189
+
190
+ // wp code to get classname
191
+ $classname_ = '';
192
+ //foreach ( (array) $wp_registered_widgets[$widget_id]['classname'] as $cn ) {
193
+ $cn = $wp_registered_widgets[$widget_id]['classname'];
194
+ if ( is_string($cn) )
195
+ $classname_ .= '_' . $cn;
196
+ elseif ( is_object($cn) )
197
+ $classname_ .= '_' . get_class($cn);
198
+ //}
199
+ $classname_ = ltrim($classname_, '_');
200
+
201
+ // add MKM and others requested class in to the wp classname string
202
+ // if no class specfied, then class will = amrwidget. These classes are so can reverse out unwanted widget styling.
203
+
204
+ $classname_ .= ' widget '.$class;
205
+
206
+ // Substitute HTML id and class attributes into before_widget
207
+ if (!empty($params[0]['before_widget']))
208
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $widget_id, $classname_);
209
+ else
210
+ $params[0]['before_widget'] = '';
211
+
212
+ if (empty($params[0]['before_widget'])) $params[0]['after_widget'] = '';
213
+
214
+ //$params = apply_filters( 'dynamic_sidebar_params', $params ); // should we do this? - intended for sidebar but we not in sidebar
215
+
216
+ if (!empty($title)) {
217
+ if ($title=='false') { /* amr switch off the title html, still need to get rid of title separately */
218
+ $params[0]['before_title'] = '<span style="display: none">';
219
+ $params[0]['after_title'] = '</span>';
220
+ }
221
+ else {
222
+ if (in_array( $title, $validtitletags)) {
223
+ $params[0]['before_title'] = '<'.$title.' class="widget-title">';
224
+ $params[0]['after_title'] = '</'.$title.'>';
225
+ }
226
+ }
227
+ }
228
+
229
+ $callback = $wp_registered_widgets[$widget_id]['callback'];
230
+ if ( is_callable($callback) ) {
231
+ call_user_func_array($callback, $params);
232
+ $did_one = true;
233
+ }
234
+ // }
235
+ return $did_one;
236
+ }
237
+ /* -------------------------------------------------------------------------------------------------------------*/
238
+ function amr_reg_sidebar() { // this is fired late, so hopefully any theme sidebars will have been registered already.
239
+
240
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
241
+
242
+ if ( function_exists('register_sidebar') ) { // maybe later, get the first main sidebar and copy it's before/after etc
243
+ $args = array(
244
+ 'name' =>'Widgets for Shortcodes',
245
+ 'id' => 'widgets_for_shortcodes', // hope to avoid losing widgets
246
+ 'description' => 'Sidebar to hold widgets and their settings. These widgets will be used in a shortcode. This sidebars widgets should be saved with your theme settings now.',
247
+ 'before_widget' => '<aside'.' id="%1$s" class="%2$s ">', // 201402 to match twentyfourteen theme
248
+ 'after_widget' => '</aside>',
249
+ 'before_title' => '<h1 class="widget-title" >', // 201402 maybe dont use widget class - we are in content here not in a widget area but others want?
250
+ 'after_title' => '</h1>' );
251
+
252
+
253
+
254
+ if (!empty($wp_registered_sidebars)) { // we got some sidebars already.
255
+ $main_sidebar = array_pop($wp_registered_sidebars); // Grab the first sidebar and use that as defaults for the widgets
256
+ $args['before_widget'] = $main_sidebar['before_widget'];
257
+ $args['after_widget'] = $main_sidebar['after_widget'];
258
+ $args['before_title'] = $main_sidebar['before_title'];
259
+ $args['after_title'] = $main_sidebar['after_title'];
260
+ }
261
+
262
+ register_sidebar($args);
263
+ }
264
+
265
+ //else { echo '<h1>CANNOT REGISTER widgets_for_shortcodes SIDEBAR</h1>';}
266
+ }
267
+ /*-----------------------------------*/
268
+ include ('amr-admin-form-html.php');
269
+ include ('amr-utilities.php');
270
+
271
+ if (is_admin() ) $amr_saw_plugin_admin = new amr_saw_plugin_admin();
272
+
273
+ add_action('widgets_init', 'amr_reg_sidebar',98); // register late so it appears last
274
+ add_action('widgets_init', 'amr_upgrade_sidebar',99); // copy old shortcodes sidebar to new one if necessary
275
+ add_action('switch_theme', 'amr_save_shortcodes_sidebar');
276
+ add_action('after_switch_theme','amr_restore_shortcodes_sidebar');
277
+
278
+ add_shortcode('do_widget', 'do_widget');
279
+ add_shortcode('do_widget_area', 'do_widget_area'); // just dump the whole widget area - to get same styling
280
+
281
+ //require_once(ABSPATH . 'wp-includes/widgets.php'); // *** do we really need this here?
282
+
283
+ ?>
amr-utilities.php → tags/2.0/amr-utilities.php RENAMED
File without changes
tags/2.0/readme.txt ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === amr shortcode any widget ===
2
+ Contributors: anmari
3
+ Tags: shortcode, widget, page, templates, page template
4
+ Tested up to: 3.8.1
5
+ Version: 2
6
+ Stable tag: trunk
7
+
8
+ == Description ==
9
+ This simple 'utility' plugin allows one to have any widget used in a page shortcode in any theme - no need to use the hybrid theme or create a special template. 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/)
10
+
11
+ 1. Test your chosen widget works in a normal sidebar or widget area first.
12
+ 2. Then Activate this plugin
13
+ 3. Go to Appearance > widgets and find the " widgets for shortcode" sidebar or widget area
14
+ 4. Drag your chosen widgets from to the shortcodes sidebar. Save.
15
+ 5. Go the shortcode any widget settings. Click on one of the create page links to help you setup the shortcode.
16
+ 6. OR go to an existing page and enter a shortcode:
17
+ [do_widget widgetname] eg: [do_widget calendar]
18
+ [do_widget "widget name"]. eg: [do_widget "tag cloud"]
19
+ [do_widget_area] (will use the "widgets in shortcodes" widget area / sidebar
20
+ [do_widget_area sidebarname] for another sidebar or widget area - eg: to maximise likelihood of getting your theme's widget css to apply. Beware of white text on white background issues (TwentyFourteen theme is a good example of this.)
21
+ [do_widget id=widgetid] in a page or post
22
+ 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.
23
+ Click on the link 'Try debug'.
24
+ 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 wusing 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.
25
+
26
+ See the settings page for more examples.
27
+
28
+ To 'remove debug mode'
29
+ remove ?do_widget_debug=1 from the url you are looking at (only debugs if you are logged in and an administrator)
30
+
31
+ The plugin has been tested with most standard widgets (rss feeds, tag cloud, pages, meta, search, and of course my own plugins widgets - upcoming events list, calendar and user lists.
32
+
33
+ If you use a widget more than once for different reasons, you may need to use the widget id to isolate which widget instance and it's settings to use. ie: [do_widget id=categories-6] . If you just use the name, it will display all widgets in the shortcode sidebar with that name (all instances).
34
+
35
+ If you liked this plugin, you might also like my other plugins:
36
+ [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)
37
+ [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/)
38
+
39
+
40
+
41
+ == Changelog ==
42
+ = Version 2 =
43
+ * Shortcode widget id changed so that wordpress will save the shortcode settings per theme.
44
+ * Added Code to auto upgrade, but just in case please check your widgets page. Look at the inactive widgets if the widgets are not in your widgets for shortcodes sidebar.
45
+ * Logic added on theme switching to save shortcode widget settings and restore them after the theme switch, so you can play with themes and not have to set up your widgets again. WP kept putting them into an 'inactive sidebar'.
46
+ * Added, as requested by a few of you, the ability to add a class and control the html around the widget without having to enter html around the shortcode has been added. See the settings page for instructions.
47
+ * Added the ability to specify what html should be used for the title and the widget wrap, so that you can more easily either match your theme or get away from your thesmes widget styling.
48
+ * Added ability to insert a whole widget area into the page. The default will be the "widgets for shortcode" sidebar/widget area. You can specify others. Note Specifying other widget areas may be theme dependent, ie: switch and you'll lose that page.
49
+ * Added classes amr-widget and amr-widget-area so one can target the widgets in the page to adjust css.
50
+
51
+ = Version 1.8 =
52
+ * Whoops - had renamed the main file and forgot to delete it from the svn. Forcing a version number change to ensure files get cleaned up for everyone
53
+
54
+ = Version 1.7 =
55
+ * Change: Changed so that debugs and debug prompt will only show to a logged in administrator.
56
+
57
+ = Version 1.6 =
58
+ * Add: added a settings page to help people out (not really settings)
59
+ * Fix: changed a clashing function name
60
+
61
+ = Version 1.5 =
62
+ * Fixed: a small bug which caused a warning if you had not saved the widgets in your shortcode sidebar
63
+
64
+ = Version 1.4 =
65
+ * Updated readme - made very detailed steps and added some screen shots.
66
+ * Tested on wp 3.3.1 and fixed some notices when bad parameters entered.
67
+
68
+ = Version 1.3 =
69
+ * Added debug link and retested. Added readme.
70
+
71
+ = 1.12=
72
+ * Changed dummy shortcode sidebar so it appears after the theme sidebars to avoid taking over their widgets (this happened in numbered sidebars) PLEASE note if you have upgraded, you may appear to have "lost" your widgets due to this sidebar change. You have not - they will be in your "inactive widgets" - please drag them to the new sidebar. You may also find that you have 2 versions of the plugin, with slightly different folder names. This will allow you to go back to the previous one to check what you had there if you need to. Deactivate the old one and activate the new one. Move your widgets back in. Test then Delete the old one. In one theme it also appeared that somehow due to this change, one of the sidebar widgets "moved" down to another sidebar. I think that this may have had something to do with the fact that sidebars can be numbered or named, so please check all your sidebars before continuing. As always make sure thath you know how to restore from a backup before doing any upgrades of any kind.
73
+ * Tested in 2.9.2, can still use either the widget name "Categories" or id=categories-6. Note widget must have been created in the dummy shortcode sidebar.
74
+
75
+ = 1.1 =
76
+
77
+ * Allow for lowercase use of widget names for the those challenged by attention to detail!
78
+ * Cleaned up debug mode to make it easier for people to identify which instance of a widget they are using. Add &do_widget_debug to url string.
79
+
80
+ = 1.0 =
81
+ * Launch of the plugin
82
+
83
+ == Installation ==
84
+
85
+ 0. Activate plugin
86
+ 1. Goto Appearance > widgets and find "shortcode" sidebar
87
+ 1. Drag chosen widgets to shortcodes sidebar. Save. (note the names)
88
+ 2. Add [do_widget widgetname] in a page or post or [do_widget_area]
89
+ 3. If it fails, click on the debug prompt and look for the id of your widget, use that.
90
+
91
+ 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"].
92
+
93
+ 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]
94
+
95
+ do_widget parameters:
96
+ title=false to hide a title
97
+ title= one of h1,h2,h3,h4,h5,strong,em
98
+ class=yourclassname
99
+ wrap=one of div, section, p, aside
100
+
101
+ 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.
102
+ You may have undesired effects applying that do not work in the main content area.
103
+ You may have desired effects not applying because the css is specific to a themes sidebar.
104
+
105
+
106
+
107
+
108
+ == Screenshots ==
109
+
110
+ 1. setting up widgets in page (must be in the shortcode sidebar)
111
+ 2. widgets in a page
112
+ 3. setting up widgets in the shortcode sidebar
113
+ 4. two rss feed widgets in shortcode sidebar - both will show if just name used
114
+ 5. Demonstration of two widgets being used via the do_widget short code.
115
+ 6. The Page or post with the do_widget shortcodes
116
+ 7. The shortcode sidebar. The widget's user interface (UI) is used to provide a UI for the do_widget shortcode.
117
+ 8. Debug prompt if one enters something like id=junk
118
+ 9. Debug messages - scroll down till you see the shortcodes sidebar - the widgets and their ids will be listed. Use the id of the widet you want.
119
+
tags/2.0/screenshot-1.jpg ADDED
Binary file
tags/2.0/screenshot-2.jpg ADDED
Binary file
tags/2.0/screenshot-3.jpg ADDED
Binary file
tags/2.0/screenshot-4.jpg ADDED
Binary file
tags/2.0/screenshot-5.png ADDED
Binary file
tags/2.0/screenshot-6.png ADDED
Binary file
tags/2.0/screenshot-7.png ADDED
Binary file
tags/2.0/screenshot-8.jpg ADDED
Binary file
tags/2.0/screenshot-9.jpg ADDED
Binary file
tags/2.1/amr-admin-form-html.php ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Backend Class for use in all amr plugins
4
+ * Version 0.1
5
+ */
6
+
7
+ //------------------------------------------------------------------------------------------------------------------
8
+ if (!class_exists('amr_saw_plugin_admin')) {
9
+ class amr_saw_plugin_admin {
10
+ var $hook = 'amr_saw';
11
+ var $filename = 'amr_shortcode_any_widget/amr_shortcode_any_widget.php';
12
+ var $longname = 'Shortcode any widget - insert widgets or widget areas into a page.';
13
+ var $shortname = 'Shortcode any widget';
14
+ var $optionname = '';
15
+ var $homepage = '';
16
+ var $parent_slug = 'plugin_listings_menu';
17
+ var $accesslvl = 'manage_options';
18
+
19
+ function amr_saw_plugin_admin() {
20
+ add_action('admin_menu', array(&$this, 'register_settings_page') );
21
+ add_filter('plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
22
+ }
23
+ function register_settings_page() {
24
+ add_options_page( $this->longname, $this->shortname, $this->accesslvl, $this->hook, array(&$this,'config_page'));
25
+ }
26
+ function plugin_options_url() {
27
+ return admin_url( 'options-general.php?page='.$this->hook );
28
+ }
29
+ /**
30
+ * Add a link to the settings page to the plugins list
31
+ */
32
+ function add_action_link( $links, $file ) {
33
+ static $this_plugin;
34
+ if( empty($this_plugin) )
35
+ $this_plugin = $this->filename;
36
+ if ( $file == $this_plugin ) {
37
+ $settings_link = '<a href="' . $this->plugin_options_url() . '">' . __('Settings') . '</a>';
38
+ array_unshift( $links, $settings_link );
39
+ }
40
+ return $links;
41
+ }
42
+
43
+ function admin_heading($title) {
44
+ echo '<div class="wrap" >
45
+ <div id="icon-options-general" class="icon32"><br />
46
+ </div>
47
+ <h2>'.$title.' </h2>';
48
+ // <form method="post" action="'
49
+ // .esc_url($_SERVER['PHP_SELF'])
50
+ // .'">';
51
+ // wp_nonce_field($this->hook); /* outputs hidden field */
52
+ // ;
53
+ }
54
+
55
+ function admin_subheading($title) {
56
+ echo '<h2>'.$title.'</h2>';
57
+ }
58
+ function config_page() {
59
+ $this->admin_heading($this->longname);
60
+ echo '<ul>';
61
+ echo '<li>';
62
+ _e('Drag the widgets you want to use to the shortcodes sidebar.');
63
+
64
+ echo '</li>';
65
+ echo '<li>';
66
+ _e('Set the widgets parameters if there are any.');
67
+ echo '</li>';
68
+ echo '<li>';
69
+ _e('You could test the widgets out in a displayable widget area (sidebar/footer), then drag them to the widgets_for_shortcodes sidebar.');
70
+
71
+ echo '</li>';
72
+ echo '<li>';
73
+ echo '<a title="Go to widget area" href="'.get_admin_url('','widgets.php').'"> ';
74
+ _e('Go to widgets');
75
+ echo '</a>';
76
+ echo '</li>';
77
+ echo '</ul>';
78
+
79
+ echo '<h2>';
80
+ _e('To add a widget area - all widgets in the widget area:');
81
+
82
+ echo '</h2>';
83
+ echo '<ul>';
84
+ echo '<li>';
85
+ echo '<a title="Create a page" href="'
86
+ .add_query_arg('content','[do_widget_area]', get_admin_url('','post-new.php?post_type=page'))
87
+ .'"> ';
88
+ _e('Create a page with do_widget_area shortcode');
89
+ echo '</a>';
90
+ echo '</li>';
91
+ echo '<li>';
92
+ _e('Examples:');
93
+ echo '</li>';
94
+ echo '<li>';
95
+ _e('[do_widget_area] or [do_widget_area widget_area=sidebar-1]');
96
+ echo '</li>';
97
+ echo '<li>';
98
+ _e('NB: Using something like the twenty-fourteen theme? you might end up with white text on a white background. Be prepared to adjust your css!');
99
+ echo '</li>';
100
+ echo '</ul>';
101
+ echo '<br />';
102
+
103
+ echo '<h2>';
104
+ _e('To add a single widget to a page');
105
+
106
+ echo '</h2>';
107
+ echo '<ul>';
108
+ echo '<li>';
109
+ _e('Add the shortcode [do_widget widgetname] to a page.');
110
+ _e('Examples:');
111
+ echo '</li>';
112
+ echo '<li>';
113
+ _e('[do_widget "tag cloud"] or [do_widget id=widgetid]');
114
+ echo '</li>';
115
+ echo '<li>';
116
+ echo '<a title="Create a page" href="'
117
+ .add_query_arg('content','[do_widget Archives]', get_admin_url('','post-new.php?post_type=page'))
118
+ .'"> ';
119
+ _e('Create a page with do_widget shortcode');
120
+ echo '</a>';
121
+ echo '</li>';
122
+ echo '<li>';
123
+ echo 'Use title=false to hide a widget title. ';
124
+ echo 'Use title=somehtmltag and wrap=somehtmltag to change the html used.';
125
+ echo ' Use class=yourclassname to add a class - maybe to override your themes widget styling?';
126
+ echo '</li>';
127
+ echo '<li>';
128
+ echo '[do_widget pages title=false] will hide the widget title';
129
+ echo '</li>';
130
+ echo '<li>';
131
+ echo '[do_widget pages title=h3] give the title a heading 3 html tag.';
132
+ echo '</li>';
133
+ echo '<li>';
134
+ echo '[do_widget categories] or [do_widget name=categories] will do the same thing: display the categories widget.';
135
+ echo '</li>';
136
+ echo '<li>';
137
+ echo '[do_widget "tag cloud" wrap=aside] will wrap the widget in an "aside" html tag.';
138
+ echo '</li>';
139
+ echo '<li>';
140
+ echo '[do_widget "recent posts"]';
141
+ echo '</li>';
142
+ echo '</ul>';
143
+
144
+ echo '<p>';
145
+ echo 'If the plugin cannot work out what you want, it will show a debug prompt
146
+ , click on the debug prompt and look for the name or id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug info). If the name does not work, try with the 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.';
147
+ echo '</p><p><b>';
148
+ echo "Valid title html tags are : h1, h2, h3, h4, h5, header, strong, em ";
149
+ echo '</b></p><p><b>';
150
+ echo "Valid html wrap tags are : div, p, aside , section";
151
+ echo '</b></p>';
152
+
153
+ }
154
+
155
+
156
+ /**
157
+ * Info box with link to the support forums.
158
+ */
159
+ function plugin_support() {
160
+ $content = '<p>'.__('If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the','amrplugin').' <a href="http://wordpress.org/tags/'.$this->hook.'">'.__("Support forums",'amrplugin').'</a>.</p>';
161
+ $this->postbox($this->hook.'support', 'Need support?', $content);
162
+ }
163
+
164
+ function text_limit( $text, $limit, $finish = ' [&hellip;]') {
165
+ if( strlen( $text ) > $limit ) {
166
+ $text = substr( $text, 0, $limit );
167
+ $text = substr( $text, 0, - ( strlen( strrchr( $text,' ') ) ) );
168
+ $text .= $finish;
169
+ }
170
+ return $text;
171
+ }
172
+ }
173
+ }
174
+
175
+ ?>
tags/2.1/amr-shortcode-any-widget.php ADDED
@@ -0,0 +1,282 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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.1
8
+ Author URI: http://webdesign.anmari.com
9
+
10
+ */
11
+ /*-----------------------------------*/
12
+ function do_widget_area($atts) {
13
+
14
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
15
+
16
+ extract(shortcode_atts(array(
17
+ 'widget_area' => 'widgets_for_shortcodes'
18
+ ), $atts));
19
+
20
+ $output = PHP_EOL.'<div id="'.$widget_area.'" class="amr-widget-area widget-area">';
21
+
22
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
23
+ dynamic_sidebar($widget_area);
24
+ $output .= ob_get_clean();
25
+
26
+ $output .= '</div>'.PHP_EOL;
27
+
28
+ return ($output);
29
+ }
30
+ /*-----------------------------------*/
31
+ function do_widget($atts) {
32
+
33
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
34
+
35
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
36
+ if it is in, then get the instance data and use that */
37
+
38
+ if (isset($_wp_sidebars_widgets) ) {
39
+ amr_show_widget_debug('which one'); //check for debug prompt and show widgets in shortcode sidebar if requested and logged in etc
40
+ }
41
+ else {
42
+ echo '<br />No widgets defined at all in any sidebar!';
43
+ return (false);
44
+ }
45
+
46
+ extract(shortcode_atts(array(
47
+ 'sidebar' => 'Widgets for Shortcodes',
48
+ 'id' => '',
49
+ 'name' => '', /* MKM added explicit 'name' attribute. For existing users we still need to allow prev method, else too many support queries will happen */
50
+ 'title' => '', /* do the default title unless they ask us not to - use string here not boolean */
51
+ 'class' => 'amr_widget', /* 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 */
52
+ 'wrap' => '' /* wrap the whole thing - title plus widget in a div - maybe the themes use a div, maybe not, maybe we want that styling, maybe not */
53
+ ), $atts));
54
+
55
+
56
+
57
+ /* compatibility check - if the name is not entered, then the first parameter is the name */
58
+ if (empty($name) and !empty($atts[0]))
59
+ $name = $atts[0];
60
+
61
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
62
+ if (!empty($name)) { // we have a name
63
+ $widget = $name;
64
+
65
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
66
+ if (strtolower($w['name']) === strtolower($widget)) $widget_ids[] = $i;
67
+ //if ($debug) {echo '<br /> Check: '.$w['name'];}
68
+ }
69
+ }
70
+ else { /* check for id if we do not have a name */
71
+ if (!empty($id)) { /* if a specific id has been specified */
72
+
73
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
74
+ if ($w['id'] === $id) $widget_ids[] = $id;
75
+ }
76
+ //if ($debug) { echo '<h2>We have an id: '.$id.'</h2>'; if (!empty($widget_ids)) var_dump($widget_ids); }
77
+ }
78
+ else {
79
+ echo '<br />No valid widget name or id given in shortcode parameters';
80
+ return (false);
81
+ }
82
+ }
83
+
84
+ if (empty ($widget_ids)) {
85
+ echo '<br /><a href="" title="Error: Your Requested widget '.$widget.' '.$id.' is not in the widget list. Typo maybe?">!</a><br />';
86
+ amr_show_widget_debug('empty', $atts);
87
+ return (false) ;
88
+ }
89
+
90
+ if (!($sidebarid = get_sidebar_id ($sidebar)))
91
+ $sidebarid=$sidebar; /* get the official sidebar id for this widget area - will take the first one */
92
+
93
+ if (empty($widget))
94
+ $widget = '';
95
+
96
+ $content = '';
97
+ /* if the widget is in our chosen sidebar, then use the options stored for that */
98
+
99
+ if ((!isset ($_wp_sidebars_widgets[$sidebarid])) or (empty ($_wp_sidebars_widgets[$sidebarid]))) { // try upgrade
100
+ amr_upgrade_sidebar();
101
+ }
102
+
103
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
104
+ /* if ($debug) {
105
+ echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
106
+ sort ($_wp_sidebars_widgets[$sidebarid]);
107
+ foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
108
+ echo $i.' '.$w.'<br />';
109
+ };
110
+ }
111
+ */
112
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
113
+
114
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
115
+ /* if ($debug) { echo '<br />Will use widget ids'.'<br />';
116
+ foreach ($widget_ids as $i=> $w) {
117
+ echo '&nbsp;&nbsp;&nbsp;'.$w.'<br />';
118
+ };
119
+ }
120
+ */
121
+ }
122
+ else { /* the sidebar is not defined */
123
+ //if ($debug) {
124
+ echo '<br /><a href="" title="Error: Sidebar '.$sidebar.' with sidebarid '.$sidebarid.' is empty (no widgets) or is not defined.">!</a><br />';
125
+ //}
126
+ }
127
+
128
+ $output = '';
129
+ if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
130
+ //if ($debug) {
131
+ echo '<br /><a href="" title="Error: Your requested Widget '.$widget.' is not in the '.$sidebar.' sidebar ">!</a><br />';
132
+ amr_show_widget_debug('empty', $atts);
133
+ //}
134
+ unset($sidebar);
135
+ unset($sidebarid);
136
+
137
+ }
138
+ else {
139
+ /* There may only be one but if we have two in our chosen widget then it will do both */
140
+ $output = '';
141
+ foreach ($wid as $i=>$widget_instance) {
142
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
143
+ shortcode_sidebar($widget_instance, $sidebar, $title, $class, $wrap);
144
+ $output .= ob_get_clean();
145
+ }
146
+ }
147
+
148
+ return ($output);
149
+ }
150
+ /* -------------------------------------------------------------------------*/
151
+ function shortcode_sidebar( $widget_id, $name="widgets_for_shortcode", $title=true, $class='', $wrap='') { /* This is basically the wordpress code, slightly modified */
152
+ global $wp_registered_sidebars, $wp_registered_widgets;
153
+
154
+ $debug = amr_check_if_widget_debug();
155
+
156
+ $sidebarid = get_sidebar_id ($name);
157
+
158
+ $sidebars_widgets = wp_get_sidebars_widgets();
159
+
160
+ $sidebar = $wp_registered_sidebars[$sidebarid]; // has the params etc
161
+
162
+ $did_one = false;
163
+
164
+ /* lifted from wordpress code, keep as similar as possible for now */
165
+
166
+ if ( !isset($wp_registered_widgets[$widget_id]) ) continue;
167
+
168
+ $params = array_merge(
169
+ array(
170
+ array_merge( $sidebar, array('widget_id' => $widget_id, 'widget_name' => $wp_registered_widgets[$widget_id]['name']) ) ),
171
+ (array) $wp_registered_widgets[$widget_id]['params']
172
+ );
173
+
174
+ $validtitletags = array ('h1','h2','h3','h4','h5','header','strong','em');
175
+ $validwraptags = array ('div','p','main','aside','section');
176
+
177
+ if (!empty($wrap)) { /* then folks want to 'wrap' with their own html tag, or wrap = yes */
178
+ if ((!in_array( $wrap, $validwraptags)))
179
+ $wrap = '';
180
+ /* To match a variety of themes, allow for a variety of html tags. */
181
+ /* May not need if our sidebar match attempt has worked */
182
+ }
183
+
184
+ if (!empty ($wrap)) {
185
+ $params[0]['before_widget'] = '<'.$wrap.' id="%1$s" class="%2$s ">';
186
+ $params[0]['after_widget'] = '</'.$wrap.'>';
187
+ }
188
+
189
+ // wp code to get classname
190
+ $classname_ = '';
191
+ //foreach ( (array) $wp_registered_widgets[$widget_id]['classname'] as $cn ) {
192
+ $cn = $wp_registered_widgets[$widget_id]['classname'];
193
+ if ( is_string($cn) )
194
+ $classname_ .= '_' . $cn;
195
+ elseif ( is_object($cn) )
196
+ $classname_ .= '_' . get_class($cn);
197
+ //}
198
+ $classname_ = ltrim($classname_, '_');
199
+
200
+ // add MKM and others requested class in to the wp classname string
201
+ // if no class specfied, then class will = amrwidget. These classes are so can reverse out unwanted widget styling.
202
+
203
+ $classname_ .= ' widget '.$class;
204
+
205
+ // Substitute HTML id and class attributes into before_widget
206
+ if (!empty($params[0]['before_widget']))
207
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $widget_id, $classname_);
208
+ else
209
+ $params[0]['before_widget'] = '';
210
+
211
+ if (empty($params[0]['before_widget'])) $params[0]['after_widget'] = '';
212
+
213
+ //$params = apply_filters( 'dynamic_sidebar_params', $params ); // should we do this? - intended for sidebar but we not in sidebar
214
+
215
+ if (!empty($title)) {
216
+ if ($title=='false') { /* amr switch off the title html, still need to get rid of title separately */
217
+ $params[0]['before_title'] = '<span style="display: none">';
218
+ $params[0]['after_title'] = '</span>';
219
+ }
220
+ else {
221
+ if (in_array( $title, $validtitletags)) {
222
+ $params[0]['before_title'] = '<'.$title.' class="widget-title">';
223
+ $params[0]['after_title'] = '</'.$title.'>';
224
+ }
225
+ }
226
+ }
227
+
228
+ $callback = $wp_registered_widgets[$widget_id]['callback'];
229
+ if ( is_callable($callback) ) {
230
+ call_user_func_array($callback, $params);
231
+ $did_one = true;
232
+ }
233
+ // }
234
+ return $did_one;
235
+ }
236
+ /* -------------------------------------------------------------------------------------------------------------*/
237
+ function amr_reg_sidebar() { // this is fired late, so hopefully any theme sidebars will have been registered already.
238
+
239
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
240
+
241
+ if ( function_exists('register_sidebar') ) { // maybe later, get the first main sidebar and copy it's before/after etc
242
+ $args = array(
243
+ 'name' =>'Widgets for Shortcodes',
244
+ 'id' => 'widgets_for_shortcodes', // hope to avoid losing widgets
245
+ 'description' => 'Sidebar to hold widgets and their settings. These widgets will be used in a shortcode. This sidebars widgets should be saved with your theme settings now.',
246
+ 'before_widget' => '<aside'.' id="%1$s" class="%2$s ">', // 201402 to match twentyfourteen theme
247
+ 'after_widget' => '</aside>',
248
+ 'before_title' => '<h1 class="widget-title" >', // 201402 maybe dont use widget class - we are in content here not in a widget area but others want?
249
+ 'after_title' => '</h1>' );
250
+
251
+
252
+
253
+ if (!empty($wp_registered_sidebars)) { // we got some sidebars already.
254
+ $main_sidebar = reset($wp_registered_sidebars); // Grab the first sidebar and use that as defaults for the widgets
255
+ $args['before_widget'] = $main_sidebar['before_widget'];
256
+ $args['after_widget'] = $main_sidebar['after_widget'];
257
+ $args['before_title'] = $main_sidebar['before_title'];
258
+ $args['after_title'] = $main_sidebar['after_title'];
259
+ }
260
+
261
+ register_sidebar($args);
262
+ }
263
+
264
+ //else { echo '<h1>CANNOT REGISTER widgets_for_shortcodes SIDEBAR</h1>';}
265
+ }
266
+ /*-----------------------------------*/
267
+ include ('amr-admin-form-html.php');
268
+ include ('amr-utilities.php');
269
+
270
+ if (is_admin() ) $amr_saw_plugin_admin = new amr_saw_plugin_admin();
271
+
272
+ add_action('widgets_init', 'amr_reg_sidebar',98); // register late so it appears last
273
+ //add_action('widgets_init', 'amr_upgrade_sidebar',99); // copy old shortcodes sidebar to new one if necessary
274
+ //add_action('switch_theme', 'amr_save_shortcodes_sidebar');
275
+ //add_action('after_switch_theme','amr_restore_shortcodes_sidebar');
276
+
277
+ add_shortcode('do_widget', 'do_widget');
278
+ add_shortcode('do_widget_area', 'do_widget_area'); // just dump the whole widget area - to get same styling
279
+
280
+ //require_once(ABSPATH . 'wp-includes/widgets.php'); // *** do we really need this here?
281
+
282
+ ?>
tags/2.1/amr-utilities.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*-----------------------------------*/
3
+ function get_sidebar_id ($name) {
4
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer.
5
+ take the first one that matches */
6
+ global $wp_registered_sidebars;
7
+
8
+ foreach ($wp_registered_sidebars as $i => $a) {
9
+ if ((isset ($a['name'])) and ( $a['name'] === $name))
10
+ return ($i);
11
+ }
12
+ return (false);
13
+ }
14
+ /*-----------------------------------*/
15
+ function amr_get_sidebar_name ($id) { /* dont need anymore ? or at least temporarily */
16
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
17
+ global $wp_registered_sidebars;
18
+ foreach ($wp_registered_sidebars as $i => $a) {
19
+ if ((isset ($a['id'])) and ( $a['id'] === $id)) {
20
+ if (isset($a['name'])) return ($a['name']);
21
+ else return ($id);
22
+ }
23
+ }
24
+ return (false);
25
+ }
26
+ /*-----------------------------------*/
27
+ function amr_check_if_widget_debug() {
28
+ // only do these debug if we are logged in and are the administrator
29
+
30
+ if ((!is_user_logged_in()) or (!current_user_can('administrator')))
31
+ return false;
32
+
33
+ if (isset($_REQUEST['do_widget_debug'])) {
34
+ $url_without_debug_query = remove_query_arg( 'do_widget_debug');
35
+ $eek = '<a href="'.$url_without_debug_query.'">Remove debug</a>';
36
+ echo '<br/>Note: Debugs only shown to a Logged in Administrator.'
37
+ .'<br />'
38
+ .$eek
39
+ .'<br />';
40
+ return true;
41
+ }
42
+ else
43
+ return false;
44
+ }
45
+ /*-----------------------------------*/
46
+ function amr_show_widget_debug($type='', $atts=array()) {
47
+ global $wp_registered_sidebars, $wp_registered_widgets, $_wp_sidebars_widgets;
48
+ // only do these debug if we are logged in and are the administrator
49
+
50
+ $debug = amr_check_if_widget_debug();
51
+
52
+ if ($type=='empty') {
53
+ if (current_user_can('administrator'))
54
+ echo '<br /> You are admin: <a href="'.add_query_arg('do_widget_debug','1').'">Try debug </a></b>'
55
+ .'See a exclamation point ! above ?. Hover over to see error message.'
56
+ .'</p>';
57
+
58
+ if ($debug) {
59
+
60
+ echo '<p>As a last resort, we may dump the wp variables to do with sidebars and widgets. Maybe that will help you:</p>';
61
+ $sidebars_widgets = wp_get_sidebars_widgets();
62
+ echo '<h3> result of wp_get_sidebars_widgets():</h3>';
63
+ foreach ($sidebars_widgets as $i=>$w) {
64
+ echo '<br/>'.$i; var_dump($w);
65
+ };
66
+
67
+ echo '<h3>$_wp_sidebars_widgets:</h3>';
68
+ var_dump($_wp_sidebars_widgets);
69
+ //echo '<br /><h3>$wp_registered_widgets:</h3>';
70
+ //var_dump($wp_registered_widgets);
71
+ echo '<br /><h3>$wp_registered_sidebars:</h3>';
72
+ var_dump($wp_registered_sidebars);
73
+ }
74
+ }
75
+
76
+ if (($type=='which one') and ($debug)) {
77
+ echo '<h3>DEBUG on: Is your widget in the widgets_for_shortcodes sidebar?</h3>';
78
+ //echo '<br />The shortcode attributes you entered are:<br />';
79
+ //var_dump($atts);
80
+ echo '<br /><h2>widgets_for_shortcodes sidebar and widgets</h2>';
81
+ $found = false;
82
+ foreach ($_wp_sidebars_widgets as $i=> $w) {
83
+ if (($i == "widgets_for_shortcodes")) {
84
+ echo 'Sidebar:&nbsp;<b>'.$i.': '.amr_get_sidebar_name($i).'</b> has widgets: <br />';
85
+ $found = true;
86
+ if (is_array($w)) {
87
+ sort ($w);
88
+ foreach ($w as $i2=> $w2) {
89
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$w2.' <br />';
90
+ };
91
+ }
92
+ echo '<br />';
93
+ }
94
+ //else {echo ' '.$i;}
95
+ };
96
+ if (!$found) echo '<h2>widgets_for_shortcodes sidebar empty or not defined.</h2>';
97
+ }
98
+ }
99
+ /*-----------------------------------*/
100
+ function amr_save_shortcodes_sidebar() { // when switching a theme, save the widgets we use for the shortcodes as they are getting overwritten
101
+ $sidebars_widgets = wp_get_sidebars_widgets();
102
+ if (!empty($sidebars_widgets['widgets_for_shortcodes']))
103
+ update_option('sidebars_widgets_for_shortcodes_saved',$sidebars_widgets['widgets_for_shortcodes']);
104
+ else { // our shortcodes sidebar is empty but when to fix ?
105
+
106
+ }
107
+ }
108
+ /*-----------------------------------*/
109
+ function amr_restore_shortcodes_sidebar() { // when switching a theme, restore the widgets we use for the shortcodes as they are getting overwritten
110
+ global $_wp_sidebars_widgets;
111
+
112
+ $sidebars_widgets = wp_get_sidebars_widgets();
113
+ if (empty($sidebars_widgets['widgets_for_shortcodes'])) {
114
+ $sidebars_widgets['widgets_for_shortcodes'] = get_option('sidebars_widgets_for_shortcodes_saved');
115
+ update_option('sidebars_widgets',$sidebars_widgets);
116
+
117
+ }
118
+
119
+ }
120
+ /*-----------------------------------*/
121
+ function amr_upgrade_sidebar() { // added in 2014 February for compatibility.. keep for how long. till no sites running older versions.?
122
+ $sidebars_widgets = wp_get_sidebars_widgets();
123
+ if (!empty($sidebars_widgets['Shortcodes']) and empty($sidebars_widgets['widgets_for_shortcodes'])) { // we need to upgrade
124
+ $sidebars_widgets['widgets_for_shortcodes'] = $sidebars_widgets['Shortcodes'];
125
+ unset ($sidebars_widgets['Shortcodes']);
126
+ update_option('sidebars_widgets',$sidebars_widgets );
127
+ add_action( 'admin_notices', 'widgets_shortcode_admin_notice' );
128
+ }
129
+ }
130
+
131
+ /*-----------------------------------*/
132
+ function widgets_shortcode_admin_notice() {
133
+ ?>
134
+ <div class="updated">
135
+ <p>Please go to widgets page and check your "widgets for shortcodes" sidebar. It will hopefully have been corrected upgraded with your widgets and all should be fine.</p>
136
+ </div>
137
+ <?php
138
+ }
139
+ /*-----------------------------------*/
140
+
141
+ ?>
tags/2.1/readme.txt ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === amr shortcode any widget ===
2
+ Contributors: anmari
3
+ Tags: shortcode, widget, page, templates, page template
4
+ Tested up to: 3.8.1
5
+ Version: 2.1
6
+ Stable tag: trunk
7
+
8
+ == Description ==
9
+ Insert widgets or a widget area into a page. Works by creating an extra sidebar/widget area that you can use to store the widgets settings. Plugin will then call that widget instance from the do_widget shortcode, or that sidebar from the do_wdget_area shortcode.
10
+ 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.
11
+ For more details see [anmari.com](http://webdesign.anmari.com/category/plugins/shortcode-any-widget/)
12
+
13
+ 1. Test your chosen widget works in a normal sidebar or widget area first.
14
+ 2. Then Activate this plugin
15
+ 3. Go to Appearance > widgets and find the " widgets for shortcode" sidebar or widget area
16
+ 4. Drag your chosen widgets from to the shortcodes sidebar. Save.
17
+ 5. Go the shortcode any widget settings. Click on one of the create page links to help you setup the shortcode.
18
+ 6. OR go to an existing page and enter a shortcode:
19
+ [do_widget widgetname] eg: [do_widget calendar]
20
+ [do_widget "widget name"]. eg: [do_widget "tag cloud"]
21
+ [do_widget_area] (will use the "widgets in shortcodes" widget area / sidebar
22
+ [do_widget_area sidebarname] for another sidebar or widget area - eg: to maximise likelihood of getting your theme's widget css to apply. Beware of white text on white background issues (TwentyFourteen theme is a good example of this.)
23
+ [do_widget id=widgetid] in a page or post
24
+ 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.
25
+ Click on the link 'Try debug'.
26
+ 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 wusing 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.
27
+
28
+ See the settings page for more examples.
29
+
30
+ To 'remove debug mode'
31
+ remove ?do_widget_debug=1 from the url you are looking at (only debugs if you are logged in and an administrator)
32
+
33
+ The plugin has been tested with most standard widgets (rss feeds, tag cloud, pages, meta, search, and of course my own plugins widgets - upcoming events list, calendar and user lists.
34
+
35
+ If you use a widget more than once for different reasons, you may need to use the widget id to isolate which widget instance and it's settings to use. ie: [do_widget id=categories-6] . If you just use the name, it will display all widgets in the shortcode sidebar with that name (all instances).
36
+
37
+ If you liked this plugin, you might also like my other plugins:
38
+ [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)
39
+ [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/)
40
+
41
+
42
+
43
+ == Changelog ==
44
+ = Version 2.1 =
45
+ * Bug Fix - last sidebar registered by theme was being overwritten by the attempt to copy the themes sidebar arguments so that cleverly (hopefully) the shortcode widgets would pick up the same styling. Fixed now. Now it really does pickup the first sidebars styling - with devasting consquence in twenty-fourteen theme - yes white text on white background is not fun to read. But on other themes it works a treat.
46
+
47
+
48
+ = Version 2 =
49
+ * Shortcode widget id changed so that wordpress will save the shortcode settings per theme.
50
+ * Added Code to auto upgrade, but just in case please check your widgets page. Look at the inactive widgets if the widgets are not in your widgets for shortcodes sidebar.
51
+ * Logic added on theme switching to save shortcode widget settings and restore them after the theme switch, so you can play with themes and not have to set up your widgets again. WP kept putting them into an 'inactive sidebar'.
52
+ * Added, as requested by a few of you, the ability to add a class and control the html around the widget without having to enter html around the shortcode has been added. See the settings page for instructions.
53
+ * Added the ability to specify what html should be used for the title and the widget wrap, so that you can more easily either match your theme or get away from your thesmes widget styling.
54
+ * Added ability to insert a whole widget area into the page. The default will be the "widgets for shortcode" sidebar/widget area. You can specify others. Note Specifying other widget areas may be theme dependent, ie: switch and you'll lose that page.
55
+ * Added classes amr-widget and amr-widget-area so one can target the widgets in the page to adjust css.
56
+
57
+ = Version 1.8 =
58
+ * Whoops - had renamed the main file and forgot to delete it from the svn. Forcing a version number change to ensure files get cleaned up for everyone
59
+
60
+ = Version 1.7 =
61
+ * Change: Changed so that debugs and debug prompt will only show to a logged in administrator.
62
+
63
+ = Version 1.6 =
64
+ * Add: added a settings page to help people out (not really settings)
65
+ * Fix: changed a clashing function name
66
+
67
+ = Version 1.5 =
68
+ * Fixed: a small bug which caused a warning if you had not saved the widgets in your shortcode sidebar
69
+
70
+ = Version 1.4 =
71
+ * Updated readme - made very detailed steps and added some screen shots.
72
+ * Tested on wp 3.3.1 and fixed some notices when bad parameters entered.
73
+
74
+ = Version 1.3 =
75
+ * Added debug link and retested. Added readme.
76
+
77
+ = 1.12=
78
+ * Changed dummy shortcode sidebar so it appears after the theme sidebars to avoid taking over their widgets (this happened in numbered sidebars) PLEASE note if you have upgraded, you may appear to have "lost" your widgets due to this sidebar change. You have not - they will be in your "inactive widgets" - please drag them to the new sidebar. You may also find that you have 2 versions of the plugin, with slightly different folder names. This will allow you to go back to the previous one to check what you had there if you need to. Deactivate the old one and activate the new one. Move your widgets back in. Test then Delete the old one. In one theme it also appeared that somehow due to this change, one of the sidebar widgets "moved" down to another sidebar. I think that this may have had something to do with the fact that sidebars can be numbered or named, so please check all your sidebars before continuing. As always make sure thath you know how to restore from a backup before doing any upgrades of any kind.
79
+ * Tested in 2.9.2, can still use either the widget name "Categories" or id=categories-6. Note widget must have been created in the dummy shortcode sidebar.
80
+
81
+ = 1.1 =
82
+
83
+ * Allow for lowercase use of widget names for the those challenged by attention to detail!
84
+ * Cleaned up debug mode to make it easier for people to identify which instance of a widget they are using. Add &do_widget_debug to url string.
85
+
86
+ = 1.0 =
87
+ * Launch of the plugin
88
+
89
+ == Installation ==
90
+
91
+ 0. Activate plugin
92
+ 1. Goto Appearance > widgets and find "shortcode" sidebar
93
+ 1. Drag chosen widgets to shortcodes sidebar. Save. (note the names)
94
+ 2. Add [do_widget widgetname] in a page or post or [do_widget_area]
95
+ 3. If it fails, click on the debug prompt and look for the id of your widget, use that.
96
+
97
+ 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"].
98
+
99
+ 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]
100
+
101
+ do_widget parameters:
102
+ title=false to hide a title
103
+ title= one of h1,h2,h3,h4,h5,strong,em
104
+ class=yourclassname
105
+ wrap=one of div, section, p, aside
106
+
107
+ 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.
108
+ You may have undesired effects applying that do not work in the main content area.
109
+ You may have desired effects not applying because the css is specific to a themes sidebar.
110
+
111
+
112
+
113
+
114
+ == Screenshots ==
115
+
116
+ 1. setting up widgets in page (must be in the shortcode sidebar)
117
+ 2. widgets in a page
118
+ 3. setting up widgets in the shortcode sidebar
119
+ 4. two rss feed widgets in shortcode sidebar - both will show if just name used
120
+ 5. Demonstration of two widgets being used via the do_widget short code.
121
+ 6. The Page or post with the do_widget shortcodes
122
+ 7. The shortcode sidebar. The widget's user interface (UI) is used to provide a UI for the do_widget shortcode.
123
+ 8. Debug prompt if one enters something like id=junk
124
+ 9. Debug messages - scroll down till you see the shortcodes sidebar - the widgets and their ids will be listed. Use the id of the widet you want.
125
+
tags/2.1/screenshot-1.jpg ADDED
Binary file
tags/2.1/screenshot-2.jpg ADDED
Binary file
tags/2.1/screenshot-3.jpg ADDED
Binary file
tags/2.1/screenshot-4.jpg ADDED
Binary file
tags/2.1/screenshot-5.png ADDED
Binary file
tags/2.1/screenshot-6.png ADDED
Binary file
tags/2.1/screenshot-7.png ADDED
Binary file
tags/2.1/screenshot-8.jpg ADDED
Binary file
tags/2.1/screenshot-9.jpg ADDED
Binary file
tags/2.2/amr-admin-form-html.php ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Backend Class for use in all amr plugins
4
+ * Version 0.1
5
+ */
6
+
7
+ //------------------------------------------------------------------------------------------------------------------
8
+ if (!class_exists('amr_saw_plugin_admin')) {
9
+ class amr_saw_plugin_admin {
10
+ var $hook = 'amr_saw';
11
+ var $filename = 'amr_shortcode_any_widget/amr_shortcode_any_widget.php';
12
+ var $longname = 'Shortcode any widget - insert widgets or widget areas into a page.';
13
+ var $shortname = 'Shortcode any widget';
14
+ var $optionname = '';
15
+ var $homepage = '';
16
+ var $parent_slug = 'plugin_listings_menu';
17
+ var $accesslvl = 'manage_options';
18
+
19
+ function amr_saw_plugin_admin() {
20
+ add_action('admin_menu', array(&$this, 'register_settings_page') );
21
+ add_filter('plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
22
+ }
23
+ function register_settings_page() {
24
+ add_options_page( $this->longname, $this->shortname, $this->accesslvl, $this->hook, array(&$this,'config_page'));
25
+ }
26
+ function plugin_options_url() {
27
+ return admin_url( 'options-general.php?page='.$this->hook );
28
+ }
29
+ /**
30
+ * Add a link to the settings page to the plugins list
31
+ */
32
+ function add_action_link( $links, $file ) {
33
+ static $this_plugin;
34
+ if( empty($this_plugin) )
35
+ $this_plugin = $this->filename;
36
+ if ( $file == $this_plugin ) {
37
+ $settings_link = '<a href="' . $this->plugin_options_url() . '">' . __('Settings') . '</a>';
38
+ array_unshift( $links, $settings_link );
39
+ }
40
+ return $links;
41
+ }
42
+
43
+ function admin_heading($title) {
44
+ echo '<div class="wrap" >
45
+ <div id="icon-options-general" class="icon32"><br />
46
+ </div>
47
+ <h2>'.$title.' </h2>';
48
+ // <form method="post" action="'
49
+ // .esc_url($_SERVER['PHP_SELF'])
50
+ // .'">';
51
+ // wp_nonce_field($this->hook); /* outputs hidden field */
52
+ // ;
53
+ }
54
+
55
+ function admin_subheading($title) {
56
+ echo '<h2>'.$title.'</h2>';
57
+ }
58
+ function config_page() {
59
+ $this->admin_heading($this->longname);
60
+ echo '<h3><a href="http://wordpress.org/plugins/amr-shortcode-any-widget/">More detailed instructions at the wordpress plugin page.</a></h3>';
61
+ echo '<ul>';
62
+ echo '<li>';
63
+ _e('Drag the widgets you want to use to the shortcodes sidebar.');
64
+
65
+ echo '</li>';
66
+ echo '<li>';
67
+ _e('Set the widgets parameters if there are any.');
68
+ echo '</li>';
69
+ echo '<li>';
70
+ _e('You could test the widgets out in a displayable widget area (sidebar/footer), then drag them to the widgets_for_shortcodes sidebar.');
71
+
72
+ echo '</li>';
73
+ echo '<li>';
74
+ echo '<a title="Go to widget area" href="'.get_admin_url('','widgets.php').'"> ';
75
+ _e('Go to widgets');
76
+ echo '</a>';
77
+ echo '</li>';
78
+ echo '</ul>';
79
+
80
+ echo '<h2>';
81
+ _e('To add a widget area - all widgets in the widget area:');
82
+
83
+ echo '</h2>';
84
+ echo '<ul>';
85
+ echo '<li>';
86
+ echo '<a title="Create a page" href="'
87
+ .add_query_arg('content','[do_widget_area]', get_admin_url('','post-new.php?post_type=page'))
88
+ .'"> ';
89
+ _e('Create a page with do_widget_area shortcode without the widget_area class');
90
+ echo '</a> Hoping to avoid theme styling.';
91
+ echo '</li>';
92
+ echo '<li>';
93
+ echo '<a title="Create a page" href="'
94
+ .add_query_arg('content','[do_widget_area widget_area_class=none]', get_admin_url('','post-new.php?post_type=page'))
95
+ .'"> ';
96
+ _e('Create a page with do_widget_area shortcode');
97
+ echo '</a> Hoping to use theme styling.';
98
+ echo '</li>';
99
+ echo '<li>';
100
+ _e('Examples:');
101
+ echo '</li>';
102
+ echo '<li>';
103
+ _e('[do_widget_area] or [do_widget_area widget_area=sidebar-1]');
104
+ echo '</li>';
105
+ echo '<li>';
106
+ _e('NB: Using something like the twenty-fourteen theme? you might end up with white text on a white background. Tweak the widget classes or the html of the wrap or title. If that fails, adjust your css.');
107
+ echo '</li>';
108
+ echo '</ul>';
109
+ echo '<br />';
110
+
111
+ echo '<h2>';
112
+ _e('To add a single widget to a page');
113
+ echo '</h2>';
114
+ echo '<ul>';
115
+ echo '<li>';
116
+ _e('Add the shortcode [do_widget widgetname] to a page.');
117
+ _e('Examples:');
118
+ echo '</li>';
119
+ echo '<li>';
120
+ _e('[do_widget "tag cloud"] or [do_widget id=widgetid]');
121
+ echo '</li>';
122
+ echo '<li>';
123
+ echo '<a title="Create a page" href="'
124
+ .add_query_arg('content','[do_widget Archives widget_classes=none]', get_admin_url('','post-new.php?post_type=page'))
125
+ .'"> ';
126
+ _e('Create a page with do_widget shortcode and remove widget_classes');
127
+ echo '</a>';
128
+ echo '</li>';
129
+ echo '<li>';
130
+ echo '<a title="Create a page" href="'
131
+ .add_query_arg('content','[do_widget Archives]', get_admin_url('','post-new.php?post_type=page'))
132
+ .'"> ';
133
+ _e('Create a page with do_widget shortcode');
134
+ echo '</a>';
135
+ echo '</li>';
136
+ echo '<li>';
137
+ echo 'Use title=false to hide a widget title. ';
138
+ echo 'Use title=somehtmltag and wrap=somehtmltag to change the html used.';
139
+ echo ' Use class=yourclassname to add a class - maybe to override your themes widget styling?';
140
+ echo '</li>';
141
+ echo '<li>';
142
+ echo '[do_widget pages title=false] will hide the widget title';
143
+ echo '</li>';
144
+ echo '<li>';
145
+ echo '[do_widget pages title=h3] give the title a heading 3 html tag.';
146
+ echo '</li>';
147
+ echo '<li>';
148
+ echo '[do_widget categories] or [do_widget name=categories] will do the same thing: display the categories widget.';
149
+ echo '</li>';
150
+ echo '<li>';
151
+ echo '[do_widget "tag cloud" wrap=aside] will wrap the widget in an "aside" html tag.';
152
+ echo '</li>';
153
+ echo '<li>';
154
+ echo '[do_widget "recent posts"]';
155
+ echo '</li>';
156
+ echo '</ul>';
157
+
158
+ echo '<p>';
159
+ echo 'If the plugin cannot work out what you want, it will show a debug prompt
160
+ , click on the debug prompt and look for the name or id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug info). If the name does not work, try with the 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.';
161
+ echo '</p><p><b>';
162
+ echo "Valid title html tags are : h1, h2, h3, h4, h5, header, strong, em ";
163
+ echo '</b></p><p><b>';
164
+ echo "Valid html wrap tags are : div, p, aside , section";
165
+ echo '</b></p>';
166
+
167
+ }
168
+
169
+
170
+ /**
171
+ * Info box with link to the support forums.
172
+ */
173
+ function plugin_support() {
174
+ $content = '<p>'.__('If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the','amrplugin').' <a href="http://wordpress.org/tags/'.$this->hook.'">'.__("Support forums",'amrplugin').'</a>.</p>';
175
+ $this->postbox($this->hook.'support', 'Need support?', $content);
176
+ }
177
+
178
+ function text_limit( $text, $limit, $finish = ' [&hellip;]') {
179
+ if( strlen( $text ) > $limit ) {
180
+ $text = substr( $text, 0, $limit );
181
+ $text = substr( $text, 0, - ( strlen( strrchr( $text,' ') ) ) );
182
+ $text .= $finish;
183
+ }
184
+ return $text;
185
+ }
186
+ }
187
+ }
188
+
189
+ ?>
tags/2.2/amr-shortcode-any-widget.php ADDED
@@ -0,0 +1,326 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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
+ */
11
+ function amr_remove_widget_class($params) { // remove the widget classes
12
+ if (!empty($params[0]['before_widget'])) {
13
+ $params[0]['before_widget'] =
14
+ str_replace ('"widget ','"',$params[0]['before_widget']);
15
+ }
16
+
17
+ if (!empty($params[0]['before_title'])) {
18
+
19
+ $params[0]['before_title'] =
20
+ $params[0]['before_title'] = str_replace ('widget-title','',$params[0]['before_title']);
21
+
22
+ }
23
+
24
+ return ($params);
25
+ }
26
+ /*-----------------------------------*/
27
+ function do_widget_area($atts) {
28
+
29
+ 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
+ }
56
+ /*-----------------------------------*/
57
+ function do_widget($atts) {
58
+
59
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
60
+
61
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
62
+ if it is in, then get the instance data and use that */
63
+
64
+ if (isset($_wp_sidebars_widgets) ) {
65
+ amr_show_widget_debug('which one'); //check for debug prompt and show widgets in shortcode sidebar if requested and logged in etc
66
+ }
67
+ else {
68
+ echo '<br />No widgets defined at all in any sidebar!';
69
+ return (false);
70
+ }
71
+
72
+ extract(shortcode_atts(array(
73
+ 'sidebar' => 'Widgets for Shortcodes',
74
+ 'id' => '',
75
+ 'name' => '', /* MKM added explicit 'name' attribute. For existing users we still need to allow prev method, else too many support queries will happen */
76
+ 'title' => '', /* do the default title unless they ask us not to - use string here not boolean */
77
+ 'class' => 'amr_widget', /* 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 */
78
+ 'wrap' => '', /* wrap the whole thing - title plus widget in a div - maybe the themes use a div, maybe not, maybe we want that styling, maybe not */
79
+ 'widget_classes' => '' /* option to disassociate from themes widget styling */
80
+ ), $atts));
81
+
82
+
83
+
84
+ /* compatibility check - if the name is not entered, then the first parameter is the name */
85
+ if (empty($name) and !empty($atts[0]))
86
+ $name = $atts[0];
87
+
88
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
89
+ if (!empty($name)) { // we have a name
90
+ $widget = $name;
91
+
92
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
93
+ if (strtolower($w['name']) === strtolower($widget)) $widget_ids[] = $i;
94
+ //if ($debug) {echo '<br /> Check: '.$w['name'];}
95
+ }
96
+ }
97
+ else { /* check for id if we do not have a name */
98
+ if (!empty($id)) { /* if a specific id has been specified */
99
+
100
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
101
+ if ($w['id'] === $id) $widget_ids[] = $id;
102
+ }
103
+ //if ($debug) { echo '<h2>We have an id: '.$id.'</h2>'; if (!empty($widget_ids)) var_dump($widget_ids); }
104
+ }
105
+ else {
106
+ echo '<br />No valid widget name or id given in shortcode parameters';
107
+ return (false);
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);
114
+ return (false) ;
115
+ }
116
+
117
+ if (!($sidebarid = get_sidebar_id ($sidebar)))
118
+ $sidebarid=$sidebar; /* get the official sidebar id for this widget area - will take the first one */
119
+
120
+ if (empty($widget))
121
+ $widget = '';
122
+
123
+ $content = '';
124
+ /* if the widget is in our chosen sidebar, then use the options stored for that */
125
+
126
+ if ((!isset ($_wp_sidebars_widgets[$sidebarid])) or (empty ($_wp_sidebars_widgets[$sidebarid]))) { // try upgrade
127
+ amr_upgrade_sidebar();
128
+ }
129
+
130
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
131
+ /* if ($debug) {
132
+ echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
133
+ sort ($_wp_sidebars_widgets[$sidebarid]);
134
+ foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
135
+ echo $i.' '.$w.'<br />';
136
+ };
137
+ }
138
+ */
139
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
140
+
141
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
142
+ /* if ($debug) { echo '<br />Will use widget ids'.'<br />';
143
+ foreach ($widget_ids as $i=> $w) {
144
+ echo '&nbsp;&nbsp;&nbsp;'.$w.'<br />';
145
+ };
146
+ }
147
+ */
148
+ }
149
+ else { /* the sidebar is not defined */
150
+ //if ($debug) {
151
+ echo '<br /><a href="" title="Error: Sidebar '.$sidebar.' with sidebarid '.$sidebarid.' is empty (no widgets) or is not defined.">!</a><br />';
152
+ //}
153
+ }
154
+
155
+ $output = '';
156
+ if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
157
+ //if ($debug) {
158
+ echo '<br /><a href="" title="Error: Your requested Widget '.$widget.' is not in the '.$sidebar.' sidebar ">!</a><br />';
159
+ amr_show_widget_debug('empty', $atts);
160
+ //}
161
+ unset($sidebar);
162
+ unset($sidebarid);
163
+
164
+ }
165
+ else {
166
+ /* There may only be one but if we have two in our chosen widget then it will do both */
167
+ $output = '';
168
+ foreach ($wid as $i=>$widget_instance) {
169
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
170
+ shortcode_sidebar($widget_instance, $sidebar, $title, $class, $wrap, $widget_classes);
171
+ $output .= ob_get_clean();
172
+ }
173
+ }
174
+
175
+ return ($output);
176
+ }
177
+ /* -------------------------------------------------------------------------*/
178
+ function shortcode_sidebar( $widget_id, $name="widgets_for_shortcode", $title=true, $class='', $wrap='', $widget_classes='') { /* This is basically the wordpress code, slightly modified */
179
+ global $wp_registered_sidebars, $wp_registered_widgets;
180
+
181
+ $debug = amr_check_if_widget_debug();
182
+
183
+ $sidebarid = get_sidebar_id ($name);
184
+
185
+ $sidebars_widgets = wp_get_sidebars_widgets();
186
+
187
+ $sidebar = $wp_registered_sidebars[$sidebarid]; // has the params etc
188
+
189
+ $did_one = false;
190
+
191
+ /* lifted from wordpress code, keep as similar as possible for now */
192
+
193
+ if ( !isset($wp_registered_widgets[$widget_id]) ) continue;
194
+
195
+ $params = array_merge(
196
+ array(
197
+ array_merge( $sidebar,
198
+ array('widget_id' => $widget_id,
199
+ 'widget_name' => $wp_registered_widgets[$widget_id]['name']) ) ),
200
+ (array) $wp_registered_widgets[$widget_id]['params']
201
+ );
202
+
203
+ $validtitletags = array ('h1','h2','h3','h4','h5','header','strong','em');
204
+ $validwraptags = array ('div','p','main','aside','section');
205
+
206
+ if (!empty($wrap)) { /* then folks want to 'wrap' with their own html tag, or wrap = yes */
207
+ if ((!in_array( $wrap, $validwraptags)))
208
+ $wrap = '';
209
+ /* To match a variety of themes, allow for a variety of html tags. */
210
+ /* May not need if our sidebar match attempt has worked */
211
+ }
212
+
213
+ if (!empty ($wrap)) {
214
+ $params[0]['before_widget'] = '<'.$wrap.' id="%1$s" class="%2$s">';
215
+ $params[0]['after_widget'] = '</'.$wrap.'>';
216
+ }
217
+
218
+ // wp code to get classname
219
+ $classname_ = '';
220
+ //foreach ( (array) $wp_registered_widgets[$widget_id]['classname'] as $cn ) {
221
+ $cn = $wp_registered_widgets[$widget_id]['classname'];
222
+ if ( is_string($cn) )
223
+ $classname_ .= '_' . $cn;
224
+ elseif ( is_object($cn) )
225
+ $classname_ .= '_' . get_class($cn);
226
+ //}
227
+ $classname_ = ltrim($classname_, '_');
228
+
229
+ // add MKM and others requested class in to the wp classname string
230
+ // if no class specfied, then class will = amrwidget. These classes are so can reverse out unwanted widget styling.
231
+
232
+ // $classname_ .= ' widget '; // wordpress seems to almost always adds the widget class
233
+
234
+
235
+ $classname_ .= ' '.$class;
236
+
237
+ // we are picking up the defaults from the thems sidebar ad they have registered heir sidebar to issue widget classes?
238
+
239
+
240
+ // Substitute HTML id and class attributes into before_widget
241
+ if (!empty($params[0]['before_widget']))
242
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $widget_id, $classname_);
243
+ else
244
+ $params[0]['before_widget'] = '';
245
+
246
+ if (empty($params[0]['before_widget']))
247
+ $params[0]['after_widget'] = '';
248
+
249
+ $params = apply_filters( 'dynamic_sidebar_params', $params );
250
+ // allow, any pne usingmust ensure they apply to the correct sidebars
251
+
252
+ if (!empty($title)) {
253
+ if ($title=='false') { /* amr switch off the title html, still need to get rid of title separately */
254
+ $params[0]['before_title'] = '<span style="display: none">';
255
+ $params[0]['after_title'] = '</span>';
256
+ }
257
+ else {
258
+ if (in_array( $title, $validtitletags)) {
259
+ $class = ' class="widget-title" ';
260
+
261
+ $params[0]['before_title'] = '<'.$title.' '.$class.' >';
262
+ $params[0]['after_title'] = '</'.$title.'>';
263
+ }
264
+ }
265
+ }
266
+
267
+ if (!empty($widget_classes) and ($widget_classes == 'none') ) {
268
+ $params = amr_remove_widget_class($params); // also called in widget area shortcode
269
+ }
270
+
271
+
272
+ $callback = $wp_registered_widgets[$widget_id]['callback'];
273
+ if ( is_callable($callback) ) {
274
+ call_user_func_array($callback, $params);
275
+ $did_one = true;
276
+ }
277
+ // }
278
+ return $did_one;
279
+ }
280
+ /* -------------------------------------------------------------------------------------------------------------*/
281
+ function amr_reg_sidebar() { // this is fired late, so hopefully any theme sidebars will have been registered already.
282
+
283
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
284
+
285
+ if ( function_exists('register_sidebar') ) { // maybe later, get the first main sidebar and copy it's before/after etc
286
+ $args = array(
287
+ 'name' =>'Widgets for Shortcodes',
288
+ 'id' => 'widgets_for_shortcodes', // hope to avoid losing widgets
289
+ 'description' => 'Sidebar to hold widgets and their settings. These widgets will be used in a shortcode. This sidebars widgets should be saved with your theme settings now.',
290
+ 'before_widget' => '<aside'.' id="%1$s" class="%2$s ">', // 201402 to match twentyfourteen theme
291
+ 'after_widget' => '</aside>',
292
+ 'before_title' => '<h1 class="widget-title" >', // 201402 maybe dont use widget class - we are in content here not in a widget area but others want the widget styling. ?
293
+ 'after_title' => '</h1>' );
294
+
295
+
296
+
297
+ if (!empty($wp_registered_sidebars)) { // we got some sidebars already.
298
+ $main_sidebar = reset($wp_registered_sidebars); // Grab the first sidebar and use that as defaults for the widgets
299
+ $args['before_widget'] = $main_sidebar['before_widget'];
300
+ $args['after_widget'] = $main_sidebar['after_widget'];
301
+ $args['before_title'] = $main_sidebar['before_title'];
302
+ $args['after_title'] = $main_sidebar['after_title'];
303
+ }
304
+
305
+ register_sidebar($args);
306
+ }
307
+
308
+ //else { echo '<h1>CANNOT REGISTER widgets_for_shortcodes SIDEBAR</h1>';}
309
+ }
310
+ /*-----------------------------------*/
311
+ include ('amr-admin-form-html.php');
312
+ include ('amr-utilities.php');
313
+
314
+ if (is_admin() ) $amr_saw_plugin_admin = new amr_saw_plugin_admin();
315
+
316
+ add_action('widgets_init', 'amr_reg_sidebar',98); // register late so it appears last
317
+ //add_action('widgets_init', 'amr_upgrade_sidebar',99); // copy old shortcodes sidebar to new one if necessary
318
+ //add_action('switch_theme', 'amr_save_shortcodes_sidebar');
319
+ //add_action('after_switch_theme','amr_restore_shortcodes_sidebar');
320
+
321
+ add_shortcode('do_widget', 'do_widget');
322
+ add_shortcode('do_widget_area', 'do_widget_area'); // just dump the whole widget area - to get same styling
323
+
324
+ //require_once(ABSPATH . 'wp-includes/widgets.php'); // *** do we really need this here?
325
+
326
+ ?>
tags/2.2/amr-utilities.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*-----------------------------------*/
3
+ function get_sidebar_id ($name) {
4
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer.
5
+ take the first one that matches */
6
+ global $wp_registered_sidebars;
7
+
8
+ foreach ($wp_registered_sidebars as $i => $a) {
9
+ if ((isset ($a['name'])) and ( $a['name'] === $name))
10
+ return ($i);
11
+ }
12
+ return (false);
13
+ }
14
+ /*-----------------------------------*/
15
+ function amr_get_sidebar_name ($id) { /* dont need anymore ? or at least temporarily */
16
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
17
+ global $wp_registered_sidebars;
18
+ foreach ($wp_registered_sidebars as $i => $a) {
19
+ if ((isset ($a['id'])) and ( $a['id'] === $id)) {
20
+ if (isset($a['name'])) return ($a['name']);
21
+ else return ($id);
22
+ }
23
+ }
24
+ return (false);
25
+ }
26
+ /*-----------------------------------*/
27
+ function amr_check_if_widget_debug() {
28
+ // only do these debug if we are logged in and are the administrator
29
+
30
+ if ((!is_user_logged_in()) or (!current_user_can('administrator')))
31
+ return false;
32
+
33
+ if (isset($_REQUEST['do_widget_debug'])) {
34
+ $url_without_debug_query = remove_query_arg( 'do_widget_debug');
35
+ $eek = '<a href="'.$url_without_debug_query.'">Remove debug</a>';
36
+ echo '<br/>Note: Debugs only shown to a Logged in Administrator.'
37
+ .'<br />'
38
+ .$eek
39
+ .'<br />';
40
+ return true;
41
+ }
42
+ else
43
+ return false;
44
+ }
45
+ /*-----------------------------------*/
46
+ function amr_show_widget_debug($type='', $atts=array()) {
47
+ global $wp_registered_sidebars, $wp_registered_widgets, $_wp_sidebars_widgets;
48
+ // only do these debug if we are logged in and are the administrator
49
+
50
+ $debug = amr_check_if_widget_debug();
51
+
52
+ if ($type=='empty') {
53
+ if (current_user_can('administrator'))
54
+ echo '<br /> You are admin: <a href="'.add_query_arg('do_widget_debug','1').'">Try debug </a></b>'
55
+ .'See a exclamation point ! above ?. Hover over to see error message.'
56
+ .'</p>';
57
+
58
+ if ($debug) {
59
+
60
+ echo '<p>As a last resort, we may dump the wp variables to do with sidebars and widgets. Maybe that will help you:</p>';
61
+ $sidebars_widgets = wp_get_sidebars_widgets();
62
+ echo '<h3> result of wp_get_sidebars_widgets():</h3>';
63
+ foreach ($sidebars_widgets as $i=>$w) {
64
+ echo '<br/>'.$i; var_dump($w);
65
+ };
66
+
67
+ echo '<h3>$_wp_sidebars_widgets:</h3>';
68
+ var_dump($_wp_sidebars_widgets);
69
+ //echo '<br /><h3>$wp_registered_widgets:</h3>';
70
+ //var_dump($wp_registered_widgets);
71
+ echo '<br /><h3>$wp_registered_sidebars:</h3>';
72
+ var_dump($wp_registered_sidebars);
73
+ }
74
+ }
75
+
76
+ if (($type=='which one') and ($debug)) {
77
+ echo '<h3>DEBUG on: Is your widget in the widgets_for_shortcodes sidebar?</h3>';
78
+ //echo '<br />The shortcode attributes you entered are:<br />';
79
+ //var_dump($atts);
80
+ echo '<br /><h2>widgets_for_shortcodes sidebar and widgets</h2>';
81
+ $found = false;
82
+ foreach ($_wp_sidebars_widgets as $i=> $w) {
83
+ if (($i == "widgets_for_shortcodes")) {
84
+ echo 'Sidebar:&nbsp;<b>'.$i.': '.amr_get_sidebar_name($i).'</b> has widgets: <br />';
85
+ $found = true;
86
+ if (is_array($w)) {
87
+ sort ($w);
88
+ foreach ($w as $i2=> $w2) {
89
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$w2.' <br />';
90
+ };
91
+ }
92
+ echo '<br />';
93
+ }
94
+ //else {echo ' '.$i;}
95
+ };
96
+ if (!$found) echo '<h2>widgets_for_shortcodes sidebar empty or not defined.</h2>';
97
+ }
98
+ }
99
+ /*-----------------------------------*/
100
+ function amr_save_shortcodes_sidebar() { // when switching a theme, save the widgets we use for the shortcodes as they are getting overwritten
101
+ $sidebars_widgets = wp_get_sidebars_widgets();
102
+ if (!empty($sidebars_widgets['widgets_for_shortcodes']))
103
+ update_option('sidebars_widgets_for_shortcodes_saved',$sidebars_widgets['widgets_for_shortcodes']);
104
+ else { // our shortcodes sidebar is empty but when to fix ?
105
+
106
+ }
107
+ }
108
+ /*-----------------------------------*/
109
+ function amr_restore_shortcodes_sidebar() { // when switching a theme, restore the widgets we use for the shortcodes as they are getting overwritten
110
+ global $_wp_sidebars_widgets;
111
+
112
+ $sidebars_widgets = wp_get_sidebars_widgets();
113
+ if (empty($sidebars_widgets['widgets_for_shortcodes'])) {
114
+ $sidebars_widgets['widgets_for_shortcodes'] = get_option('sidebars_widgets_for_shortcodes_saved');
115
+ update_option('sidebars_widgets',$sidebars_widgets);
116
+
117
+ }
118
+
119
+ }
120
+ /*-----------------------------------*/
121
+ function amr_upgrade_sidebar() { // added in 2014 February for compatibility.. keep for how long. till no sites running older versions.?
122
+ $sidebars_widgets = wp_get_sidebars_widgets();
123
+ if (!empty($sidebars_widgets['Shortcodes']) and empty($sidebars_widgets['widgets_for_shortcodes'])) { // we need to upgrade
124
+ $sidebars_widgets['widgets_for_shortcodes'] = $sidebars_widgets['Shortcodes'];
125
+ unset ($sidebars_widgets['Shortcodes']);
126
+ update_option('sidebars_widgets',$sidebars_widgets );
127
+ add_action( 'admin_notices', 'widgets_shortcode_admin_notice' );
128
+ }
129
+ }
130
+
131
+ /*-----------------------------------*/
132
+ function widgets_shortcode_admin_notice() {
133
+ ?>
134
+ <div class="updated">
135
+ <p>Please go to widgets page and check your "widgets for shortcodes" sidebar. It will hopefully have been corrected upgraded with your widgets and all should be fine.</p>
136
+ </div>
137
+ <?php
138
+ }
139
+ /*-----------------------------------*/
140
+
141
+ ?>
index.php → tags/2.2/index.php RENAMED
File without changes
tags/2.2/readme.txt ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ The plugins default action is that it will magically find the settings for your themes first sidebar and use them to control the widget's output. In most cases this would mean that the widget will be styled as per the rest of your theme.
18
+
19
+ If that does not look good, parameters exist to override this behaviour.
20
+
21
+ Change your theme? No problem, the plugin will save and restore the widgets_for_shortcode settings. On display it will then pick up the new themes sidebar settings. Check this still looks nice please! in some themes you may ned up with white text on a white background and will then have to override or change css.
22
+
23
+ **Instructions:**
24
+
25
+ 1. Test your chosen widget works in a normal sidebar or widget area first.
26
+ 2. Then Activate this plugin
27
+ 3. Go to Appearance > widgets and find the " widgets for shortcode" sidebar or widget area
28
+ 4. Drag your chosen widgets from to the shortcodes sidebar. Save.
29
+ 5. Go the shortcode any widget settings. Click on one of the create page links to help you setup the shortcode.
30
+ 6. OR go to an existing page and enter a shortcode:
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.
51
+ * class=*yourclassname* By default the plugin will add a class of amr-widget tto the wrapping html. You can use this to add any special css. Add css either by editing your themes stylesheet if it is a custom theme, or using something like the wordpress custom css plugin.
52
+ * sidebar="*sidebarname*" will default to widgets_for_shortcode sidebar. Only use if you want to re-use a widget already beingused in another sidebar. THis is theme dependent and WILL break if you change themes.
53
+
54
+ **[do_widget_area ...] Parameters:**
55
+
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.
63
+
64
+ To 'remove debug mode'
65
+ remove ?do_widget_debug=1 from the url you are looking at (NOTE it only debugs if you are logged in and an administrator, so this is really NOT a problem.)
66
+
67
+ The plugin has been tested with most standard widgets (rss feeds, tag cloud, pages, meta, search, and of course my own plugins widgets - upcoming events list, calendar and user lists.
68
+
69
+ If you use a widget more than once for different reasons, you may need to use the widget id to isolate which widget instance and it's settings to use. ie: [do_widget id=categories-6] . If you just use the name, it will display all widgets in the shortcode sidebar with that name (all instances).
70
+
71
+ 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
81
+ * Add widget_area_class=none
82
+
83
+ = Version 2.1 =
84
+ * Bug Fix - last sidebar registered by theme was being overwritten by the attempt to copy the themes sidebar arguments so that cleverly (hopefully) the shortcode widgets would pick up the same styling. Fixed now. Now it really does pickup the first sidebars styling - with devasting consquence in twenty-fourteen theme - yes white text on white background is not fun to read. But on other themes it works a treat.
85
+
86
+
87
+ = Version 2 =
88
+ * Shortcode widget id changed so that wordpress will save the shortcode settings per theme.
89
+ * Added Code to auto upgrade, but just in case please check your widgets page. Look at the inactive widgets if the widgets are not in your widgets for shortcodes sidebar.
90
+ * Logic added on theme switching to save shortcode widget settings and restore them after the theme switch, so you can play with themes and not have to set up your widgets again. WP kept putting them into an 'inactive sidebar'.
91
+ * Added, as requested by a few of you, the ability to add a class and control the html around the widget without having to enter html around the shortcode has been added. See the settings page for instructions.
92
+ * Added the ability to specify what html should be used for the title and the widget wrap, so that you can more easily either match your theme or get away from your thesmes widget styling.
93
+ * Added ability to insert a whole widget area into the page. The default will be the "widgets for shortcode" sidebar/widget area. You can specify others. Note Specifying other widget areas may be theme dependent, ie: switch and you'll lose that page.
94
+ * Added classes amr-widget and amr-widget-area so one can target the widgets in the page to adjust css.
95
+
96
+ = Version 1.8 =
97
+ * Whoops - had renamed the main file and forgot to delete it from the svn. Forcing a version number change to ensure files get cleaned up for everyone
98
+
99
+ = Version 1.7 =
100
+ * Change: Changed so that debugs and debug prompt will only show to a logged in administrator.
101
+
102
+ = Version 1.6 =
103
+ * Add: added a settings page to help people out (not really settings)
104
+ * Fix: changed a clashing function name
105
+
106
+ = Version 1.5 =
107
+ * Fixed: a small bug which caused a warning if you had not saved the widgets in your shortcode sidebar
108
+
109
+ = Version 1.4 =
110
+ * Updated readme - made very detailed steps and added some screen shots.
111
+ * Tested on wp 3.3.1 and fixed some notices when bad parameters entered.
112
+
113
+ = Version 1.3 =
114
+ * Added debug link and retested. Added readme.
115
+
116
+ = 1.12 =
117
+ * Changed dummy shortcode sidebar so it appears after the theme sidebars to avoid taking over their widgets (this happened in numbered sidebars) PLEASE note if you have upgraded, you may appear to have "lost" your widgets due to this sidebar change. You have not - they will be in your "inactive widgets" - please drag them to the new sidebar. You may also find that you have 2 versions of the plugin, with slightly different folder names. This will allow you to go back to the previous one to check what you had there if you need to. Deactivate the old one and activate the new one. Move your widgets back in. Test then Delete the old one. In one theme it also appeared that somehow due to this change, one of the sidebar widgets "moved" down to another sidebar. I think that this may have had something to do with the fact that sidebars can be numbered or named, so please check all your sidebars before continuing. As always make sure thath you know how to restore from a backup before doing any upgrades of any kind.
118
+ * Tested in 2.9.2, can still use either the widget name "Categories" or id=categories-6. Note widget must have been created in the dummy shortcode sidebar.
119
+
120
+ = 1.1 =
121
+
122
+ * Allow for lowercase use of widget names for the those challenged by attention to detail!
123
+ * Cleaned up debug mode to make it easier for people to identify which instance of a widget they are using. Add &do_widget_debug to url string.
124
+
125
+ = 1.0 =
126
+ * Launch of the plugin
127
+
128
+ == Installation ==
129
+
130
+ 0. Activate plugin
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
+
170
+ 1. setting up widgets in the widgets for shortcode sidebar. The widget's user interface (UI) is used to provide a UI for the do_widget shortcode.
171
+ 2. add shortcode for widgets in a page (must be in the widgets for shortcode sidebar)
172
+ 3. widgets in a page
173
+ 4. with the default widget class and with widget_classes=none
174
+ two rss feed widgets in shortcode sidebar - both will show if just name used
175
+ 5. Debug messages - scroll down till you see the shortcodes sidebar - the widgets and their ids will be listed. Use the id of the widget you want.
176
+ 6. Examples of a page with several do_widgets: query_posts and tag cloud
177
+ 7. Example of rss widgets in a custom theme
178
+
179
+
180
+
tags/2.2/screenshot-1.png ADDED
Binary file
tags/2.2/screenshot-2.jpg ADDED
Binary file
tags/2.2/screenshot-3.jpg ADDED
Binary file
tags/2.2/screenshot-4.png ADDED
Binary file
screenshot-5.png → tags/2.2/screenshot-5.png RENAMED
File without changes
tags/2.2/screenshot-6.png ADDED
Binary file
tags/2.2/screenshot-7.jpg ADDED
Binary file
tags/2.3/amr-admin-form-html.php ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Backend Class for use in all amr plugins
4
+ * Version 0.1
5
+ */
6
+
7
+ //------------------------------------------------------------------------------------------------------------------
8
+ if (!class_exists('amr_saw_plugin_admin')) {
9
+ class amr_saw_plugin_admin {
10
+ var $hook = 'amr_saw';
11
+ var $filename = 'amr_shortcode_any_widget/amr_shortcode_any_widget.php';
12
+ var $longname = 'Shortcode any widget - insert widgets or widget areas into a page.';
13
+ var $shortname = 'Shortcode any widget';
14
+ var $optionname = '';
15
+ var $homepage = '';
16
+ var $parent_slug = 'plugin_listings_menu';
17
+ var $accesslvl = 'manage_options';
18
+
19
+ function amr_saw_plugin_admin() {
20
+ add_action('admin_menu', array(&$this, 'register_settings_page') );
21
+ add_filter('plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
22
+ }
23
+ function register_settings_page() {
24
+ add_options_page( $this->longname, $this->shortname, $this->accesslvl, $this->hook, array(&$this,'config_page'));
25
+ }
26
+ function plugin_options_url() {
27
+ return admin_url( 'options-general.php?page='.$this->hook );
28
+ }
29
+ /**
30
+ * Add a link to the settings page to the plugins list
31
+ */
32
+ function add_action_link( $links, $file ) {
33
+ static $this_plugin;
34
+ if( empty($this_plugin) )
35
+ $this_plugin = $this->filename;
36
+ if ( $file == $this_plugin ) {
37
+ $settings_link = '<a href="' . $this->plugin_options_url() . '">' . __('Settings') . '</a>';
38
+ array_unshift( $links, $settings_link );
39
+ }
40
+ return $links;
41
+ }
42
+
43
+ function admin_heading($title) {
44
+ echo '<div class="wrap" >
45
+ <div id="icon-options-general" class="icon32"><br />
46
+ </div>
47
+ <h2>'.$title.' </h2>';
48
+ // <form method="post" action="'
49
+ // .esc_url($_SERVER['PHP_SELF'])
50
+ // .'">';
51
+ // wp_nonce_field($this->hook); /* outputs hidden field */
52
+ // ;
53
+ }
54
+
55
+ function admin_subheading($title) {
56
+ echo '<h2>'.$title.'</h2>';
57
+ }
58
+ function config_page() {
59
+ $this->admin_heading($this->longname);
60
+ echo '<h3><a href="http://wordpress.org/plugins/amr-shortcode-any-widget/">More detailed instructions at the wordpress plugin page.</a></h3>';
61
+ echo '<ul>';
62
+ echo '<li>';
63
+ _e('Drag the widgets you want to use to the shortcodes sidebar.');
64
+
65
+ echo '</li>';
66
+ echo '<li>';
67
+ _e('Set the widgets parameters if there are any.');
68
+ echo '</li>';
69
+ echo '<li>';
70
+ _e('You could test the widgets out in a displayable widget area (sidebar/footer), then drag them to the widgets_for_shortcodes sidebar.');
71
+
72
+ echo '</li>';
73
+ echo '<li>';
74
+ echo '<a title="Go to widget area" href="'.get_admin_url('','widgets.php').'"> ';
75
+ _e('Go to widgets');
76
+ echo '</a>';
77
+ echo '</li>';
78
+ echo '</ul>';
79
+
80
+ echo '<h2>';
81
+ _e('To add a widget area - all widgets in the widget area:');
82
+
83
+ echo '</h2>';
84
+ echo '<ul>';
85
+ echo '<li>';
86
+ echo '<a title="Create a page" href="'
87
+ .add_query_arg('content','[do_widget_area]', get_admin_url('','post-new.php?post_type=page'))
88
+ .'"> ';
89
+ _e('Create a page with do_widget_area shortcode without the widget_area class');
90
+ echo '</a> Hoping to avoid theme styling.';
91
+ echo '</li>';
92
+ echo '<li>';
93
+ echo '<a title="Create a page" href="'
94
+ .add_query_arg('content','[do_widget_area widget_area_class=none]', get_admin_url('','post-new.php?post_type=page'))
95
+ .'"> ';
96
+ _e('Create a page with do_widget_area shortcode');
97
+ echo '</a> Hoping to use theme styling.';
98
+ echo '</li>';
99
+ echo '<li>';
100
+ _e('Examples:');
101
+ echo '</li>';
102
+ echo '<li>';
103
+ _e('[do_widget_area] or [do_widget_area widget_area=sidebar-1]');
104
+ echo '</li>';
105
+ echo '<li>';
106
+ _e('NB: Using something like the twenty-fourteen theme? you might end up with white text on a white background. Tweak the widget classes or the html of the wrap or title. If that fails, adjust your css.');
107
+ echo '</li>';
108
+ echo '</ul>';
109
+ echo '<br />';
110
+
111
+ echo '<h2>';
112
+ _e('To add a single widget to a page');
113
+ echo '</h2>';
114
+ echo '<ul>';
115
+ echo '<li>';
116
+ _e('Add the shortcode [do_widget widgetname] to a page.');
117
+ _e('Examples:');
118
+ echo '</li>';
119
+ echo '<li>';
120
+ _e('[do_widget "tag cloud"] or [do_widget id=widgetid]');
121
+ echo '</li>';
122
+ echo '<li>';
123
+ echo '<a title="Create a page" href="'
124
+ .add_query_arg('content','[do_widget Archives widget_classes=none]', get_admin_url('','post-new.php?post_type=page'))
125
+ .'"> ';
126
+ _e('Create a page with do_widget shortcode and remove widget_classes');
127
+ echo '</a>';
128
+ echo '</li>';
129
+ echo '<li>';
130
+ echo '<a title="Create a page" href="'
131
+ .add_query_arg('content','[do_widget Archives]', get_admin_url('','post-new.php?post_type=page'))
132
+ .'"> ';
133
+ _e('Create a page with do_widget shortcode');
134
+ echo '</a>';
135
+ echo '</li>';
136
+ echo '<li>';
137
+ echo 'Use title=false to hide a widget title. ';
138
+ echo 'Use title=somehtmltag and wrap=somehtmltag to change the html used.';
139
+ echo ' Use class=yourclassname to add a class - maybe to override your themes widget styling?';
140
+ echo '</li>';
141
+ echo '<li>';
142
+ echo '[do_widget pages title=false] will hide the widget title';
143
+ echo '</li>';
144
+ echo '<li>';
145
+ echo '[do_widget pages title=h3] give the title a heading 3 html tag.';
146
+ echo '</li>';
147
+ echo '<li>';
148
+ echo '[do_widget categories] or [do_widget name=categories] will do the same thing: display the categories widget.';
149
+ echo '</li>';
150
+ echo '<li>';
151
+ echo '[do_widget "tag cloud" wrap=aside] will wrap the widget in an "aside" html tag.';
152
+ echo '</li>';
153
+ echo '<li>';
154
+ echo '[do_widget "recent posts"]';
155
+ echo '</li>';
156
+ echo '</ul>';
157
+
158
+ echo '<p>';
159
+ echo 'If the plugin cannot work out what you want, it will show a debug prompt
160
+ , click on the debug prompt and look for the name or id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug info). If the name does not work, try with the 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.';
161
+ echo '</p><p><b>';
162
+ echo "Valid title html tags are : h1, h2, h3, h4, h5, header, strong, em ";
163
+ echo '</b></p><p><b>';
164
+ echo "Valid html wrap tags are : div, p, aside , section";
165
+ echo '</b></p>';
166
+
167
+ }
168
+
169
+
170
+ /**
171
+ * Info box with link to the support forums.
172
+ */
173
+ function plugin_support() {
174
+ $content = '<p>'.__('If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the','amrplugin').' <a href="http://wordpress.org/tags/'.$this->hook.'">'.__("Support forums",'amrplugin').'</a>.</p>';
175
+ $this->postbox($this->hook.'support', 'Need support?', $content);
176
+ }
177
+
178
+ function text_limit( $text, $limit, $finish = ' [&hellip;]') {
179
+ if( strlen( $text ) > $limit ) {
180
+ $text = substr( $text, 0, $limit );
181
+ $text = substr( $text, 0, - ( strlen( strrchr( $text,' ') ) ) );
182
+ $text .= $finish;
183
+ }
184
+ return $text;
185
+ }
186
+ }
187
+ }
188
+
189
+ ?>
tags/2.3/amr-shortcode-any-widget.php ADDED
@@ -0,0 +1,343 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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.3
8
+ Author URI: http://webdesign.anmari.com
9
+
10
+ */
11
+ function amr_remove_widget_class($params) { // remove the widget classes
12
+ if (!empty($params[0]['before_widget'])) {
13
+ $params[0]['before_widget'] =
14
+ str_replace ('"widget ','"',$params[0]['before_widget']);
15
+ }
16
+
17
+ if (!empty($params[0]['before_title'])) {
18
+
19
+ $params[0]['before_title'] =
20
+ $params[0]['before_title'] = str_replace ('widget-title','',$params[0]['before_title']);
21
+
22
+ }
23
+
24
+ return ($params);
25
+ }
26
+ /*-----------------------------------*/
27
+ function do_widget_area($atts) {
28
+
29
+ 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
+
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
+ }
70
+ /*-----------------------------------*/
71
+ function do_widget($atts) {
72
+
73
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
74
+
75
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
76
+ if it is in, then get the instance data and use that */
77
+
78
+ if (isset($_wp_sidebars_widgets) ) {
79
+ amr_show_widget_debug('which one'); //check for debug prompt and show widgets in shortcode sidebar if requested and logged in etc
80
+ }
81
+ else {
82
+ echo '<br />No widgets defined at all in any sidebar!';
83
+ return (false);
84
+ }
85
+
86
+ extract(shortcode_atts(array(
87
+ 'sidebar' => 'Widgets for Shortcodes',
88
+ 'id' => '',
89
+ 'name' => '', /* MKM added explicit 'name' attribute. For existing users we still need to allow prev method, else too many support queries will happen */
90
+ 'title' => '', /* do the default title unless they ask us not to - use string here not boolean */
91
+ 'class' => 'amr_widget', /* 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 */
92
+ 'wrap' => '', /* wrap the whole thing - title plus widget in a div - maybe the themes use a div, maybe not, maybe we want that styling, maybe not */
93
+ 'widget_classes' => '' /* option to disassociate from themes widget styling */
94
+ ), $atts));
95
+
96
+
97
+
98
+ /* compatibility check - if the name is not entered, then the first parameter is the name */
99
+ if (empty($name) and !empty($atts[0]))
100
+ $name = $atts[0];
101
+
102
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
103
+ if (!empty($name)) { // we have a name
104
+ $widget = $name;
105
+
106
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
107
+ if (strtolower($w['name']) === strtolower($widget)) $widget_ids[] = $i;
108
+ //if ($debug) {echo '<br /> Check: '.$w['name'];}
109
+ }
110
+ }
111
+ else { /* check for id if we do not have a name */
112
+ if (!empty($id)) { /* if a specific id has been specified */
113
+
114
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
115
+ if ($w['id'] === $id) $widget_ids[] = $id;
116
+ }
117
+ //if ($debug) { echo '<h2>We have an id: '.$id.'</h2>'; if (!empty($widget_ids)) var_dump($widget_ids); }
118
+ }
119
+ else {
120
+ echo '<br />No valid widget name or id given in shortcode parameters';
121
+ return (false);
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);
131
+ return (false) ;
132
+ }
133
+
134
+ if (!($sidebarid = get_sidebar_id ($sidebar)))
135
+ $sidebarid=$sidebar; /* get the official sidebar id for this widget area - will take the first one */
136
+
137
+ if (empty($widget))
138
+ $widget = '';
139
+
140
+ $content = '';
141
+ /* if the widget is in our chosen sidebar, then use the options stored for that */
142
+
143
+ if ((!isset ($_wp_sidebars_widgets[$sidebarid])) or (empty ($_wp_sidebars_widgets[$sidebarid]))) { // try upgrade
144
+ amr_upgrade_sidebar();
145
+ }
146
+
147
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
148
+ /* if ($debug) {
149
+ echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
150
+ sort ($_wp_sidebars_widgets[$sidebarid]);
151
+ foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
152
+ echo $i.' '.$w.'<br />';
153
+ };
154
+ }
155
+ */
156
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
157
+
158
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
159
+ /* if ($debug) { echo '<br />Will use widget ids'.'<br />';
160
+ foreach ($widget_ids as $i=> $w) {
161
+ echo '&nbsp;&nbsp;&nbsp;'.$w.'<br />';
162
+ };
163
+ }
164
+ */
165
+ }
166
+ else { /* the sidebar is not defined */
167
+ //if ($debug) {
168
+ echo '<br /><a href="" title="Error: Sidebar '.$sidebar.' with sidebarid '.$sidebarid.' is empty (no widgets) or is not defined.">!</a><br />';
169
+ //}
170
+ }
171
+
172
+ $output = '';
173
+ if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
174
+ //if ($debug) {
175
+ echo '<br /><a href="" title="Error: Your requested Widget '.$widget.' is not in the '.$sidebar.' sidebar ">!</a><br />';
176
+ amr_show_widget_debug('empty', $atts);
177
+ //}
178
+ unset($sidebar);
179
+ unset($sidebarid);
180
+
181
+ }
182
+ else {
183
+ /* There may only be one but if we have two in our chosen widget then it will do both */
184
+ $output = '';
185
+ foreach ($wid as $i=>$widget_instance) {
186
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
187
+ shortcode_sidebar($widget_instance, $sidebar, $title, $class, $wrap, $widget_classes);
188
+ $output .= ob_get_clean();
189
+ }
190
+ }
191
+
192
+ return ($output);
193
+ }
194
+ /* -------------------------------------------------------------------------*/
195
+ function shortcode_sidebar( $widget_id, $name="widgets_for_shortcode", $title=true, $class='', $wrap='', $widget_classes='') { /* This is basically the wordpress code, slightly modified */
196
+ global $wp_registered_sidebars, $wp_registered_widgets;
197
+
198
+ $debug = amr_check_if_widget_debug();
199
+
200
+ $sidebarid = get_sidebar_id ($name);
201
+
202
+ $sidebars_widgets = wp_get_sidebars_widgets();
203
+
204
+ $sidebar = $wp_registered_sidebars[$sidebarid]; // has the params etc
205
+
206
+ $did_one = false;
207
+
208
+ /* lifted from wordpress code, keep as similar as possible for now */
209
+
210
+ if ( !isset($wp_registered_widgets[$widget_id]) ) continue;
211
+
212
+ $params = array_merge(
213
+ array(
214
+ array_merge( $sidebar,
215
+ array('widget_id' => $widget_id,
216
+ 'widget_name' => $wp_registered_widgets[$widget_id]['name']) ) ),
217
+ (array) $wp_registered_widgets[$widget_id]['params']
218
+ );
219
+
220
+ $validtitletags = array ('h1','h2','h3','h4','h5','header','strong','em');
221
+ $validwraptags = array ('div','p','main','aside','section');
222
+
223
+ if (!empty($wrap)) { /* then folks want to 'wrap' with their own html tag, or wrap = yes */
224
+ if ((!in_array( $wrap, $validwraptags)))
225
+ $wrap = '';
226
+ /* To match a variety of themes, allow for a variety of html tags. */
227
+ /* May not need if our sidebar match attempt has worked */
228
+ }
229
+
230
+ if (!empty ($wrap)) {
231
+ $params[0]['before_widget'] = '<'.$wrap.' id="%1$s" class="%2$s">';
232
+ $params[0]['after_widget'] = '</'.$wrap.'>';
233
+ }
234
+
235
+ // wp code to get classname
236
+ $classname_ = '';
237
+ //foreach ( (array) $wp_registered_widgets[$widget_id]['classname'] as $cn ) {
238
+ $cn = $wp_registered_widgets[$widget_id]['classname'];
239
+ if ( is_string($cn) )
240
+ $classname_ .= '_' . $cn;
241
+ elseif ( is_object($cn) )
242
+ $classname_ .= '_' . get_class($cn);
243
+ //}
244
+ $classname_ = ltrim($classname_, '_');
245
+
246
+ // add MKM and others requested class in to the wp classname string
247
+ // if no class specfied, then class will = amrwidget. These classes are so can reverse out unwanted widget styling.
248
+
249
+ // $classname_ .= ' widget '; // wordpress seems to almost always adds the widget class
250
+
251
+
252
+ $classname_ .= ' '.$class;
253
+
254
+ // we are picking up the defaults from the thems sidebar ad they have registered heir sidebar to issue widget classes?
255
+
256
+
257
+ // Substitute HTML id and class attributes into before_widget
258
+ if (!empty($params[0]['before_widget']))
259
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $widget_id, $classname_);
260
+ else
261
+ $params[0]['before_widget'] = '';
262
+
263
+ if (empty($params[0]['before_widget']))
264
+ $params[0]['after_widget'] = '';
265
+
266
+ $params = apply_filters( 'dynamic_sidebar_params', $params );
267
+ // allow, any pne usingmust ensure they apply to the correct sidebars
268
+
269
+ if (!empty($title)) {
270
+ if ($title=='false') { /* amr switch off the title html, still need to get rid of title separately */
271
+ $params[0]['before_title'] = '<span style="display: none">';
272
+ $params[0]['after_title'] = '</span>';
273
+ }
274
+ else {
275
+ if (in_array( $title, $validtitletags)) {
276
+ $class = ' class="widget-title" ';
277
+
278
+ $params[0]['before_title'] = '<'.$title.' '.$class.' >';
279
+ $params[0]['after_title'] = '</'.$title.'>';
280
+ }
281
+ }
282
+ }
283
+
284
+ if (!empty($widget_classes) and ($widget_classes == 'none') ) {
285
+ $params = amr_remove_widget_class($params); // also called in widget area shortcode
286
+ }
287
+
288
+
289
+ $callback = $wp_registered_widgets[$widget_id]['callback'];
290
+ if ( is_callable($callback) ) {
291
+ call_user_func_array($callback, $params);
292
+ $did_one = true;
293
+ }
294
+ // }
295
+ return $did_one;
296
+ }
297
+ /* -------------------------------------------------------------------------------------------------------------*/
298
+ function amr_reg_sidebar() { // this is fired late, so hopefully any theme sidebars will have been registered already.
299
+
300
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
301
+
302
+ if ( function_exists('register_sidebar') ) { // maybe later, get the first main sidebar and copy it's before/after etc
303
+ $args = array(
304
+ 'name' =>'Widgets for Shortcodes',
305
+ 'id' => 'widgets_for_shortcodes', // hope to avoid losing widgets
306
+ 'description' => 'Sidebar to hold widgets and their settings. These widgets will be used in a shortcode. This sidebars widgets should be saved with your theme settings now.',
307
+ 'before_widget' => '<aside'.' id="%1$s" class="%2$s ">', // 201402 to match twentyfourteen theme
308
+ 'after_widget' => '</aside>',
309
+ 'before_title' => '<h1 class="widget-title" >', // 201402 maybe dont use widget class - we are in content here not in a widget area but others want the widget styling. ?
310
+ 'after_title' => '</h1>' );
311
+
312
+
313
+
314
+ if (!empty($wp_registered_sidebars)) { // we got some sidebars already.
315
+ $main_sidebar = reset($wp_registered_sidebars); // Grab the first sidebar and use that as defaults for the widgets
316
+ $args['before_widget'] = $main_sidebar['before_widget'];
317
+ $args['after_widget'] = $main_sidebar['after_widget'];
318
+ $args['before_title'] = $main_sidebar['before_title'];
319
+ $args['after_title'] = $main_sidebar['after_title'];
320
+ }
321
+
322
+ register_sidebar($args);
323
+ }
324
+
325
+ //else { echo '<h1>CANNOT REGISTER widgets_for_shortcodes SIDEBAR</h1>';}
326
+ }
327
+ /*-----------------------------------*/
328
+ include ('amr-admin-form-html.php');
329
+ include ('amr-utilities.php');
330
+
331
+ if (is_admin() ) $amr_saw_plugin_admin = new amr_saw_plugin_admin();
332
+
333
+ add_action('widgets_init', 'amr_reg_sidebar',98); // register late so it appears last
334
+ //add_action('widgets_init', 'amr_upgrade_sidebar',99); // copy old shortcodes sidebar to new one if necessary
335
+ //add_action('switch_theme', 'amr_save_shortcodes_sidebar');
336
+ //add_action('after_switch_theme','amr_restore_shortcodes_sidebar');
337
+
338
+ add_shortcode('do_widget', 'do_widget');
339
+ add_shortcode('do_widget_area', 'do_widget_area'); // just dump the whole widget area - to get same styling
340
+
341
+ //require_once(ABSPATH . 'wp-includes/widgets.php'); // *** do we really need this here?
342
+
343
+ ?>
tags/2.3/amr-utilities.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*-----------------------------------*/
3
+ function get_sidebar_id ($name) {
4
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer.
5
+ take the first one that matches */
6
+ global $wp_registered_sidebars;
7
+
8
+ foreach ($wp_registered_sidebars as $i => $a) {
9
+ if ((isset ($a['name'])) and ( $a['name'] === $name))
10
+ return ($i);
11
+ }
12
+ return (false);
13
+ }
14
+ /*-----------------------------------*/
15
+ function amr_get_sidebar_name ($id) { /* dont need anymore ? or at least temporarily */
16
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
17
+ global $wp_registered_sidebars;
18
+ foreach ($wp_registered_sidebars as $i => $a) {
19
+ if ((isset ($a['id'])) and ( $a['id'] === $id)) {
20
+ if (isset($a['name'])) return ($a['name']);
21
+ else return ($id);
22
+ }
23
+ }
24
+ return (false);
25
+ }
26
+ /*-----------------------------------*/
27
+ function amr_check_if_widget_debug() {
28
+ // only do these debug if we are logged in and are the administrator
29
+
30
+ if ((!is_user_logged_in()) or (!current_user_can('administrator')))
31
+ return false;
32
+
33
+ if (isset($_REQUEST['do_widget_debug'])) {
34
+ $url_without_debug_query = remove_query_arg( 'do_widget_debug');
35
+ $eek = '<a href="'.$url_without_debug_query.'">Remove debug</a>';
36
+ echo '<br/>Note: Debugs only shown to a Logged in Administrator.'
37
+ .'<br />'
38
+ .$eek
39
+ .'<br />';
40
+ return true;
41
+ }
42
+ else
43
+ return false;
44
+ }
45
+ /*-----------------------------------*/
46
+ function amr_show_widget_debug($type='', $atts=array()) {
47
+ global $wp_registered_sidebars, $wp_registered_widgets, $_wp_sidebars_widgets;
48
+ // only do these debug if we are logged in and are the administrator
49
+
50
+ $debug = amr_check_if_widget_debug();
51
+
52
+ if ($type=='empty') {
53
+ if (current_user_can('administrator'))
54
+ echo '<br /> You are admin: <a href="'.add_query_arg('do_widget_debug','1').'">Try debug </a></b>'
55
+ .'See a exclamation point ! above ?. Hover over to see error message.'
56
+ .'</p>';
57
+
58
+ if ($debug) {
59
+
60
+ echo '<p>As a last resort, we may dump the wp variables to do with sidebars and widgets. Maybe that will help you:</p>';
61
+ $sidebars_widgets = wp_get_sidebars_widgets();
62
+ echo '<h3> result of wp_get_sidebars_widgets():</h3>';
63
+ foreach ($sidebars_widgets as $i=>$w) {
64
+ echo '<br/>'.$i; var_dump($w);
65
+ };
66
+
67
+ echo '<h3>$_wp_sidebars_widgets:</h3>';
68
+ var_dump($_wp_sidebars_widgets);
69
+ //echo '<br /><h3>$wp_registered_widgets:</h3>';
70
+ //var_dump($wp_registered_widgets);
71
+ echo '<br /><h3>$wp_registered_sidebars:</h3>';
72
+ var_dump($wp_registered_sidebars);
73
+ }
74
+ }
75
+
76
+ if (($type=='which one') and ($debug)) {
77
+ echo '<h3>DEBUG on: Is your widget in the widgets_for_shortcodes sidebar?</h3>';
78
+ //echo '<br />The shortcode attributes you entered are:<br />';
79
+ //var_dump($atts);
80
+ echo '<br /><h2>widgets_for_shortcodes sidebar and widgets</h2>';
81
+ $found = false;
82
+ foreach ($_wp_sidebars_widgets as $i=> $w) {
83
+ if (($i == "widgets_for_shortcodes")) {
84
+ echo 'Sidebar:&nbsp;<b>'.$i.': '.amr_get_sidebar_name($i).'</b> has widgets: <br />';
85
+ $found = true;
86
+ if (is_array($w)) {
87
+ sort ($w);
88
+ foreach ($w as $i2=> $w2) {
89
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$w2.' <br />';
90
+ };
91
+ }
92
+ echo '<br />';
93
+ }
94
+ //else {echo ' '.$i;}
95
+ };
96
+ if (!$found) echo '<h2>widgets_for_shortcodes sidebar empty or not defined.</h2>';
97
+ }
98
+ }
99
+ /*-----------------------------------*/
100
+ function amr_save_shortcodes_sidebar() { // when switching a theme, save the widgets we use for the shortcodes as they are getting overwritten
101
+ $sidebars_widgets = wp_get_sidebars_widgets();
102
+ if (!empty($sidebars_widgets['widgets_for_shortcodes']))
103
+ update_option('sidebars_widgets_for_shortcodes_saved',$sidebars_widgets['widgets_for_shortcodes']);
104
+ else { // our shortcodes sidebar is empty but when to fix ?
105
+
106
+ }
107
+ }
108
+ /*-----------------------------------*/
109
+ function amr_restore_shortcodes_sidebar() { // when switching a theme, restore the widgets we use for the shortcodes as they are getting overwritten
110
+ global $_wp_sidebars_widgets;
111
+
112
+ $sidebars_widgets = wp_get_sidebars_widgets();
113
+ if (empty($sidebars_widgets['widgets_for_shortcodes'])) {
114
+ $sidebars_widgets['widgets_for_shortcodes'] = get_option('sidebars_widgets_for_shortcodes_saved');
115
+ update_option('sidebars_widgets',$sidebars_widgets);
116
+
117
+ }
118
+
119
+ }
120
+ /*-----------------------------------*/
121
+ function amr_upgrade_sidebar() { // added in 2014 February for compatibility.. keep for how long. till no sites running older versions.?
122
+ $sidebars_widgets = wp_get_sidebars_widgets();
123
+ if (!empty($sidebars_widgets['Shortcodes']) and empty($sidebars_widgets['widgets_for_shortcodes'])) { // we need to upgrade
124
+ $sidebars_widgets['widgets_for_shortcodes'] = $sidebars_widgets['Shortcodes'];
125
+ unset ($sidebars_widgets['Shortcodes']);
126
+ update_option('sidebars_widgets',$sidebars_widgets );
127
+ add_action( 'admin_notices', 'widgets_shortcode_admin_notice' );
128
+ }
129
+ }
130
+
131
+ /*-----------------------------------*/
132
+ function widgets_shortcode_admin_notice() {
133
+ ?>
134
+ <div class="updated">
135
+ <p>Please go to widgets page and check your "widgets for shortcodes" sidebar. It will hopefully have been corrected upgraded with your widgets and all should be fine.</p>
136
+ </div>
137
+ <?php
138
+ }
139
+ /*-----------------------------------*/
140
+
141
+ ?>
tags/2.3/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ ?>
tags/2.3/readme.txt ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
17
+ The plugins default action is that it will magically find the settings for your themes first sidebar and use them to control the widget's output. In most cases this would mean that the widget will be styled as per the rest of your theme.
18
+
19
+ If that does not look good, parameters exist to override this behaviour.
20
+
21
+ Change your theme? No problem, the plugin will save and restore the widgets_for_shortcode settings. On display it will then pick up the new themes sidebar settings. Check this still looks nice please! in some themes you may ned up with white text on a white background and will then have to override or change css.
22
+
23
+ **Instructions:**
24
+
25
+ 1. Test your chosen widget works in a normal sidebar or widget area first.
26
+ 2. Then Activate this plugin
27
+ 3. Go to Appearance > widgets and find the " widgets for shortcode" sidebar or widget area
28
+ 4. Drag your chosen widgets from to the shortcodes sidebar. Save.
29
+ 5. Go the shortcode any widget settings. Click on one of the create page links to help you setup the shortcode.
30
+ 6. OR go to an existing page and enter a shortcode:
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.
51
+ * class=*yourclassname* By default the plugin will add a class of amr-widget tto the wrapping html. You can use this to add any special css. Add css either by editing your themes stylesheet if it is a custom theme, or using something like the wordpress custom css plugin.
52
+ * sidebar="*sidebarname*" will default to widgets_for_shortcode sidebar. Only use if you want to re-use a widget already beingused in another sidebar. THis is theme dependent and WILL break if you change themes.
53
+
54
+ **[do_widget_area ...] Parameters:**
55
+
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.
63
+
64
+ To 'remove debug mode'
65
+ remove ?do_widget_debug=1 from the url you are looking at (NOTE it only debugs if you are logged in and an administrator, so this is really NOT a problem.)
66
+
67
+ The plugin has been tested with most standard widgets (rss feeds, tag cloud, pages, meta, search, and of course my own plugins widgets - upcoming events list, calendar and user lists.
68
+
69
+ If you use a widget more than once for different reasons, you may need to use the widget id to isolate which widget instance and it's settings to use. ie: [do_widget id=categories-6] . If you just use the name, it will display all widgets in the shortcode sidebar with that name (all instances).
70
+
71
+ 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
+ == 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
186
+ * Add widget_area_class=none
187
+
188
+ = Version 2.1 =
189
+ * Bug Fix - last sidebar registered by theme was being overwritten by the attempt to copy the themes sidebar arguments so that cleverly (hopefully) the shortcode widgets would pick up the same styling. Fixed now. Now it really does pickup the first sidebars styling - with devasting consquence in twenty-fourteen theme - yes white text on white background is not fun to read. But on other themes it works a treat.
190
+
191
+
192
+ = Version 2 =
193
+ * Shortcode widget id changed so that wordpress will save the shortcode settings per theme.
194
+ * Added Code to auto upgrade, but just in case please check your widgets page. Look at the inactive widgets if the widgets are not in your widgets for shortcodes sidebar.
195
+ * Logic added on theme switching to save shortcode widget settings and restore them after the theme switch, so you can play with themes and not have to set up your widgets again. WP kept putting them into an 'inactive sidebar'.
196
+ * Added, as requested by a few of you, the ability to add a class and control the html around the widget without having to enter html around the shortcode has been added. See the settings page for instructions.
197
+ * Added the ability to specify what html should be used for the title and the widget wrap, so that you can more easily either match your theme or get away from your thesmes widget styling.
198
+ * Added ability to insert a whole widget area into the page. The default will be the "widgets for shortcode" sidebar/widget area. You can specify others. Note Specifying other widget areas may be theme dependent, ie: switch and you'll lose that page.
199
+ * Added classes amr-widget and amr-widget-area so one can target the widgets in the page to adjust css.
200
+
201
+ = Version 1.8 =
202
+ * Whoops - had renamed the main file and forgot to delete it from the svn. Forcing a version number change to ensure files get cleaned up for everyone
203
+
204
+ = Version 1.7 =
205
+ * Change: Changed so that debugs and debug prompt will only show to a logged in administrator.
206
+
207
+ = Version 1.6 =
208
+ * Add: added a settings page to help people out (not really settings)
209
+ * Fix: changed a clashing function name
210
+
211
+ = Version 1.5 =
212
+ * Fixed: a small bug which caused a warning if you had not saved the widgets in your shortcode sidebar
213
+
214
+ = Version 1.4 =
215
+ * Updated readme - made very detailed steps and added some screen shots.
216
+ * Tested on wp 3.3.1 and fixed some notices when bad parameters entered.
217
+
218
+ = Version 1.3 =
219
+ * Added debug link and retested. Added readme.
220
+
221
+ = 1.12 =
222
+ * Changed dummy shortcode sidebar so it appears after the theme sidebars to avoid taking over their widgets (this happened in numbered sidebars) PLEASE note if you have upgraded, you may appear to have "lost" your widgets due to this sidebar change. You have not - they will be in your "inactive widgets" - please drag them to the new sidebar. You may also find that you have 2 versions of the plugin, with slightly different folder names. This will allow you to go back to the previous one to check what you had there if you need to. Deactivate the old one and activate the new one. Move your widgets back in. Test then Delete the old one. In one theme it also appeared that somehow due to this change, one of the sidebar widgets "moved" down to another sidebar. I think that this may have had something to do with the fact that sidebars can be numbered or named, so please check all your sidebars before continuing. As always make sure thath you know how to restore from a backup before doing any upgrades of any kind.
223
+ * Tested in 2.9.2, can still use either the widget name "Categories" or id=categories-6. Note widget must have been created in the dummy shortcode sidebar.
224
+
225
+ = 1.1 =
226
+
227
+ * Allow for lowercase use of widget names for the those challenged by attention to detail!
228
+ * Cleaned up debug mode to make it easier for people to identify which instance of a widget they are using. Add &do_widget_debug to url string.
229
+
230
+ = 1.0 =
231
+ * Launch of the plugin
232
+
233
+ == Installation ==
234
+
235
+ 0. Activate plugin
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
+
251
+ 1. setting up widgets in the widgets for shortcode sidebar. The widget's user interface (UI) is used to provide a UI for the do_widget shortcode.
252
+ 2. add shortcode for widgets in a page (must be in the widgets for shortcode sidebar)
253
+ 3. widgets in a page
254
+ 4. with the default widget class and with widget_classes=none
255
+ two rss feed widgets in shortcode sidebar - both will show if just name used
256
+ 5. Debug messages - scroll down till you see the shortcodes sidebar - the widgets and their ids will be listed. Use the id of the widget you want.
257
+ 6. Examples of a page with several do_widgets: query_posts and tag cloud
258
+ 7. Example of rss widgets in a custom theme
259
+
260
+
261
+
tags/2.3/screenshot-1.png ADDED
Binary file
tags/2.3/screenshot-2.jpg ADDED
Binary file
tags/2.3/screenshot-3.jpg ADDED
Binary file
tags/2.3/screenshot-4.png ADDED
Binary file
tags/2.3/screenshot-5.png ADDED
Binary file
tags/2.3/screenshot-6.png ADDED
Binary file
tags/2.3/screenshot-7.jpg ADDED
Binary file
amr-admin-form-html.php → tags/2.4/amr-admin-form-html.php RENAMED
File without changes
amr-shortcode-any-widget.php → tags/2.4/amr-shortcode-any-widget.php RENAMED
File without changes
tags/2.4/amr-utilities.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*-----------------------------------*/
3
+ function get_sidebar_id ($name) {
4
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer.
5
+ take the first one that matches */
6
+ global $wp_registered_sidebars;
7
+
8
+ foreach ($wp_registered_sidebars as $i => $a) {
9
+ if ((isset ($a['name'])) and ( $a['name'] === $name))
10
+ return ($i);
11
+ }
12
+ return (false);
13
+ }
14
+ /*-----------------------------------*/
15
+ function amr_get_sidebar_name ($id) { /* dont need anymore ? or at least temporarily */
16
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
17
+ global $wp_registered_sidebars;
18
+ foreach ($wp_registered_sidebars as $i => $a) {
19
+ if ((isset ($a['id'])) and ( $a['id'] === $id)) {
20
+ if (isset($a['name'])) return ($a['name']);
21
+ else return ($id);
22
+ }
23
+ }
24
+ return (false);
25
+ }
26
+ /*-----------------------------------*/
27
+ function amr_check_if_widget_debug() {
28
+ // only do these debug if we are logged in and are the administrator
29
+
30
+ if ((!is_user_logged_in()) or (!current_user_can('administrator')))
31
+ return false;
32
+
33
+ if (isset($_REQUEST['do_widget_debug'])) {
34
+ $url_without_debug_query = remove_query_arg( 'do_widget_debug');
35
+ $eek = '<a href="'.$url_without_debug_query.'">Remove debug</a>';
36
+ echo '<br/>Note: Debugs only shown to a Logged in Administrator.'
37
+ .'<br />'
38
+ .$eek
39
+ .'<br />';
40
+ return true;
41
+ }
42
+ else
43
+ return false;
44
+ }
45
+ /*-----------------------------------*/
46
+ function amr_show_widget_debug($type='', $atts=array()) {
47
+ global $wp_registered_sidebars, $wp_registered_widgets, $_wp_sidebars_widgets;
48
+ // only do these debug if we are logged in and are the administrator
49
+
50
+ $debug = amr_check_if_widget_debug();
51
+
52
+ if ($type=='empty') {
53
+ if (current_user_can('administrator'))
54
+ echo '<br /> You are admin: <a href="'.add_query_arg('do_widget_debug','1').'">Try debug </a></b>'
55
+ .'See a exclamation point ! above ?. Hover over to see error message.'
56
+ .'</p>';
57
+
58
+ if ($debug) {
59
+
60
+ echo '<p>As a last resort, we may dump the wp variables to do with sidebars and widgets. Maybe that will help you:</p>';
61
+ $sidebars_widgets = wp_get_sidebars_widgets();
62
+ echo '<h3> result of wp_get_sidebars_widgets():</h3>';
63
+ foreach ($sidebars_widgets as $i=>$w) {
64
+ echo '<br/>'.$i; var_dump($w);
65
+ };
66
+
67
+ echo '<h3>$_wp_sidebars_widgets:</h3>';
68
+ var_dump($_wp_sidebars_widgets);
69
+ //echo '<br /><h3>$wp_registered_widgets:</h3>';
70
+ //var_dump($wp_registered_widgets);
71
+ echo '<br /><h3>$wp_registered_sidebars:</h3>';
72
+ var_dump($wp_registered_sidebars);
73
+ }
74
+ }
75
+
76
+ if (($type=='which one') and ($debug)) {
77
+ echo '<h3>DEBUG on: Is your widget in the widgets_for_shortcodes sidebar?</h3>';
78
+ //echo '<br />The shortcode attributes you entered are:<br />';
79
+ //var_dump($atts);
80
+ echo '<br /><h2>widgets_for_shortcodes sidebar and widgets</h2>';
81
+ $found = false;
82
+ foreach ($_wp_sidebars_widgets as $i=> $w) {
83
+ if (($i == "widgets_for_shortcodes")) {
84
+ echo 'Sidebar:&nbsp;<b>'.$i.': '.amr_get_sidebar_name($i).'</b> has widgets: <br />';
85
+ $found = true;
86
+ if (is_array($w)) {
87
+ sort ($w);
88
+ foreach ($w as $i2=> $w2) {
89
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$w2.' <br />';
90
+ };
91
+ }
92
+ echo '<br />';
93
+ }
94
+ //else {echo ' '.$i;}
95
+ };
96
+ if (!$found) echo '<h2>widgets_for_shortcodes sidebar empty or not defined.</h2>';
97
+ }
98
+ }
99
+ /*-----------------------------------*/
100
+ function amr_save_shortcodes_sidebar() { // when switching a theme, save the widgets we use for the shortcodes as they are getting overwritten
101
+ $sidebars_widgets = wp_get_sidebars_widgets();
102
+ if (!empty($sidebars_widgets['widgets_for_shortcodes']))
103
+ update_option('sidebars_widgets_for_shortcodes_saved',$sidebars_widgets['widgets_for_shortcodes']);
104
+ else { // our shortcodes sidebar is empty but when to fix ?
105
+
106
+ }
107
+ }
108
+ /*-----------------------------------*/
109
+ function amr_restore_shortcodes_sidebar() { // when switching a theme, restore the widgets we use for the shortcodes as they are getting overwritten
110
+ global $_wp_sidebars_widgets;
111
+
112
+ $sidebars_widgets = wp_get_sidebars_widgets();
113
+ if (empty($sidebars_widgets['widgets_for_shortcodes'])) {
114
+ $sidebars_widgets['widgets_for_shortcodes'] = get_option('sidebars_widgets_for_shortcodes_saved');
115
+ update_option('sidebars_widgets',$sidebars_widgets);
116
+
117
+ }
118
+
119
+ }
120
+ /*-----------------------------------*/
121
+ function amr_upgrade_sidebar() { // added in 2014 February for compatibility.. keep for how long. till no sites running older versions.?
122
+ $sidebars_widgets = wp_get_sidebars_widgets();
123
+ if (!empty($sidebars_widgets['Shortcodes']) and empty($sidebars_widgets['widgets_for_shortcodes'])) { // we need to upgrade
124
+ $sidebars_widgets['widgets_for_shortcodes'] = $sidebars_widgets['Shortcodes'];
125
+ unset ($sidebars_widgets['Shortcodes']);
126
+ update_option('sidebars_widgets',$sidebars_widgets );
127
+ add_action( 'admin_notices', 'widgets_shortcode_admin_notice' );
128
+ }
129
+ }
130
+
131
+ /*-----------------------------------*/
132
+ function widgets_shortcode_admin_notice() {
133
+ ?>
134
+ <div class="updated">
135
+ <p>Please go to widgets page and check your "widgets for shortcodes" sidebar. It will hopefully have been corrected upgraded with your widgets and all should be fine.</p>
136
+ </div>
137
+ <?php
138
+ }
139
+ /*-----------------------------------*/
140
+
141
+ ?>
tags/2.4/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ ?>
{languages → tags/2.4/languages}/amr-shortcode-any-widget-en_AU.mo RENAMED
File without changes
{languages → tags/2.4/languages}/amr-shortcode-any-widget-en_AU.po RENAMED
File without changes
{languages → tags/2.4/languages}/amr-shortcode-any-widget-sr_RS.mo RENAMED
File without changes
{languages → tags/2.4/languages}/amr-shortcode-any-widget-sr_RS.po RENAMED
File without changes
{languages → tags/2.4/languages}/amr-shortcode-any-widget.pot RENAMED
File without changes
readme.txt → tags/2.4/readme.txt RENAMED
File without changes
tags/2.4/screenshot-1.png ADDED
Binary file
tags/2.4/screenshot-2.jpg ADDED
Binary file
tags/2.4/screenshot-3.jpg ADDED
Binary file
tags/2.4/screenshot-4.png ADDED
Binary file
tags/2.4/screenshot-5.png ADDED
Binary file
tags/2.4/screenshot-6.png ADDED
Binary file
tags/2.4/screenshot-7.jpg ADDED
Binary file
trunk/amr-admin-form-html.php ADDED
@@ -0,0 +1,200 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Backend Class for use in all amr plugins
4
+ * Version 0.1
5
+ */
6
+
7
+ //------------------------------------------------------------------------------------------------------------------
8
+ if (!class_exists('amr_saw_plugin_admin')) {
9
+ class amr_saw_plugin_admin {
10
+ var $hook = 'amr_saw';
11
+ var $filename = 'amr_shortcode_any_widget/amr_shortcode_any_widget.php';
12
+ var $longname = 'Shortcode any widget - insert widgets or widget areas into a page.';
13
+ var $shortname = 'Shortcode any widget';
14
+ var $optionname = '';
15
+ var $homepage = '';
16
+ var $parent_slug = 'plugin_listings_menu';
17
+ var $accesslvl = 'manage_options';
18
+
19
+ function amr_saw_plugin_admin() {
20
+ add_action('admin_menu', array(&$this, 'register_settings_page') );
21
+ add_filter('plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
22
+ }
23
+ function register_settings_page() {
24
+ add_options_page( $this->longname, $this->shortname, $this->accesslvl, $this->hook, array(&$this,'config_page'));
25
+ }
26
+ function plugin_options_url() {
27
+ return admin_url( 'options-general.php?page='.$this->hook );
28
+ }
29
+ /**
30
+ * Add a link to the settings page to the plugins list
31
+ */
32
+ function add_action_link( $links, $file ) {
33
+ static $this_plugin;
34
+ if( empty($this_plugin) )
35
+ $this_plugin = $this->filename;
36
+ if ( $file == $this_plugin ) {
37
+ $settings_link = '<a href="' . $this->plugin_options_url() . '">' . __('Settings', 'amr-shortcode-any-widget') . '</a>';
38
+ array_unshift( $links, $settings_link );
39
+ }
40
+ return $links;
41
+ }
42
+
43
+ function admin_heading($title) {
44
+ echo '<div class="wrap" >
45
+ <div id="icon-options-general" class="icon32"><br />
46
+ </div>
47
+ <h2>'.$title.' </h2>';
48
+ // <form method="post" action="'
49
+ // .esc_url($_SERVER['PHP_SELF'])
50
+ // .'">';
51
+ // wp_nonce_field($this->hook); /* outputs hidden field */
52
+ // ;
53
+ }
54
+
55
+ function admin_subheading($title) {
56
+ echo '<h2>'.$title.'</h2>';
57
+ }
58
+ function config_page() {
59
+ $this->admin_heading($this->longname);
60
+ echo '<h3><a href="http://wordpress.org/plugins/amr-shortcode-any-widget/installation">More detailed instructions at the wordpress plugin page.</a></h3>';
61
+ echo '<ul>';
62
+ echo '<li>';
63
+ _e('Test your widget in a normal sidebar first.', 'amr-shortcode-any-widget');
64
+ echo '<li>';
65
+ _e('Drag the widgets you want to use to the shortcodes sidebar.', 'amr-shortcode-any-widget');
66
+
67
+ echo '</li>';
68
+ echo '<li>';
69
+ _e('Set the widgets parameters if there are any.', 'amr-shortcode-any-widget');
70
+ echo '</li>';
71
+
72
+ echo '<li>';
73
+ echo '<a title="Go to widget area" href="'.get_admin_url('','widgets.php').'"> ';
74
+ _e('Go to widgets', 'amr-shortcode-any-widget');
75
+ echo '</a>';
76
+ echo '</li>';
77
+ echo '</ul>';
78
+
79
+
80
+ echo '<h2>';
81
+ _e('To add a single widget to a page', 'amr-shortcode-any-widget');
82
+ echo '</h2>';
83
+ echo '<ul>';
84
+ echo '<li>';
85
+ _e('Add the shortcode [do_widget widgetname] to a page.', 'amr-shortcode-any-widget');
86
+ _e('Examples:', 'amr-shortcode-any-widget');
87
+ echo '</li>';
88
+ echo '<li>';
89
+ _e('[do_widget "tag cloud"] or [do_widget id=widgetid]', 'amr-shortcode-any-widget');
90
+ echo '</li>';
91
+ echo '<li>';
92
+ echo '<a title="Create a page" href="'
93
+ .add_query_arg('content','[do_widget Archives widget_classes=none]', get_admin_url('','post-new.php?post_type=page'))
94
+ .'"> ';
95
+ _e('Create a page with do_widget shortcode and remove widget_classes', 'amr-shortcode-any-widget');
96
+ echo '</a>';
97
+ echo '</li>';
98
+ echo '<li>';
99
+ echo '<a title="Create a page" href="'
100
+ .add_query_arg('content','[do_widget Archives]', get_admin_url('','post-new.php?post_type=page'))
101
+ .'"> ';
102
+ _e('Create a page with do_widget shortcode', 'amr-shortcode-any-widget');
103
+ echo '</a>';
104
+ echo '</li>';
105
+ echo '<li>';
106
+ echo 'Use title=false to hide a widget title. ';
107
+ echo 'Use title=somehtmltag and wrap=somehtmltag to change the html used.';
108
+ echo ' Use class=yourclassname to add a class - maybe to override your themes widget styling?';
109
+ echo '</li>';
110
+ echo '<li>';
111
+ echo '[do_widget pages title=false] will hide the widget title';
112
+ echo '</li>';
113
+ echo '<li>';
114
+ echo '[do_widget pages title=h3] give the title a heading 3 html tag.';
115
+ echo '</li>';
116
+ echo '<li>';
117
+ echo '[do_widget categories] or [do_widget name=categories] will do the same thing: display the categories widget.';
118
+ echo '</li>';
119
+ echo '<li>';
120
+ echo '[do_widget "tag cloud" wrap=aside] will wrap the widget in an "aside" html tag.';
121
+ echo '</li>';
122
+ echo '<li>';
123
+ echo '[do_widget "recent posts"]';
124
+ echo '</li>';
125
+ echo '</ul>';
126
+
127
+ echo '<p>';
128
+ echo 'If the plugin cannot work out what you want, it will show a debug prompt
129
+ , click on the debug prompt and look for the name or id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug info). If the name does not work, try with the 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.';
130
+ echo '</p><p><b>';
131
+ echo "Valid title html tags are : h1, h2, h3, h4, h5, header, strong, em ";
132
+ echo '</b></p><p><b>';
133
+ echo "Valid html wrap tags are : div, p, aside , section";
134
+ echo '</b></p>';
135
+
136
+ echo '<h2>';
137
+ _e('To add multiple instances of the same widget:', 'amr-shortcode-any-widget');
138
+
139
+ echo '</h2>';
140
+ echo '<ul>';
141
+ echo '<li>';
142
+ echo '[do_widget id=widgetid1] [do_widget id=widgetid2]';
143
+ echo '</li>';
144
+ echo '</ul>';
145
+ echo '<br />';
146
+
147
+ echo '<h2>';
148
+ _e('To add a widget area - all widgets in the widget area:', 'amr-shortcode-any-widget');
149
+
150
+ echo '</h2>';
151
+ echo '<ul>';
152
+ echo '<li>';
153
+ echo '<a title="Create a page" href="'
154
+ .add_query_arg('content','[do_widget_area]', get_admin_url('','post-new.php?post_type=page'))
155
+ .'"> ';
156
+ _e('Create a page with do_widget_area shortcode without the widget_area class', 'amr-shortcode-any-widget');
157
+ echo '</a> Hoping to avoid theme styling.';
158
+ echo '</li>';
159
+ echo '<li>';
160
+ echo '<a title="Create a page" href="'
161
+ .add_query_arg('content','[do_widget_area widget_area_class=none]', get_admin_url('','post-new.php?post_type=page'))
162
+ .'"> ';
163
+ _e('Create a page with do_widget_area shortcode', 'amr-shortcode-any-widget');
164
+ echo '</a> Hoping to use theme styling.';
165
+ echo '</li>';
166
+ echo '<li>';
167
+ _e('Examples:', 'amr-shortcode-any-widget');
168
+ echo '</li>';
169
+ echo '<li>';
170
+ _e('[do_widget_area] or [do_widget_area widget_area=sidebar-1]', 'amr-shortcode-any-widget');
171
+ echo '</li>';
172
+ echo '<li>';
173
+ _e('NB: Using something like the twenty-fourteen theme? you might end up with white text on a white background. Tweak the widget classes or the html of the wrap or title. If that fails, adjust your css.', 'amr-shortcode-any-widget');
174
+ echo '</li>';
175
+ echo '</ul>';
176
+ echo '<br />';
177
+
178
+ }
179
+
180
+
181
+ /**
182
+ * Info box with link to the support forums.
183
+ */
184
+ function plugin_support() {
185
+ $content = '<p>'.__('If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the','amr-shortcode-any-widget').' <a href="http://wordpress.org/tags/'.$this->hook.'">'.__("Support forums",'amr-shortcode-any-widget').'</a>.</p>';
186
+ $this->postbox($this->hook.'support', 'Need support?', $content);
187
+ }
188
+
189
+ function text_limit( $text, $limit, $finish = ' [&hellip;]') {
190
+ if( strlen( $text ) > $limit ) {
191
+ $text = substr( $text, 0, $limit );
192
+ $text = substr( $text, 0, - ( strlen( strrchr( $text,' ') ) ) );
193
+ $text .= $finish;
194
+ }
195
+ return $text;
196
+ }
197
+ }
198
+ }
199
+
200
+ ?>
trunk/amr-shortcode-any-widget.php ADDED
@@ -0,0 +1,359 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ 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" ] [do_widget id=widgetnamedashed-n ]or include a whole widget area [do_widget_area]. Please read: <a href="https://wordpress.org/plugins/amr-shortcode-any-widget/installation/">Installation</a> and <a href="https://wordpress.org/plugins/amr-shortcode-any-widget/faq/">FAQ</a>.
6
+ Author: anmari
7
+ Version: 2.5
8
+ Author URI: http://webdesign.anmari.com
9
+
10
+ */
11
+ function amr_remove_widget_class($params) { // remove the widget classes
12
+ if (!empty($params[0]['before_widget'])) {
13
+ $params[0]['before_widget'] =
14
+ str_replace ('"widget ','"',$params[0]['before_widget']);
15
+ }
16
+
17
+ if (!empty($params[0]['before_title'])) {
18
+
19
+ $params[0]['before_title'] =
20
+ $params[0]['before_title'] = str_replace ('widget-title','',$params[0]['before_title']);
21
+
22
+ }
23
+
24
+ return ($params);
25
+ }
26
+ /*-----------------------------------*/
27
+ function do_widget_area($atts) {
28
+
29
+ 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
+
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
+ }
70
+ /*-----------------------------------*/
71
+ function do_widget($atts) {
72
+
73
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
74
+
75
+ /* check if the widget is in the shortcode x sidebar if not , just use generic,
76
+ if it is in, then get the instance data and use that */
77
+
78
+ if (isset($_wp_sidebars_widgets) ) {
79
+ amr_show_widget_debug('which one'); //check for debug prompt and show widgets in shortcode sidebar if requested and logged in etc
80
+ }
81
+ else {
82
+ echo '<br />No widgets defined at all in any sidebar!';
83
+ return (false);
84
+ }
85
+
86
+ extract(shortcode_atts(array(
87
+ 'sidebar' => 'Widgets for Shortcodes',
88
+ 'id' => '',
89
+ 'name' => '', /* MKM added explicit 'name' attribute. For existing users we still need to allow prev method, else too many support queries will happen */
90
+ 'title' => '', /* do the default title unless they ask us not to - use string here not boolean */
91
+ 'class' => 'amr_widget', /* 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 */
92
+ 'wrap' => '', /* wrap the whole thing - title plus widget in a div - maybe the themes use a div, maybe not, maybe we want that styling, maybe not */
93
+ 'widget_classes' => '' /* option to disassociate from themes widget styling */
94
+ ), $atts));
95
+
96
+
97
+
98
+ /* compatibility check - if the name is not entered, then the first parameter is the name */
99
+ if (empty($name) and !empty($atts[0]))
100
+ $name = $atts[0];
101
+
102
+ /* the widget need not be specified, [do_widget widgetname] is adequate */
103
+ if (!empty($name)) { // we have a name
104
+ $widget = $name;
105
+
106
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
107
+ if (strtolower($w['name']) === strtolower($widget)) $widget_ids[] = $i;
108
+ //if ($debug) {echo '<br /> Check: '.$w['name'];}
109
+ }
110
+ }
111
+ else { /* check for id if we do not have a name */
112
+ if (!empty($id)) { /* if a specific id has been specified */
113
+
114
+ foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
115
+ if ($w['id'] === $id) $widget_ids[] = $id;
116
+ }
117
+ //if ($debug) { echo '<h2>We have an id: '.$id.'</h2>'; if (!empty($widget_ids)) var_dump($widget_ids); }
118
+ }
119
+ else {
120
+ echo '<br />No valid widget name or id given in shortcode parameters';
121
+ return (false);
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);
131
+ return (false) ;
132
+ }
133
+
134
+ if (!($sidebarid = get_sidebar_id ($sidebar)))
135
+ $sidebarid=$sidebar; /* get the official sidebar id for this widget area - will take the first one */
136
+
137
+ if (empty($widget))
138
+ $widget = '';
139
+
140
+ $content = '';
141
+ /* if the widget is in our chosen sidebar, then use the options stored for that */
142
+
143
+ if ((!isset ($_wp_sidebars_widgets[$sidebarid])) or (empty ($_wp_sidebars_widgets[$sidebarid]))) { // try upgrade
144
+ amr_upgrade_sidebar();
145
+ }
146
+
147
+ if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
148
+ /* if ($debug) {
149
+ echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
150
+ sort ($_wp_sidebars_widgets[$sidebarid]);
151
+ foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
152
+ echo $i.' '.$w.'<br />';
153
+ };
154
+ }
155
+ */
156
+ /* get the intersect of the 2 widget setups so we just get the widget we want */
157
+
158
+ $wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
159
+ /* if ($debug) { echo '<br />Will use widget ids'.'<br />';
160
+ foreach ($widget_ids as $i=> $w) {
161
+ echo '&nbsp;&nbsp;&nbsp;'.$w.'<br />';
162
+ };
163
+ }
164
+ */
165
+ }
166
+ else { /* the sidebar is not defined */
167
+ //if ($debug) {
168
+ echo '<br /><a href="" title="Error: Sidebar '.$sidebar.' with sidebarid '.$sidebarid.' is empty (no widgets) or is not defined.">!</a><br />';
169
+ //}
170
+ }
171
+
172
+ $output = '';
173
+ if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
174
+ //if ($debug) {
175
+ echo '<br /><a href="" title="Error: Your requested Widget '.$widget.' is not in the '.$sidebar.' sidebar ">!</a><br />';
176
+ amr_show_widget_debug('empty', $atts);
177
+ //}
178
+ unset($sidebar);
179
+ unset($sidebarid);
180
+
181
+ }
182
+ else {
183
+ /* There may only be one but if we have two in our chosen widget then it will do both */
184
+ $output = '';
185
+ foreach ($wid as $i=>$widget_instance) {
186
+ ob_start(); /* catch the echo output, so we can control where it appears in the text */
187
+ shortcode_sidebar($widget_instance, $sidebar, $title, $class, $wrap, $widget_classes);
188
+ $output .= ob_get_clean();
189
+ }
190
+ }
191
+
192
+ return ($output);
193
+ }
194
+ /* -------------------------------------------------------------------------*/
195
+ function shortcode_sidebar( $widget_id, $name="widgets_for_shortcode", $title=true, $class='', $wrap='', $widget_classes='') { /* This is basically the wordpress code, slightly modified */
196
+ global $wp_registered_sidebars, $wp_registered_widgets;
197
+
198
+ $debug = amr_check_if_widget_debug();
199
+
200
+ $sidebarid = get_sidebar_id ($name);
201
+
202
+ $sidebars_widgets = wp_get_sidebars_widgets();
203
+
204
+ $sidebar = $wp_registered_sidebars[$sidebarid]; // has the params etc
205
+
206
+ $did_one = false;
207
+
208
+ /* lifted from wordpress code, keep as similar as possible for now */
209
+
210
+ if ( !isset($wp_registered_widgets[$widget_id]) ) continue;
211
+
212
+ $params = array_merge(
213
+ array(
214
+ array_merge( $sidebar,
215
+ array('widget_id' => $widget_id,
216
+ 'widget_name' => $wp_registered_widgets[$widget_id]['name']) ) ),
217
+ (array) $wp_registered_widgets[$widget_id]['params']
218
+ );
219
+
220
+ $validtitletags = array ('h1','h2','h3','h4','h5','header','strong','em');
221
+ $validwraptags = array ('div','p','main','aside','section');
222
+
223
+ if (!empty($wrap)) { /* then folks want to 'wrap' with their own html tag, or wrap = yes */
224
+ if ((!in_array( $wrap, $validwraptags)))
225
+ $wrap = '';
226
+ /* To match a variety of themes, allow for a variety of html tags. */
227
+ /* May not need if our sidebar match attempt has worked */
228
+ }
229
+
230
+ if (!empty ($wrap)) {
231
+ $params[0]['before_widget'] = '<'.$wrap.' id="%1$s" class="%2$s">';
232
+ $params[0]['after_widget'] = '</'.$wrap.'>';
233
+ }
234
+
235
+ // wp code to get classname
236
+ $classname_ = '';
237
+ //foreach ( (array) $wp_registered_widgets[$widget_id]['classname'] as $cn ) {
238
+ $cn = $wp_registered_widgets[$widget_id]['classname'];
239
+ if ( is_string($cn) )
240
+ $classname_ .= '_' . $cn;
241
+ elseif ( is_object($cn) )
242
+ $classname_ .= '_' . get_class($cn);
243
+ //}
244
+ $classname_ = ltrim($classname_, '_');
245
+
246
+ // add MKM and others requested class in to the wp classname string
247
+ // if no class specfied, then class will = amrwidget. These classes are so can reverse out unwanted widget styling.
248
+
249
+ // $classname_ .= ' widget '; // wordpress seems to almost always adds the widget class
250
+
251
+
252
+ $classname_ .= ' '.$class;
253
+
254
+ // we are picking up the defaults from the thems sidebar ad they have registered heir sidebar to issue widget classes?
255
+
256
+
257
+ // Substitute HTML id and class attributes into before_widget
258
+ if (!empty($params[0]['before_widget']))
259
+ $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $widget_id, $classname_);
260
+ else
261
+ $params[0]['before_widget'] = '';
262
+
263
+ if (empty($params[0]['before_widget']))
264
+ $params[0]['after_widget'] = '';
265
+
266
+ $params = apply_filters( 'dynamic_sidebar_params', $params );
267
+ // allow, any pne usingmust ensure they apply to the correct sidebars
268
+
269
+ if (!empty($title)) {
270
+ if ($title=='false') { /* amr switch off the title html, still need to get rid of title separately */
271
+ $params[0]['before_title'] = '<span style="display: none">';
272
+ $params[0]['after_title'] = '</span>';
273
+ }
274
+ else {
275
+ if (in_array( $title, $validtitletags)) {
276
+ $class = ' class="widget-title" ';
277
+
278
+ $params[0]['before_title'] = '<'.$title.' '.$class.' >';
279
+ $params[0]['after_title'] = '</'.$title.'>';
280
+ }
281
+ }
282
+ }
283
+
284
+ if (!empty($widget_classes) and ($widget_classes == 'none') ) {
285
+ $params = amr_remove_widget_class($params); // also called in widget area shortcode
286
+ }
287
+
288
+
289
+ $callback = $wp_registered_widgets[$widget_id]['callback'];
290
+ if ( is_callable($callback) ) {
291
+ call_user_func_array($callback, $params);
292
+ $did_one = true;
293
+ }
294
+ // }
295
+ return $did_one;
296
+ }
297
+ /* ---------------------------------------------------------------------------*/
298
+ function amr_reg_sidebar() { // this is fired late, so hopefully any theme sidebars will have been registered already.
299
+
300
+ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
301
+
302
+ if ( function_exists('register_sidebar') ) { // maybe later, get the first main sidebar and copy it's before/after etc
303
+ $args = array(
304
+ 'name' =>'Widgets for Shortcodes',
305
+ 'id' => 'widgets_for_shortcodes', // hope to avoid losing widgets
306
+ 'description' => __('Sidebar to hold widgets and their settings. These widgets will be used in a shortcode. This sidebars widgets should be saved with your theme settings now.','amr-shortcode-any-widget'),
307
+ 'before_widget' => '<aside'.' id="%1$s" class="%2$s ">', // 201402 to match twentyfourteen theme
308
+ 'after_widget' => '</aside>',
309
+ 'before_title' => '<h1 class="widget-title" >', // 201402 maybe dont use widget class - we are in content here not in a widget area but others want the widget styling. ?
310
+ 'after_title' => '</h1>' );
311
+
312
+
313
+
314
+ if (!empty($wp_registered_sidebars)) { // we got some sidebars already.
315
+ $main_sidebar = reset($wp_registered_sidebars); // Grab the first sidebar and use that as defaults for the widgets
316
+ $args['before_widget'] = $main_sidebar['before_widget'];
317
+ $args['after_widget'] = $main_sidebar['after_widget'];
318
+ $args['before_title'] = $main_sidebar['before_title'];
319
+ $args['after_title'] = $main_sidebar['after_title'];
320
+ }
321
+
322
+ register_sidebar($args);
323
+ }
324
+
325
+ //else { echo '<h1>CANNOT REGISTER widgets_for_shortcodes SIDEBAR</h1>';}
326
+ }
327
+ /*-----------------------------------*/
328
+ include ('amr-admin-form-html.php');
329
+ include ('amr-utilities.php');
330
+
331
+ if (is_admin() ) $amr_saw_plugin_admin = new amr_saw_plugin_admin();
332
+
333
+ add_action('widgets_init', 'amr_reg_sidebar',98); // register late so it appears last
334
+ //add_action('widgets_init', 'amr_upgrade_sidebar',99); // copy old shortcodes sidebar to new one if necessary
335
+ //add_action('switch_theme', 'amr_save_shortcodes_sidebar');
336
+ //add_action('after_switch_theme','amr_restore_shortcodes_sidebar');
337
+
338
+ add_shortcode('do_widget', 'do_widget');
339
+ add_shortcode('do_widget_area', 'do_widget_area'); // just dump the whole widget area - to get same styling
340
+
341
+ //require_once(ABSPATH . 'wp-includes/widgets.php'); // *** do we really need this here?
342
+ function amr_saw_load_text() {
343
+ // wp (see l10n.php) will check wp-content/languages/plugins if nothing found in plugin dir
344
+ $result = load_plugin_textdomain( 'amr-shortcode-any-widget', false,
345
+ dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
346
+ }
347
+
348
+
349
+ add_action('plugins_loaded' , 'amr_saw_load_text' );
350
+
351
+ add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'add_action_links' );
352
+
353
+ function add_action_links ( $links ) {
354
+ $mylinks = array(
355
+ '<a href="' . admin_url( 'options-general.php?page=amr_saw' ) . '">HELP</a>',
356
+ );
357
+ return array_merge( $links, $mylinks );
358
+ }
359
+ ?>
trunk/amr-utilities.php ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*-----------------------------------*/
3
+ function get_sidebar_id ($name) {
4
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer.
5
+ take the first one that matches */
6
+ global $wp_registered_sidebars;
7
+
8
+ foreach ($wp_registered_sidebars as $i => $a) {
9
+ if ((isset ($a['name'])) and ( $a['name'] === $name))
10
+ return ($i);
11
+ }
12
+ return (false);
13
+ }
14
+ /*-----------------------------------*/
15
+ function amr_get_sidebar_name ($id) { /* dont need anymore ? or at least temporarily */
16
+ /* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer. take the first one */
17
+ global $wp_registered_sidebars;
18
+ foreach ($wp_registered_sidebars as $i => $a) {
19
+ if ((isset ($a['id'])) and ( $a['id'] === $id)) {
20
+ if (isset($a['name'])) return ($a['name']);
21
+ else return ($id);
22
+ }
23
+ }
24
+ return (false);
25
+ }
26
+ /*-----------------------------------*/
27
+ function amr_check_if_widget_debug() {
28
+ // only do these debug if we are logged in and are the administrator
29
+
30
+ if ((!is_user_logged_in()) or (!current_user_can('administrator')))
31
+ return false;
32
+
33
+ if (isset($_REQUEST['do_widget_debug'])) {
34
+ $url_without_debug_query = remove_query_arg( 'do_widget_debug');
35
+ $eek = '<a href="'.$url_without_debug_query.'">Remove debug</a>';
36
+ echo '<br/>Note: Debugs only shown to a Logged in Administrator.'
37
+ .'<br />'
38
+ .$eek
39
+ .'<br />';
40
+ return true;
41
+ }
42
+ else
43
+ return false;
44
+ }
45
+ /*-----------------------------------*/
46
+ function amr_show_widget_debug($type='', $atts=array()) {
47
+ global $wp_registered_sidebars, $wp_registered_widgets, $_wp_sidebars_widgets;
48
+ // only do these debug if we are logged in and are the administrator
49
+
50
+ $debug = amr_check_if_widget_debug();
51
+
52
+ if ($type=='empty') {
53
+ if (current_user_can('administrator'))
54
+ echo '<br /> You are admin: <a href="'.add_query_arg('do_widget_debug','1').'">Try debug </a></b>'
55
+ .'See a exclamation point ! above ?. Hover over to see error message.'
56
+ .'</p>';
57
+
58
+ if ($debug) {
59
+
60
+ echo '<p>As a last resort, we may dump the wp variables to do with sidebars and widgets. Maybe that will help you:</p>';
61
+ $sidebars_widgets = wp_get_sidebars_widgets();
62
+ echo '<h3> result of wp_get_sidebars_widgets():</h3>';
63
+ foreach ($sidebars_widgets as $i=>$w) {
64
+ echo '<br/>'.$i; var_dump($w);
65
+ };
66
+
67
+ echo '<h3>$_wp_sidebars_widgets:</h3>';
68
+ var_dump($_wp_sidebars_widgets);
69
+ //echo '<br /><h3>$wp_registered_widgets:</h3>';
70
+ //var_dump($wp_registered_widgets);
71
+ echo '<br /><h3>$wp_registered_sidebars:</h3>';
72
+ var_dump($wp_registered_sidebars);
73
+ }
74
+ }
75
+
76
+ if (($type=='which one') and ($debug)) {
77
+ echo '<h3>DEBUG on: Is your widget in the widgets_for_shortcodes sidebar?</h3>';
78
+ //echo '<br />The shortcode attributes you entered are:<br />';
79
+ //var_dump($atts);
80
+ echo '<br /><h2>widgets_for_shortcodes sidebar and widgets</h2>';
81
+ $found = false;
82
+ foreach ($_wp_sidebars_widgets as $i=> $w) {
83
+ if (($i == "widgets_for_shortcodes")) {
84
+ echo 'Sidebar:&nbsp;<b>'.$i.': '.amr_get_sidebar_name($i).'</b> has widgets with these ids: <br />';
85
+ $found = true;
86
+ if (is_array($w)) {
87
+ sort ($w);
88
+ foreach ($w as $i2=> $w2) {
89
+ echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$w2.' <br />';
90
+ };
91
+ }
92
+ echo '<br />';
93
+ }
94
+ //else {echo ' '.$i;}
95
+ };
96
+ if (!$found) echo '<h2>widgets_for_shortcodes sidebar empty or not defined.</h2>';
97
+ }
98
+ }
99
+ /*-----------------------------------*/
100
+ function amr_save_shortcodes_sidebar() { // when switching a theme, save the widgets we use for the shortcodes as they are getting overwritten
101
+ $sidebars_widgets = wp_get_sidebars_widgets();
102
+ if (!empty($sidebars_widgets['widgets_for_shortcodes']))
103
+ update_option('sidebars_widgets_for_shortcodes_saved',$sidebars_widgets['widgets_for_shortcodes']);
104
+ else { // our shortcodes sidebar is empty but when to fix ?
105
+
106
+ }
107
+ }
108
+ /*-----------------------------------*/
109
+ function amr_restore_shortcodes_sidebar() { // when switching a theme, restore the widgets we use for the shortcodes as they are getting overwritten
110
+ global $_wp_sidebars_widgets;
111
+
112
+ $sidebars_widgets = wp_get_sidebars_widgets();
113
+ if (empty($sidebars_widgets['widgets_for_shortcodes'])) {
114
+ $sidebars_widgets['widgets_for_shortcodes'] = get_option('sidebars_widgets_for_shortcodes_saved');
115
+ update_option('sidebars_widgets',$sidebars_widgets);
116
+
117
+ }
118
+
119
+ }
120
+ /*-----------------------------------*/
121
+ function amr_upgrade_sidebar() { // added in 2014 February for compatibility.. keep for how long. till no sites running older versions.?
122
+ $sidebars_widgets = wp_get_sidebars_widgets();
123
+ if (!empty($sidebars_widgets['Shortcodes']) and empty($sidebars_widgets['widgets_for_shortcodes'])) { // we need to upgrade
124
+ $sidebars_widgets['widgets_for_shortcodes'] = $sidebars_widgets['Shortcodes'];
125
+ unset ($sidebars_widgets['Shortcodes']);
126
+ update_option('sidebars_widgets',$sidebars_widgets );
127
+ add_action( 'admin_notices', 'widgets_shortcode_admin_notice' );
128
+ }
129
+ }
130
+
131
+ /*-----------------------------------*/
132
+ function widgets_shortcode_admin_notice() {
133
+ ?>
134
+ <div class="updated">
135
+ <p>Please go to widgets page and check your "widgets for shortcodes" sidebar. It will hopefully have been corrected upgraded with your widgets and all should be fine.</p>
136
+ </div>
137
+ <?php
138
+ }
139
+ /*-----------------------------------*/
140
+
141
+ ?>
trunk/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+ // Silence is golden.
3
+ ?>
trunk/languages/amr-shortcode-any-widget-en_AU.mo ADDED
Binary file
trunk/languages/amr-shortcode-any-widget-en_AU.po ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: amr shortcode any widget v2.4\n"
4
+ "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: \n"
6
+ "PO-Revision-Date: 2015-02-05 07:36:42+0000\n"
7
+ "Last-Translator: anmari <anmari@anmari.com>\n"
8
+ "Language-Team: \n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
13
+ "X-Generator: CSL v1.x\n"
14
+ "X-Poedit-Language: English\n"
15
+ "X-Poedit-Country: AUSTRALIA\n"
16
+ "X-Poedit-SourceCharset: utf-8\n"
17
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
18
+ "X-Poedit-Basepath: ../\n"
19
+ "X-Poedit-Bookmarks: \n"
20
+ "X-Poedit-SearchPath-0: .\n"
21
+ "X-Textdomain-Support: yes"
22
+
23
+ #: amr-admin-form-html.php:37
24
+ #@ amr-shortcode-any-widget
25
+ msgid "Settings"
26
+ msgstr ""
27
+
28
+ #: amr-admin-form-html.php:63
29
+ #@ amr-shortcode-any-widget
30
+ msgid "Drag the widgets you want to use to the shortcodes sidebar."
31
+ msgstr ""
32
+
33
+ #: amr-admin-form-html.php:67
34
+ #@ amr-shortcode-any-widget
35
+ msgid "Set the widgets parameters if there are any."
36
+ msgstr ""
37
+
38
+ #: amr-admin-form-html.php:70
39
+ #@ amr-shortcode-any-widget
40
+ msgid "You could test the widgets out in a displayable widget area (sidebar/footer), then drag them to the widgets_for_shortcodes sidebar."
41
+ msgstr ""
42
+
43
+ #: amr-admin-form-html.php:75
44
+ #@ amr-shortcode-any-widget
45
+ msgid "Go to widgets"
46
+ msgstr ""
47
+
48
+ #: amr-admin-form-html.php:81
49
+ #@ amr-shortcode-any-widget
50
+ msgid "To add a widget area - all widgets in the widget area:"
51
+ msgstr ""
52
+
53
+ #: amr-admin-form-html.php:89
54
+ #@ amr-shortcode-any-widget
55
+ msgid "Create a page with do_widget_area shortcode without the widget_area class"
56
+ msgstr ""
57
+
58
+ #: amr-admin-form-html.php:96
59
+ #@ amr-shortcode-any-widget
60
+ msgid "Create a page with do_widget_area shortcode"
61
+ msgstr ""
62
+
63
+ #: amr-admin-form-html.php:100
64
+ #: amr-admin-form-html.php:117
65
+ #@ amr-shortcode-any-widget
66
+ msgid "Examples:"
67
+ msgstr ""
68
+
69
+ #: amr-admin-form-html.php:103
70
+ #@ amr-shortcode-any-widget
71
+ msgid "[do_widget_area] or [do_widget_area widget_area=sidebar-1]"
72
+ msgstr ""
73
+
74
+ #: amr-admin-form-html.php:106
75
+ #@ amr-shortcode-any-widget
76
+ msgid "NB: Using something like the twenty-fourteen theme? you might end up with white text on a white background. Tweak the widget classes or the html of the wrap or title. If that fails, adjust your css."
77
+ msgstr ""
78
+
79
+ #: amr-admin-form-html.php:112
80
+ #@ amr-shortcode-any-widget
81
+ msgid "To add a single widget to a page"
82
+ msgstr ""
83
+
84
+ #: amr-admin-form-html.php:116
85
+ #@ amr-shortcode-any-widget
86
+ msgid "Add the shortcode [do_widget widgetname] to a page."
87
+ msgstr ""
88
+
89
+ #: amr-admin-form-html.php:120
90
+ #@ amr-shortcode-any-widget
91
+ msgid "[do_widget \"tag cloud\"] or [do_widget id=widgetid]"
92
+ msgstr ""
93
+
94
+ #: amr-admin-form-html.php:126
95
+ #@ amr-shortcode-any-widget
96
+ msgid "Create a page with do_widget shortcode and remove widget_classes"
97
+ msgstr ""
98
+
99
+ #: amr-admin-form-html.php:133
100
+ #@ amr-shortcode-any-widget
101
+ msgid "Create a page with do_widget shortcode"
102
+ msgstr ""
103
+
104
+ #: amr-admin-form-html.php:174
105
+ #@ amr-shortcode-any-widget
106
+ msgid "If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the"
107
+ msgstr ""
108
+
109
+ #: amr-admin-form-html.php:174
110
+ #@ amr-shortcode-any-widget
111
+ msgid "Support forums"
112
+ msgstr ""
113
+
114
+ #: amr-shortcode-any-widget.php:306
115
+ #@ amr-shortcode-any-widget
116
+ msgid "Sidebar to hold widgets and their settings. These widgets will be used in a shortcode. This sidebars widgets should be saved with your theme settings now."
117
+ msgstr "G'day - this is the sidebar to hold widgets for shotcode"
118
+
trunk/languages/amr-shortcode-any-widget-sr_RS.mo ADDED
Binary file
trunk/languages/amr-shortcode-any-widget-sr_RS.po ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: amr shortcode any widget v2.4\n"
4
+ "Report-Msgid-Bugs-To: http://wordpress.org/tag/amr-shortcode-any-widget\n"
5
+ "POT-Creation-Date: 2014-09-10 04:32:05+00:00\n"
6
+ "PO-Revision-Date: 2015-02-05 07:22:13+0000\n"
7
+ "Last-Translator: Borisa Djuraskovic <borisad@webhostinghub.com>\n"
8
+ "Language-Team: LANGUAGE <LL@li.org>\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
13
+ "X-Generator: Poedit 1.5.7\n"
14
+ "X-Poedit-Language: \n"
15
+ "X-Poedit-Country: \n"
16
+ "X-Poedit-SourceCharset: utf-8\n"
17
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;__ngettext_noop:1,2;_n_noop:1,2;_c,_nc:4c,1,2;_x:1,2c;_ex:1,2c;_nx:4c,1,2;_nx_noop:4c,1,2;\n"
18
+ "X-Poedit-Basepath: \n"
19
+ "X-Poedit-Bookmarks: \n"
20
+ "X-Poedit-SearchPath-0: .\n"
21
+ "X-Textdomain-Support: yes"
22
+
23
+ #: amr-admin-form-html.php:37
24
+ #@ amr-shortcode-any-widget
25
+ msgid "Settings"
26
+ msgstr "Podešavanja"
27
+
28
+ #: amr-admin-form-html.php:63
29
+ #@ amr-shortcode-any-widget
30
+ msgid "Drag the widgets you want to use to the shortcodes sidebar."
31
+ msgstr "Prevucite widget-e koje želite da koristite u shortcode bočni meni. "
32
+
33
+ #: amr-admin-form-html.php:67
34
+ #@ amr-shortcode-any-widget
35
+ msgid "Set the widgets parameters if there are any."
36
+ msgstr "Podesite parametre widget-a ako ih ima."
37
+
38
+ #: amr-admin-form-html.php:70
39
+ #@ amr-shortcode-any-widget
40
+ msgid "You could test the widgets out in a displayable widget area (sidebar/footer), then drag them to the widgets_for_shortcodes sidebar."
41
+ msgstr "Možete da testirate widget-e u widget oblasti za prikazivanje (bočni meni/podnožje), a zatim ih prevucite u widgets_for_shortcodes bočni meni. "
42
+
43
+ #: amr-admin-form-html.php:75
44
+ #@ amr-shortcode-any-widget
45
+ msgid "Go to widgets"
46
+ msgstr "Idite na widget-e"
47
+
48
+ #: amr-admin-form-html.php:81
49
+ #@ amr-shortcode-any-widget
50
+ msgid "To add a widget area - all widgets in the widget area:"
51
+ msgstr "Da biste sve widget-e dodali u widget oblast:"
52
+
53
+ #: amr-admin-form-html.php:89
54
+ #@ amr-shortcode-any-widget
55
+ msgid "Create a page with do_widget_area shortcode without the widget_area class"
56
+ msgstr "Kreirajte stranicu uz shortcode do_widget_area, ali bez widget_area klase"
57
+
58
+ #: amr-admin-form-html.php:96
59
+ #@ amr-shortcode-any-widget
60
+ msgid "Create a page with do_widget_area shortcode"
61
+ msgstr "Kreirajte stranicu uz do_widget_area shortcode"
62
+
63
+ #: amr-admin-form-html.php:100
64
+ #: amr-admin-form-html.php:117
65
+ #@ amr-shortcode-any-widget
66
+ msgid "Examples:"
67
+ msgstr "Primeri:"
68
+
69
+ #: amr-admin-form-html.php:103
70
+ #@ amr-shortcode-any-widget
71
+ msgid "[do_widget_area] or [do_widget_area widget_area=sidebar-1]"
72
+ msgstr "[do_widget_area] ili [do_widget_area widget_area=sidebar-1]"
73
+
74
+ #: amr-admin-form-html.php:106
75
+ #@ amr-shortcode-any-widget
76
+ msgid "NB: Using something like the twenty-fourteen theme? you might end up with white text on a white background. Tweak the widget classes or the html of the wrap or title. If that fails, adjust your css."
77
+ msgstr "Zapamtite: Koristite li nešto poput 2014 teme? Možete završiti sa belim tekstom na beloj pozadini. Uzmite klase widget-a ili html sa preloma ili iz naslova. Ako to ne uspe, prilagodite svoj css."
78
+
79
+ #: amr-admin-form-html.php:112
80
+ #@ amr-shortcode-any-widget
81
+ msgid "To add a single widget to a page"
82
+ msgstr "Da biste dodali pojedinačni widget stranici"
83
+
84
+ #: amr-admin-form-html.php:116
85
+ #@ amr-shortcode-any-widget
86
+ msgid "Add the shortcode [do_widget widgetname] to a page."
87
+ msgstr "Dodajte shortcode [do_widget widgetname] stranici."
88
+
89
+ #: amr-admin-form-html.php:120
90
+ #@ amr-shortcode-any-widget
91
+ msgid "[do_widget \"tag cloud\"] or [do_widget id=widgetid]"
92
+ msgstr "[do_widget \"tag cloud\"] ili [do_widget id=widgetid]"
93
+
94
+ #: amr-admin-form-html.php:126
95
+ #@ amr-shortcode-any-widget
96
+ msgid "Create a page with do_widget shortcode and remove widget_classes"
97
+ msgstr "Kreirajte stranicu uz pomoć do_widget shortcode i remove widget_classes"
98
+
99
+ #: amr-admin-form-html.php:133
100
+ #@ amr-shortcode-any-widget
101
+ msgid "Create a page with do_widget shortcode"
102
+ msgstr "Kreirajte stranicu koristeći do_widget shortcode"
103
+
104
+ #: amr-admin-form-html.php:174
105
+ #@ amr-shortcode-any-widget
106
+ msgid "If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the"
107
+ msgstr "Ako imate bilo kakvih problema s ovim plugin-om ili dobre ideje za poboljšanja, odnosno, nove funkcionalnosti, pričajte o njima na"
108
+
109
+ #: amr-admin-form-html.php:174
110
+ #@ amr-shortcode-any-widget
111
+ msgid "Support forums"
112
+ msgstr "Forumima za podršku"
113
+
trunk/languages/amr-shortcode-any-widget.pot ADDED
@@ -0,0 +1,118 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (C) 2015 amr shortcode any widget
2
+ # This file is distributed under the same license as the amr shortcode any widget package.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: amr shortcode any widget 2.3\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/amr-shortcode-any-"
7
+ "widget\n"
8
+ "POT-Creation-Date: 2015-02-05 06:56:45+00:00\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+
16
+ #: amr-admin-form-html.php:37
17
+ msgid "Settings"
18
+ msgstr ""
19
+
20
+ #: amr-admin-form-html.php:63
21
+ msgid "Drag the widgets you want to use to the shortcodes sidebar."
22
+ msgstr ""
23
+
24
+ #: amr-admin-form-html.php:67
25
+ msgid "Set the widgets parameters if there are any."
26
+ msgstr ""
27
+
28
+ #: amr-admin-form-html.php:70
29
+ msgid ""
30
+ "You could test the widgets out in a displayable widget area (sidebar/"
31
+ "footer), then drag them to the widgets_for_shortcodes sidebar."
32
+ msgstr ""
33
+
34
+ #: amr-admin-form-html.php:75
35
+ msgid "Go to widgets"
36
+ msgstr ""
37
+
38
+ #: amr-admin-form-html.php:81
39
+ msgid "To add a widget area - all widgets in the widget area:"
40
+ msgstr ""
41
+
42
+ #: amr-admin-form-html.php:89
43
+ msgid ""
44
+ "Create a page with do_widget_area shortcode without the widget_area class"
45
+ msgstr ""
46
+
47
+ #: amr-admin-form-html.php:96
48
+ msgid "Create a page with do_widget_area shortcode"
49
+ msgstr ""
50
+
51
+ #: amr-admin-form-html.php:100 amr-admin-form-html.php:117
52
+ msgid "Examples:"
53
+ msgstr ""
54
+
55
+ #: amr-admin-form-html.php:103
56
+ msgid "[do_widget_area] or [do_widget_area widget_area=sidebar-1]"
57
+ msgstr ""
58
+
59
+ #: amr-admin-form-html.php:106
60
+ msgid ""
61
+ "NB: Using something like the twenty-fourteen theme? you might end up with "
62
+ "white text on a white background. Tweak the widget classes or the html of "
63
+ "the wrap or title. If that fails, adjust your css."
64
+ msgstr ""
65
+
66
+ #: amr-admin-form-html.php:112
67
+ msgid "To add a single widget to a page"
68
+ msgstr ""
69
+
70
+ #: amr-admin-form-html.php:116
71
+ msgid "Add the shortcode [do_widget widgetname] to a page."
72
+ msgstr ""
73
+
74
+ #: amr-admin-form-html.php:120
75
+ msgid "[do_widget \"tag cloud\"] or [do_widget id=widgetid]"
76
+ msgstr ""
77
+
78
+ #: amr-admin-form-html.php:126
79
+ msgid "Create a page with do_widget shortcode and remove widget_classes"
80
+ msgstr ""
81
+
82
+ #: amr-admin-form-html.php:133
83
+ msgid "Create a page with do_widget shortcode"
84
+ msgstr ""
85
+
86
+ #: amr-admin-form-html.php:174
87
+ msgid ""
88
+ "If you have any problems with this plugin or good ideas for improvements or "
89
+ "new features, please talk about them in the"
90
+ msgstr ""
91
+
92
+ #: amr-admin-form-html.php:174
93
+ msgid "Support forums"
94
+ msgstr ""
95
+
96
+ #. Plugin Name of the plugin/theme
97
+ msgid "amr shortcode any widget"
98
+ msgstr ""
99
+
100
+ #. Plugin URI of the plugin/theme
101
+ msgid "http://webdesign.anmari.com/shortcode-any-widget/"
102
+ msgstr ""
103
+
104
+ #. Description of the plugin/theme
105
+ msgid ""
106
+ "Include any widget in a page for any theme. [do_widget widgetname ] or "
107
+ "[do_widget \"widget name\" ] or include a whole widget area "
108
+ "[do_widget_area]. If upgrading see changelog. Can be very powerful eg: with "
109
+ "queryposts widget it can become a templater."
110
+ msgstr ""
111
+
112
+ #. Author of the plugin/theme
113
+ msgid "anmari"
114
+ msgstr ""
115
+
116
+ #. Author URI of the plugin/theme
117
+ msgid "http://webdesign.anmari.com"
118
+ msgstr ""
trunk/readme.txt ADDED
@@ -0,0 +1,273 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.5
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
+ Set up your widget first in a normal sidebar. Check it works. THEN Drag your chosen widgets to the sidebar called "widgets for shortcode".
12
+
13
+ Using a widget more than once? Reference a specific widget instance from the do_widget shortcode, or the chosen sidebar from the do_widget_area shortcode. Eg: [do_widget id=widget-n]
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
+
17
+ The plugins default action is that it will magically find the settings for your themes first sidebar and use the sidebars html to control the widgets output. In most cases this means the widget will be styled as per the rest of your theme. If that does not look good, parameters exist to override this behaviour. EG: in twenty-fourteen theme widget text ends up being white on white! widget_classes=none fixes that. Eg: [do_widget widget_classes=none yourwidget]
18
+
19
+ Change your theme and woried about losing the sidebar settings ? No problem, the plugin will save and restore the widgets_for_shortcode settings. On display it will then pick up the new themes sidebar settings. Check this still looks nice please! in some themes you may ned up with white text on a white background and will then have to override or change css.
20
+
21
+ PLEASE get your widgets working in a sidebar BEFORE activating this plugin, and PLEASE read https://wordpress.org/plugins/amr-shortcode-any-widget/installation/ before asking any questions.
22
+
23
+ == Installation ==
24
+
25
+ 1. Test your chosen widget in a normal sidebar or widget area first. Make sure it works.
26
+ 2. Then and only then activate this plugin
27
+ 3. Go to Appearance > widgets and find the " widgets for shortcode" sidebar or widget area
28
+ 4. Drag your chosen widget from your normal sidebar to the shortcodes sidebar. Save.
29
+ 5. Now go to a page and enter a shortcode (Or Go the shortcode any widget settings. Click on one of the create page links to help you setup the shortcode in a new page.)
30
+
31
+ * [do_widget widgetname] eg: [do_widget calendar]
32
+ * [do_widget "widget name"]. eg: [do_widget "tag cloud"]
33
+ * [do_widget id=widgetid] . eg: [do_widget id=tag-cloud-3]
34
+
35
+ * [do_widget_area] (will use the "widgets in shortcodes" widget area / sidebar
36
+ * [do_widget_area sidebarname] for another sidebar or widget area - eg: to maximise likelihood of getting your theme's widget css to apply.
37
+
38
+ 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. 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.
39
+ * Click on the link 'Try debug'. It will produce a bunch of info.
40
+ * Look for the id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug info).
41
+ * Try using the widget id - ie [do_widget id=somename-n]. Examples are tag-cloud-3, meta-2 etc.
42
+
43
+ **STOP - Do not read any further until you have got the basics working. You may make it too complicated, when it can be so simple.**
44
+
45
+
46
+ **[do_widget ...] Parameters:**
47
+
48
+ * *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 be the first parameter then. You can only do this with the name, not the id.
49
+ * id=*wordpress assigned id of widget*. Examples: id=meta-3, id=tag-cloud-9 etc
50
+ * 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.
51
+ * 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.
52
+ * 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.
53
+ * class=*yourclassname* By default the plugin will add a class of amr-widget tto the wrapping html. You can use this to add any special css. Add css either by editing your themes stylesheet if it is a custom theme, or using something like the wordpress custom css plugin.
54
+ * sidebar="*sidebarname*" will default to widgets_for_shortcode sidebar. Only use if you want to re-use a widget already beingused in another sidebar. THis is theme dependent and WILL break if you change themes.
55
+
56
+ **[do_widget_area ...] Parameters:**
57
+
58
+ * widget_area=*yourwidgetarea* defaults to 'widgets_for_shortcodes' if nothing entered
59
+ * widget_area_class=none /* option to remove theme styling by removing the widget_area class from the sidebar html */
60
+ * widget_classes=none /* option to remove the widget class from the widget wrappinghtml
61
+ * 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.
62
+
63
+ Advanced users 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 widget area will not work. Got that ?
64
+
65
+ See the settings page for links to help your create the shortcodes in a page.
66
+
67
+ To 'remove debug mode'
68
+ remove ?do_widget_debug=1 from the url you are looking at (NOTE it only debugs if you are logged in and an administrator, so this is really NOT a problem.)
69
+
70
+ The plugin has been tested with most standard widgets (rss feeds, tag cloud, pages, meta, search, and of course my own plugins widgets - upcoming events list, calendar and user lists.
71
+
72
+ If you use a widget more than once for different reasons, you may need to use the widget id to isolate which widget instance and it's settings to use. ie: [do_widget id=categories-6] . If you just use the name, it will display all widgets in the shortcode sidebar with that name (all instances).
73
+
74
+ See also [home page](http://wordpress.org/plugins/amr-shortcode-any-widget/)
75
+
76
+ **If you liked this plugin, you might also like my other plugins:**
77
+
78
+ * [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)
79
+ * [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/)
80
+
81
+ == Frequently Asked Questions ==
82
+
83
+ **Widget help, the widget is doing this, when it should do that**
84
+
85
+ Please get the widget working first in a normal sidebar without this plugin and ask for support on the widgets forum it is does not work in a normal sidebar. There are 1000's and 1000's of widgets. I cannot help you with all ofthese. Please see
86
+ http://wordpress.org/support/topic/widget-help-settings-functioning-etc?replies=1
87
+
88
+
89
+ **How to identify widget**
90
+
91
+ To identify your widget in the shortcode, use a safe constant identifier like the NAME or the ID.
92
+
93
+ The name is the generic NAME like "tag cloud".
94
+
95
+ 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 it 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).
96
+
97
+ 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.
98
+
99
+ 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.
100
+
101
+ The id is how wordpress identifies the instance of the widget.
102
+ To help you find the wordpress id of your chosen widget you can either:
103
+
104
+ 1)
105
+ 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)
106
+ Click on the "try debug"
107
+
108
+ 2) else add ?do_widget_debug=1 to the url of the page that contains the [do_widget] shortcode.
109
+
110
+ either way you should see a list of stuff. See the screenshots for examples. It will say something like the widgets in "widgets for shortcode" are:
111
+ xxx-n
112
+ xxxxxx-n
113
+ xxx-xxxxx-n
114
+
115
+ and it will list the ids of your widget - the n's are numbers that distinguish multiple instances of the same widget. xxx's are the abbreviated names of the widgets.
116
+
117
+ as per screenshot 5
118
+ http://s.w.org/plugins/amr-shortcode-any-widget/screenshot-5.png?r=884849
119
+
120
+ Those are the ids you should use. They look like this:
121
+
122
+ meta-3
123
+ tag-cloud-2
124
+
125
+
126
+ More info here: http://wordpress.org/support/topic/ids-and-multiple-instances-of-widget?replies=2
127
+
128
+
129
+ **Styling, your theme, css, overriding**
130
+
131
+ Yes anything could happen wrt the appearance.(There are 10s of 1000s of themes and widgets. Multiply out the possible combinations. Add in css specifity, inheritance and cascading rules. Consider you are moving the widget out of the sidebar where the the theme and widget plugin expect it to be. ) 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. This plugin tries to help encourage that 'belonging' look. If it fails then it offers ways to switch the html and/or the classes being generated.
132
+
133
+
134
+ Examples:
135
+ * you may have undesired effects applying that do not work in the main content area
136
+ * You may have desired effects not applying because the css is specific to a themes sidebar and does not apply to the html in a page.
137
+
138
+ The plugin can help a bit - Via the plugin you can do the following to affect styling:
139
+
140
+ * 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]
141
+
142
+ * 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.
143
+
144
+ * Apply an existing class in your theme. Use [do_widget *widgetname* class=*yourclass*].
145
+
146
+ * Use the additional class 'amr-widget' provided to specify alternate css in your themes stylesheet or with something like wordpress custom css.
147
+
148
+ 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.
149
+
150
+ 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.
151
+
152
+ 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.
153
+
154
+ 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.
155
+
156
+ For example: An unwanted effect could be white text on a white background as in the twenty fourteen theme.
157
+
158
+ ** If you have an undesired styling effect with the default settings: **
159
+
160
+ 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.
161
+
162
+ Options if you don't like the default result:
163
+
164
+ Use the 'amr-widget' class that has been added to the widget wrapping html to override any css.
165
+
166
+ eg:
167
+ .amr-widget [
168
+ color: #000000;
169
+ }
170
+
171
+ Tap into a class you already have in your theme:
172
+
173
+ [do_widget class=yourclass]
174
+
175
+ Change the html that the shortcode-any-widget plugin will use.
176
+
177
+ eg: don't like the h3.widget-title styling ? change the title html to h2 in the shotcode parameters
178
+
179
+ [do_widget title=h2]
180
+
181
+ eg: don't like the 'aside' wrapping html styling? change the wrapping html:
182
+
183
+ [do_widget wrap=div]
184
+
185
+ If you only using widget, maybe inserting the whole sidebar or widgertarea would give an interesting effect. Sidebar background css may apply.
186
+
187
+ [do_widget_area]
188
+ More info on background: http://wordpress.org/support/topic/your-theme-your-sidebars-and-the-plugin-overriding?replies=10
189
+
190
+
191
+
192
+ == Changelog ==
193
+ = Version 2.5 =
194
+ * Tested on 4.1.1, Linked to the settings help page from the plugin action menu.
195
+ * Changed the readme a bit to try further aid understanding and reduce support issues
196
+ * Updated some screenshots.
197
+
198
+ = Version 2.4 =
199
+ * Tested on 4.1, Cleaned up the readme, Lang file for info page - most texts.
200
+
201
+ = Version 2.3 =
202
+ * Fixed some widget area class options that were not working.
203
+ * 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.
204
+ * Tested on 3.9.1
205
+ * Updated readme
206
+
207
+ = Version 2.2 =
208
+ * Attempt to add more styling control.
209
+ * Add widget_classes=none to reverse out widget type class. NOte to totally override wordpress widget
210
+ * Add widget_area_class=none
211
+
212
+ = Version 2.1 =
213
+ * Bug Fix - last sidebar registered by theme was being overwritten by the attempt to copy the themes sidebar arguments so that cleverly (hopefully) the shortcode widgets would pick up the same styling. Fixed now. Now it really does pickup the first sidebars styling - with devasting consquence in twenty-fourteen theme - yes white text on white background is not fun to read. But on other themes it works a treat.
214
+
215
+
216
+ = Version 2 =
217
+ * Shortcode widget id changed so that wordpress will save the shortcode settings per theme.
218
+ * Added Code to auto upgrade, but just in case please check your widgets page. Look at the inactive widgets if the widgets are not in your widgets for shortcodes sidebar.
219
+ * Logic added on theme switching to save shortcode widget settings and restore them after the theme switch, so you can play with themes and not have to set up your widgets again. WP kept putting them into an 'inactive sidebar'.
220
+ * Added, as requested by a few of you, the ability to add a class and control the html around the widget without having to enter html around the shortcode has been added. See the settings page for instructions.
221
+ * Added the ability to specify what html should be used for the title and the widget wrap, so that you can more easily either match your theme or get away from your thesmes widget styling.
222
+ * Added ability to insert a whole widget area into the page. The default will be the "widgets for shortcode" sidebar/widget area. You can specify others. Note Specifying other widget areas may be theme dependent, ie: switch and you'll lose that page.
223
+ * Added classes amr-widget and amr-widget-area so one can target the widgets in the page to adjust css.
224
+
225
+ = Version 1.8 =
226
+ * Whoops - had renamed the main file and forgot to delete it from the svn. Forcing a version number change to ensure files get cleaned up for everyone
227
+
228
+ = Version 1.7 =
229
+ * Change: Changed so that debugs and debug prompt will only show to a logged in administrator.
230
+
231
+ = Version 1.6 =
232
+ * Add: added a settings page to help people out (not really settings)
233
+ * Fix: changed a clashing function name
234
+
235
+ = Version 1.5 =
236
+ * Fixed: a small bug which caused a warning if you had not saved the widgets in your shortcode sidebar
237
+
238
+ = Version 1.4 =
239
+ * Updated readme - made very detailed steps and added some screen shots.
240
+ * Tested on wp 3.3.1 and fixed some notices when bad parameters entered.
241
+
242
+ = Version 1.3 =
243
+ * Added debug link and retested. Added readme.
244
+
245
+ = 1.12 =
246
+ * Changed dummy shortcode sidebar so it appears after the theme sidebars to avoid taking over their widgets (this happened in numbered sidebars) PLEASE note if you have upgraded, you may appear to have "lost" your widgets due to this sidebar change. You have not - they will be in your "inactive widgets" - please drag them to the new sidebar. You may also find that you have 2 versions of the plugin, with slightly different folder names. This will allow you to go back to the previous one to check what you had there if you need to. Deactivate the old one and activate the new one. Move your widgets back in. Test then Delete the old one. In one theme it also appeared that somehow due to this change, one of the sidebar widgets "moved" down to another sidebar. I think that this may have had something to do with the fact that sidebars can be numbered or named, so please check all your sidebars before continuing. As always make sure thath you know how to restore from a backup before doing any upgrades of any kind.
247
+ * Tested in 2.9.2, can still use either the widget name "Categories" or id=categories-6. Note widget must have been created in the dummy shortcode sidebar.
248
+
249
+ = 1.1 =
250
+
251
+ * Allow for lowercase use of widget names for the those challenged by attention to detail!
252
+ * Cleaned up debug mode to make it easier for people to identify which instance of a widget they are using. Add &do_widget_debug to url string.
253
+
254
+ = 1.0 =
255
+ * Launch of the plugin
256
+
257
+
258
+
259
+
260
+ == Screenshots ==
261
+
262
+ 1. setting up widgets in the widgets for shortcode sidebar. The widget's user interface (UI) is used to provide a UI for the do_widget shortcode.
263
+ 2. add shortcode for widgets in a page (must be in the widgets for shortcode sidebar)
264
+ 3. widgets in a page
265
+ 4. with the default widget class and with widget_classes=none
266
+ two rss feed widgets in shortcode sidebar - both will show if just name used
267
+ 5. Don't know the id? Just type junk and view page - the debug message will show. Click on it.
268
+ 6. After clicking on debug message - scroll down till you see the shortcodes sidebar - the widgets and their ids will be listed. Find the id of the widget you want.
269
+ 7. Shortcode parameters to remove widget-classes in theme like the twenty-fourteen theme (avoid white text on white background)
270
+ 8. Example of multiple rss widgets in twenty-fourteen theme
271
+
272
+
273
+