Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/woocomme.../src/Admin/Features
File: TransientNotices.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WooCommerce Transient Notices
[2] Fix | Delete
*/
[3] Fix | Delete
[4] Fix | Delete
namespace Automattic\WooCommerce\Admin\Features;
[5] Fix | Delete
[6] Fix | Delete
use Automattic\WooCommerce\Internal\Admin\Loader;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Shows print shipping label banner on edit order page.
[10] Fix | Delete
*/
[11] Fix | Delete
class TransientNotices {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Option name for the queue.
[15] Fix | Delete
*/
[16] Fix | Delete
const QUEUE_OPTION = 'woocommerce_admin_transient_notices_queue';
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Constructor
[20] Fix | Delete
*/
[21] Fix | Delete
public function __construct() {
[22] Fix | Delete
add_filter( 'woocommerce_admin_preload_options', array( $this, 'preload_options' ) );
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Get all notices in the queue.
[28] Fix | Delete
*
[29] Fix | Delete
* @return array
[30] Fix | Delete
*/
[31] Fix | Delete
public static function get_queue() {
[32] Fix | Delete
return get_option( self::QUEUE_OPTION, array() );
[33] Fix | Delete
}
[34] Fix | Delete
[35] Fix | Delete
/**
[36] Fix | Delete
* Get all notices in the queue by a given user ID.
[37] Fix | Delete
*
[38] Fix | Delete
* @param int $user_id User ID.
[39] Fix | Delete
* @return array
[40] Fix | Delete
*/
[41] Fix | Delete
public static function get_queue_by_user( $user_id ) {
[42] Fix | Delete
$notices = self::get_queue();
[43] Fix | Delete
[44] Fix | Delete
return array_filter(
[45] Fix | Delete
$notices,
[46] Fix | Delete
function( $notice ) use ( $user_id ) {
[47] Fix | Delete
return ! isset( $notice['user_id'] ) ||
[48] Fix | Delete
null === $notice['user_id'] ||
[49] Fix | Delete
$user_id === $notice['user_id'];
[50] Fix | Delete
}
[51] Fix | Delete
);
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Get a notice by ID.
[56] Fix | Delete
*
[57] Fix | Delete
* @param array $notice_id Notice of ID to get.
[58] Fix | Delete
* @return array|null
[59] Fix | Delete
*/
[60] Fix | Delete
public static function get( $notice_id ) {
[61] Fix | Delete
$queue = self::get_queue();
[62] Fix | Delete
[63] Fix | Delete
if ( isset( $queue[ $notice_id ] ) ) {
[64] Fix | Delete
return $queue[ $notice_id ];
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
return null;
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
/**
[71] Fix | Delete
* Add a notice to be shown.
[72] Fix | Delete
*
[73] Fix | Delete
* @param array $notice Notice.
[74] Fix | Delete
* $notice = array(
[75] Fix | Delete
* 'id' => (string) Unique ID for the notice. Required.
[76] Fix | Delete
* 'user_id' => (int|null) User ID to show the notice to.
[77] Fix | Delete
* 'status' => (string) info|error|success
[78] Fix | Delete
* 'content' => (string) Content to be shown for the notice. Required.
[79] Fix | Delete
* 'options' => (array) Array of options to be passed to the notice component.
[80] Fix | Delete
* See https://developer.wordpress.org/block-editor/reference-guides/data/data-core-notices/#createNotice for available options.
[81] Fix | Delete
* ).
[82] Fix | Delete
*/
[83] Fix | Delete
public static function add( $notice ) {
[84] Fix | Delete
$queue = self::get_queue();
[85] Fix | Delete
[86] Fix | Delete
$defaults = array(
[87] Fix | Delete
'user_id' => null,
[88] Fix | Delete
'status' => 'info',
[89] Fix | Delete
'options' => array(),
[90] Fix | Delete
);
[91] Fix | Delete
$notice_data = array_merge( $defaults, $notice );
[92] Fix | Delete
$notice_data['options'] = (object) $notice_data['options'];
[93] Fix | Delete
[94] Fix | Delete
$queue[ $notice['id'] ] = $notice_data;
[95] Fix | Delete
update_option( self::QUEUE_OPTION, $queue );
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Remove a notice by ID.
[100] Fix | Delete
*
[101] Fix | Delete
* @param array $notice_id Notice of ID to remove.
[102] Fix | Delete
*/
[103] Fix | Delete
public static function remove( $notice_id ) {
[104] Fix | Delete
$queue = self::get_queue();
[105] Fix | Delete
unset( $queue[ $notice_id ] );
[106] Fix | Delete
update_option( self::QUEUE_OPTION, $queue );
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
/**
[110] Fix | Delete
* Preload options to prime state of the application.
[111] Fix | Delete
*
[112] Fix | Delete
* @param array $options Array of options to preload.
[113] Fix | Delete
* @return array
[114] Fix | Delete
*/
[115] Fix | Delete
public function preload_options( $options ) {
[116] Fix | Delete
$options[] = self::QUEUE_OPTION;
[117] Fix | Delete
[118] Fix | Delete
return $options;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function