WooCommerce Code Reference

WC_Admin_Notices
in package

WC_Admin_Notices Class.

Table of Contents

$core_notices  : array<string|int, mixed>
Array of notices - name => callback.
$is_multisite  : bool
Stores a flag indicating if the code is running in a multisite setup.
$notices  : array<string|int, mixed>
Local notices cache.
add_custom_notice()  : void
Add a custom notice.
add_maxmind_missing_license_key_notice()  : void
Previously added a MaxMind missing license key notice.
add_min_version_notice()  : void
Add notice about minimum PHP and WordPress requirement.
add_notice()  : void
Show a notice.
add_notices()  : void
Add notices + styles if needed.
add_redirect_download_method_notice()  : void
Previously added a Redirect only download method notice.
base_tables_missing_notice()  : void
Previously displayed a missing database tables notice.
download_directories_sync_complete()  : void
Previously displayed the approved download directories sync completion notice.
get_notices()  : array<string|int, mixed>
Get the value of the locally cached notices array for the current site.
has_notice()  : bool
See if a notice is being shown.
hide_notices()  : void
Hide a notice if the GET variable is set.
init()  : void
Initializes the class.
install_notice()  : void
If we have just installed, show a message with the install pages button.
legacy_shipping_notice()  : void
Previously showed a notice asking users to convert to shipping zones.
maxmind_missing_license_key_notice()  : void
Previously displayed a MaxMind missing license key notice.
no_shipping_methods_notice()  : void
Previously showed a notice when no shipping methods were configured.
output_custom_notices()  : void
Output any stored custom notices.
prepare_note_with_nonce()  : object
Parses query to create nonces when available.
redirect_download_method_notice()  : void
Previously displayed a Redirect only download method notice.
regenerating_lookup_table_notice()  : void
Previously showed a notice while product lookup tables regenerated.
regenerating_thumbnails_notice()  : void
Previously showed a notice while thumbnails regenerated in the background.
remove_all_notices()  : void
Remove all notices from the locally cached notices array.
remove_notice()  : void
Remove a notice from being displayed.
remove_notices()  : void
Remove a given set of notices.
reset_admin_notices()  : void
Reset notices for themes when switched or a new version of WC is installed.
secure_connection_notice()  : void
Previously showed a notice about secure connections.
simplify_commerce_notice()  : void
Simplify Commerce is no longer in core.
store_notices()  : void
Store the locally cached notices to DB.
sync_on_read_disabled_notice()  : void
Previously displayed a notice about HPOS sync-on-read being disabled by default.
template_file_check_notice()  : void
Previously showed a notice highlighting bad template files.
theme_check_notice()  : void
Show the Theme Check notice.
update_notice()  : void
If we need to update the database, include a message with the DB update button.
uploads_directory_is_unprotected_notice()  : void
Previously displayed an uploads directory protection notice.
user_has_dismissed_notice()  : bool
Check if a given user has dismissed a given admin notice.
wp_php_min_requirements_notice()  : void
Notice about WordPress and PHP minimum requirements.
is_plugin_active()  : bool
Wrapper for is_plugin_active.
hide_notice()  : void
Hide a single notice.
set_notices()  : void
Set the locally cached notices array for the current site.

Properties

$core_notices

Array of notices - name => callback.

private static array<string|int, mixed> $core_notices = array('update' => 'update_notice', 'template_files' => 'template_file_check_notice', 'legacy_shipping' => 'legacy_shipping_notice', 'no_shipping_methods' => 'no_shipping_methods_notice', 'regenerating_thumbnails' => 'regenerating_thumbnails_notice', 'regenerating_lookup_table' => 'regenerating_lookup_table_notice', 'no_secure_connection' => 'secure_connection_notice', 'maxmind_license_key' => 'maxmind_missing_license_key_notice', 'redirect_download_method' => 'redirect_download_method_notice', 'uploads_directory_is_unprotected' => 'uploads_directory_is_unprotected_notice', 'base_tables_missing' => 'base_tables_missing_notice', 'download_directories_sync_complete' => 'download_directories_sync_complete', 'hpos_sync_on_read_disabled' => 'sync_on_read_disabled_notice')

$notices

Local notices cache.

private static array<string|int, mixed> $notices = array()

DON'T manipulate this field directly! Always use get_notices and set_notices instead.

Methods

add_custom_notice()

Add a custom notice.

public static add_custom_notice(string $name, string $notice_html) : void
Parameters
$name : string

Notice name.

$notice_html : string

Notice HTML.

Return values
void

add_maxmind_missing_license_key_notice()

Previously added a MaxMind missing license key notice.

public static add_maxmind_missing_license_key_notice() : void

MaxMind geolocation status is now shown in Site Health.

Tags
since
3.9.0
Return values
void

add_min_version_notice()

Add notice about minimum PHP and WordPress requirement.

public static add_min_version_notice() : void
Tags
deprecated
11.0.0

WordPress and PHP minimum requirements notices are no longer shown.

since
3.6.5
Return values
void

add_notice()

Show a notice.

public static add_notice(string $name[, bool $force_save = false ]) : void
Parameters
$name : string

Notice name.

$force_save : bool = false

Force saving inside this method instead of at the 'shutdown'.

Return values
void

add_redirect_download_method_notice()

Previously added a Redirect only download method notice.

public static add_redirect_download_method_notice() : void

Download method status is now shown in Site Health.

Return values
void

base_tables_missing_notice()

Previously displayed a missing database tables notice.

public static base_tables_missing_notice() : void

Database table status is now shown in Site Health.

Return values
void

download_directories_sync_complete()

Previously displayed the approved download directories sync completion notice.

public static download_directories_sync_complete() : void

Approved download directory sync status is now shown in Site Health. The notice ID remains stored until the merchant marks it reviewed in Site Health.

Return values
void

get_notices()

Get the value of the locally cached notices array for the current site.

public static get_notices() : array<string|int, mixed>
Return values
array<string|int, mixed>

install_notice()

If we have just installed, show a message with the install pages button.

public static install_notice() : void
Tags
deprecated
4.6.0
Return values
void

legacy_shipping_notice()

Previously showed a notice asking users to convert to shipping zones.

public static legacy_shipping_notice() : void

Legacy shipping status is now shown in Site Health.

Return values
void

maxmind_missing_license_key_notice()

Previously displayed a MaxMind missing license key notice.

public static maxmind_missing_license_key_notice() : void

MaxMind geolocation status is now shown in Site Health.

Tags
since
3.9.0
Return values
void

no_shipping_methods_notice()

Previously showed a notice when no shipping methods were configured.

public static no_shipping_methods_notice() : void

Shipping method status is now shown in Site Health.

Return values
void

prepare_note_with_nonce()

Parses query to create nonces when available.

public static prepare_note_with_nonce(object $response) : object
Parameters
$response : object

The WP_REST_Response we're working with.

Tags
deprecated
5.4.0
Return values
object$response The prepared WP_REST_Response object.

redirect_download_method_notice()

Previously displayed a Redirect only download method notice.

public static redirect_download_method_notice() : void

Download method status is now shown in Site Health.

Tags
since
4.0
Return values
void

regenerating_lookup_table_notice()

Previously showed a notice while product lookup tables regenerated.

public static regenerating_lookup_table_notice() : void

Product lookup table regeneration status is now shown beside the matching status tool.

Tags
since
3.6.0
Return values
void

regenerating_thumbnails_notice()

Previously showed a notice while thumbnails regenerated in the background.

public static regenerating_thumbnails_notice() : void

Thumbnail regeneration progress is now shown beside the matching status tool.

Return values
void

remove_notice()

Remove a notice from being displayed.

public static remove_notice(string $name[, bool $force_save = false ]) : void
Parameters
$name : string

Notice name.

$force_save : bool = false

Force saving inside this method instead of at the 'shutdown'.

Return values
void

remove_notices()

Remove a given set of notices.

public static remove_notices(array<string|int, mixed>|string $names_array_or_regex[, bool $force_save = false ]) : void

An array of notice names or a regular expression string can be passed, in the later case all the notices whose name matches the regular expression will be removed.

Parameters
$names_array_or_regex : array<string|int, mixed>|string

An array of notice names, or a string representing a regular expression.

$force_save : bool = false

Force saving inside this method instead of at the 'shutdown'.

Return values
void

reset_admin_notices()

Reset notices for themes when switched or a new version of WC is installed.

public static reset_admin_notices() : void
Return values
void

secure_connection_notice()

Previously showed a notice about secure connections.

public static secure_connection_notice() : void

Secure connection status is now shown in Site Health.

Return values
void

simplify_commerce_notice()

Simplify Commerce is no longer in core.

public static simplify_commerce_notice() : void
Tags
deprecated
3.6.0

No longer shown.

Return values
void

sync_on_read_disabled_notice()

Previously displayed a notice about HPOS sync-on-read being disabled by default.

public static sync_on_read_disabled_notice() : void

HPOS sync-on-read status is now shown in Site Health.

Tags
since
10.7.0
Return values
void

template_file_check_notice()

Previously showed a notice highlighting bad template files.

public static template_file_check_notice() : void

Template override status is now shown in Site Health.

Return values
void

update_notice()

If we need to update the database, include a message with the DB update button.

public static update_notice() : void
Return values
void

uploads_directory_is_unprotected_notice()

Previously displayed an uploads directory protection notice.

public static uploads_directory_is_unprotected_notice() : void

Uploads directory protection status is now shown in Site Health.

Tags
since
4.2.0
Return values
void

user_has_dismissed_notice()

Check if a given user has dismissed a given admin notice.

public static user_has_dismissed_notice(string $name[, int|null $user_id = null ]) : bool
Parameters
$name : string

The name of the admin notice to check.

$user_id : int|null = null

User id, or null for the current user.

Tags
since
8.5.0
Return values
boolTrue if the user has dismissed the notice.

wp_php_min_requirements_notice()

Notice about WordPress and PHP minimum requirements.

public static wp_php_min_requirements_notice() : void
Tags
deprecated
8.2.0

WordPress and PHP minimum requirements notices are no longer shown.

since
3.6.5
Return values
void

is_plugin_active()

Wrapper for is_plugin_active.

protected static is_plugin_active(string $plugin) : bool
Parameters
$plugin : string

Plugin to check.

Return values
bool

set_notices()

Set the locally cached notices array for the current site.

private static set_notices(array<string|int, mixed> $notices) : void
Parameters
$notices : array<string|int, mixed>

New value for the locally cached notices array.

Return values
void