Welcome Guest! Login? Checkout

One of the best models I think out there for asking for reviews is to produce an unobtrusive popup after a certain amount of days of using your software. I’ve seen it done before (the best example I find is the one used in the What The File plugin), and can lead to a lot of reviews.

Popups, despite being universally hated by sections of the community, are annoyingly good at converting, as you capture the user’s attention. Whether that is worth the sacrifice of mildly irritating readers, I’m not sure, but what I like about What The File’s implementation is that it fits in with.

Here’s code on how you can build similar into your plugins. For this example, we’re using a generic base, so if you want to use this code in public, be sure to add your own prefixes.

1. Set an Option on Activation To Set The Date

The first job is to make sure we set the date correctly. By default, WordPress doesn’t have an “activation date” setting on it’s plugins, so we’re going to have to set it.

Luckily, there are hooks we can hook into. One we can use is the “register_activation_hook” that – upon activation of a plugin, runs whatever we need.

So the function we need to run gets the time of activation, and then adds it to the option page. This is very simple, two line function, which you can see here:-

Notice we use add_option, as adding an option doesn’t overwrite any option that is currently present, so a user can activate or deactivate the plugin without this value changing.

2. Display A Notification To Review After X Days

We don’t want to display the notice right away, as that can be seen as desperate for a review, and we’ll be taking before we give.

As a result, we’ll make something appear after 7 days, to do this we’ll use strtotime again to make sure that there has been 7 days since the plugin has elapsed. If so, we’ll add to the admin_notices our admin notice prompting the user to leave a review.

3. If Dismissed, Set An Option To Never Show Again

However, we’ll need to make sure we don’t annoy our plugin users. To do this, you need to allow the user to dismiss the notice, never to be shown again.

This is quite straightforward, you will notice we’ve started this previously by setting a “$nobugurl”. We will check for this URL and, if present, set an option which bypasses all we’ve done so far.

Notice we run this before the code is run in step 2 by setting the priority in add_action to 5. This is so that this check is made before the admin noticed is displayed. It prevents the user having to click the “Leave Me Alone” link twice.

That sets the option, but we’ll have to add a couple of new lines to the code created in Step 2 to run a check if this option is present. To do this, we’ll have to add the following lines to winwar_check_installation_date():-

That’s the basic installation, you will probably want to expand it if you use it on actual plugins (in particular step 2, you may want to check if the current user can install plugins), but that’s the basic code.

I’ve uploaded the code to Github, which runs the basic check outlined above. You can download it here.

Thoughts? Have you implemented it into your plugin? Any way to improve this? Please let me know in the comments!

Update: Ryan Hellyer has improved on this code significantly, and put it into a class. You can check out his class here.

 
 
 

Comments

Polite Disclaimer: I am welcome, open and willing for corrections to be shared in the comments (with corrections being added to posts and credited), and the comments field should be used to promote discussion and make this post better. I do not know everything and if anybody finds a better way to do something, then by all means please share it below.

However, I'm unable to offer support to posts. The reason being is that WordPress has tens of thousands of plugins and millions of themes. As such, finding out exactly why code doesn't work with your setup is a long process. If you wish for me to look at your code, please use the priority support area.

Comments asking support will be left on the site, but there is no guarantee of answer.

    Comments are closed.