PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.4.5
EmailKit – Email Customizer for WooCommerce & WP v1.4.5
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
emailkit / includes / Admin / Api / FetchData.php

FetchData.php in EmailKit – Email Customizer for WooCommerce & WP 1.4.5, at includes/Admin/Api/FetchData.php

89 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace EmailKit\Admin\Api;
4
5 defined('ABSPATH') || exit;
6
7 use WP_Query;
8
9 class FetchData
10 {
11
12 public $prefix = '';
13 public $param = '';
14 public $request = null;
15
16
17 public function __construct()
18 {
19 add_action('rest_api_init', function () {
20 register_rest_route('emailkit/v1', 'fetch-data', array(
21 'methods' => \WP_REST_Server::ALLMETHODS,
22 'callback' => [$this, 'action'],
23 'permission_callback' => '__return_true',
24 ));
25 });
26 }
27
28 public function action($request)
29 {
30
31 if (!wp_verify_nonce($request->get_header('X-WP-Nonce'), 'wp_rest')) {
32 return [
33 'status' => 'fail',
34 'message' => [ esc_html__( 'Nonce mismatch.', 'emailkit' ) ]
35 ];
36 }
37
38 if (!is_user_logged_in() || !current_user_can('publish_posts')) {
39 return [
40 'status' => 'fail',
41 'message' => [ esc_html__('Access denied.', 'emailkit') ]
42 ];
43 }
44
45 $args = array(
46 'id' => get_the_ID(),
47 'post_type' => 'emailkit',
48 'post_status' => 'publish',
49 'orderby' => 'date',
50 'order' => 'DESC',
51 'posts_per_page' => -1,
52
53 );
54
55
56 $loop = new \WP_Query($args);
57
58 $email_data = [];
59
60 while ($loop->have_posts()) : $loop->the_post();
61
62 $email_data[] = [
63 "id" => get_the_ID(),
64 "date" => get_the_date('Y-m-d H:i:s'),
65 "object" => get_post_meta(get_the_ID(), 'emailkit_template_content_object', true),
66 "html" => get_post_meta(get_the_ID(), 'emailkit_template_content_html', true),
67 'emailkit_template_type' => get_post_meta(get_the_ID(),'emailkit_template_status', true),
68 'emailkit_template_status' => get_post_meta(get_the_ID(),'emailkit_template_status', true),
69 "subject" => get_post_meta(get_the_ID(), 'emailkit_email_subject', true),
70 "preheader" => get_post_meta(get_the_ID(), 'emailkit_email_preheader', true),
71 'emailkit_template_initial_content_object' => get_post_meta(get_the_ID(),'emailkit_template_initial_content_object', true),
72
73 ];
74
75 endwhile;
76
77 wp_reset_postdata();
78
79 return [
80 "status" => "success",
81 "data" => [
82 "history" => $email_data,
83 ],
84 "message" => [
85 esc_html__( "Email list has been fetched successfully.", 'emailkit' ),
86 ],
87 ];
88 }
89 }