| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Проверяет совместимость с плагинами Webcraftic, с версиями php, с версиями Wordpress |
| 5 |
* |
| 6 |
* @author Alex Kovalev <alex.kovalevv@gmail.com>, repo: https://github.com/alexkovalevv |
| 7 |
* @author Webcraftic <wordpress.webraftic@gmail.com>, site: https://webcraftic.com |
| 8 |
* |
| 9 |
* @version 1.0.0 |
| 10 |
* @since 4.0.8 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! class_exists( 'Wbcr_Factory_Compatibility' ) ) { |
| 14 |
class Wbcr_Factory_Compatibility { |
| 15 |
|
| 16 |
protected $plugin_prefix; |
| 17 |
protected $plugin_class_prefix; |
| 18 |
protected $plugin_name; |
| 19 |
protected $plugin_title = "(no title)"; |
| 20 |
protected $required_php_version = '5.3'; |
| 21 |
protected $required_wp_version = '4.2.0'; |
| 22 |
|
| 23 |
function __construct( array $plugin_info ) { |
| 24 |
foreach ( (array) $plugin_info as $property => $value ) { |
| 25 |
$this->$property = $value; |
| 26 |
} |
| 27 |
|
| 28 |
add_action( 'admin_init', [ $this, 'registerNotices' ] ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Метод проверяет совместимость плагина с php и wordpress версией |
| 33 |
* |
| 34 |
* @return bool |
| 35 |
*/ |
| 36 |
public function check() { |
| 37 |
if ( ! $this->isPhpCompatibility() ) { |
| 38 |
return false; |
| 39 |
} |
| 40 |
|
| 41 |
if ( ! $this->isWpCompatibility() ) { |
| 42 |
return false; |
| 43 |
} |
| 44 |
|
| 45 |
return true; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Метод проверяет совместимость плагина с php версией сервера |
| 50 |
* |
| 51 |
* @return mixed |
| 52 |
*/ |
| 53 |
public function isPhpCompatibility() { |
| 54 |
return version_compare( PHP_VERSION, $this->required_php_version, '>=' ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Метод проверяет совместимость плагина с Wordpress версией сайта |
| 59 |
* |
| 60 |
* @return mixed |
| 61 |
*/ |
| 62 |
public function isWpCompatibility() { |
| 63 |
// Get the WP Version global. |
| 64 |
global $wp_version; |
| 65 |
|
| 66 |
return version_compare( $wp_version, $this->required_wp_version, '>=' ); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Метод возвращает текст уведомления |
| 71 |
* |
| 72 |
* @return string |
| 73 |
*/ |
| 74 |
public function getNoticeText() { |
| 75 |
$notice_text = $notice_default_text = ''; |
| 76 |
$notice_default_text .= '<b>' . $this->plugin_title . ' ' . __( 'warning', '' ) . ':</b>' . '<br>'; |
| 77 |
|
| 78 |
$notice_default_text .= sprintf( __( 'The %s plugin has stopped.', 'wbcr_factory_templates_134' ), $this->plugin_title ) . ' '; |
| 79 |
$notice_default_text .= __( 'Possible reasons:', '' ) . ' <br>'; |
| 80 |
|
| 81 |
$has_one = false; |
| 82 |
|
| 83 |
if ( ! $this->isPhpCompatibility() ) { |
| 84 |
$has_one = true; |
| 85 |
$notice_text .= '- ' . sprintf( __( 'You need to update the PHP version to %s or higher!', 'wbcr_factory_480' ), $this->required_php_version ) . '<br>'; |
| 86 |
} |
| 87 |
|
| 88 |
if ( ! $this->isWpCompatibility() ) { |
| 89 |
$has_one = true; |
| 90 |
$notice_text .= '- ' . sprintf( __( 'You need to update WordPress to %s or higher!', 'wbcr_factory_480' ), $this->required_wp_version ) . '<br>'; |
| 91 |
} |
| 92 |
|
| 93 |
if ( $has_one ) { |
| 94 |
$notice_text = $notice_default_text . $notice_text; |
| 95 |
} |
| 96 |
|
| 97 |
return $notice_text; |
| 98 |
} |
| 99 |
|
| 100 |
public function registerNotices() { |
| 101 |
if ( current_user_can( 'activate_plugins' ) && current_user_can( 'edit_plugins' ) && current_user_can( 'install_plugins' ) ) { |
| 102 |
if ( is_multisite() ) { |
| 103 |
add_action( 'network_admin_notices', [ $this, 'showNotice' ] ); |
| 104 |
} |
| 105 |
|
| 106 |
add_action( 'admin_notices', [ $this, 'showNotice' ] ); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
public function showNotice() { |
| 111 |
$notice_text = $this->getNoticeText(); |
| 112 |
|
| 113 |
if ( empty( $notice_text ) ) { |
| 114 |
return; |
| 115 |
} |
| 116 |
|
| 117 |
$notice_text = '<p>' . $this->getNoticeText() . '</p>'; |
| 118 |
|
| 119 |
echo '<div class="notice notice-error">' . esc_html(apply_filters( 'wbcr/factory/check_compatibility/notice_text', $notice_text, $this->plugin_name )) . '</div>'; |
| 120 |
} |
| 121 |
} |
| 122 |
} |