major_untested_plugins ) ? array_diff_key( $this->minor_untested_plugins, $this->major_untested_plugins ) : $this->minor_untested_plugins; $version_parts = explode( '.', $this->new_version ); $new_version = $version_parts[0] . '.' . $version_parts[1]; if ( empty( $plugins ) ) { return; } /* translators: %s: version number */ $message = sprintf( __( "Heads up! The versions of the following plugins you're running haven't been tested with the latest version of WooCommerce (%s).", 'woocommerce' ), $new_version ); ob_start(); include 'views/html-notice-untested-extensions-inline.php'; return ob_get_clean(); } /** * Get the inline warning notice for major version updates. * * @return string */ protected function get_extensions_inline_warning_major() { $upgrade_type = 'major'; $plugins = $this->major_untested_plugins; $version_parts = explode( '.', $this->new_version ); $new_version = $version_parts[0] . '.0'; if ( empty( $plugins ) ) { return; } /* translators: %s: version number */ $message = sprintf( __( "Heads up! The versions of the following plugins you're running haven't been tested with WooCommerce %s. Please update them or confirm compatibility before updating WooCommerce, or you may experience issues:", 'woocommerce' ), $new_version ); ob_start(); include 'views/html-notice-untested-extensions-inline.php'; return ob_get_clean(); } /** * Get the warning notice for the modal window. * * @return string */ protected function get_extensions_modal_warning() { $version_parts = explode( '.', $this->new_version ); $new_version = $version_parts[0] . '.0'; $plugins = $this->major_untested_plugins; ob_start(); include 'views/html-notice-untested-extensions-modal.php'; return ob_get_clean(); } /* |-------------------------------------------------------------------------- | Data Helpers |-------------------------------------------------------------------------- | | Methods for getting & manipulating data. */ /** * Get active plugins that have a tested version lower than the input version. * * @param string $new_version * @param string $release 'major' or 'minor'. * @return array of plugin info arrays */ public function get_untested_plugins( $new_version, $release ) { $extensions = array_merge( $this->get_plugins_with_header( self::VERSION_TESTED_HEADER ), $this->get_plugins_for_woocommerce() ); $untested = array(); $new_version_parts = explode( '.', $new_version ); $version = $new_version_parts[0]; if ( 'minor' === $release ) { $version .= '.' . $new_version_parts[1]; } if ( 'major' === $release ) { $current_version_parts = explode( '.', WC_VERSION ); // If user has already moved to the major version, we don't need to flag up anything. if ( version_compare( $current_version_parts[0] . '.' . $current_version_parts[1], $new_version_parts[0] . '.0', '>=' ) ) { return array(); } } foreach ( $extensions as $file => $plugin ) { if ( ! empty( $plugin[ self::VERSION_TESTED_HEADER ] ) ) { $plugin_version_parts = explode( '.', $plugin[ self::VERSION_TESTED_HEADER ] ); if ( ! is_numeric( $plugin_version_parts[0] ) || ( 'minor' === $release && ! isset( $plugin_version_parts[1] ) ) || ( 'minor' === $release && ! is_numeric( $plugin_version_parts[1] ) ) ) { continue; } $plugin_version = $plugin_version_parts[0]; if ( 'minor' === $release ) { $plugin_version .= '.' . $plugin_version_parts[1]; } if ( version_compare( $plugin_version, $version, '<' ) ) { $untested[ $file ] = $plugin; } } else { $plugin[ self::VERSION_TESTED_HEADER ] = __( 'unknown', 'woocommerce' ); $untested[ $file ] = $plugin; } } return $untested; } /** * Get plugins that have a valid value for a specific header. * * @param string $header * @return array of plugin info arrays */ protected function get_plugins_with_header( $header ) { $plugins = get_plugins(); $matches = array(); foreach ( $plugins as $file => $plugin ) { if ( ! empty( $plugin[ $header ] ) ) { $matches[ $file ] = $plugin; } } return apply_filters( 'woocommerce_get_plugins_with_header', $matches, $header, $plugins ); } /** * Get plugins which "maybe" are for WooCommerce. * * @return array of plugin info arrays */ protected function get_plugins_for_woocommerce() { $plugins = get_plugins(); $matches = array(); foreach ( $plugins as $file => $plugin ) { if ( $plugin['Name'] !== 'WooCommerce' && ( stristr( $plugin['Name'], 'woocommerce' ) || stristr( $plugin['Description'], 'woocommerce' ) ) ) { $matches[ $file ] = $plugin; } } return apply_filters( 'woocommerce_get_plugins_for_woocommerce', $matches, $plugins ); } }