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 a really simple problem here, and i'm sure that the solution is going to be really simple. Here is the code:

function the_fat_lady_sings() {
    echo 'this plugin is a far harder than i imagined';
}
add_action( 'publish_post','the_fat_lady_sings' );

I just want to echo that line, and it simply does not work. Please help, i have no idea what's wrong. If I use init instead of publish_post, it works.

share|improve this question
add comment

1 Answer

If you did this instead...

function the_fat_lady_sings() 
{
    wp_die("this plugin is a far harder than i imageined");
}
add_action('publish_post','the_fat_lady_sings')

I think you will see that it does work. The problem you are having with the echo is because WordPress processes the submission and then redirects back to form. You'll never see the echoed string. That submit/process/redirect pattern helps to avoid duplicate form submission. There is a name for the technique, which I can't remember. :)

PS: I am hoping somebody will tell me the name of that technique because it driving me a little crazy.

share|improve this answer
1  
en.wikipedia.org/wiki/Post/Redirect/Get this? –  RRikesh Jan 30 '13 at 9:31
    
That's it, @rrikesh ... thought it had a pronouncable name though. I guess not. –  s_ha_dum Jan 30 '13 at 14:19
    
I don't know, I came across this answer, it is called Post/Redirect/Get there too... –  RRikesh Jan 30 '13 at 17:04
1  
In German, we call this Affenformular (monkey form), because 1000 monkeys can submit it 1000 times without ever sending the same request twice. –  toscho Nov 14 '13 at 21:38
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.