PluginProbe
Additional Terms Lite for WooCommerce / 1.6.1
Additional Terms Lite for WooCommerce v1.6.1
1.7.3 1.7.2.1 trunk 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.6.3 All 35 releases
woo-additional-terms / src / Ajax / Ajax.php

Ajax.php in Additional Terms Lite for WooCommerce 1.6.1, at src/Ajax/Ajax.php

86 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Abstract AJAX class.
4 *
5 * @author MyPreview (Github: @mahdiyazdani, @gooklani, @mypreview)
6 *
7 * @since 1.6.0
8 *
9 * @package woo-additional-terms
10 */
11
12 namespace Woo_Additional_Terms\Ajax;
13
14 /**
15 * AJAX class.
16 */
17 abstract class Ajax {
18
19 /**
20 * The action name.
21 *
22 * @since 1.6.0
23 *
24 * @var string
25 */
26 private $action;
27
28 /**
29 * The nonce name.
30 *
31 * @since 1.6.0
32 *
33 * @var string
34 */
35 private $nonce;
36
37 /**
38 * Constructor.
39 *
40 * @since 1.6.0
41 *
42 * @param string $action The action name.
43 * @param string $nonce The nonce name. Default is empty.
44 *
45 * @return void
46 */
47 public function __construct( $action, $nonce = '' ) {
48
49 $this->action = sanitize_key( $action );
50 $this->nonce = ! empty( $nonce ) ? sanitize_key( $nonce ) : $this->action;
51 }
52
53 /**
54 * Register the AJAX action for the admin area.
55 *
56 * @since 1.6.0
57 *
58 * @return void
59 */
60 public function register_admin() {
61
62 add_action( "wp_ajax_woo_additional_terms_{$this->action}", array( $this, 'ajax_callback' ) );
63 }
64
65 /**
66 * Verify the AJAX nonce.
67 *
68 * @since 1.6.0
69 *
70 * @return void
71 */
72 protected function verify_nonce() {
73
74 check_ajax_referer( $this->nonce );
75 }
76
77 /**
78 * AJAX callback.
79 *
80 * @since 1.6.0
81 *
82 * @return void
83 */
84 abstract public function ajax_callback();
85 }
86