| 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 |
$plugins[] = plugin_basename( dirname( dirname( __FILE__ ) ) . '/code-snippets.php' ); |
| 31 |
|
| 32 |
printf( |
| 33 |
'<div class="code-snippets-notice error fade" role="region" aria-label="%s"><p><strong>%s</strong>', |
| 34 |
esc_attr__( 'Code Snippets PHP version notice', 'code-snippets' ), |
| 35 |
// translators: %s: required PHP version number. |
| 36 |
esc_html( sprintf( __( 'Code Snippets requires PHP %s or later.', 'code-snippets' ), $required_php_version ) ) |
| 37 |
); |
| 38 |
|
| 39 |
$update_url = function_exists( 'wp_get_default_update_php_url' ) ? |
| 40 |
wp_get_default_update_php_url() : |
| 41 |
'https://wordpress.org/support/update-php/'; |
| 42 |
|
| 43 |
// translators: %s: Update PHP URL. |
| 44 |
$update_text = __( 'Please <a href="%s">upgrade your server to the latest version of PHP</a> to continue using Code Snippets.', 'code-snippets' ); |
| 45 |
|
| 46 |
echo '<br>', wp_kses( sprintf( $update_text, $update_url ), array( 'a' => array( 'href' => array() ) ) ); |
| 47 |
echo '</p></div>'; |
| 48 |
} |
| 49 |
|
| 50 |
if ( defined( 'CODE_SNIPPETS_FILE' ) ) { |
| 51 |
$plugins[] = 'code-snippets/code-snippets.php'; |
| 52 |
|
| 53 |
printf( |
| 54 |
'<div class="code-snippets-notice error fade" role="region" aria-label="%s"><p>%s</p></div>', |
| 55 |
esc_attr__( 'Code Snippets duplicate plugin notice', 'code-snippets' ), |
| 56 |
esc_html__( 'Another version of Code Snippets appears to be installed. Deactivating this version.', 'code-snippets' ) |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
if ( $plugins ) { |
| 61 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 62 |
deactivate_plugins( array_unique( $plugins ) ); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
add_action( 'admin_notices', 'code_snippets_deactivation_notice' ); |
| 67 |
|