new_version = $response->new_version; $this->upgrade_notice = $this->get_upgrade_notice( $response->new_version ); $this->major_untested_plugins = $this->get_untested_plugins( $response->new_version, 'major' ); $this->minor_untested_plugins = $this->get_untested_plugins( $response->new_version, 'minor' ); $current_version_parts = explode( '.', WC_VERSION ); $new_version_parts = explode( '.', $this->new_version ); // If user has already moved to the major version, we should only shown minor notices and assume everything is "ok" for major. if ( version_compare( $current_version_parts[0] . $current_version_parts[1], $new_version_parts[0] . '0', '>' ) ) { $this->major_untested_plugins = array(); } if ( ! empty( $this->major_untested_plugins ) ) { $this->upgrade_notice .= $this->get_extensions_inline_warning_major(); } if ( ! empty( $this->minor_untested_plugins ) ) { $this->upgrade_notice .= $this->get_extensions_inline_warning_minor(); } if ( ! empty( $this->major_untested_plugins ) ) { $this->upgrade_notice .= $this->get_extensions_modal_warning(); add_action( 'admin_print_footer_scripts', array( $this, 'plugin_screen_modal_js' ) ); } echo apply_filters( 'woocommerce_in_plugin_update_message', $this->upgrade_notice ? '

' . wp_kses_post( $this->upgrade_notice ) . '

' : '' ); } /** * Get the upgrade notice from WordPress.org. * * @param string $version * @return string */ protected function get_upgrade_notice( $version ) { $transient_name = 'wc_upgrade_notice_' . $version; if ( false === ( $upgrade_notice = get_transient( $transient_name ) ) ) { $response = wp_safe_remote_get( 'https://plugins.svn.wordpress.org/woocommerce/trunk/readme.txt' ); if ( ! is_wp_error( $response ) && ! empty( $response['body'] ) ) { $upgrade_notice = $this->parse_update_notice( $response['body'], $version ); set_transient( $transient_name, $upgrade_notice, DAY_IN_SECONDS ); } } return $upgrade_notice; } /** * Parse update notice from readme file. * * @param string $content * @param string $new_version * @return string */ private function parse_update_notice( $content, $new_version ) { $version_parts = explode( '.', $new_version ); $check_for_notices = array( $version_parts[0] . '.0', // Major $version_parts[0] . '.0.0', // Major $version_parts[0] . '.' . $version_parts[1], // Minor $version_parts[0] . '.' . $version_parts[1] . '.' . $version_parts[2], // Patch ); foreach ( $check_for_notices as $check_version ) { if ( version_compare( WC_VERSION, $check_version, '>' ) ) { continue; } $matches = null; $regexp = '~==\s*Upgrade Notice\s*==\s*=\s*(.*)\s*=(.*)(=\s*' . preg_quote( $new_version ) . '\s*=|$)~Uis'; $upgrade_notice = ''; if ( preg_match( $regexp, $content, $matches ) ) { $notices = (array) preg_split( '~[\r\n]+~', trim( $matches[2] ) ); if ( version_compare( trim( $matches[1] ), $check_version, '=' ) ) { $upgrade_notice .= '

'; foreach ( $notices as $index => $line ) { $upgrade_notice .= preg_replace( '~\[([^\]]*)\]\(([^\)]*)\)~', '${1}', $line ); } $upgrade_notice .= '

'; } break; } } return wp_kses_post( $upgrade_notice ); } /** * JS for the modal window on the plugins screen. */ public function plugin_screen_modal_js() { ?> generic_modal_js(); } } new WC_Plugins_Screen_Updates();