Skip to content

Instantly share code, notes, and snippets.

@wpmu-authors
Last active February 3, 2021 17:40
Show Gist options
  • Save wpmu-authors/79a2c5414969291ec90cac11c38b7522 to your computer and use it in GitHub Desktop.
Save wpmu-authors/79a2c5414969291ec90cac11c38b7522 to your computer and use it in GitHub Desktop.
dependency-check.php
register_activation_hook( __FILE__, 'my_plugin_activation' );
function my_plugin_activation() {
global $wp_version;
$php = '5.3';
$wp = '3.8';
if ( version_compare( PHP_VERSION, $php, '<' ) ) {
deactivate_plugins( basename( __FILE__ ) );
wp_die(
'<p>' .
sprintf(
__( 'This plugin can not be activated because it requires a PHP version greater than %1$s. Your PHP version can be updated by your hosting company.', 'my_plugin' ),
$php
)
. '</p> <a href="' . admin_url( 'plugins.php' ) . '">' . __( 'go back', 'my_plugin' ) . '</a>'
);
}
if ( version_compare( $wp_version, $wp, '<' ) ) {
deactivate_plugins( basename( __FILE__ ) );
wp_die(
'<p>' .
sprintf(
__( 'This plugin can not be activated because it requires a WordPress version greater than %1$s. Please go to Dashboard &#9656; Updates to gran the latest version of WordPress .', 'my_plugin' ),
$php
)
. '</p> <a href="' . admin_url( 'plugins.php' ) . '">' . __( 'go back', 'my_plugin' ) . '</a>'
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment