Automattic\WooCommerce\Admin
PluginsHelper::should_show_notice
Determine whether a specific notice should be shown to the current user.
Метод класса: PluginsHelper{}
Хуков нет.
Возвращает
true|false. True if the notice should be shown, false otherwise.
Использование
$result = PluginsHelper::should_show_notice( $dismiss_notice_meta, $show_after_one_month );
- $dismiss_notice_meta(строка) (обязательный)
- User meta that includes the timestamp when a store notice was dismissed.
- $show_after_one_month(true|false)
- Show the notices dismissed earlier than one month.
По умолчанию: true
Код PluginsHelper::should_show_notice() PluginsHelper::should show notice WC 10.3.5
public static function should_show_notice( $dismiss_notice_meta, $show_after_one_month = true ) {
// Get the current user ID.
$user_id = get_current_user_id();
// Get the timestamp when the notice was dismissed.
$dismissed_timestamp = get_user_meta( $user_id, $dismiss_notice_meta, true );
if ( ! $show_after_one_month ) {
return empty( $dismissed_timestamp );
}
// If the notice was dismissed within the last month, do not show it.
if ( ! empty( $dismissed_timestamp ) && ( time() - $dismissed_timestamp ) < 30 * DAY_IN_SECONDS ) {
return false;
}
// If the notice was dismissed more than a month ago, delete the meta value and show the notice.
if ( ! empty( $dismissed_timestamp ) ) {
delete_user_meta( $user_id, $dismiss_notice_meta );
}
return true;
}