$type, 'message' => $message, 'options' => is_array($options) ? $options : array(), ), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT ); if (!$payload) { return; } // Single-shot emitter: wait until BOTH (1) the EasyInvoiceToast API is // exposed by easy-invoice-toast.js AND (2) its container element has been // appended to
by its jQuery-ready init() — calling show() before // the container exists crashes on `toastContainer.append(...)`. // The `fired` latch guarantees we fire exactly once across the interval, // DOMContentLoaded, and load triggers. echo ""; } /** * Display a success toast notification * * @since 1.0.0 * @param string $message The message to display * @param array $options Additional options */ function easy_invoice_toast_success($message, $options = array()) { if (wp_doing_ajax()) { wp_send_json_success(array( 'toast' => array( 'type' => 'success', 'message' => $message, 'options' => $options ) )); } else { _easy_invoice_emit_toast_script('success', $message, $options); } } /** * Display an error toast notification * * @since 1.0.0 * @param string $message The message to display * @param array $options Additional options */ function easy_invoice_toast_error($message, $options = array()) { if (wp_doing_ajax()) { wp_send_json_error(array( 'toast' => array( 'type' => 'error', 'message' => $message, 'options' => $options ) )); } else { _easy_invoice_emit_toast_script('error', $message, $options); } } /** * Display a warning toast notification * * @since 1.0.0 * @param string $message The message to display * @param array $options Additional options */ function easy_invoice_toast_warning($message, $options = array()) { if (wp_doing_ajax()) { wp_send_json_error(array( 'toast' => array( 'type' => 'warning', 'message' => $message, 'options' => $options ) )); } else { _easy_invoice_emit_toast_script('warning', $message, $options); } } /** * Display an info toast notification * * @since 1.0.0 * @param string $message The message to display * @param array $options Additional options */ function easy_invoice_toast_info($message, $options = array()) { if (wp_doing_ajax()) { wp_send_json_success(array( 'toast' => array( 'type' => 'info', 'message' => $message, 'options' => $options ) )); } else { _easy_invoice_emit_toast_script('info', $message, $options); } }