false, 'need_plugin' => $dependency ]; wp_send_json_success($need_plugin); exit; } $template_name = []; // Set data for dropdown foreach(self::get_type_wise_mails($email_type) as $key => $value) { if($email_type == 'saved-templates'){ $template_name[] = ["id" => $value['id'], "text" => '('.$value['template_type'].') '.$value['title']]; }else{ $template_name[] = ["id" => $key, "text" => $value]; } } $templates = []; foreach(TemplateList::get_templates() as $template): if(isset($template['mail_type']) && $email_type == $template['mail_type']) { ob_start(); include EMAILKIT_DIR.'includes/views/modal-form-template-item.php'; $templates[] = ob_get_clean(); } endforeach; $data = ['templates' => $templates, 'template_name' => $template_name]; wp_send_json_success($data); } static function get_type_wise_mails($type) { $type_list = [ 'woocommerce' => \EmailKit\Admin\Emails\EmailLists::woocommerce_email(), 'wordpress' => \EmailKit\Admin\Emails\EmailLists::wordpress_email(), 'saved-templates' => \EmailKit\Admin\Emails\EmailLists::save_templates(), ]; return $type_list[$type] ?? []; } function get_template_data() { // verify request if(empty($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'emailkit_nonce')) { return false; } $ID = isset($_POST['ID']) ? sanitize_text_field(wp_unslash($_POST['ID'])) : null; if($ID) { wp_send_json_success(get_the_title($ID), 200); } wp_send_json_error(esc_html__('Failed to get template', 'emailkit'), 400); exit; } function emailkit_filter_save_as_template() { // verify request if(empty($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'emailkit_nonce')) { return false; } $template_id = isset($_POST['template_id']) ? sanitize_text_field(wp_unslash($_POST['template_id'])) : null; $saved_template_type = isset($_POST['email_type']) ? sanitize_text_field(wp_unslash($_POST['email_type'])) : null; $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); $dependency = \EmailKit\Admin\Dependency::check($email_type); if(true !== $dependency){ $need_plugin = ['dependency_status' => false, 'need_plugin' => $dependency ]; wp_send_json_success($need_plugin); exit; } if(true == $dependency){ $need_plugin = ['dependency_status' => true, 'need_plugin' => $dependency ]; wp_send_json_success($need_plugin); exit; } } function update_template_data() { // verify request if(empty($_POST['nonce']) || !wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'emailkit_nonce')) { return false; } $ID = isset($_POST['id']) ? sanitize_text_field(wp_unslash($_POST['id'])) : null; $new_title = isset($_POST['title']) ? sanitize_text_field(wp_unslash($_POST['title'])) : ''; $data = []; $post_update = array( 'ID' => $ID, 'post_title' => $new_title ); $ID = wp_update_post($post_update); $data['templateId'] = $ID; $data['title'] = get_the_title($ID); if(isset($_POST['action_type']) && sanitize_text_field(wp_unslash($_POST['action_type'])) == 'loadbuilder') { $data['builder_url'] = admin_url("post.php?post={$ID}&action=emailkit-builder"); } if($ID) { wp_send_json_success($data, 200); } wp_send_json_error(esc_html__('Failed to get template', 'emailkit'), 400); exit; } }