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 had added some content to contextual help section for plugin options page.

Now I'd like that page defaulted/toggled to contextual help section open on specific condition in my PHP code. My only issue is that I am not strong with JS and don't see clear approach to coding that (I know how to pass variable to JS through localize, but not what code will actually get it done).

I had found relevant JS functions in source, but not sure how to properly reuse them for my task.

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

You could also trigger/simulate the help button being clicked by binding to the ready event.

Pre jQuery 1.7

<script type="text/javascript">
jQuery(document).bind( 'ready', function() {
    jQuery('a#contextual-help-link').trigger('click');
});
</script>

jQuery 1.7+ (bind deprecated as of 1.7)

<script type="text/javascript">
jQuery(document).on( 'ready', function() {
    jQuery('a#contextual-help-link').trigger('click');
});
</script>

The difference here is that you'll see the help section slide down as the page finishes loading, as if a user had clicked the link.

Can't hurt to have another option though. :)

share|improve this answer
    
+1, also works finely. –  Rarst Mar 1 '11 at 14:01
    
You're welcome. :) –  t31os Mar 1 '11 at 14:10
add comment

Injecting this whereever you find suitable (or loading it as external js via wp_enqueue_script() should do it:

<script type="text/javascript">
    addLoadEvent(function() {
        jQuery(document).ready(function () {
            jQuery('#contextual-help-wrap').show().addClass('contextual-help-open');
            jQuery('#contextual-help-link').css({'backgroundPosition':'bottom right'});
            jQuery('#screen-options-link-wrap').css('visibility', 'hidden');
        });
    });
</script>
share|improve this answer
    
@Rarst: I hope i got you right in that the JS code to initially open the box is what you were asking for? –  wyrfel Mar 1 '11 at 12:58
    
yes, exactly that. :) Thanks. –  Rarst Mar 1 '11 at 13:17
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.