activation
5 months ago
assets-managment
5 months ago
components
5 months ago
entities
5 months ago
premium
5 months ago
updates
5 months ago
class-check-compatibility.php
5 months ago
class-factory-migrations.php
5 months ago
class-factory-notices.php
5 months ago
class-factory-options.php
3 months ago
class-factory-plugin-abstract.php
5 months ago
class-factory-plugin-base.php
5 months ago
class-factory-requests.php
5 months ago
class-factory-requirements.php
5 months ago
functions.php
5 months ago
index.php
5 months ago
class-check-compatibility.php
123 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Проверяет совместимость с плагинами, с версиями php, с версиями WordPress |
| 5 | * |
| 6 | * @version 1.0.0 |
| 7 | * @since 4.0.8 |
| 8 | */ |
| 9 | |
| 10 | if ( ! class_exists( 'Wbcr_Factory_Compatibility' ) ) { |
| 11 | class Wbcr_Factory_Compatibility { |
| 12 | |
| 13 | protected $plugin_prefix; |
| 14 | protected $plugin_class_prefix; |
| 15 | protected $plugin_name; |
| 16 | protected $plugin_title = '(no title)'; |
| 17 | protected $required_php_version = '5.3'; |
| 18 | protected $required_wp_version = '4.2.0'; |
| 19 | |
| 20 | function __construct( array $plugin_info ) { |
| 21 | foreach ( (array) $plugin_info as $property => $value ) { |
| 22 | $this->$property = $value; |
| 23 | } |
| 24 | |
| 25 | add_action( 'admin_init', [ $this, 'registerNotices' ] ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Метод проверяет совместимость плагина с php и WordPress версией |
| 30 | * |
| 31 | * @return bool |
| 32 | */ |
| 33 | public function check() { |
| 34 | if ( ! $this->isPhpCompatibility() ) { |
| 35 | return false; |
| 36 | } |
| 37 | |
| 38 | if ( ! $this->isWpCompatibility() ) { |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Метод проверяет совместимость плагина с php версией сервера |
| 47 | * |
| 48 | * @return mixed |
| 49 | */ |
| 50 | public function isPhpCompatibility() { |
| 51 | return version_compare( PHP_VERSION, $this->required_php_version, '>=' ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Метод проверяет совместимость плагина с WordPress версией сайта |
| 56 | * |
| 57 | * @return mixed |
| 58 | */ |
| 59 | public function isWpCompatibility() { |
| 60 | // Get the WP Version global. |
| 61 | global $wp_version; |
| 62 | |
| 63 | return version_compare( $wp_version, $this->required_wp_version, '>=' ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Метод возвращает текст уведомления |
| 68 | * |
| 69 | * @return string |
| 70 | */ |
| 71 | public function getNoticeText() { |
| 72 | $notice_text = $notice_default_text = ''; |
| 73 | $notice_default_text .= '<b>' . $this->plugin_title . ' ' . __( 'warning', 'robin-image-optimizer' ) . ':</b>' . '<br>'; |
| 74 | |
| 75 | // translators: %s is the plugin title |
| 76 | $notice_default_text .= sprintf( __( 'The %s plugin has stopped.', 'robin-image-optimizer' ), $this->plugin_title ) . ' '; |
| 77 | $notice_default_text .= __( 'Possible reasons:', 'robin-image-optimizer' ) . ' <br>'; |
| 78 | |
| 79 | $has_one = false; |
| 80 | |
| 81 | if ( ! $this->isPhpCompatibility() ) { |
| 82 | $has_one = true; |
| 83 | // translators: %s is the required php version |
| 84 | $notice_text .= '- ' . sprintf( __( 'You need to update the PHP version to %s or higher!', 'robin-image-optimizer' ), $this->required_php_version ) . '<br>'; |
| 85 | } |
| 86 | |
| 87 | if ( ! $this->isWpCompatibility() ) { |
| 88 | $has_one = true; |
| 89 | // translators: %s is the required WordPress version |
| 90 | $notice_text .= '- ' . sprintf( __( 'You need to update WordPress to %s or higher!', 'robin-image-optimizer' ), $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 | } |
| 123 |