golden hour
/home/godaofbq/dev.hyperredbed.com/wp-content/plugins/emailkit-pro/includes/Admin/Api
⬆️ Go Up
Upload
File/Folder
Size
Actions
CreateFromSavedTemplate.php
3.07 KB
Del
OK
DeleteSavedTemplate.php
1.46 KB
Del
OK
SaveAsTemplate.php
3.57 KB
Del
OK
Edit: CreateFromSavedTemplate.php
<?php namespace EmailKitPro\Admin\Api; use EmailKitPro; use WP_REST_Server; defined('ABSPATH') || exit; class CreateFromSavedTemplate { public function __construct() { add_action('rest_api_init', function () { register_rest_route('emailkit/v1', 'create-from-saved-template', 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.'] ]; } $template = ''; $html = ''; $body = $request->get_body(); $req = json_decode($body); if ($request->get_param('emailkit_email_type') == 'saved-templates') { // in this condition emailkit_template_type contains saved template id $template_id = $request->get_param('emailkit_template_type'); $email_template_id = get_post_meta($template_id, 'emailkit_template_id', true); $email_type = get_post_meta($email_template_id, 'emailkit_email_type', true); $template_type = get_post_meta($email_template_id, 'emailkit_template_type', true); $html = get_post_meta($template_id, 'emailkit_template_content_html', true); $template = get_post_meta($template_id, 'emailkit_template_content_object', true); $subject = !empty($request->get_param('emailkit_template_title')) ? trim($request->get_param('emailkit_template_title')) : ''; $data = array( 'post_type' => 'emailkit', 'post_status' => 'publish', 'post_author' => get_current_user_id(), 'post_title' => $subject !== '' ? $subject : "New Template " . uniqid(), 'meta_input' => array( 'emailkit_template_content_html' => $html, 'emailkit_template_content_object' => EmailKitPro\Admin\Helpers\Utils::escape_quotes( $template), 'emailkit_email_type' => $email_type, 'emailkit_template_type' => $template_type, 'emailkit_template_status' => 'inactive' ) ); $post_id = wp_insert_post($data); $message = __('Post created successfully.', 'emailkit-pro'); return [ "status" => "success", "data" => [ "templateId" => $post_id, 'builder_url' => (admin_url("post.php?post={$post_id}&action=emailkit-builder")), ], "message" => [ $message, ], ]; } } }
Save