Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/StoreApi/Utilitie...
File: NoticeHandler.php
<?php
[0] Fix | Delete
namespace Automattic\WooCommerce\StoreApi\Utilities;
[1] Fix | Delete
[2] Fix | Delete
use Automattic\WooCommerce\StoreApi\Exceptions\RouteException;
[3] Fix | Delete
use WP_Error;
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* NoticeHandler class.
[7] Fix | Delete
* Helper class to handle notices.
[8] Fix | Delete
*/
[9] Fix | Delete
class NoticeHandler {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Convert queued error notices into an exception.
[13] Fix | Delete
*
[14] Fix | Delete
* For example, Payment methods may add error notices during validate_fields call to prevent checkout.
[15] Fix | Delete
* Since we're not rendering notices at all, we need to convert them to exceptions.
[16] Fix | Delete
*
[17] Fix | Delete
* This method will find the first error message and thrown an exception instead. Discards notices once complete.
[18] Fix | Delete
*
[19] Fix | Delete
* @throws RouteException If an error notice is detected, Exception is thrown.
[20] Fix | Delete
*
[21] Fix | Delete
* @param string $error_code Error code for the thrown exceptions.
[22] Fix | Delete
*/
[23] Fix | Delete
public static function convert_notices_to_exceptions( $error_code = 'unknown_server_error' ) {
[24] Fix | Delete
if ( 0 === wc_notice_count( 'error' ) ) {
[25] Fix | Delete
wc_clear_notices();
[26] Fix | Delete
return;
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
$error_notices = wc_get_notices( 'error' );
[30] Fix | Delete
[31] Fix | Delete
// Prevent notices from being output later on.
[32] Fix | Delete
wc_clear_notices();
[33] Fix | Delete
[34] Fix | Delete
foreach ( $error_notices as $error_notice ) {
[35] Fix | Delete
throw new RouteException( $error_code, wp_strip_all_tags( $error_notice['notice'] ), 400 );
[36] Fix | Delete
}
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* Collects queued error notices into a \WP_Error.
[41] Fix | Delete
*
[42] Fix | Delete
* For example, cart validation processes may add error notices to prevent checkout.
[43] Fix | Delete
* Since we're not rendering notices at all, we need to catch them and group them in a single WP_Error instance.
[44] Fix | Delete
*
[45] Fix | Delete
* This method will discard notices once complete.
[46] Fix | Delete
*
[47] Fix | Delete
* @param string $error_code Error code for the thrown exceptions.
[48] Fix | Delete
*
[49] Fix | Delete
* @return \WP_Error The WP_Error object containing all error notices.
[50] Fix | Delete
*/
[51] Fix | Delete
public static function convert_notices_to_wp_errors( $error_code = 'unknown_server_error' ) {
[52] Fix | Delete
$errors = new WP_Error();
[53] Fix | Delete
[54] Fix | Delete
if ( 0 === wc_notice_count( 'error' ) ) {
[55] Fix | Delete
return $errors;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
$error_notices = wc_get_notices( 'error' );
[59] Fix | Delete
[60] Fix | Delete
foreach ( $error_notices as $error_notice ) {
[61] Fix | Delete
$errors->add( $error_code, wp_strip_all_tags( $error_notice['notice'] ) );
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
return $errors;
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function