amr shortcode any widget - Version 1.8

Version Description

Download this release

Release Info

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

Code changes from version 1.7 to 1.8

amr-shortcode-any-widget.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: amr shortcode any widget
4
  Plugin URI: http://webdesign.anmari.com/shortcode-any-widget/
5
  Description: Include any widget in a page for any theme. [do_widget widgetname ] or [do_widget "widget name" ]. 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
  */
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
  */
amr_shortcode_any_widget.php DELETED
@@ -1,300 +0,0 @@
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
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -2,7 +2,7 @@
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 ==
@@ -31,10 +31,12 @@ If you liked this plugin, you might also like my other plugins:
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
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 ==
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