| @@ -1,70 +1,70 @@ | ||
| 1 | -<?php | |
| 2 | - | |
| 3 | - | |
| 4 | -namespace FL\Assistant\System\Util; | |
| 5 | - | |
| 6 | - | |
| 7 | -class PhpVersionCheck { | |
| 8 | - | |
| 9 | - public function check() { | |
| 10 | - if ( ! $this->is_minimum_php_version() ) { | |
| 11 | - $this->admin_notice_hooks(); | |
| 12 | - return; | |
| 13 | - } | |
| 14 | - } | |
| 15 | - | |
| 16 | - /** | |
| 17 | - * Initializes actions for the admin notice if the plugin can't load. | |
| 18 | - */ | |
| 19 | - protected function admin_notice_hooks() { | |
| 20 | - global $pagenow; | |
| 21 | - | |
| 22 | - if ( 'plugins.php' === $pagenow ) { | |
| 23 | - add_action( 'admin_notices', [ $this, 'admin_notice' ] ); | |
| 24 | - add_action( 'network_admin_notices', [ $this, 'admin_notice' ] ); | |
| 25 | - } | |
| 26 | - } | |
| 27 | - | |
| 28 | - /** | |
| 29 | - * Shows an admin notice if the plugin can't load. | |
| 30 | - */ | |
| 31 | - protected function admin_notice() { | |
| 32 | - if ( ! is_admin() ) { | |
| 33 | - return; | |
| 34 | - } elseif ( ! is_user_logged_in() ) { | |
| 35 | - return; | |
| 36 | - } elseif ( ! current_user_can( 'update_core' ) ) { | |
| 37 | - return; | |
| 38 | - } | |
| 39 | - | |
| 40 | - $message = $this->get_loading_error(); | |
| 41 | - | |
| 42 | - if ( $message ) { | |
| 43 | - echo '<div class="error">'; | |
| 44 | - echo '<p>' . sprintf( $message ) . '</p>'; | |
| 45 | - echo '</div>'; | |
| 46 | - } | |
| 47 | - } | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * @return bool | |
| 51 | - */ | |
| 52 | - protected function is_minimum_php_version() { | |
| 53 | - return ! version_compare( phpversion(), '5.6', '<' ); | |
| 54 | - } | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * Returns a plugin loading error if there is one. | |
| 58 | - */ | |
| 59 | - protected function get_loading_error() { | |
| 60 | - | |
| 61 | - $url = 'http://www.wpupdatephp.com/contact-host/'; | |
| 62 | - | |
| 63 | - /* translators: php upgrade url. */ | |
| 64 | - | |
| 65 | - return sprintf( | |
| 66 | - __( 'Assistant requires PHP 5.6 or above. Please <a href="%s">update your PHP version</a> before continuing.', 'assistant' ), | |
| 67 | - $url | |
| 68 | - ); | |
| 69 | - } | |
| 70 | -} | |
| 1 | +<?php | |
| 2 | + | |
| 3 | + | |
| 4 | +namespace FL\Assistant\System\Util; | |
| 5 | + | |
| 6 | + | |
| 7 | +class PhpVersionCheck { | |
| 8 | + | |
| 9 | + public function check() { | |
| 10 | + if ( ! $this->is_minimum_php_version() ) { | |
| 11 | + $this->admin_notice_hooks(); | |
| 12 | + return; | |
| 13 | + } | |
| 14 | + } | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * Initializes actions for the admin notice if the plugin can't load. | |
| 18 | + */ | |
| 19 | + protected function admin_notice_hooks() { | |
| 20 | + global $pagenow; | |
| 21 | + | |
| 22 | + if ( 'plugins.php' === $pagenow ) { | |
| 23 | + add_action( 'admin_notices', [ $this, 'admin_notice' ] ); | |
| 24 | + add_action( 'network_admin_notices', [ $this, 'admin_notice' ] ); | |
| 25 | + } | |
| 26 | + } | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * Shows an admin notice if the plugin can't load. | |
| 30 | + */ | |
| 31 | + protected function admin_notice() { | |
| 32 | + if ( ! is_admin() ) { | |
| 33 | + return; | |
| 34 | + } elseif ( ! is_user_logged_in() ) { | |
| 35 | + return; | |
| 36 | + } elseif ( ! current_user_can( 'update_core' ) ) { | |
| 37 | + return; | |
| 38 | + } | |
| 39 | + | |
| 40 | + $message = $this->get_loading_error(); | |
| 41 | + | |
| 42 | + if ( $message ) { | |
| 43 | + echo '<div class="error">'; | |
| 44 | + echo '<p>' . sprintf( $message ) . '</p>'; | |
| 45 | + echo '</div>'; | |
| 46 | + } | |
| 47 | + } | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * @return bool | |
| 51 | + */ | |
| 52 | + protected function is_minimum_php_version() { | |
| 53 | + return ! version_compare( phpversion(), '5.6', '<' ); | |
| 54 | + } | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * Returns a plugin loading error if there is one. | |
| 58 | + */ | |
| 59 | + protected function get_loading_error() { | |
| 60 | + | |
| 61 | + $url = 'http://www.wpupdatephp.com/contact-host/'; | |
| 62 | + | |
| 63 | + /* translators: php upgrade url. */ | |
| 64 | + | |
| 65 | + return sprintf( | |
| 66 | + __( 'Assistant requires PHP 5.6 or above. Please <a href="%s">update your PHP version</a> before continuing.', 'assistant' ), | |
| 67 | + $url | |
| 68 | + ); | |
| 69 | + } | |
| 70 | +} | |