$setting = $args[ $setting ]; } } if ( empty( $this->wp_last_version ) ) { $this->wp_last_version = '1.6.14.2'; } if ( empty( $this->php_last_version ) ) { $this->php_last_version = '1.8.4.1'; } } /** * Check if all requirements are ok, if not, display a notice and the rollback. * * @since 1.9 * @access public * @author Grégory Viguier * * @return bool */ public function check() { if ( ! $this->php_passes() || ! $this->wp_passes() ) { add_action( 'admin_notices', array( $this, 'print_notice' ) ); add_action( 'admin_post_imagify_rollback', array( $this, 'rollback' ) ); return false; } return true; } /** * Check if the current PHP version is equal or superior to the required PHP version. * * @since 1.9 * @access private * @author Grégory Viguier * * @return bool */ private function php_passes() { return version_compare( PHP_VERSION, $this->php_version ) >= 0; } /** * Check if the current WordPress version is equal or superior to the required PHP version. * * @since 1.9 * @access private * @author Grégory Viguier * * @return bool */ private function wp_passes() { global $wp_version; return version_compare( $wp_version, $this->wp_version ) >= 0; } /** * Get the last version of the plugin that can run with the current WP and PHP versions. * * @since 1.9 * @access private * @author Grégory Viguier * * @return string */ private function get_last_version() { $last_version = ''; if ( ! $this->php_passes() ) { $last_version = $this->php_last_version; } if ( ! $this->wp_passes() ) { $last_version = ! $last_version || version_compare( $last_version, $this->wp_last_version ) > 0 ? $this->wp_last_version : $last_version; } return $last_version; } /** * Tell if the current user can rollback. * * @since 1.9 * @access private * @author Grégory Viguier * * @return bool */ private function current_user_can() { $describer = 'manage'; $capacity = $this->is_active_for_network() ? 'manage_network_options' : 'manage_options'; // This filter is documented in classes/Context/AbstractContext.php. $capacity = (string) apply_filters( 'imagify_capacity', $capacity, $describer, 'wp' ); $user_can = current_user_can( $capacity ); // This filter is documented in classes/Context/AbstractContext.php. $user_can = (bool) apply_filters( 'imagify_current_user_can', $user_can, $capacity, $describer, null, 'wp' ); return $user_can; } /** * Tell if Imagify is activated on the network. * * @since 1.9 * @access private * @author Grégory Viguier * * return bool True if Imagify is activated on the network. */ private function is_active_for_network() { if ( ! is_multisite() ) { return false; } if ( ! function_exists( 'is_plugin_active_for_network' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } return is_plugin_active_for_network( plugin_basename( $this->plugin_file ) ); } /** * Warn if PHP version is less than 5.4 and offers to rollback. * * @since 1.9 * @access public * @author Grégory Viguier */ public function print_notice() { if ( ! $this->current_user_can() ) { return; } imagify_load_translations(); $message = array(); $required = array(); $rollback_url = wp_nonce_url( admin_url( 'admin-post.php?action=imagify_rollback' ), 'imagify_rollback' ); if ( ! $this->php_passes() ) { /* translators: %1$s = Plugin name, %2$s = PHP version required. */ $message[] = sprintf( esc_html__( 'To use this %1$s version, please ask your web host how to upgrade your server to PHP %2$s or higher.', 'imagify' ), $this->plugin_name, $this->php_version ); $required[] = 'PHP ' . $this->php_version; } if ( ! $this->wp_passes() ) { /* translators: %1$s = Plugin name, %2$s = WordPress version required. */ $message[] = sprintf( esc_html__( 'To use this %1$s version, please upgrade WordPress to version %2$s or higher.', 'imagify' ), $this->plugin_name, $this->wp_version ); $required[] = 'WordPress ' . $this->wp_version; } $message = '
' . implode( '
', $message ) . "
' . sprintf( esc_html__( 'To function properly, %1$s %2$s requires at least %3$s.', 'imagify' ), '' . $this->plugin_name . '', $this->plugin_version, $required ) . "
\n" . $message; $message .= '' . esc_html__( 'If you are not able to upgrade, you can rollback to the previous version by using the button below.', 'imagify' ) . "
\n"; /* translators: %s = Previous plugin version. */ $message .= '' . sprintf( __( 'Re-install version %s', 'imagify' ), $this->get_last_version() ) . '
'; echo '