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 am reposting. As my last questions wasn't famous.

My users are submitting custom post types (projects) from the frontend. How do I display notices (such as the one displayed on admin board) to the front end for when the user performs an action, example edit a post.

I know there are hooks for update/submit (post_updated_messages...) but those do not display anything on the frontend.

I tried putting the following but it doesn't work:

add_filter('post_updated','alert_user');

function alert_user()
{
add_action('display_message','prepare_text');
}

function prepare_text(){
return 'You did it!';
}

in my theme I have

do_action('display_message');

It doesn't work as prepare_text is never hooked to display_message!

Any help?

Thanks

share|improve this question
4  
Next time, improve the existing question. Do not just ask the same question again. –  toscho Jul 9 '13 at 21:19
    
I did. But my question didn't get any interactions. Now, you can see. I've got an answer! –  semyou Jul 10 '13 at 7:32

1 Answer 1

You could filter the_content:

add_action( 'post_updated', 'wpse105892_add_message', 10 );
function wpse105892_add_message() {
    add_filter( 'the_content', 'wpse105892_display_message' );
}

function wpse105892_display_message( $content ) {
    // remove the action once it's run
    remove_action( 'post_updated', 'wpse105892_add_message', 11 );

    $content = "<div class='your-message'>You did it!</div>\n\n" . $content;
    return $content;
}
share|improve this answer
    
I will try it and let you know! Thanks! Just curious, is there a reason why it would work on a core hook 'the_content' and not on my own hook. –  semyou Jul 10 '13 at 18:32
    
If you've added a hook of your own that displays in the front end, then sure, you can hook it to that instead. I didn't see anything in your question about creating your own hook (is it display_message?). –  Pat J Jul 10 '13 at 19:03
    
Yes. It is display_message! –  semyou Jul 11 '13 at 13:44
    
Can you update your question to show how/where your display_message hook is created, please? –  Pat J Jul 11 '13 at 14:07
    
Maybe this is my mistake. I use only add_action in the first function and then do_action (as seen above). Am I supposed to do anything else? –  semyou Jul 11 '13 at 20:53

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.