| 1 |
<?php |
| 2 |
/** |
| 3 |
* CartFlows Ajax Errors. |
| 4 |
* |
| 5 |
* @package CartFlows |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace CartflowsAdmin\Wizard\Ajax; |
| 9 |
|
| 10 |
// Exit if accessed directly. |
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* Class AjaxErrors |
| 17 |
*/ |
| 18 |
class AjaxErrors { |
| 19 |
|
| 20 |
/** |
| 21 |
* Instance |
| 22 |
* |
| 23 |
* @access private |
| 24 |
* @var object Class object. |
| 25 |
* @since 1.0.0 |
| 26 |
*/ |
| 27 |
private static $instance; |
| 28 |
|
| 29 |
/** |
| 30 |
* Errors |
| 31 |
* |
| 32 |
* @access private |
| 33 |
* @var array Errors strings. |
| 34 |
* @since 1.0.0 |
| 35 |
*/ |
| 36 |
private static $errors = array(); |
| 37 |
|
| 38 |
/** |
| 39 |
* Initiator |
| 40 |
* |
| 41 |
* @since 1.0.0 |
| 42 |
* @return object initialized object of class. |
| 43 |
*/ |
| 44 |
public static function get_instance() { |
| 45 |
if ( ! isset( self::$instance ) ) { |
| 46 |
self::$instance = new self(); |
| 47 |
} |
| 48 |
return self::$instance; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Constructor |
| 53 |
* |
| 54 |
* @since 1.0.0 |
| 55 |
*/ |
| 56 |
public function __construct() { |
| 57 |
|
| 58 |
add_action( 'init', array( $this, 'prepare_ajax_errors' ) ); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Prepare Ajax Error Messages |
| 63 |
* |
| 64 |
* @return void |
| 65 |
*/ |
| 66 |
public function prepare_ajax_errors() { |
| 67 |
self::$errors = array( |
| 68 |
'permission' => __( 'Sorry, you are not allowed to do this operation.', 'cartflows' ), |
| 69 |
'nonce' => __( 'Nonce validation failed', 'cartflows' ), |
| 70 |
'default' => __( 'Sorry, something went wrong.', 'cartflows' ), |
| 71 |
); |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Get error message. |
| 76 |
* |
| 77 |
* @param string $type Message type. |
| 78 |
* @return string |
| 79 |
*/ |
| 80 |
public function get_error_msg( $type ) { |
| 81 |
|
| 82 |
if ( ! isset( self::$errors[ $type ] ) ) { |
| 83 |
$type = 'default'; |
| 84 |
} |
| 85 |
|
| 86 |
return self::$errors[ $type ]; |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
AjaxErrors::get_instance(); |
| 91 |
|