WC_Plugins_Screen_Updates::parse_update_notice()
Parse update notice from readme file.
Method of the class: WC_Plugins_Screen_Updates{}
No Hooks.
Return
String
.
Usage
// private - for code of main (parent) class only $result = $this->parse_update_notice( $content, $new_version );
- $content(string) (required)
- WooCommerce readme file content.
- $new_version(string) (required)
- WooCommerce new version.
WC_Plugins_Screen_Updates::parse_update_notice() WC Plugins Screen Updates::parse update notice code WC 9.4.2
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. ); $notice_regexp = '~==\s*Upgrade Notice\s*==\s*=\s*(.*)\s*=(.*)(=\s*' . preg_quote( $new_version ) . '\s*=|$)~Uis'; $upgrade_notice = ''; foreach ( $check_for_notices as $check_version ) { if ( version_compare( Constants::get_constant( 'WC_VERSION' ), $check_version, '>' ) ) { continue; } $matches = null; if ( preg_match( $notice_regexp, $content, $matches ) ) { $notices = (array) preg_split( '~[\r\n]+~', trim( $matches[2] ) ); if ( version_compare( trim( $matches[1] ), $check_version, '=' ) ) { $upgrade_notice .= '<p class="wc_plugin_upgrade_notice">'; foreach ( $notices as $index => $line ) { $upgrade_notice .= preg_replace( '~\[([^\]]*)\]\(([^\)]*)\)~', '<a href="${2}">${1}</a>', $line ); } $upgrade_notice .= '</p>'; } break; } } return wp_kses_post( $upgrade_notice ); }