Skip to content

Instantly share code, notes, and snippets.

@BrookeDot
Created December 22, 2017 02:00
Show Gist options
  • Save BrookeDot/a51978a14ebb27cbc583a2b6bba79c9a to your computer and use it in GitHub Desktop.
Save BrookeDot/a51978a14ebb27cbc583a2b6bba79c9a to your computer and use it in GitHub Desktop.
wp_die to admin_notice
Index: trunk/plugin.php
===================================================================
--- trunk/plugin.php (revision 1791008)
+++ trunk/plugin.php (working copy)
@@ -13,8 +13,9 @@
*/
register_activation_hook( __FILE__, 'genesis_tabs_activation_check' );
+
/**
- * This function runs on plugin activation. It checks to make sure the required
+ * This function runs on plugin activation and theme switch. It checks to make sure the required
* minimum Genesis version is installed. If not, it deactivates itself.
*
* @since 0.9.0
@@ -21,22 +22,38 @@
*/
function genesis_tabs_activation_check() {
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
+
$latest = '2.5.0';
$genesis = wp_get_theme( 'genesis' );
if ( 'genesis' != basename( TEMPLATEPATH ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) ); /** Deactivate ourself */
- wp_die( sprintf( __( 'Sorry, you can\'t activate unless you have installed <a href="%s">Genesis</a>', 'apl' ), 'http://www.studiopress.com/themes/genesis' ) );
+ return( sprintf( __( '<div class="%s"><p>Sorry, you can\'t activate unless you have installed <a href="%s">Genesis</a></p></div>', 'apl' ), 'notice notice-error', 'http://www.studiopress.com/themes/genesis' ) );
+
}
if ( version_compare( $genesis->get( 'Version' ), $latest, '<' ) ) {
deactivate_plugins( plugin_basename( __FILE__ ) ); /** Deactivate ourself */
- wp_die( sprintf( __( 'Sorry, you cannot activate without <a href="%s">Genesis %s</a> or greater', 'apl' ), 'http://www.studiopress.com/support/showthread.php?t=19576', $latest ) );
+ return ( sprintf( __( '<div class="%s"><p>Sorry, you cannot activate without <a href="%s">Genesis %s</a> or greater</p></div>', 'apl' ), 'notice notice-error', 'http://www.studiopress.com/support/showthread.php?t=19576', $latest ) );
}
}
+add_action( 'admin_notices', 'genesis_tabs_admin_notice__error' );
/**
+ * This function runs on plugin activation and theme switch. It checks to make sure the required
+ * minimum Genesis version is installed. If not, it shows an admin error.
+ *
+ * @since 0.9.5
+ */
+function genesis_tabs_admin_notice__error() {
+
+ echo( genesis_tabs_activation_check() );
+
+}
+
+/**
* Simple class to handle all the non-widget aspects of the plugin
*
* @package Genesis Tabs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment