Add Admin notice for review of your plugin from users in WordPress

Add Admin notice for review of your plugin from users in WordPress | wp admin notice

 

It’s not good to show the review notice right after user activated the plugin , as to give a review user need to use the plugin for a while ! So we will  show the notice let’s say after 1 week, so first what we need to know when user started using the plugin so we will keep data when user first activated the plugin ! Let’s Do it.

// add plugin activation time

function void_activation_time(){
    $get_activation_time = strtotime("now");
    add_option('your_plugin_activation_time', $get_activation_time );  // replace your_plugin with Your plugin name
}
register_activation_hook( __FILE__, 'void_activation_time' );

What the above code does is whenever use activates the plugin it creates an option name your_plugin_activation_time  and set the value to current Unix timestamp.

to know more about strtotime() you can check this link and to know more about the register_activation_hook you can check this link.

To be assured that our code worked you can go to your wordpress dahsboard url/options.php (e.g: http://voidthemes.com/wp-admin/options.php )  and look for your_plugin_activation_time

Now that we are done setting activation time so lets show notice when it’s past 7 days after the plugin was activated.

//check if review notice should be shown or not

function void_check_installation_time() {   
    
        $install_date = get_option( 'your_plugin_activation_time' );
        $past_date = strtotime( '-7 days' );
     
        if ( $past_date >= $install_date ) {
     
            add_action( 'admin_notices', 'void_display_admin_notice' );
     
        }
 
}
add_action( 'admin_init', 'void_check_installation_time' );

the above code will run whenever user accesses dashboard but will only run review notice function which is void_display_admin_notice we will define below  only if  7 days passed after installation.

User won’t like if we should the review notice on every admin page ! so will show it only on index.php

/**
* Display Admin Notice, asking for a review
**/
function void_grid_display_admin_notice() {
    // WordPress global variable 
    global $pagenow;
    if( $pagenow == 'index.php' ){ 
       
        $plugin_info = get_plugin_data( __FILE__ , true, true );       
        $reviewurl = esc_url( 'https://wordpress.org/support/plugin/'. sanitize_title( $plugin_info['Name'] ) . '/reviews/' );
     
        printf(__('<div class="void-review wrap">You have been using <b> %s </b> for a while. We hope you liked it ! Please give us a quick rating, it works as a boost for us to keep working on the plugin !<div class="void-review-btn"><a href="%s" class="button button-primary" target=
            "_blank">Rate Now!</a></div></div>', $plugin_info['TextDomain']), $plugin_info['Name'], $reviewurl);
    }
}

You can know more about WordPress global variables here . To know more about get_plugin_data() click here

Though we managed to show review notice but we lack one thing which is we have to give user an option to remove the review notice so that it does not bug the user ever again. Let’s do that.

How we will achieve that is we will also add another link on review notice saying already done and whenever user clicks it we will not bug the user again but of course to do that we will need to pass value via URL to do that.

Below is the final void_grid_display_admin_notice  function

/**
* Display Admin Notice, asking for a review
**/
function void_display_admin_notice() {
    // wordpress global variable 
    global $pagenow;
    if( $pagenow == 'index.php' ){
 
        $dont_disturb = esc_url( get_admin_url() . '?spare_me=1' );
        $plugin_info = get_plugin_data( __FILE__ , true, true );       
        $reviewurl = esc_url( 'https://wordpress.org/support/plugin/'. sanitize_title( $plugin_info['Name'] ) . '/reviews/' );
     
        printf(__('<div class="void-review wrap">You have been using <b> %s </b> for a while. We hope you liked it ! Please give us a quick rating, it works as a boost for us to keep working on the plugin !<div class="void-review-btn"><a href="%s" class="button button-primary" target=
            "_blank">Rate Now!</a><a href="%s" class="void-grid-review-done"> Already Done !</a></div></div>', $plugin_info['TextDomain']), $plugin_info['Name'], $reviewurl, $dont_disturb );
    }
}

Notice is looking fine now but we have to get the value and set it as an option so that we don’t bug the user again , we can do that with the below code.

// remove the notice for the user if review already done or if the user does not want to
function void_spare_me(){    
    if( isset( $_GET['spare_me'] ) && !empty( $_GET['spare_me'] ) ){
        $spare_me = $_GET['spare_me'];
        if( $spare_me == 1 ){
            add_option( 'void_spare_me' , TRUE );
        }
    }
}
add_action( 'admin_init', 'void_spare_me', 5 );

To make the review notice look clean we might like to use CSS for that , so lets enqueue a stylesheet so that we can do that

//add admin css
function void_admin_css(){
     global $pagenow;
    if( $pagenow == 'index.php' ){
        wp_enqueue_style( 'void-admin', plugins_url( 'assets/css/void-admin.css', __FILE__ ) );
    }
}
add_action( 'admin_enqueue_scripts', 'void_admin_css' );

I was inspired to write this tutorial by seeing winwar’s article which  you can check out here .

Major Update in New WordPress 4.8

Major Update in New WordPress 4.8

What has Changed In WordPress 4.8 ?

Well WordPress members has been working on this platform day and night to make it better in each release for their customers! So if you are a WordPress user like me and you regularly login to your dashboard of WordPress you will get the update notification of the great 4.8 WordPress. When I saw the notification I wasn’t thinking much about the update. I thought like other updates it would have some improvements but not noticeable to end users ! But boy !! I was so wrong ! Right after update here is what I saw on my dashboard –


wp-update

So the latest update of wordpress you will notice immediately are :

  • Exciting Widget Updates
  • Link Boundaries
  • Nearby WordPress Events

In this update I have seen major changes in the widgets of WordPress ! Before a lot of things like inserting image, video we had to use plugins or maybe raw html ! But now it’s possible with builtin wp !!

Image Widget
Adding an image to a widget is now a simple task that is achievable for any WordPress user without needing to know code. Simply insert your image right within the widget settings. Try adding something like a headshot or a photo of your latest weekend adventure — and see it appear automatically.
Video Widget
A welcome video is a great way to humanize the branding of your website. You can now add any video from the Media Library to a sidebar on your site with the new Video widget. Use this to showcase a welcome video to introduce visitors to your site or promote your latest and greatest content.
Audio Widget
Are you a podcaster, musician, or avid blogger? Adding a widget with your audio file has never been easier. Upload your audio file to the Media Library, go to the widget settings, select your file, and you’re ready for listeners. This would be a easy way to add a more personal welcome message, too!
Rich Text Editor Widget

For Developers under the hood there are the new features wordpress offers :

More Accessible Admin Panel Headings

New CSS rules mean extraneous content (like “Add New” links) no longer need to be included in admin-area headings. These panel headings improve the experience for people using assistive technologies.

Some Video Support Removed

As fewer and fewer browsers support Silverlight, file formats which require the presence of the Silverlight plugin are being removed from core support. Files will still display as a download link, but will no longer be embedded automatically.

Multisite update

New capabilities have been introduced to 4.8 with an eye towards removing calls to is_super_admin().Multisite performance twerks has been seen

Text-Editor Anyhere !!

Before this update when you wanted for wordpress text editor to any widget you would have used some plugin to do so! Something like the : Black Studio TinyMCE Widget !! But with wp update & with the addition of TinyMCE to the text widget in 4.8 comes a new JavaScript API for instantiating the editor after page load. This can be used to add an editor instance to any text area, and customize it with buttons and functions. Great for plugin authors!

Media Api update

The introduction of a new base media widget REST API schema to 4.8 opens up possibilities for even more media widgets (like galleries or playlists) in the future. The three new media widgets are powered by a shared base class that covers most of the interactions with the media modal. That class also makes it easier to create new media widgets and paves the way for more to come.

Reuse your post/page

We understand that you don’t want to do the same thing over and over again ! Suppose you create a page/post and now you want to use it on sidebar or maybe footer or maybe you want to use it on another page/post , our themes comes with built in shortcode to do that ! But one prerequisite to do that is page must be built using Elementor page builder with our theme.

https://youtu.be/5Oqp7dc-nJ8