Notices
**Site relevance:** Antichrist.net
**Memory type:** plugin source memory
**Source path:** Antichrist.net/wp-content/plugins/uaix-locale-router/src/Admin/Notices.php
**Size:** 2.6 KB
Summary
namespace UAIXLocaleRouter\Admin;
Source Preview
This source file is short enough to preview directly on its source-memory page.
<?php
namespace UAIXLocaleRouter\Admin;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
final class Notices {
/**
* Save a flash notice for the next admin page load.
*
* @param string $message Notice message.
* @param string $type Notice type.
* @param array $data Extra payload.
* @return void
*/
public static function set_flash_notice( $message, $type = 'success', array $data = array() ) {
set_transient(
'uaixlr_admin_notice',
array(
'message' => (string) $message,
'type' => (string) $type,
'data' => $data,
),
60
);
}
/**
* Return and clear the next flash notice.
*
* @return array|null
*/
public static function consume_flash_notice() {
$notice = get_transient( 'uaixlr_admin_notice' );
if ( false === $notice ) {
return null;
}
delete_transient( 'uaixlr_admin_notice' );
return is_array( $notice ) ? $notice : null;
}
/**
* Persist a bootstrap or install notice for the plugins screen.
*
* @param string $message Notice message.
* @param string $type Notice type.
* @return void
*/
public static function store_bootstrap_notice( $message, $type = 'error' ) {
update_option(
'uaixlr_bootstrap_notice',
array(
'message' => (string) $message,
'type' => in_array( $type, array( 'success', 'warning', 'error', 'info' ), true ) ? $type : 'error',
)
);
}
/**
* Clear the stored bootstrap notice.
*
* @return void
*/
public static function clear_bootstrap_notice() {
delete_option( 'uaixlr_bootstrap_notice' );
delete_option( 'uaixlr_bootstrap_notice_raw' );
}
/**
* Render a bootstrap or install notice in wp-admin.
*
* @return void
*/
public static function render_bootstrap_notice() {
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
$notice = get_option( 'uaixlr_bootstrap_notice', array() );
if ( empty( $notice['message'] ) ) {
return;
}
$type = isset( $notice['type'] ) ? (string) $notice['type'] : 'error';
$type = in_array( $type, array( 'success', 'warning', 'error', 'info' ), true ) ? $type : 'error';
echo '<div class="notice notice-' . esc_attr( $type ) . '"><p>' . esc_html( $notice['message'] ) . '</p></div>';
}
/**
* Write a diagnostic line to the PHP error log when available.
*
* @param string $context Diagnostic context.
* @param string $message Diagnostic message.
* @return void
*/
public static function log_bootstrap_issue( $context, $message ) {
if ( function_exists( 'error_log' ) ) {
error_log( sprintf( '[UAIX Locale Router][%s] %s', (string) $context, (string) $message ) );
}
}
}