3

I know by watching the akismet plugin source how to show a custom message on the plugins page, but I want my message to appear only once after my plugin is activated.

How could i do this?

2

The easiest way would be to check for an stub get_option something like

$run_once = get_option('run_once');

if (!$run_once){
    //show your custom message here
    // then update the option so this message won't show again
    update_option('run_once',true);
}

hope this helps

  • 1
    Thanks, that looks logical, should I use the hook "admin_notices" to "echo" my message or is there another better hook to do it? Because if I use register_activation_hook() it will show an error on activation. – user3007 Feb 8 '11 at 0:51
  • admin_notices is the correct hook to use – Wipqozn Aug 22 '11 at 19:49
  • You have an error in your code. get_option will return FALSE if the option does not exist, therefore isset will return true in your example. – Wipqozn Aug 22 '11 at 19:55
  • @Wipqozn: 100% agreed. – Bainternet Aug 23 '11 at 11:15
  • 3
    This is an option but it is a bit dirty IMO. Let's say you have the plugin activated for a year. Now this value is checked in the database for the whole year, but it was needed only once. That's a whole bunch of spilled db look-ups and checks for something so simple. – Saif Bechan Nov 30 '11 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy