Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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).

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

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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');
share|improve this answer
    
this is brilliant, worked like a charm! Thanks a lot!!! :) –  dashaluna Jun 2 '11 at 9:33
    
Oh the small hick up I've noticed is that the "Displayed on" doesn't appear when you specify the widget logic value in a widget instance and hit "Save". It does appear when you refresh the whole widgets page. I would really appreciate you help with it! Thanks :) –  dashaluna Jun 2 '11 at 10:02
    
OK i see what you mean, i've updated my answer and it should show the updated condition once you hit "save". since its a very hackish way of getting this and its all done on the client side then there could be an issue with the title displaying twice but it has an "auto refresh" which should take care of it. let me know. –  Bainternet Jun 2 '11 at 12:57
    
thanks a lot! It does take several seconds to update "Display on" after hitting the "Save" button. However, given that it works (and is very helpful) I don't mind about the refresh delay. Thanks for your help again :) –  dashaluna Jun 3 '11 at 9:10
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.