# emailkit/1.2.0/includes/Admin/Api/FetchData.php

EmailKit – Email Customizer for WooCommerce &amp; WP, version 1.2.0. 88 lines.

- Page: https://pluginprobe.com/plugins/emailkit/1.2.0/code/includes/Admin/Api/FetchData.php
- Raw: https://pluginprobe.com/plugins/emailkit/1.2.0/raw/includes/Admin/Api/FetchData.php
- Modified: 2023-11-28T13:24:06+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/emailkit/1.2.0/code/includes/Admin/Api/FetchData.php#L10-L20`.

```php
<?php 

namespace EmailKit\Admin\Api;

defined('ABSPATH') || exit;

use WP_Query;

class FetchData
{

    public $prefix = '';
    public $param = '';
    public $request = null;


    public function __construct()
    {
        add_action('rest_api_init', function () {
            register_rest_route('emailkit/v1', 'fetch-data', array(
                'methods'  => \WP_REST_Server::ALLMETHODS,
                'callback' => [$this, 'action'],
                'permission_callback' => '__return_true',
            ));
        });
    }

    public function action($request)
    {

        if (!wp_verify_nonce($request->get_header('X-WP-Nonce'), 'wp_rest')) {
            return [
                'status'    => 'fail',
                'message'   => ['Nonce mismatch.']
            ];
        }

        if (!is_user_logged_in() || !current_user_can('publish_posts')) {
            return [
                'status'    => 'fail',
                'message'   => ['Access denied.']
            ];
        }

        $args = array(

            'post_type' => 'emailkit',
            'author'    => get_current_user_id(),
            'post_status'    => 'publish',
            'orderby'    => 'date',
            'order'    => 'DESC',
            'posts_per_page' => -1,

        );


        $loop = new \WP_Query($args);

        $email_data = [];

        while ($loop->have_posts()) : $loop->the_post();

            $email_data[] = [
                "id"              => get_the_ID(),
                "object"          => get_post_meta(get_the_ID(), 'emailkit_template_content_object', true),
                "html"            => get_post_meta(get_the_ID(), 'emailkit_template_content_html', true),
                "date"            => get_the_date('Y-m-d H:i:s'),
                "user"            => get_the_author(),
                'emailkit_template_type' => get_post_meta(get_the_ID(),'emailkit_template_status', true),
                'emailkit_template_status' => get_post_meta(get_the_ID(),'emailkit_template_status', true),

            ];

        endwhile;

        wp_reset_postdata();

        return [
            "status"    => "success",
            "data"      => [
                "history" => $email_data,
            ],
            "message"   => [
                "Email list has been fetched successfully.",
            ],
        ];
    }
}
```
