Month: December 2018

How to Show Admin Notice on Plugin Activation?

1. Add the code in the Notice Class like Below –

	/**
	 * Set transient only when the plugin is activated.
	 *
	 * @since 3.0.2
	 * @return void
	 */
	public static function add_the_transient() {
	    /* Create transient data */
	    set_transient( 'prefix-activation-notice', true, 5 );

	}
	/**
	 * Admin Notice on Activation.
	 *
	 * @since 3.0.2
	 * @return void
	 */
	public function add_activation_notice() {
		$itesm = get_posts( array( 'post_type' => 'my_post_type' ) );
		if ( count( $items ) > 0 ) {
			/* Check transient, if available display notice */
			if ( get_transient( 'prefix-activation-notice' ) ) {
				?>
				<div class="updated notice is-dismissible">
				<p>Thank you for using this plugin! <strong>You are awesome</strong>.</p>
				</div>
				<?php
				/* Delete transient, only display this notice once. */
				delete_transient( 'prefix-activation-notice' );
			}
		}
	}

Read More “How to Show Admin Notice on Plugin Activation?”