Version Description
Download this release
Release Info
Developer | anmari |
Plugin | amr shortcode any widget |
Version | 3.1 |
Comparing to | |
See all releases |
Code changes from version 3 to 3.1
- amr-admin-form-html.php +59 -46
- amr-shortcode-any-widget.php +61 -46
- amr-utilities.php +55 -61
- readme.txt +36 -70
amr-admin-form-html.php
CHANGED
@@ -16,7 +16,7 @@ if (!class_exists('amr_saw_plugin_admin')) {
|
|
16 |
var $parent_slug = 'plugin_listings_menu';
|
17 |
var $accesslvl = 'manage_options';
|
18 |
|
19 |
-
function
|
20 |
add_action('admin_menu', array(&$this, 'register_settings_page') );
|
21 |
add_filter('plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
|
22 |
}
|
@@ -57,24 +57,25 @@ if (!class_exists('amr_saw_plugin_admin')) {
|
|
57 |
}
|
58 |
function config_page() {
|
59 |
$this->admin_heading($this->longname);
|
60 |
-
echo '<h3
|
61 |
-
echo '<
|
62 |
-
|
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('
|
70 |
-
echo '
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
_e('Go to widgets', 'amr-shortcode-any-widget');
|
75 |
echo '</a>';
|
76 |
echo '</li>';
|
77 |
-
echo '</
|
78 |
|
79 |
|
80 |
echo '<h2>';
|
@@ -82,56 +83,69 @@ if (!class_exists('amr_saw_plugin_admin')) {
|
|
82 |
echo '</h2>';
|
83 |
echo '<ul>';
|
84 |
echo '<li>';
|
85 |
-
_e('Add the shortcode [do_widget widgetname] to a page
|
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 '
|
93 |
-
.get_admin_url('','post-new.php?post_type=page&content=[do_widget Archives widget_classes=none]')
|
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 |
-
|
100 |
-
.get_admin_url('','post-new.php?post_type=page&content=[do_widget Archives ]')
|
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 '
|
115 |
echo '</li>';
|
116 |
echo '<li>';
|
117 |
-
echo '
|
118 |
echo '</li>';
|
|
|
119 |
echo '<li>';
|
120 |
-
echo '[do_widget
|
121 |
echo '</li>';
|
122 |
echo '<li>';
|
123 |
-
echo '[do_widget "
|
124 |
echo '</li>';
|
|
|
125 |
echo '</ul>';
|
126 |
|
127 |
-
echo '<
|
128 |
-
echo
|
129 |
-
|
130 |
-
echo '</
|
131 |
-
echo
|
132 |
-
echo '</
|
133 |
-
echo
|
134 |
-
echo '</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
echo '<h2>';
|
137 |
_e('To add multiple instances of the same widget:', 'amr-shortcode-any-widget');
|
@@ -142,7 +156,6 @@ if (!class_exists('amr_saw_plugin_admin')) {
|
|
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');
|
@@ -153,16 +166,16 @@ if (!class_exists('amr_saw_plugin_admin')) {
|
|
153 |
echo '<a title="Create a page" href="'
|
154 |
.get_admin_url('','post-new.php?post_type=page&content=[do_widget_area]')
|
155 |
.'"> ';
|
156 |
-
_e('Create a page with do_widget_area shortcode
|
157 |
-
echo '</a> Hoping to
|
158 |
echo '</li>';
|
159 |
echo '<li>';
|
160 |
echo '<a title="Create a page" href="'
|
161 |
.get_admin_url('',
|
162 |
'post-new.php?post_type=page&content=[do_widget_area widget_area_class=none]')
|
163 |
.'"> ';
|
164 |
-
_e('Create a page with do_widget_area shortcode', 'amr-shortcode-any-widget');
|
165 |
-
echo '</a> Hoping to
|
166 |
echo '</li>';
|
167 |
echo '<li>';
|
168 |
_e('Examples:', 'amr-shortcode-any-widget');
|
16 |
var $parent_slug = 'plugin_listings_menu';
|
17 |
var $accesslvl = 'manage_options';
|
18 |
|
19 |
+
function __construct() {
|
20 |
add_action('admin_menu', array(&$this, 'register_settings_page') );
|
21 |
add_filter('plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
|
22 |
}
|
57 |
}
|
58 |
function config_page() {
|
59 |
$this->admin_heading($this->longname);
|
60 |
+
echo '<h3>More detailed instructions at the wordpress plugin <a target="_new" href="http://wordpress.org/plugins/amr-shortcode-any-widget/installation">installation and faq pages.</a></h3>';
|
61 |
+
echo '<ol>';
|
62 |
+
echo '<li>';
|
63 |
_e('Test your widget in a normal sidebar first.', 'amr-shortcode-any-widget');
|
64 |
+
echo ' <a title="Go to widget area" href="'.get_admin_url('','widgets.php').'">';
|
65 |
+
_e('Go to widgets', 'amr-shortcode-any-widget');
|
66 |
+
echo '</a>';
|
67 |
echo '<li>';
|
68 |
_e('Drag the widgets you want to use to the shortcodes sidebar.', 'amr-shortcode-any-widget');
|
|
|
69 |
echo '</li>';
|
70 |
echo '<li>';
|
71 |
+
_e('Add a do_widget or do_widget_area shortcode to a page.', 'amr-shortcode-any-widget');
|
72 |
+
echo ' <a title="Create a page" href="'
|
73 |
+
.get_admin_url('','post-new.php?post_type=page&content=[do_widget Archives ]')
|
74 |
+
.'">';
|
75 |
+
_e('Create a page with example do_widget shortcode', 'amr-shortcode-any-widget');
|
|
|
76 |
echo '</a>';
|
77 |
echo '</li>';
|
78 |
+
echo '</ol>';
|
79 |
|
80 |
|
81 |
echo '<h2>';
|
83 |
echo '</h2>';
|
84 |
echo '<ul>';
|
85 |
echo '<li>';
|
86 |
+
_e('Add the shortcode [do_widget widgetname] to a page:', 'amr-shortcode-any-widget');
|
|
|
87 |
echo '</li>';
|
88 |
echo '<li>';
|
|
|
|
|
89 |
echo '<li>';
|
90 |
+
echo '[do_widget categories] or [do_widget name=categories] ';
|
|
|
|
|
|
|
|
|
91 |
echo '</li>';
|
92 |
echo '<li>';
|
93 |
+
_e('[do_widget "tag cloud"] or [do_widget id=widgetid]', 'amr-shortcode-any-widget');
|
|
|
|
|
|
|
|
|
94 |
echo '</li>';
|
95 |
echo '<li>';
|
96 |
+
echo 'To see a list of your widgets in their sidebars, add <b>?do_widget_debug</b> to the url of page with the do_widget shortcode.';
|
97 |
+
echo '</li>';
|
98 |
+
echo '</ul>';
|
99 |
+
|
100 |
+
echo '<br />';
|
101 |
+
echo '<h2>';
|
102 |
+
_e('More advanced options:','amr-shortcode-any-widget');
|
103 |
+
echo '</h2>';
|
104 |
+
echo '<ul><li>';
|
105 |
echo 'Use title=false to hide a widget title. ';
|
|
|
|
|
106 |
echo '</li>';
|
107 |
echo '<li>';
|
108 |
echo '[do_widget pages title=false] will hide the widget title';
|
109 |
+
echo '</li></ul>';
|
110 |
+
echo '<h3>';
|
111 |
+
_e('To change the style, change the html:','amr-shortcode-any-widget');
|
112 |
+
echo '</h3>';
|
113 |
+
echo '<ul>';
|
114 |
+
|
115 |
echo '<li>';
|
116 |
+
echo 'Use title=somehtmltag and wrap=somehtmltag to change the html used. This may change how your theme\'s css affects the widget when it is in page. It all depends what what html selectors your theme uses.';
|
117 |
echo '</li>';
|
118 |
echo '<li>';
|
119 |
+
echo ' Use class=yourclassname to add a class - maybe to override your themes widget styling? Obviously you must have css that applies to that class.';
|
120 |
echo '</li>';
|
121 |
+
|
122 |
echo '<li>';
|
123 |
+
echo '[do_widget pages title=h3] give the title a heading 3 html tag.';
|
124 |
echo '</li>';
|
125 |
echo '<li>';
|
126 |
+
echo '[do_widget "tag cloud" wrap=aside] will wrap the widget in an "aside" html tag.';
|
127 |
echo '</li>';
|
128 |
+
|
129 |
echo '</ul>';
|
130 |
|
131 |
+
echo '<h4>';
|
132 |
+
echo "Valid title html tags are : </h4><ul>";
|
133 |
+
echo '<li>h1</li>';
|
134 |
+
echo '<li>h2</li>';
|
135 |
+
echo '<li>h3</li>';
|
136 |
+
echo '<li>h4</li>';
|
137 |
+
echo '<li>h5</li>';
|
138 |
+
echo '<li>header</li>';
|
139 |
+
echo '<li>strong</li>';
|
140 |
+
echo '<li>em</li>';
|
141 |
+
echo '</ul>';
|
142 |
+
|
143 |
+
echo "<h4>Valid html wrap tags are :</h4><ul>";
|
144 |
+
echo '<li>div</li>';
|
145 |
+
echo '<li>p</li>';
|
146 |
+
echo '<li>aside</li>';
|
147 |
+
echo '<li>section</li>';
|
148 |
+
echo '</ul>';
|
149 |
|
150 |
echo '<h2>';
|
151 |
_e('To add multiple instances of the same widget:', 'amr-shortcode-any-widget');
|
156 |
echo '[do_widget id=widgetid1] [do_widget id=widgetid2]';
|
157 |
echo '</li>';
|
158 |
echo '</ul>';
|
|
|
159 |
|
160 |
echo '<h2>';
|
161 |
_e('To add a widget area - all widgets in the widget area:', 'amr-shortcode-any-widget');
|
166 |
echo '<a title="Create a page" href="'
|
167 |
.get_admin_url('','post-new.php?post_type=page&content=[do_widget_area]')
|
168 |
.'"> ';
|
169 |
+
_e('Create a page with do_widget_area shortcode', 'amr-shortcode-any-widget');
|
170 |
+
echo '</a> Hoping to use theme styling.';
|
171 |
echo '</li>';
|
172 |
echo '<li>';
|
173 |
echo '<a title="Create a page" href="'
|
174 |
.get_admin_url('',
|
175 |
'post-new.php?post_type=page&content=[do_widget_area widget_area_class=none]')
|
176 |
.'"> ';
|
177 |
+
_e('Create a page with do_widget_area shortcode without the widget_area class', 'amr-shortcode-any-widget');
|
178 |
+
echo '</a> Hoping to avoid theme sidebar styling.';
|
179 |
echo '</li>';
|
180 |
echo '<li>';
|
181 |
_e('Examples:', 'amr-shortcode-any-widget');
|
amr-shortcode-any-widget.php
CHANGED
@@ -4,10 +4,23 @@ 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:
|
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'] =
|
@@ -45,7 +58,7 @@ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
|
|
45 |
echo '<br/>Widget area "'.$widget_area.'" not found. Registered widget areas (sidebars) are: <br/>';
|
46 |
foreach ($wp_registered_sidebars as $area=> $sidebar) echo $area.'<br />';
|
47 |
}
|
48 |
-
if (isset($_REQUEST['do_widget_debug']) and current_user_can('administrator')) var_dump( $wp_registered_sidebars); /**/
|
49 |
|
50 |
if ($widget_area_class=='none')
|
51 |
$class = '';
|
@@ -80,11 +93,9 @@ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
|
|
80 |
if it is in, then get the instance data and use that */
|
81 |
|
82 |
if (is_admin()) {return '';} // eg in case someone decides to apply content filters when apost is saved, and not all widget stuff is there.
|
83 |
-
|
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 */
|
@@ -97,8 +108,8 @@ if it is in, then get the instance data and use that */
|
|
97 |
amr_show_widget_debug('which one', $name, $id, $sidebar); //check for debug prompt and show widgets in shortcode sidebar if requested and logged in etc
|
98 |
}
|
99 |
else {
|
100 |
-
|
101 |
-
return (
|
102 |
}
|
103 |
|
104 |
/* compatibility check - if the name is not entered, then the first parameter is the name */
|
@@ -110,35 +121,49 @@ if it is in, then get the instance data and use that */
|
|
110 |
$widget = $name;
|
111 |
|
112 |
foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
|
113 |
-
if (strtolower($w['name']) === strtolower($widget))
|
|
|
114 |
//if ($debug) {echo '<br /> Check: '.$w['name'];}
|
115 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
}
|
117 |
else { /* check for id if we do not have a name */
|
118 |
-
|
119 |
-
|
120 |
foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
|
121 |
-
if ($w['id'] === $id)
|
|
|
|
|
122 |
}
|
123 |
-
//
|
124 |
}
|
125 |
else {
|
126 |
-
|
127 |
-
|
|
|
128 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
}
|
130 |
|
131 |
-
if (empty($widget))
|
132 |
-
if (empty($id))
|
133 |
|
134 |
if (empty ($widget_ids)) {
|
135 |
-
|
136 |
-
amr_show_widget_debug('empty', $name, $id, $sidebar);
|
137 |
-
return (
|
138 |
}
|
139 |
-
|
140 |
-
if (!($sidebarid = amr_get_sidebar_id ($sidebar)))
|
141 |
-
$sidebarid=$sidebar; /* get the official sidebar id for this widget area - will take the first one */
|
142 |
|
143 |
if (empty($widget))
|
144 |
$widget = '';
|
@@ -149,44 +174,29 @@ if it is in, then get the instance data and use that */
|
|
149 |
if ((!isset ($_wp_sidebars_widgets[$sidebarid])) or (empty ($_wp_sidebars_widgets[$sidebarid]))) { // try upgrade
|
150 |
amr_upgrade_sidebar();
|
151 |
}
|
152 |
-
|
153 |
|
|
|
154 |
if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
|
155 |
-
/* if ($debug) {
|
156 |
-
echo '<br />Widget ids in sidebar: "'.$sidebar.'" with id: '.$sidebarid .'<br />';
|
157 |
-
sort ($_wp_sidebars_widgets[$sidebarid]);
|
158 |
-
foreach ($_wp_sidebars_widgets[$sidebarid] as $i=> $w) {
|
159 |
-
echo $i.' '.$w.'<br />';
|
160 |
-
};
|
161 |
-
}
|
162 |
-
*/
|
163 |
/* get the intersect of the 2 widget setups so we just get the widget we want */
|
164 |
|
165 |
$wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
|
166 |
-
|
167 |
-
foreach ($widget_ids as $i=> $w) {
|
168 |
-
echo ' '.$w.'<br />';
|
169 |
-
};
|
170 |
-
}
|
171 |
-
*/
|
172 |
}
|
173 |
-
|
174 |
-
|
175 |
if (isset($debug)) { // only do this in debug mode
|
176 |
if (!isset($_wp_sidebars_widgets[$sidebarid]))
|
177 |
-
|
178 |
// shouldnt happen - maybe someone running content filters on save
|
179 |
else
|
180 |
-
|
181 |
-
}
|
182 |
-
|
183 |
}
|
184 |
|
185 |
$output = '';
|
186 |
if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
|
187 |
|
188 |
-
|
189 |
-
amr_show_widget_debug('empty', $name, $id, $sidebar);
|
190 |
|
191 |
unset($sidebar);
|
192 |
unset($sidebarid);
|
@@ -205,7 +215,12 @@ if it is in, then get the instance data and use that */
|
|
205 |
return ($output);
|
206 |
}
|
207 |
/* -------------------------------------------------------------------------*/
|
208 |
-
function amr_shortcode_sidebar( $widget_id,
|
|
|
|
|
|
|
|
|
|
|
209 |
global $wp_registered_sidebars, $wp_registered_widgets;
|
210 |
|
211 |
$debug = amr_check_if_widget_debug();
|
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: 3.1
|
8 |
Author URI: http://webdesign.anmari.com
|
9 |
|
10 |
*/
|
11 |
+
|
12 |
+
|
13 |
+
add_action('in_widget_form', 'amr_spice_get_widget_id');
|
14 |
+
function amr_spice_get_widget_id($widget_instance) {
|
15 |
+
echo "<p><strong>To use as shortcode with id:</strong> ";
|
16 |
+
if ($widget_instance->number=="__i__"){
|
17 |
+
echo "Save the widget first!</p>" ;
|
18 |
+
} else {
|
19 |
+
echo "[do_widget id=".$widget_instance->id. "]</p>";
|
20 |
+
}
|
21 |
+
}
|
22 |
+
|
23 |
+
|
24 |
function amr_remove_widget_class($params) { // remove the widget classes
|
25 |
if (!empty($params[0]['before_widget'])) {
|
26 |
$params[0]['before_widget'] =
|
58 |
echo '<br/>Widget area "'.$widget_area.'" not found. Registered widget areas (sidebars) are: <br/>';
|
59 |
foreach ($wp_registered_sidebars as $area=> $sidebar) echo $area.'<br />';
|
60 |
}
|
61 |
+
//if (isset($_REQUEST['do_widget_debug']) and current_user_can('administrator')) var_dump( $wp_registered_sidebars); /**/
|
62 |
|
63 |
if ($widget_area_class=='none')
|
64 |
$class = '';
|
93 |
if it is in, then get the instance data and use that */
|
94 |
|
95 |
if (is_admin()) {return '';} // eg in case someone decides to apply content filters when apost is saved, and not all widget stuff is there.
|
|
|
|
|
96 |
|
97 |
extract(shortcode_atts(array(
|
98 |
+
'sidebar' => 'Widgets for Shortcodes', //default
|
99 |
'id' => '',
|
100 |
'name' => '', /* MKM added explicit 'name' attribute. For existing users we still need to allow prev method, else too many support queries will happen */
|
101 |
'title' => '', /* do the default title unless they ask us not to - use string here not boolean */
|
108 |
amr_show_widget_debug('which one', $name, $id, $sidebar); //check for debug prompt and show widgets in shortcode sidebar if requested and logged in etc
|
109 |
}
|
110 |
else {
|
111 |
+
$output = '<br />No widgets defined at all in any sidebar!';
|
112 |
+
return ($output);
|
113 |
}
|
114 |
|
115 |
/* compatibility check - if the name is not entered, then the first parameter is the name */
|
121 |
$widget = $name;
|
122 |
|
123 |
foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
|
124 |
+
if (strtolower($w['name']) === strtolower($widget))
|
125 |
+
$widget_ids[] = $i;
|
126 |
//if ($debug) {echo '<br /> Check: '.$w['name'];}
|
127 |
}
|
128 |
+
|
129 |
+
if (!($sidebarid = amr_get_sidebar_id ($sidebar))) {
|
130 |
+
$sidebarid=$sidebar; /* get the official sidebar id for this widget area - will take the first one */
|
131 |
+
}
|
132 |
+
|
133 |
+
|
134 |
}
|
135 |
else { /* check for id if we do not have a name */
|
136 |
+
|
137 |
+
if (!empty($id)) { /* if a specific id has been specified */
|
138 |
foreach ($wp_registered_widgets as $i => $w) { /* get the official internal name or id that the widget was registered with */
|
139 |
+
if ($w['id'] === $id) {
|
140 |
+
$widget_ids[] = $id;
|
141 |
+
}
|
142 |
}
|
143 |
+
//echo '<h2>We have an id: '.$id.'</h2>'; if (!empty($widget_ids)) var_dump($widget_ids);
|
144 |
}
|
145 |
else {
|
146 |
+
$output = '<br />No valid widget name or id given in shortcode parameters';
|
147 |
+
|
148 |
+
return $output;
|
149 |
}
|
150 |
+
// if we have id, get the sidebar for it
|
151 |
+
$sidebarid = amr_get_widgets_sidebar($id);
|
152 |
+
if (!$sidebarid) {
|
153 |
+
$output = '<br />Widget not in any sidebars<br />';
|
154 |
+
return $output;
|
155 |
+
}
|
156 |
}
|
157 |
|
158 |
+
if (empty($widget)) $widget = '';
|
159 |
+
if (empty($id)) $id = '';
|
160 |
|
161 |
if (empty ($widget_ids)) {
|
162 |
+
$output = '<br />Error: Your Requested widget "'.$widget.' '.$id.'" is not in the widget list.<br />';
|
163 |
+
$output .= amr_show_widget_debug('empty', $name, $id, $sidebar);
|
164 |
+
return ($output) ;
|
165 |
}
|
166 |
+
|
|
|
|
|
167 |
|
168 |
if (empty($widget))
|
169 |
$widget = '';
|
174 |
if ((!isset ($_wp_sidebars_widgets[$sidebarid])) or (empty ($_wp_sidebars_widgets[$sidebarid]))) { // try upgrade
|
175 |
amr_upgrade_sidebar();
|
176 |
}
|
|
|
177 |
|
178 |
+
//if we have a specific sidebar selected, use that
|
179 |
if ((isset ($_wp_sidebars_widgets[$sidebarid])) and (!empty ($_wp_sidebars_widgets[$sidebarid]))) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
/* get the intersect of the 2 widget setups so we just get the widget we want */
|
181 |
|
182 |
$wid = array_intersect ($_wp_sidebars_widgets[$sidebarid], $widget_ids );
|
183 |
+
|
|
|
|
|
|
|
|
|
|
|
184 |
}
|
185 |
+
else { /* the sidebar is not defined or selected - should not happen */
|
|
|
186 |
if (isset($debug)) { // only do this in debug mode
|
187 |
if (!isset($_wp_sidebars_widgets[$sidebarid]))
|
188 |
+
$output = '<br /><a href="" title="Error: Sidebar '.$sidebar.' with sidebarid '.$sidebarid.' is not defined.">!</a><br />';
|
189 |
// shouldnt happen - maybe someone running content filters on save
|
190 |
else
|
191 |
+
$output = '<br /><a href="" title="Error: Sidebar '.$sidebar.' with sidebarid '.$sidebarid.' is empty (no widgets)">!</a><br />';
|
192 |
+
}
|
|
|
193 |
}
|
194 |
|
195 |
$output = '';
|
196 |
if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
|
197 |
|
198 |
+
$output = '<p><a href="" title="Error: Your requested Widget '.$widget.' is not in the '.$sidebar.' sidebar ">!</a></p>';
|
199 |
+
$output .= amr_show_widget_debug('empty', $name, $id, $sidebar);
|
200 |
|
201 |
unset($sidebar);
|
202 |
unset($sidebarid);
|
215 |
return ($output);
|
216 |
}
|
217 |
/* -------------------------------------------------------------------------*/
|
218 |
+
function amr_shortcode_sidebar( $widget_id,
|
219 |
+
$name="widgets_for_shortcode",
|
220 |
+
$title=true,
|
221 |
+
$class='',
|
222 |
+
$wrap='',
|
223 |
+
$widget_classes='') { /* This is basically the wordpress code, slightly modified */
|
224 |
global $wp_registered_sidebars, $wp_registered_widgets;
|
225 |
|
226 |
$debug = amr_check_if_widget_debug();
|
amr-utilities.php
CHANGED
@@ -1,4 +1,44 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
/*-----------------------------------*/
|
3 |
function amr_get_sidebar_id ($name) {
|
4 |
/* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer.
|
@@ -41,9 +81,11 @@ global $said;
|
|
41 |
|
42 |
$url_without_debug_query = esc_url(remove_query_arg( 'do_widget_debug'));
|
43 |
$eek = '<a href="'.$url_without_debug_query.'">Remove debug</a>';
|
44 |
-
echo '<br/>Note:
|
45 |
.$eek
|
46 |
.'<br />';
|
|
|
|
|
47 |
return true;
|
48 |
}
|
49 |
else
|
@@ -52,68 +94,21 @@ global $said;
|
|
52 |
/*-----------------------------------*/
|
53 |
function amr_show_widget_debug($type='', $name, $id, $sidebar) {
|
54 |
global $wp_registered_sidebars, $wp_registered_widgets, $_wp_sidebars_widgets, $debugcount;
|
55 |
-
// only do these debug if we are logged in and are the administrator
|
56 |
-
|
57 |
-
|
58 |
-
$debug = amr_check_if_widget_debug();
|
59 |
-
|
60 |
-
if ($type=='empty') {
|
61 |
-
if (!$debug and current_user_can('administrator'))
|
62 |
-
|
63 |
-
echo '<br/>Problem? Have you read <a title="Detailed help on how to use this plugin" href="https://wordpress.org/plugins/amr-shortcode-any-widget/installation/">this</a> carefully?<br />';
|
64 |
-
echo '<br /> You are admin: <a href="'.esc_url(add_query_arg('do_widget_debug','1')).'">Click here to try debug </a></b>'
|
65 |
-
.'(or see a exclamation point ! above ?. Hover over to see error message.)'
|
66 |
-
.'</p>';
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
echo '<h3>do_widget sidebar='.$i.' ....</h3><table>';
|
75 |
-
echo '<tr><th>Widget name</th><th>Widget id</th>';
|
76 |
-
foreach ($w as $j=>$id) {
|
77 |
-
echo '<tr><td>';
|
78 |
-
if (isset($wp_registered_widgets[$id])) echo $wp_registered_widgets[$id]['name'];
|
79 |
-
|
80 |
-
echo '</td><td> id='.$id.'</td></tr>';
|
81 |
-
}
|
82 |
-
echo '</table>';
|
83 |
-
//var_dump($w);
|
84 |
-
};
|
85 |
-
|
86 |
-
//echo '<h3>$_wp_sidebars_widgets:</h3>';
|
87 |
-
//var_dump($_wp_sidebars_widgets);
|
88 |
-
//echo '<br /><h3>$wp_registered_widgets:</h3>';
|
89 |
-
//var_dump($wp_registered_widgets);
|
90 |
-
//echo '<br /><h3>$wp_registered_sidebars:</h3>';
|
91 |
-
//var_dump($wp_registered_sidebars);
|
92 |
-
}
|
93 |
}
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
//echo '<br />The shortcode attributes you entered are:<br />';
|
98 |
-
//var_dump($atts);
|
99 |
-
$found = false;
|
100 |
-
foreach ($_wp_sidebars_widgets as $i=> $w) {
|
101 |
-
if (($i == "widgets_for_shortcodes") and !empty($w)) {
|
102 |
-
echo 'To access the widgets in '.$i.': <b>'.amr_get_sidebar_name($i).'</b> by id, use these shortcodes:';
|
103 |
-
echo '<div style="border: solid medium green; padding: 40px;" />';
|
104 |
-
$found = true;
|
105 |
-
if (is_array($w)) {
|
106 |
-
sort ($w);
|
107 |
-
foreach ($w as $i2=> $w2) {
|
108 |
-
echo '<p>[do_widget id='.$w2.'] </p>';
|
109 |
-
};
|
110 |
-
}
|
111 |
-
echo '</div>';
|
112 |
-
}
|
113 |
-
//else {echo ' '.$i;}
|
114 |
-
};
|
115 |
-
if (!$found) echo '<h2>widgets_for_shortcodes sidebar empty or not defined.</h2>';
|
116 |
}
|
|
|
|
|
117 |
}
|
118 |
/*-----------------------------------*/
|
119 |
function amr_save_shortcodes_sidebar() { // when switching a theme, save the widgets we use for the shortcodes as they are getting overwritten
|
@@ -147,7 +142,6 @@ function amr_upgrade_sidebar() { // added in 2014 February for compatibility.. k
|
|
147 |
}
|
148 |
}
|
149 |
|
150 |
-
/*-----------------------------------*/
|
151 |
function widgets_shortcode_admin_notice() {
|
152 |
?>
|
153 |
<div class="updated">
|
1 |
<?php
|
2 |
+
|
3 |
+
function amr_show_shortcode_widget_possibilities () {
|
4 |
+
global $_wp_sidebars_widgets;
|
5 |
+
|
6 |
+
$sidebars_widgets = $_wp_sidebars_widgets;
|
7 |
+
ksort ($sidebars_widgets); // push inactive down the bottom of the list
|
8 |
+
$text= '<ul>';
|
9 |
+
foreach ($sidebars_widgets as $sidebarid => $sidebar) {
|
10 |
+
|
11 |
+
if (is_array($sidebar)) {
|
12 |
+
$text .= '<li><em>[do_widget_area '.$sidebarid.']</em><ul>';
|
13 |
+
foreach ($sidebar as $i=> $w) {
|
14 |
+
|
15 |
+
$text .= '<li>';
|
16 |
+
$text .= '[do_widget id="'.$w.'"]';
|
17 |
+
$text .= '</li>';
|
18 |
+
|
19 |
+
};
|
20 |
+
$text .= '</ul></li>';
|
21 |
+
}
|
22 |
+
}
|
23 |
+
$text .= '</ul>';
|
24 |
+
return ($text);
|
25 |
+
}
|
26 |
+
|
27 |
+
/*-----------------------------------*/
|
28 |
+
function amr_get_widgets_sidebar($wid) {
|
29 |
+
/* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer.
|
30 |
+
take the first one that matches */
|
31 |
+
global $_wp_sidebars_widgets;
|
32 |
+
|
33 |
+
foreach ($_wp_sidebars_widgets as $sidebarid => $sidebar) {
|
34 |
+
foreach ($sidebar as $i=> $w) {
|
35 |
+
if ($w == $wid) {
|
36 |
+
return $sidebarid;
|
37 |
+
}
|
38 |
+
};
|
39 |
+
}
|
40 |
+
return (false); // widget id not in any sidebar
|
41 |
+
}
|
42 |
/*-----------------------------------*/
|
43 |
function amr_get_sidebar_id ($name) {
|
44 |
/* walk through the registered sidebars with a name and find the id - will be something like sidebar-integer.
|
81 |
|
82 |
$url_without_debug_query = esc_url(remove_query_arg( 'do_widget_debug'));
|
83 |
$eek = '<a href="'.$url_without_debug_query.'">Remove debug</a>';
|
84 |
+
echo '<br/>Note: Debug help is only shown to a logged-in Administrator.'
|
85 |
.$eek
|
86 |
.'<br />';
|
87 |
+
$text = amr_show_shortcode_widget_possibilities () ;
|
88 |
+
echo $text;
|
89 |
return true;
|
90 |
}
|
91 |
else
|
94 |
/*-----------------------------------*/
|
95 |
function amr_show_widget_debug($type='', $name, $id, $sidebar) {
|
96 |
global $wp_registered_sidebars, $wp_registered_widgets, $_wp_sidebars_widgets, $debugcount;
|
97 |
+
// only do these debug if we are logged in and are the administrator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
|
99 |
+
$debug = amr_check_if_widget_debug();
|
100 |
+
$text = amr_show_shortcode_widget_possibilities () ;
|
101 |
+
|
102 |
+
if ($type=='empty') {
|
103 |
+
if (current_user_can('administrator'))
|
104 |
+
$text = '<p>Problem with do_widget shortcode? Try one of the following:</p>'.$text;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
}
|
106 |
+
elseif (($type=='which one') and ($debug)) {
|
107 |
+
$text = '<p>Debug help is on: Is your widget in the widgets_for_shortcodes sidebar?</p>'
|
108 |
+
.$text;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
}
|
110 |
+
|
111 |
+
return ($text);
|
112 |
}
|
113 |
/*-----------------------------------*/
|
114 |
function amr_save_shortcodes_sidebar() { // when switching a theme, save the widgets we use for the shortcodes as they are getting overwritten
|
142 |
}
|
143 |
}
|
144 |
|
|
|
145 |
function widgets_shortcode_admin_notice() {
|
146 |
?>
|
147 |
<div class="updated">
|
readme.txt
CHANGED
@@ -2,33 +2,36 @@
|
|
2 |
Contributors: anmari
|
3 |
Tags: shortcode, widget, page, templates, page template, widget_area, sidebar
|
4 |
Tested up to: 4.4.1
|
5 |
-
Version: 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 |
-
Set up your widget first in a normal sidebar. Check it works.
|
12 |
-
|
13 |
-
|
14 |
|
15 |
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]
|
16 |
|
17 |
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/)
|
18 |
|
19 |
-
The plugins default action is that it will magically find the settings for your themes
|
|
|
20 |
|
21 |
-
|
22 |
|
|
|
23 |
|
|
|
24 |
|
25 |
== Installation ==
|
26 |
|
27 |
-
1. Test your chosen widget in a normal sidebar or widget area first.
|
28 |
-
2. Then
|
29 |
3. Go to Appearance > widgets and find the " widgets for shortcode" sidebar or widget area
|
30 |
4. Drag your chosen widget from your normal sidebar to the shortcodes sidebar. Save.
|
31 |
-
5. Now go to a page and enter a shortcode
|
32 |
|
33 |
* [do_widget widgetname] eg: [do_widget calendar]
|
34 |
* [do_widget "widget name"]. eg: [do_widget "tag cloud"]
|
@@ -37,23 +40,15 @@ Change your theme and woried about losing the sidebar settings ? No problem, the
|
|
37 |
* [do_widget_area] (will use the "widgets in shortcodes" widget area / sidebar
|
38 |
* [do_widget_area sidebarname] or [do_widget_area widget_area=sidebarname] for another sidebar or widget area - eg: to maximise likelihood of getting your theme's widget css to apply.
|
39 |
|
40 |
-
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.
|
41 |
-
* Click on the link 'Try debug'. It will produce a bunch of info.
|
42 |
-
* Look for the id of your widget in the shortcodes sidebar (you may have to scroll through a lot of debug info).
|
43 |
-
* Try using the widget id - ie [do_widget id=somename-n]. Examples are tag-cloud-3, meta-2 etc.
|
44 |
-
|
45 |
-
**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.**
|
46 |
-
|
47 |
-
|
48 |
**[do_widget ...] Parameters:**
|
49 |
|
50 |
* *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.
|
51 |
* id=*wordpress assigned id of widget*. Examples: id=meta-3, id=tag-cloud-9 etc
|
52 |
-
* 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.
|
53 |
-
* wrap=*htmltag* where *htmltag* is one of div,p,main,aside,section. This will override your themes first sidebar
|
54 |
-
* 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
|
55 |
-
* class=*yourclassname* By default the plugin will add a class of amr-widget
|
56 |
-
* sidebar="*sidebarname*" will default to widgets_for_shortcode sidebar. Only use if you want to re-use a widget already
|
57 |
|
58 |
**[do_widget_area ...] Parameters:**
|
59 |
|
@@ -62,18 +57,14 @@ Change your theme and woried about losing the sidebar settings ? No problem, the
|
|
62 |
* widget_classes=none /* option to remove the widget class from the widget wrappinghtml
|
63 |
* 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.
|
64 |
|
65 |
-
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.
|
66 |
|
67 |
See the settings page for links to help your create the shortcodes in a page.
|
68 |
|
69 |
-
To 'remove debug mode'
|
70 |
-
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.)
|
71 |
-
|
72 |
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.
|
73 |
|
74 |
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).
|
75 |
|
76 |
-
See also [home page](http://wordpress.org/plugins/amr-shortcode-any-widget/)
|
77 |
|
78 |
**If you liked this plugin, you might also like my other plugins:**
|
79 |
|
@@ -82,57 +73,27 @@ See also [home page](http://wordpress.org/plugins/amr-shortcode-any-widget/)
|
|
82 |
|
83 |
== Frequently Asked Questions ==
|
84 |
|
85 |
-
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.
|
86 |
|
87 |
**Widget help, the widget is doing this, when it should do that**
|
88 |
|
89 |
-
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.
|
90 |
-
http://wordpress.org/support/topic/widget-help-settings-functioning-etc?replies=1
|
91 |
-
|
92 |
|
93 |
**How to identify widget**
|
94 |
|
95 |
-
To identify your widget in the shortcode, use
|
96 |
-
|
97 |
-
The name is the generic NAME like "tag cloud".
|
98 |
-
|
99 |
-
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).
|
100 |
-
|
101 |
-
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.
|
102 |
-
|
103 |
-
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.
|
104 |
|
105 |
-
The
|
106 |
-
To help you find the wordpress id of your chosen widget you can either:
|
107 |
|
108 |
-
|
109 |
-
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)
|
110 |
-
Click on the "try debug"
|
111 |
-
|
112 |
-
2) else add ?do_widget_debug=1 to the url of the page that contains the [do_widget] shortcode.
|
113 |
-
|
114 |
-
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:
|
115 |
-
xxx-n
|
116 |
-
xxxxxx-n
|
117 |
-
xxx-xxxxx-n
|
118 |
-
|
119 |
-
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.
|
120 |
-
|
121 |
-
as per screenshot 5
|
122 |
-
http://s.w.org/plugins/amr-shortcode-any-widget/screenshot-5.png?r=884849
|
123 |
-
|
124 |
-
Those are the ids you should use. They look like this:
|
125 |
-
|
126 |
-
meta-3
|
127 |
-
tag-cloud-2
|
128 |
|
|
|
129 |
|
130 |
-
|
131 |
|
|
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
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.
|
136 |
|
137 |
|
138 |
Examples:
|
@@ -143,7 +104,7 @@ The plugin can help a bit - Via the plugin you can do the following to affect st
|
|
143 |
|
144 |
* 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]
|
145 |
|
146 |
-
*
|
147 |
|
148 |
* Apply an existing class in your theme. Use [do_widget *widgetname* class=*yourclass*].
|
149 |
|
@@ -159,7 +120,7 @@ It also depends on what the original widget plugin does with css and js. It may
|
|
159 |
|
160 |
For example: An unwanted effect could be white text on a white background as in the twenty fourteen theme.
|
161 |
|
162 |
-
**
|
163 |
|
164 |
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.
|
165 |
|
@@ -189,12 +150,17 @@ eg: don't like the 'aside' wrapping html styling? change the wrapping html:
|
|
189 |
If you only using widget, maybe inserting the whole sidebar or widgertarea would give an interesting effect. Sidebar background css may apply.
|
190 |
|
191 |
[do_widget_area]
|
192 |
-
More info on background: http://wordpress.org/support/topic/your-theme-your-sidebars-and-the-plugin-overriding?replies=10
|
193 |
|
194 |
|
195 |
|
196 |
== Changelog ==
|
197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
198 |
= Version 3 =
|
199 |
* added code to not output anything if in admin (eg: in edit/save mode) in case something has forced application of content filters when saving (and not all widget stuff is active, so errors are output.
|
200 |
* prefixed unprefixed function names to avoid conflicts
|
@@ -287,7 +253,7 @@ More info on background: http://wordpress.org/support/topic/your-theme-your-side
|
|
287 |
3. widgets in a page
|
288 |
4. with the default widget class and with widget_classes=none
|
289 |
two rss feed widgets in shortcode sidebar - both will show if just name used
|
290 |
-
5.
|
291 |
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.
|
292 |
7. Shortcode parameters to remove widget-classes in theme like the twenty-fourteen theme (avoid white text on white background)
|
293 |
8. Example of multiple rss widgets in twenty-fourteen theme
|
2 |
Contributors: anmari
|
3 |
Tags: shortcode, widget, page, templates, page template, widget_area, sidebar
|
4 |
Tested up to: 4.4.1
|
5 |
+
Version: 3.1
|
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.
|
12 |
+
THEN Drag your chosen widgets to the sidebar called "widgets for shortcode".
|
13 |
+
Add the do_widget shortcode to the page where you would like the widget to appear.
|
14 |
|
15 |
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]
|
16 |
|
17 |
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/)
|
18 |
|
19 |
+
The plugins default action is that it will magically find the settings for your themes sidebar and use the sidebar 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 try override this behaviour.
|
20 |
+
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]
|
21 |
|
22 |
+
Changed your theme and worried 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.
|
23 |
|
24 |
+
**Note:**
|
25 |
|
26 |
+
PLEASE get your widgets working in a sidebar BEFORE activating this plugin, and please read https://wordpress.org/plugins/amr-shortcode-any-widget/installation/ and https://wordpress.org/plugins/amr-shortcode-any-widget/faq/ and/or see the settings page. To see a list of your widgets in their sidebars, add ?do_widget_debug to the page with the do_widget shortcode.
|
27 |
|
28 |
== Installation ==
|
29 |
|
30 |
+
1. Test your chosen widget in a normal sidebar or widget area first.
|
31 |
+
2. Then activate this plugin
|
32 |
3. Go to Appearance > widgets and find the " widgets for shortcode" sidebar or widget area
|
33 |
4. Drag your chosen widget from your normal sidebar to the shortcodes sidebar. Save.
|
34 |
+
5. Now go to a page and enter a do_widget shortcode The shortcode any widget settings page has some helpful (hopefully) examples and links.
|
35 |
|
36 |
* [do_widget widgetname] eg: [do_widget calendar]
|
37 |
* [do_widget "widget name"]. eg: [do_widget "tag cloud"]
|
40 |
* [do_widget_area] (will use the "widgets in shortcodes" widget area / sidebar
|
41 |
* [do_widget_area sidebarname] or [do_widget_area widget_area=sidebarname] for another sidebar or widget area - eg: to maximise likelihood of getting your theme's widget css to apply.
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
**[do_widget ...] Parameters:**
|
44 |
|
45 |
* *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.
|
46 |
* id=*wordpress assigned id of widget*. Examples: id=meta-3, id=tag-cloud-9 etc
|
47 |
+
* 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.
|
48 |
+
* wrap=*htmltag* where *htmltag* is one of div,p,main,aside,section. This will override your themes first sidebar widget wrapping html.
|
49 |
+
* 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 caused by your theme.
|
50 |
+
* class=*yourclassname* By default the plugin will add a class of amr-widget to 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.
|
51 |
+
* sidebar="*sidebarname*" will default to widgets_for_shortcode sidebar. Only use if you want to re-use a widget already being used in another sidebar. THis is theme dependent and WILL break if you change themes. Safer to use the widget_id.
|
52 |
|
53 |
**[do_widget_area ...] Parameters:**
|
54 |
|
57 |
* widget_classes=none /* option to remove the widget class from the widget wrappinghtml
|
58 |
* 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.
|
59 |
|
60 |
+
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.
|
61 |
|
62 |
See the settings page for links to help your create the shortcodes in a page.
|
63 |
|
|
|
|
|
|
|
64 |
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.
|
65 |
|
66 |
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).
|
67 |
|
|
|
68 |
|
69 |
**If you liked this plugin, you might also like my other plugins:**
|
70 |
|
73 |
|
74 |
== Frequently Asked Questions ==
|
75 |
|
76 |
+
PLEASE get your widgets working in a sidebar BEFORE activating this plugin, and PLEASE read https://wordpress.org/plugins/amr-shortcode-any-widget/installation/ and the settings page before asking any questions.
|
77 |
|
78 |
**Widget help, the widget is doing this, when it should do that**
|
79 |
|
80 |
+
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.
|
|
|
|
|
81 |
|
82 |
**How to identify widget**
|
83 |
|
84 |
+
To identify your widget in the shortcode, use the NAME or the ID.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
+
The name is the generic NAME like "tag cloud".
|
|
|
87 |
|
88 |
+
The id is how wordpress identifies the instance of the widget. The id is visible at the bottom of the widget settings box.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
|
90 |
+
**Styling, your theme, css, overriding**
|
91 |
|
92 |
+
Yes anything could happen wrt the appearance.(There are tens 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.
|
93 |
|
94 |
+
It may work beautifully and have the content looking like it belongs with your theme.
|
95 |
|
96 |
+
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.
|
|
|
|
|
97 |
|
98 |
|
99 |
Examples:
|
104 |
|
105 |
* 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]
|
106 |
|
107 |
+
* Change the 'wrap' html and the title html with parameters wrap=div title=h3. See the settings page.
|
108 |
|
109 |
* Apply an existing class in your theme. Use [do_widget *widgetname* class=*yourclass*].
|
110 |
|
120 |
|
121 |
For example: An unwanted effect could be white text on a white background as in the twenty fourteen theme.
|
122 |
|
123 |
+
**If you have an undesired styling effect with the default settings:**
|
124 |
|
125 |
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.
|
126 |
|
150 |
If you only using widget, maybe inserting the whole sidebar or widgertarea would give an interesting effect. Sidebar background css may apply.
|
151 |
|
152 |
[do_widget_area]
|
|
|
153 |
|
154 |
|
155 |
|
156 |
== Changelog ==
|
157 |
|
158 |
+
= Version 3.1 =
|
159 |
+
* added code for the widget-id to appear in the widget settings window.
|
160 |
+
* removed lots of the 'debug' as it will hopefully no longer be needed.
|
161 |
+
* most error messages will now be returned in the shortcode, not echoed at top of page.
|
162 |
+
* the do_widget_debug lists less, but hopefully more usefully a list of the do_widget and do_widget_area options based on your sidebars and the widgets in them.
|
163 |
+
|
164 |
= Version 3 =
|
165 |
* added code to not output anything if in admin (eg: in edit/save mode) in case something has forced application of content filters when saving (and not all widget stuff is active, so errors are output.
|
166 |
* prefixed unprefixed function names to avoid conflicts
|
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. The widget id is now visible in the widget window
|
257 |
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.
|
258 |
7. Shortcode parameters to remove widget-classes in theme like the twenty-fourteen theme (avoid white text on white background)
|
259 |
8. Example of multiple rss widgets in twenty-fourteen theme
|