PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / trunk
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder vtrunk
2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 All 78 releases
ablocks / includes / ajax.php

ajax.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder trunk, at includes/ajax.php

74 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ABlocks;
4
5 use WP_Query;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 use ABlocks\Ajax\Settings;
12 use ABlocks\Ajax\Dashboard;
13 use ABlocks\Ajax\DemoImport;
14 use ABlocks\Ajax\DynamicContent;
15 use ABlocks\Ajax\FormBuilder;
16 use ABlocks\Ajax\Entry;
17 use ABlocks\Ajax\StripePaymentAjax;
18 use ABlocks\Ajax\EmailTemplate;
19 use ABlocks\Helper;
20
21 class Ajax {
22
23 public static function init() {
24 $self = new self();
25 $self->dispatch_hooks();
26 add_action( 'wp_ajax_ablocks/get_academy_terms', array( $self, 'get_academy_terms' ) );
27 add_action( 'wp_ajax_ablocks/get_storeengine_terms', array( $self, 'get_storeengine_terms' ) );
28 }
29 public function dispatch_hooks() {
30 ( new Dashboard() )->dispatch_actions();
31 ( new Settings() )->dispatch_actions();
32 ( new DynamicContent() )->dispatch_actions();
33 ( new FormBuilder() )->dispatch_actions();
34 ( new Entry() )->dispatch_actions();
35 ( new StripePaymentAjax() )->dispatch_actions();
36 ( new DemoImport() )->dispatch_actions();
37 ( new EmailTemplate() )->dispatch_actions();
38 }
39 public function get_academy_terms() {
40 check_ajax_referer( 'ablocks_nonce', 'security' );
41
42 if ( ! current_user_can( 'edit_posts' ) ) {
43 die();
44 }
45
46 $cats = Helper::get_terms_list( 'academy_courses_category' );
47 $tags = Helper::get_terms_list( 'academy_courses_tag' );
48
49 wp_send_json_success(array(
50 'categories' => $cats,
51 'tags' => $tags,
52 ), 200);
53 }
54
55 public function get_storeengine_terms() {
56 check_ajax_referer( 'ablocks_nonce', 'security' );
57
58 // The nonce alone only proves the request came from an aBlocks screen,
59 // not that this user may read the catalogue — and every logged-in user
60 // is handed that nonce. Matches get_academy_terms() above.
61 if ( ! current_user_can( 'edit_posts' ) ) {
62 die();
63 }
64
65 $cats = Helper::get_terms_list( 'storeengine_product_category' );
66 $tags = Helper::get_terms_list( 'storeengine_product_tag' );
67
68 wp_send_json_success(array(
69 'categories' => $cats,
70 'tags' => $tags,
71 ), 200);
72 }
73 }
74