0

I'm using the "inbox-status" plugin. I can use this to display unread emails.

<?php do_action( 'inbox_status_count', 'inbox-unread' ); ?>

I want to use this code in a conditional. Only the number of emails shown if more than one.

if ( 0 < did_action( 'inbox_status_count', 'inbox-unread' ) )
    echo "<span class='new badge'>";
    echo do_action( 'inbox_status_count', 'inbox-unread' );
    echo "</span>";

Why don't work?

1 Answer 1

1

Note that did_action only takes one input argument: the name of the action hook.

The scope of your if sentence is also unclear.

I don't think you want to use did_action at all here, it doesn't give you the number of emails.

You can try the following instead:

if ( $unread = do_shortcode( '[input-unread]' ) )
    printf( "<span class='new badge'>%s</span>", $unread );

or skip the expensive do_shortcode parsing by using the shortcode callback directly:

if( 
       class_exists( 'IS_Inbox_Status' ) 
    && $unread = IS_Inbox_Status::get_instance()->get_count( 'inbox-unread' )
)   
    printf( "<span class='new badge'>%s</span>", $unread );

Note that this is untested.

1
  • 1
    Thanks, both work. if ( $unread = do_shortcode("[inbox-unread]") )
    – seravifer9
    Oct 8, 2015 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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