PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.2.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.2.0
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / wizard / ajax / ajax-base.php

ajax-base.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.2.0, at wizard/ajax/ajax-base.php

97 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * CartFlows Ajax Base.
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 use CartflowsAdmin\Wizard\Ajax\AjaxErrors;
16
17 /**
18 * Class Admin_Menu.
19 */
20 abstract class AjaxBase {
21
22 /**
23 * Ajax action prefix.
24 *
25 * @var string
26 */
27 private $prefix = 'cartflows';
28
29 /**
30 * Erros class instance.
31 *
32 * @var object
33 */
34 public $errors = null;
35
36 /**
37 * Constructor
38 *
39 * @since 1.0.0
40 */
41 public function __construct() {
42
43 $this->errors = AjaxErrors::get_instance();
44 }
45
46 /**
47 * Register ajax events.
48 *
49 * @param array $ajax_events Ajax events.
50 */
51 public function init_ajax_events( $ajax_events ) {
52
53 if ( ! empty( $ajax_events ) ) {
54
55 foreach ( $ajax_events as $ajax_event ) {
56 add_action( 'wp_ajax_' . $this->prefix . '_' . $ajax_event, array( $this, $ajax_event ) );
57
58 $this->localize_ajax_action_nonce( $ajax_event );
59 }
60 }
61 }
62
63 /**
64 * Localize nonce for ajax call.
65 *
66 * @param string $action Action name.
67 * @return void
68 */
69 public function localize_ajax_action_nonce( $action ) {
70
71 if ( current_user_can( 'manage_options' ) ) {
72
73 add_filter(
74 'cartflows_admin_wizard_localized_vars',
75 function( $localize ) use ( $action ) {
76
77 $localize[ $action . '_nonce' ] = wp_create_nonce( $this->prefix . '_' . $action );
78 return $localize;
79 }
80 );
81
82 }
83 }
84
85
86 /**
87 * Get ajax error message.
88 *
89 * @param string $type Message type.
90 * @return string
91 */
92 public function get_error_msg( $type ) {
93
94 return $this->errors->get_error_msg( $type );
95 }
96 }
97