v1.0.0
This commit is contained in:
parent
3291a5f7d2
commit
212d64abfa
27 changed files with 8654 additions and 2 deletions
175
includes/class-dependency-checker.php
Normal file
175
includes/class-dependency-checker.php
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
/**
|
||||
* Dependency checker class
|
||||
*
|
||||
* @package TwoFactorExtended
|
||||
* @since 0.1.0
|
||||
*/
|
||||
|
||||
// Prevent direct access.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class Two_Factor_Extended_Dependency_Checker
|
||||
*
|
||||
* Checks plugin dependencies and displays admin notices when not met.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
class Two_Factor_Extended_Dependency_Checker {
|
||||
|
||||
/**
|
||||
* Minimum required WordPress version.
|
||||
*
|
||||
* @since 0.1.0
|
||||
* @var string
|
||||
*/
|
||||
const MIN_WP_VERSION = '6.7';
|
||||
|
||||
/**
|
||||
* Minimum required PHP version.
|
||||
*
|
||||
* @since 0.1.0
|
||||
* @var string
|
||||
*/
|
||||
const MIN_PHP_VERSION = '8.2';
|
||||
|
||||
/**
|
||||
* Check all dependencies.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*
|
||||
* @return bool True if all dependencies are met, false otherwise.
|
||||
*/
|
||||
public static function check_dependencies(): bool {
|
||||
$checks = array(
|
||||
self::check_two_factor_plugin(),
|
||||
self::check_wordpress_version(),
|
||||
self::check_php_version(),
|
||||
);
|
||||
|
||||
return ! in_array( false, $checks, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Two Factor plugin is active.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*
|
||||
* @return bool True if Two Factor plugin is active, false otherwise.
|
||||
*/
|
||||
public static function check_two_factor_plugin(): bool {
|
||||
return class_exists( 'Two_Factor_Core' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check WordPress version.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*
|
||||
* @return bool True if WordPress version is sufficient, false otherwise.
|
||||
*/
|
||||
public static function check_wordpress_version(): bool {
|
||||
global $wp_version;
|
||||
|
||||
return version_compare( $wp_version, self::MIN_WP_VERSION, '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check PHP version.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*
|
||||
* @return bool True if PHP version is sufficient, false otherwise.
|
||||
*/
|
||||
public static function check_php_version(): bool {
|
||||
return version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display admin notice for missing Two Factor plugin.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static function admin_notice_missing_two_factor(): void {
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<p>
|
||||
<strong><?php esc_html_e( 'Two Factor Extended', 'two-factor-extended' ); ?>:</strong>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: Two Factor plugin link */
|
||||
esc_html__( 'This plugin requires the %s plugin to be installed and activated.', 'two-factor-extended' ),
|
||||
'<a href="https://wordpress.org/plugins/two-factor/" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Two Factor', 'two-factor-extended' ) . '</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display admin notice for insufficient WordPress version.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static function admin_notice_wordpress_version(): void {
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<p>
|
||||
<strong><?php esc_html_e( 'Two Factor Extended', 'two-factor-extended' ); ?>:</strong>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: Minimum WordPress version */
|
||||
esc_html__( 'This plugin requires WordPress %s or higher.', 'two-factor-extended' ),
|
||||
esc_html( self::MIN_WP_VERSION )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display admin notice for insufficient PHP version.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static function admin_notice_php_version(): void {
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<p>
|
||||
<strong><?php esc_html_e( 'Two Factor Extended', 'two-factor-extended' ); ?>:</strong>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: Minimum PHP version */
|
||||
esc_html__( 'This plugin requires PHP %s or higher.', 'two-factor-extended' ),
|
||||
esc_html( self::MIN_PHP_VERSION )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Display all relevant admin notices.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
public static function display_admin_notices(): void {
|
||||
if ( ! self::check_two_factor_plugin() ) {
|
||||
self::admin_notice_missing_two_factor();
|
||||
}
|
||||
|
||||
if ( ! self::check_wordpress_version() ) {
|
||||
self::admin_notice_wordpress_version();
|
||||
}
|
||||
|
||||
if ( ! self::check_php_version() ) {
|
||||
self::admin_notice_php_version();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue