How to get “Widget Logic” plugin’s input value in a custom widget code (to display on the Widget admin page)

I’ve got the “Widget Logic” plugin installed. I have created my own widget called “Buzz”. I have a sidebar with multiple instances of my custom widget “Buzz”.

Now, on the Widgets admin page when a sidebar is toggled open and all of the widgets in that sidebar are closed up, you can see a widget name and widget instance title (if one is specified).

Read More

For example, if I have 2 instances of my “Buzz” widget with different titles, on the Widget admin page it looks something like:

Buzz: Title 1
Buzz: Title 2

What I would like to do is to display “Widget Logic” value specified for a widget instance under the “widget name: widget instance title” line on the Widget admin page. So, for example:

Buzz: Title 1
Displayed on: is_front_page()

Buzz: Title 2
Displayed on: is_page("page_slug")

Hope that makes sense.

Would really appreciate if any one could help me out with this: how to get the value specified in the “Widget Logic” input box and display it under the widget instance title on the Widget admin page.

Many thanks,
Dasha

Related posts

Leave a Reply

1 comment

  1. I’m almost sure there is no way to do that (server side) without hacking core files, bu luckly i know a little jQuery and i’ve come up with this hackish function that does the job just fine:

    enter image description here

    function widget_logic_hack(){ 
    global $pagenow;
    if ($pagenow == 'widgets.php'){
        ?>
        <script>
        function hack_logic(){
         jQuery('input[id$="widget_logic"]').each(function()
            {       
                    if (jQuery(this).val().length === 0){}else{
                        var id = this.id;
                        var value = jQuery(this).val();
                        //alert(value);
                        id = id.replace('-widget_logic','');
                        var currenttitle = jQuery("[id$='"+ id +"']").find('h4').html();
                        if (currenttitle.indexOf('Displayed on:') !=-1 ){
                            var ncurrenttitle = currenttitle.substring(0,(currenttitle.indexOf('Displayed on:')));
                            //alert(ncurrenttitle);
                             jQuery("[id$='"+ id +"']").find('h4').html(ncurrenttitle + 'Displayed on: <span class="in-widget-title">' + value + '</span>');
                        }else{
                            jQuery("[id$='"+ id +"']").find('h4').html(currenttitle + '<br /> Displayed on: <span class="in-widget-title">' + value + '</span>');
                        }
                    }
            });
        }
        jQuery(document).ready(function(){
            setTimeout("hack_logic()",500);
            jQuery('#savewidget').live('click', function() {
                 setTimeout("hack_logic()",5500);
                 return true;
            });
        });
        </script>
        <style>.widget .widget-top {height: 40px !important;}</style>
        <?php
    }
    
    }
    
    add_action('admin_footer','widget_logic_hack');