function amr_show_widget_debug($type = '', $atts = array()) { global $wp_registered_sidebars, $wp_registered_widgets, $_wp_sidebars_widgets; // only do these debug if we are logged in and are the administrator $debug = amr_check_if_widget_debug(); if ($type == 'empty') { if (current_user_can('administrator')) { echo '<br /> You are admin: <a href="' . esc_url(add_query_arg('do_widget_debug', '1')) . '">Try debug </a></b>' . 'See a exclamation point ! above ?. Hover over to see error message.' . '</p>'; } if ($debug) { echo '<p>As a last resort, we may dump the wp variables to do with sidebars and widgets. Maybe that will help you:</p>'; $sidebars_widgets = wp_get_sidebars_widgets(); echo '<h3> result of wp_get_sidebars_widgets():</h3>'; foreach ($sidebars_widgets as $i => $w) { echo '<br/>' . $i; var_dump($w); } echo '<h3>$_wp_sidebars_widgets:</h3>'; var_dump($_wp_sidebars_widgets); //echo '<br /><h3>$wp_registered_widgets:</h3>'; //var_dump($wp_registered_widgets); echo '<br /><h3>$wp_registered_sidebars:</h3>'; var_dump($wp_registered_sidebars); } } if ($type == 'which one' and $debug) { echo '<h3>DEBUG on: Is your widget in the widgets_for_shortcodes sidebar?</h3>'; //echo '<br />The shortcode attributes you entered are:<br />'; //var_dump($atts); echo '<br /><h2>widgets_for_shortcodes sidebar and widgets</h2>'; $found = false; foreach ($_wp_sidebars_widgets as $i => $w) { if ($i == "widgets_for_shortcodes") { echo 'Sidebar: <b>' . $i . ': ' . amr_get_sidebar_name($i) . '</b> has widgets with these ids: <br />'; $found = true; if (is_array($w)) { sort($w); foreach ($w as $i2 => $w2) { echo ' ' . $w2 . ' <br />'; } } echo '<br />'; } //else {echo ' '.$i;} } if (!$found) { echo '<h2>widgets_for_shortcodes sidebar empty or not defined.</h2>'; } } }
function amr_show_widget_debug($type = '', $atts = array()) { global $wp_registered_sidebars, $wp_registered_widgets, $_wp_sidebars_widgets, $debugcount; // only do these debug if we are logged in and are the administrator $debug = amr_check_if_widget_debug(); if ($type == 'empty') { if (!$debug and current_user_can('administrator')) { 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 />'; } echo '<br /> You are admin: <a href="' . esc_url(add_query_arg('do_widget_debug', '1')) . '">Click here to try debug </a></b>' . '(or eee a exclamation point ! above ?. Hover over to see error message.)' . '</p>'; if ($debug) { echo '<p>As a last resort, we will list all sidebars and their widgets, maybe that will help?</p>'; $sidebars_widgets = wp_get_sidebars_widgets(); ksort($sidebars_widgets); // push inactive down the bottom of the list foreach ($sidebars_widgets as $i => $w) { echo '<h3>do_widget sidebar=' . $i . ' ....</h3><table>'; echo '<tr><th>Widget name</th><th>Widget id</th>'; foreach ($w as $j => $id) { echo '<tr><td>'; if (isset($wp_registered_widgets[$id])) { echo $wp_registered_widgets[$id]['name']; } echo '</td><td> id=' . $id . '</td></tr>'; } echo '</table>'; //var_dump($w); } //echo '<h3>$_wp_sidebars_widgets:</h3>'; //var_dump($_wp_sidebars_widgets); //echo '<br /><h3>$wp_registered_widgets:</h3>'; //var_dump($wp_registered_widgets); //echo '<br /><h3>$wp_registered_sidebars:</h3>'; //var_dump($wp_registered_sidebars); } } if ($type == 'which one' and $debug) { echo 'DEBUG on: Is your widget in the widgets_for_shortcodes sidebar?<br />'; //echo '<br />The shortcode attributes you entered are:<br />'; //var_dump($atts); $found = false; foreach ($_wp_sidebars_widgets as $i => $w) { if ($i == "widgets_for_shortcodes" and !empty($w)) { echo 'To access the widgets in ' . $i . ': <b>' . amr_get_sidebar_name($i) . '</b> by id, use these shortcodes:'; echo '<div style="border: solid medium green; padding: 40px;" />'; $found = true; if (is_array($w)) { sort($w); foreach ($w as $i2 => $w2) { echo '<p>[do_widget id=' . $w2 . '] </p>'; } } echo '</div>'; } //else {echo ' '.$i;} } if (!$found) { echo '<h2>widgets_for_shortcodes sidebar empty or not defined.</h2>'; } } }