PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.2.0
EmailKit – Email Customizer for WooCommerce & WP v1.2.0
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.2.0, at includes/Admin/Api/FetchData.php

88 lines 2.3 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' => ['Nonce mismatch.']
35 ];
36 }
37
38 if (!is_user_logged_in() || !current_user_can('publish_posts')) {
39 return [
40 'status' => 'fail',
41 'message' => ['Access denied.']
42 ];
43 }
44
45 $args = array(
46
47 'post_type' => 'emailkit',
48 'author' => get_current_user_id(),
49 'post_status' => 'publish',
50 'orderby' => 'date',
51 'order' => 'DESC',
52 'posts_per_page' => -1,
53
54 );
55
56
57 $loop = new \WP_Query($args);
58
59 $email_data = [];
60
61 while ($loop->have_posts()) : $loop->the_post();
62
63 $email_data[] = [
64 "id" => get_the_ID(),
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 "date" => get_the_date('Y-m-d H:i:s'),
68 "user" => get_the_author(),
69 'emailkit_template_type' => get_post_meta(get_the_ID(),'emailkit_template_status', true),
70 'emailkit_template_status' => get_post_meta(get_the_ID(),'emailkit_template_status', true),
71
72 ];
73
74 endwhile;
75
76 wp_reset_postdata();
77
78 return [
79 "status" => "success",
80 "data" => [
81 "history" => $email_data,
82 ],
83 "message" => [
84 "Email list has been fetched successfully.",
85 ],
86 ];
87 }
88 }