| 1 |
<?php |
| 2 |
/** |
| 3 |
* File loaded when the plugin cannot be activated. |
| 4 |
* |
| 5 |
* All code in this file should be compatible with PHP 5.2 or later. |
| 6 |
* |
| 7 |
* @package Code_Snippets |
| 8 |
* |
| 9 |
* @noinspection PhpNestedDirNameCallsCanBeReplacedWithLevelParameterInspection |
| 10 |
* |
| 11 |
* phpcs:disable Modernize.FunctionCalls.Dirname.FileConstant |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) || function_exists( 'code_snippets_deactivation_notice' ) ) { |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Deactivate the plugin and display a notice informing the user that this has happened. |
| 20 |
* |
| 21 |
* @return void |
| 22 |
* |
| 23 |
* @since 3.3.0 |
| 24 |
*/ |
| 25 |
function code_snippets_deactivation_notice() { |
| 26 |
$plugins = array(); |
| 27 |
$required_php_version = '7.4'; |
| 28 |
|
| 29 |
if ( version_compare( phpversion(), $required_php_version, '<' ) ) { |
| 30 |
echo '<div class="error fade"><p><strong>'; |
| 31 |
// translators: %s: required PHP version number. |
| 32 |
echo esc_html( sprintf( __( 'Code Snippets requires PHP %s or later.', 'code-snippets' ), $required_php_version ) ); |
| 33 |
echo '</strong><br>'; |
| 34 |
|
| 35 |
$update_url = function_exists( 'wp_get_default_update_php_url' ) ? |
| 36 |
wp_get_default_update_php_url() : |
| 37 |
'https://wordpress.org/support/update-php/'; |
| 38 |
|
| 39 |
// translators: %s: Update PHP URL. |
| 40 |
$text = __( 'Please <a href="%s">upgrade your server to the latest version of PHP</a> to continue using Code Snippets.', 'code-snippets' ); |
| 41 |
|
| 42 |
echo wp_kses( sprintf( $text, $update_url ), array( 'a' => array( 'href' => array() ) ) ); |
| 43 |
echo '</p></div>'; |
| 44 |
|
| 45 |
$plugins[] = plugin_basename( dirname( dirname( __FILE__ ) ) . '/code-snippets.php' ); |
| 46 |
} |
| 47 |
|
| 48 |
if ( defined( 'CODE_SNIPPETS_FILE' ) ) { |
| 49 |
echo '<div class="error fade"><p>'; |
| 50 |
esc_html_e( 'Another version of Code Snippets appears to be installed. Deactivating this version.', 'code-snippets' ); |
| 51 |
echo '</p></div>'; |
| 52 |
|
| 53 |
$plugins[] = 'code-snippets/code-snippets.php'; |
| 54 |
} |
| 55 |
|
| 56 |
if ( $plugins ) { |
| 57 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 58 |
deactivate_plugins( array_unique( $plugins ) ); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
add_action( 'admin_notices', 'code_snippets_deactivation_notice' ); |
| 63 |
|