amr shortcode any widget - Version 1.6

Version Description

Download this release

Release Info

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

Code changes from version 1.5 to 1.6

Files changed (3) hide show
  1. amr-admin-form-html.php +214 -0
  2. amr_shortcode_any_widget.php +36 -18
  3. readme.txt +8 -4
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
+ ?>
amr_shortcode_any_widget.php CHANGED
@@ -2,9 +2,9 @@
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
  */
@@ -28,7 +28,7 @@ if it is in, then get the instance data and use that */
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) {
@@ -39,7 +39,9 @@ if it is in, then get the instance data and use that */
39
  };
40
  }
41
  }
42
- else { if ($debug) {echo '<br />No widgets defined'; }
 
 
43
  return (false);
44
  }
45
 
@@ -73,7 +75,10 @@ if it is in, then get the instance data and use that */
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';}
@@ -102,10 +107,13 @@ if it is in, then get the instance data and use that */
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 = '';
@@ -127,21 +135,26 @@ if it is in, then get the instance data and use that */
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 {
@@ -158,7 +171,7 @@ if it is in, then get the instance data and use that */
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) {
@@ -182,8 +195,10 @@ global $wp_registered_sidebars;
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";
@@ -202,7 +217,7 @@ function shortcode_sidebar( $id, $index=1, $title=true) { /* This is basically t
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
 
@@ -272,11 +287,14 @@ if ( function_exists('register_sidebar') )
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
  ?>
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
  */
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) {
39
  };
40
  }
41
  }
42
+ else { //if ($debug) {
43
+ echo '<br />No widgets defined at all';
44
+ //}
45
  return (false);
46
  }
47
 
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';}
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 = '';
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 {
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) {
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";
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
 
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
@@ -1,8 +1,8 @@
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 ==
@@ -17,8 +17,8 @@ This simple 'utility' plugin allows one to have any widget used in a page shortc
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
 
@@ -30,6 +30,10 @@ If you liked this plugin, you might also like my other plugins:
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
 
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 ==
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
 
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