| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Display a success toast notification |
| 5 |
* |
| 6 |
* @since 1.0.0 |
| 7 |
* @param string $message The message to display |
| 8 |
* @param array $options Additional options |
| 9 |
*/ |
| 10 |
function easy_invoice_toast_success($message, $options = array()) { |
| 11 |
if (wp_doing_ajax()) { |
| 12 |
wp_send_json_success(array( |
| 13 |
'toast' => array( |
| 14 |
'type' => 'success', |
| 15 |
'message' => $message, |
| 16 |
'options' => $options |
| 17 |
) |
| 18 |
)); |
| 19 |
} else { |
| 20 |
echo "<script>if (typeof EasyInvoiceToast !== 'undefined') { EasyInvoiceToast.success('" . esc_js($message) . "', " . json_encode($options) . "); }</script>"; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Display an error toast notification |
| 26 |
* |
| 27 |
* @since 1.0.0 |
| 28 |
* @param string $message The message to display |
| 29 |
* @param array $options Additional options |
| 30 |
*/ |
| 31 |
function easy_invoice_toast_error($message, $options = array()) { |
| 32 |
if (wp_doing_ajax()) { |
| 33 |
wp_send_json_error(array( |
| 34 |
'toast' => array( |
| 35 |
'type' => 'error', |
| 36 |
'message' => $message, |
| 37 |
'options' => $options |
| 38 |
) |
| 39 |
)); |
| 40 |
} else { |
| 41 |
echo "<script>if (typeof EasyInvoiceToast !== 'undefined') { EasyInvoiceToast.error('" . esc_js($message) . "', " . json_encode($options) . "); }</script>"; |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Display a warning toast notification |
| 47 |
* |
| 48 |
* @since 1.0.0 |
| 49 |
* @param string $message The message to display |
| 50 |
* @param array $options Additional options |
| 51 |
*/ |
| 52 |
function easy_invoice_toast_warning($message, $options = array()) { |
| 53 |
if (wp_doing_ajax()) { |
| 54 |
wp_send_json_error(array( |
| 55 |
'toast' => array( |
| 56 |
'type' => 'warning', |
| 57 |
'message' => $message, |
| 58 |
'options' => $options |
| 59 |
) |
| 60 |
)); |
| 61 |
} else { |
| 62 |
echo "<script>if (typeof EasyInvoiceToast !== 'undefined') { EasyInvoiceToast.warning('" . esc_js($message) . "', " . json_encode($options) . "); }</script>"; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Display an info toast notification |
| 68 |
* |
| 69 |
* @since 1.0.0 |
| 70 |
* @param string $message The message to display |
| 71 |
* @param array $options Additional options |
| 72 |
*/ |
| 73 |
function easy_invoice_toast_info($message, $options = array()) { |
| 74 |
if (wp_doing_ajax()) { |
| 75 |
wp_send_json_success(array( |
| 76 |
'toast' => array( |
| 77 |
'type' => 'info', |
| 78 |
'message' => $message, |
| 79 |
'options' => $options |
| 80 |
) |
| 81 |
)); |
| 82 |
} else { |
| 83 |
echo "<script>if (typeof EasyInvoiceToast !== 'undefined') { EasyInvoiceToast.info('" . esc_js($message) . "', " . json_encode($options) . "); }</script>"; |
| 84 |
} |
| 85 |
} |