Version Description
Download this release
Release Info
Developer | anmari |
Plugin | amr shortcode any widget |
Version | 3 |
Comparing to | |
See all releases |
Code changes from version 2.9 to 3
- amr-shortcode-any-widget.php +30 -27
- amr-utilities.php +5 -7
- readme.txt +7 -2
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" ] [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.
|
8 |
Author URI: http://webdesign.anmari.com
|
9 |
|
10 |
*/
|
@@ -24,7 +24,7 @@ function amr_remove_widget_class($params) { // remove the widget classes
|
|
24 |
return ($params);
|
25 |
}
|
26 |
/*-----------------------------------*/
|
27 |
-
function
|
28 |
|
29 |
global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
|
30 |
|
@@ -72,20 +72,16 @@ global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
|
|
72 |
return ($output);
|
73 |
}
|
74 |
/*-----------------------------------*/
|
75 |
-
function
|
76 |
|
77 |
global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
|
78 |
|
79 |
/* check if the widget is in the shortcode x sidebar if not , just use generic,
|
80 |
if it is in, then get the instance data and use that */
|
81 |
|
82 |
-
if (
|
83 |
-
|
84 |
-
|
85 |
-
else {
|
86 |
-
echo '<br />No widgets defined at all in any sidebar!';
|
87 |
-
return (false);
|
88 |
-
}
|
89 |
|
90 |
extract(shortcode_atts(array(
|
91 |
'sidebar' => 'Widgets for Shortcodes',
|
@@ -97,7 +93,13 @@ if it is in, then get the instance data and use that */
|
|
97 |
'widget_classes' => '' /* option to disassociate from themes widget styling */
|
98 |
), $atts));
|
99 |
|
100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
|
102 |
/* compatibility check - if the name is not entered, then the first parameter is the name */
|
103 |
if (empty($name) and !empty($atts[0]))
|
@@ -130,12 +132,12 @@ if it is in, then get the instance data and use that */
|
|
130 |
if (empty($id)) $id = '';
|
131 |
|
132 |
if (empty ($widget_ids)) {
|
133 |
-
echo '<br /><a href="" title="Error: Your Requested widget '.$widget.' '.$id.' is not in the widget list. Typo maybe?">!</a><br />';
|
134 |
-
amr_show_widget_debug('empty', $
|
135 |
return (false) ;
|
136 |
}
|
137 |
|
138 |
-
if (!($sidebarid =
|
139 |
$sidebarid=$sidebar; /* get the official sidebar id for this widget area - will take the first one */
|
140 |
|
141 |
if (empty($widget))
|
@@ -184,7 +186,7 @@ if it is in, then get the instance data and use that */
|
|
184 |
if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
|
185 |
|
186 |
echo '<br /><a href="" title="Error: Your requested Widget '.$widget.' is not in the '.$sidebar.' sidebar ">!</a><br />';
|
187 |
-
amr_show_widget_debug('empty', $
|
188 |
|
189 |
unset($sidebar);
|
190 |
unset($sidebarid);
|
@@ -195,7 +197,7 @@ if it is in, then get the instance data and use that */
|
|
195 |
$output = '';
|
196 |
foreach ($wid as $i=>$widget_instance) {
|
197 |
ob_start(); /* catch the echo output, so we can control where it appears in the text */
|
198 |
-
|
199 |
$output .= ob_get_clean();
|
200 |
}
|
201 |
}
|
@@ -203,12 +205,12 @@ if it is in, then get the instance data and use that */
|
|
203 |
return ($output);
|
204 |
}
|
205 |
/* -------------------------------------------------------------------------*/
|
206 |
-
function
|
207 |
global $wp_registered_sidebars, $wp_registered_widgets;
|
208 |
|
209 |
$debug = amr_check_if_widget_debug();
|
210 |
|
211 |
-
$sidebarid =
|
212 |
|
213 |
$sidebars_widgets = wp_get_sidebars_widgets();
|
214 |
|
@@ -218,7 +220,7 @@ function shortcode_sidebar( $widget_id, $name="widgets_for_shortcode", $title=tr
|
|
218 |
|
219 |
/* lifted from wordpress code, keep as similar as possible for now */
|
220 |
|
221 |
-
if ( !isset($wp_registered_widgets[$widget_id]) ) return; // wp had
|
222 |
|
223 |
$params = array_merge(
|
224 |
array(
|
@@ -346,8 +348,8 @@ add_action('widgets_init', 'amr_reg_sidebar',98); // register late so it app
|
|
346 |
//add_action('switch_theme', 'amr_save_shortcodes_sidebar');
|
347 |
//add_action('after_switch_theme','amr_restore_shortcodes_sidebar');
|
348 |
|
349 |
-
add_shortcode('do_widget', '
|
350 |
-
add_shortcode('do_widget_area', '
|
351 |
|
352 |
//require_once(ABSPATH . 'wp-includes/widgets.php'); // *** do we really need this here?
|
353 |
function amr_saw_load_text() {
|
@@ -357,14 +359,15 @@ function amr_saw_load_text() {
|
|
357 |
}
|
358 |
|
359 |
|
360 |
-
|
361 |
|
362 |
-
|
363 |
|
364 |
-
function
|
365 |
-
$mylinks =
|
366 |
-
'<a href="' . admin_url( 'options-general.php?page=amr_saw' ) . '">
|
367 |
-
|
|
|
368 |
return array_merge( $links, $mylinks );
|
369 |
}
|
370 |
|
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.10
|
8 |
Author URI: http://webdesign.anmari.com
|
9 |
|
10 |
*/
|
24 |
return ($params);
|
25 |
}
|
26 |
/*-----------------------------------*/
|
27 |
+
function amr_do_widget_area($atts) {
|
28 |
|
29 |
global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
|
30 |
|
72 |
return ($output);
|
73 |
}
|
74 |
/*-----------------------------------*/
|
75 |
+
function amr_do_widget($atts) {
|
76 |
|
77 |
global $wp_registered_widgets, $_wp_sidebars_widgets, $wp_registered_sidebars;
|
78 |
|
79 |
/* check if the widget is in the shortcode x sidebar if not , just use generic,
|
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',
|
93 |
'widget_classes' => '' /* option to disassociate from themes widget styling */
|
94 |
), $atts));
|
95 |
|
96 |
+
if (isset($_wp_sidebars_widgets) ) {
|
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 |
+
echo '<br />No widgets defined at all in any sidebar!';
|
101 |
+
return (false);
|
102 |
+
}
|
103 |
|
104 |
/* compatibility check - if the name is not entered, then the first parameter is the name */
|
105 |
if (empty($name) and !empty($atts[0]))
|
132 |
if (empty($id)) $id = '';
|
133 |
|
134 |
if (empty ($widget_ids)) {
|
135 |
+
echo '<br /><a href="" title="Error: Your Requested widget <'.$widget.' '.$id.'> is not in the widget list. Typo maybe?">!</a><br />';
|
136 |
+
amr_show_widget_debug('empty', $name, $id, $sidebar);
|
137 |
return (false) ;
|
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))
|
186 |
if (empty ($wid) or (!is_array($wid)) or (count($wid) < 1)) {
|
187 |
|
188 |
echo '<br /><a href="" title="Error: Your requested Widget '.$widget.' is not in the '.$sidebar.' sidebar ">!</a><br />';
|
189 |
+
amr_show_widget_debug('empty', $name, $id, $sidebar);
|
190 |
|
191 |
unset($sidebar);
|
192 |
unset($sidebarid);
|
197 |
$output = '';
|
198 |
foreach ($wid as $i=>$widget_instance) {
|
199 |
ob_start(); /* catch the echo output, so we can control where it appears in the text */
|
200 |
+
amr_shortcode_sidebar($widget_instance, $sidebar, $title, $class, $wrap, $widget_classes);
|
201 |
$output .= ob_get_clean();
|
202 |
}
|
203 |
}
|
205 |
return ($output);
|
206 |
}
|
207 |
/* -------------------------------------------------------------------------*/
|
208 |
+
function amr_shortcode_sidebar( $widget_id, $name="widgets_for_shortcode", $title=true, $class='', $wrap='', $widget_classes='') { /* This is basically the wordpress code, slightly modified */
|
209 |
global $wp_registered_sidebars, $wp_registered_widgets;
|
210 |
|
211 |
$debug = amr_check_if_widget_debug();
|
212 |
|
213 |
+
$sidebarid = amr_get_sidebar_id ($name);
|
214 |
|
215 |
$sidebars_widgets = wp_get_sidebars_widgets();
|
216 |
|
220 |
|
221 |
/* lifted from wordpress code, keep as similar as possible for now */
|
222 |
|
223 |
+
if ( !isset($wp_registered_widgets[$widget_id]) ) return; // wp had c o n t i n u e
|
224 |
|
225 |
$params = array_merge(
|
226 |
array(
|
348 |
//add_action('switch_theme', 'amr_save_shortcodes_sidebar');
|
349 |
//add_action('after_switch_theme','amr_restore_shortcodes_sidebar');
|
350 |
|
351 |
+
add_shortcode('do_widget', 'amr_do_widget');
|
352 |
+
add_shortcode('do_widget_area', 'amr_do_widget_area'); // just dump the whole widget area - to get same styling
|
353 |
|
354 |
//require_once(ABSPATH . 'wp-includes/widgets.php'); // *** do we really need this here?
|
355 |
function amr_saw_load_text() {
|
359 |
}
|
360 |
|
361 |
|
362 |
+
add_action('plugins_loaded' , 'amr_saw_load_text' );
|
363 |
|
364 |
+
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'amr_add_action_links' );
|
365 |
|
366 |
+
function amr_add_action_links ( $links ) {
|
367 |
+
$mylinks[] =
|
368 |
+
'<a title="Haven\'t read the instructions? Need your hand held?" href="' . admin_url( 'options-general.php?page=amr_saw' ) . '">Settings</a>';
|
369 |
+
$mylinks[] =
|
370 |
+
'<a title="Yes I know it is the same link, but some people ...." href="' . admin_url( 'options-general.php?page=amr_saw' ) . '">HELP</a>';
|
371 |
return array_merge( $links, $mylinks );
|
372 |
}
|
373 |
|
amr-utilities.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
/*-----------------------------------*/
|
3 |
-
function
|
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;
|
@@ -28,10 +28,10 @@ function amr_check_if_widget_debug() {
|
|
28 |
global $said;
|
29 |
// only do these debug if we are logged in and are the administrator
|
30 |
|
|
|
|
|
31 |
if ((!is_user_logged_in()) or (!current_user_can('administrator')))
|
32 |
return false;
|
33 |
-
|
34 |
-
|
35 |
|
36 |
if (isset($_REQUEST['do_widget_debug'])) {
|
37 |
if (empty($said)) {
|
@@ -39,8 +39,6 @@ global $said;
|
|
39 |
}
|
40 |
else return true;
|
41 |
|
42 |
-
|
43 |
-
|
44 |
$url_without_debug_query = esc_url(remove_query_arg( 'do_widget_debug'));
|
45 |
$eek = '<a href="'.$url_without_debug_query.'">Remove debug</a>';
|
46 |
echo '<br/>Note: Debugs only shown to a Logged in Administrator.'
|
@@ -52,7 +50,7 @@ global $said;
|
|
52 |
return false;
|
53 |
}
|
54 |
/*-----------------------------------*/
|
55 |
-
function amr_show_widget_debug($type='', $
|
56 |
global $wp_registered_sidebars, $wp_registered_widgets, $_wp_sidebars_widgets, $debugcount;
|
57 |
// only do these debug if we are logged in and are the administrator
|
58 |
|
@@ -64,7 +62,7 @@ global $wp_registered_sidebars, $wp_registered_widgets, $_wp_sidebars_widgets, $
|
|
64 |
|
65 |
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 />';
|
66 |
echo '<br /> You are admin: <a href="'.esc_url(add_query_arg('do_widget_debug','1')).'">Click here to try debug </a></b>'
|
67 |
-
.'(or
|
68 |
.'</p>';
|
69 |
|
70 |
if ($debug) {
|
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.
|
5 |
take the first one that matches */
|
6 |
global $wp_registered_sidebars;
|
28 |
global $said;
|
29 |
// only do these debug if we are logged in and are the administrator
|
30 |
|
31 |
+
if (is_admin()) return false; // if running in backend, then do not do debug. 20151217
|
32 |
+
|
33 |
if ((!is_user_logged_in()) or (!current_user_can('administrator')))
|
34 |
return false;
|
|
|
|
|
35 |
|
36 |
if (isset($_REQUEST['do_widget_debug'])) {
|
37 |
if (empty($said)) {
|
39 |
}
|
40 |
else return true;
|
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: Debugs only shown to a Logged in Administrator.'
|
50 |
return false;
|
51 |
}
|
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 |
|
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 |
if ($debug) {
|
readme.txt
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
=== amr shortcode any widget ===
|
2 |
Contributors: anmari
|
3 |
Tags: shortcode, widget, page, templates, page template, widget_area, sidebar
|
4 |
-
Tested up to: 4.
|
5 |
-
Version:
|
6 |
Stable tag: trunk
|
7 |
|
8 |
== Description ==
|
@@ -194,6 +194,11 @@ More info on background: http://wordpress.org/support/topic/your-theme-your-side
|
|
194 |
|
195 |
|
196 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
197 |
= Version 2.9 =
|
198 |
* in debug help, the link to the installation page help was not properly setup. Fixed.
|
199 |
|
1 |
=== amr shortcode any widget ===
|
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 ==
|
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
|
201 |
+
|
202 |
= Version 2.9 =
|
203 |
* in debug help, the link to the installation page help was not properly setup. Fixed.
|
204 |
|