Skip to content

Instantly share code, notes, and snippets.

@rhyswynne
Created October 28, 2014 11:04
Show Gist options
  • Save rhyswynne/9f8b72cb81d0e072c532 to your computer and use it in GitHub Desktop.
Save rhyswynne/9f8b72cb81d0e072c532 to your computer and use it in GitHub Desktop.
Code to Show a Wordpress Notice asking for a review after a week (blog post here - http://winwar.co.uk/2014/10/ask-wordpress-plugin-reviews-week/)
<?php
/*
Plugin Name: Activation Plugin Example
Plugin URI:
Description: Adds an Activation Hook & Displays a notice after 10 days.
Author: Winwar Media
Version: 0.1-alpha
Author URI: http://winwar.co.uk/
Text Domain:
Domain Path:
*/
/**
* Get the current time and set it as an option when the plugin is activated.
*
* @return null
*/
function winwar_set_activation_date() {
$now = strtotime( "now" );
add_option( 'myplugin_activation_date', $now );
}
register_activation_hook( __FILE__, 'winwar_set_activation_date' );
/**
* Check date on admin initiation and add to admin notice if it was over 10 days ago.
*
* @return null
*/
function winwar_check_installation_date() {
// Added Lines Start
$nobug = "";
$nobug = get_option('winwar_no_bug');
if (!$nobug) {
// Added Lines End
$install_date = get_option( 'myplugin_activation_date' );
$past_date = strtotime( '+7 days' );
if ( $past_date >= $install_date ) {
add_action( 'admin_notices', 'winwar_display_admin_notice' );
}
// Added Lines Start
}
// Added Lines End
}
add_action( 'admin_init', 'winwar_check_installation_date' );
/**
* Display Admin Notice, asking for a review
*
* @return null
*/
function winwar_display_admin_notice() {
// Review URL - Change to the URL of your plugin on WordPress.org
$reviewurl = 'http://wordpress.org/';
$nobugurl = get_admin_url() . '?winwarnobug=1';
echo '<div class="updated"><p>';
printf( __( "You have been using our plugin for a week now, do you like it? If so, please leave us a review with your feedback! <br /><br /> <a href='%s' target='_blank'>Leave A Review</a>/<a href='%s'>Leave Me Alone</a>" ), $reviewurl, $nobugurl );
echo "</p></div>";
}
/**
* Set the plugin to no longer bug users if user asks not to be.
*
* @return null
*/
function winwar_set_no_bug() {
$nobug = "";
if ( isset( $_GET['winwarnobug'] ) ) {
$nobug = esc_attr( $_GET['winwarnobug'] );
}
if ( 1 == $nobug ) {
add_option( 'winwar_no_bug', TRUE );
}
} add_action( 'admin_init', 'winwar_set_no_bug', 5 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment