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:&nbsp;<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 '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $w2 . ' <br />';
                    }
                }
                echo '<br />';
            }
            //else {echo ' '.$i;}
        }
        if (!$found) {
            echo '<h2>widgets_for_shortcodes sidebar empty or not defined.</h2>';
        }
    }
}
Example #2
0
function amr_show_widget_debug($type = '', $name, $id, $sidebar)
{
    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();
    $text = amr_show_shortcode_widget_possibilities();
    if ($type == 'empty') {
        if (current_user_can('administrator')) {
            $text = '<p>Problem with do_widget shortcode?  Try one of the following:</p>' . $text;
        }
    } elseif ($type == 'which one' and $debug) {
        $text = '<p>Debug help is on: Is your widget in the widgets_for_shortcodes sidebar?</p>' . $text;
    }
    return $text;
}
function shortcode_sidebar($widget_id, $name = "widgets_for_shortcode", $title = true, $class = '', $wrap = '', $widget_classes = '')
{
    /* This is basically the wordpress code, slightly modified  */
    global $wp_registered_sidebars, $wp_registered_widgets;
    $debug = amr_check_if_widget_debug();
    $sidebarid = get_sidebar_id($name);
    $sidebars_widgets = wp_get_sidebars_widgets();
    $sidebar = $wp_registered_sidebars[$sidebarid];
    // has the params etc
    $did_one = false;
    /* lifted from wordpress code, keep as similar as possible for now */
    if (!isset($wp_registered_widgets[$widget_id])) {
        continue;
    }
    $params = array_merge(array(array_merge($sidebar, array('widget_id' => $widget_id, 'widget_name' => $wp_registered_widgets[$widget_id]['name']))), (array) $wp_registered_widgets[$widget_id]['params']);
    $validtitletags = array('h1', 'h2', 'h3', 'h4', 'h5', 'header', 'strong', 'em');
    $validwraptags = array('div', 'p', 'main', 'aside', 'section');
    if (!empty($wrap)) {
        /* then folks want to 'wrap' with their own html tag, or wrap = yes  */
        if (!in_array($wrap, $validwraptags)) {
            $wrap = '';
        }
        /* To match a variety of themes, allow for a variety of html tags. */
        /* May not need if our sidebar match attempt has worked */
    }
    if (!empty($wrap)) {
        $params[0]['before_widget'] = '<' . $wrap . ' id="%1$s" class="%2$s">';
        $params[0]['after_widget'] = '</' . $wrap . '>';
    }
    // wp code to get classname
    $classname_ = '';
    //foreach ( (array) $wp_registered_widgets[$widget_id]['classname'] as $cn ) {
    $cn = $wp_registered_widgets[$widget_id]['classname'];
    if (is_string($cn)) {
        $classname_ .= '_' . $cn;
    } elseif (is_object($cn)) {
        $classname_ .= '_' . get_class($cn);
    }
    //}
    $classname_ = ltrim($classname_, '_');
    // add MKM and others requested class in to the wp classname string
    // if no class specfied, then class will = amrwidget.  These classes are so can reverse out unwanted widget styling.
    // $classname_ .= ' widget '; // wordpress seems to almost always adds the widget class
    $classname_ .= ' ' . $class;
    // we are picking up the defaults from the  thems sidebar ad they have registered heir sidebar to issue widget classes?
    // Substitute HTML id and class attributes into before_widget
    if (!empty($params[0]['before_widget'])) {
        $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $widget_id, $classname_);
    } else {
        $params[0]['before_widget'] = '';
    }
    if (empty($params[0]['before_widget'])) {
        $params[0]['after_widget'] = '';
    }
    $params = apply_filters('dynamic_sidebar_params', $params);
    // allow, any pne usingmust ensure they apply to the correct sidebars
    if (!empty($title)) {
        if ($title == 'false') {
            /* amr switch off the title html, still need to get rid of title separately */
            $params[0]['before_title'] = '<span style="display: none">';
            $params[0]['after_title'] = '</span>';
        } else {
            if (in_array($title, $validtitletags)) {
                $class = ' class="widget-title" ';
                $params[0]['before_title'] = '<' . $title . ' ' . $class . ' >';
                $params[0]['after_title'] = '</' . $title . '>';
            }
        }
    }
    if (!empty($widget_classes) and $widget_classes == 'none') {
        $params = amr_remove_widget_class($params);
        // also called in widget area shortcode
    }
    $callback = $wp_registered_widgets[$widget_id]['callback'];
    if (is_callable($callback)) {
        call_user_func_array($callback, $params);
        $did_one = true;
    }
    //	}
    return $did_one;
}
Example #4
0
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>&#91;do_widget id=' . $w2 . '&#93; </p>';
                    }
                }
                echo '</div>';
            }
            //else {echo ' '.$i;}
        }
        if (!$found) {
            echo '<h2>widgets_for_shortcodes sidebar empty or not defined.</h2>';
        }
    }
}