template_types)) { $this->template_types = [ "New Order" => __('New Order - WC', 'emailkit'), "Cancelled order" => __('Cancelled order - WC', 'emailkit'), "Failed Order" => __('Failed Order - WC', 'emailkit'), "Order On Hold" => __('Order On Hold - WC', 'emailkit'), "Processing Order" => __('Processing Order - WC', 'emailkit'), "Completed Order" => __('Completed Order - WC', 'emailkit'), "Refunded Order" => __('Refunded Order - WC', 'emailkit'), "Customer Invoice" => __('Customer Invoice - WC', 'emailkit'), "Customer Note" => __('Customer Note - WC', 'emailkit'), "Reset Password" => __('Reset Password - WC', 'emailkit'), "New Account" => __('New Account - WC', 'emailkit'), ]; } return $this->template_types; } public function add() { add_meta_box("metaBox_id", __('Email Details', 'emailkit'), [$this, 'emailTemplate'], ["emailkit"], "advanced", "high", null); } /** * MetaBox Template */ public function emailTemplate($object) { wp_nonce_field(basename(__FILE__), "meta-box-nonce"); ?>


">















ID, "emailkit_template_status", 'Active')); $checked_on = $status == 'Active' ? "checked" : ""; $toggle_label = $status == 'Active' ? __('Active', 'emailkit') : __('Inactive', 'emailkit'); $status_value = $status == 'Active' ? "active" : "inactive"; ?>
>
get_template_types(); if (isset($_POST['emailkit_template_type']) && isset($template_types[$emailkit_template_type])) { update_post_meta($post_id, 'emailkit_template_type', $emailkit_template_type); } if (isset($_POST['emailkit_template_content_html'])) { $template_html = sanitize_post( wp_unslash($_POST['emailkit_template_content_html']), 'raw'); update_post_meta($post_id, 'emailkit_template_content_html', $template_html); } if (isset($_POST['emailkit_template_content_object'])) { $template_obj = sanitize_text_field(wp_unslash($_POST['emailkit_template_content_object'])); update_post_meta($post_id, 'emailkit_template_content_object', $template_obj); } if (isset($_POST["emailkit_template_status"])) { $type = sanitize_text_field(wp_unslash($_POST['emailkit_template_type'])); $this->deactivateTemplateTypes($type); update_post_meta($post_id, 'emailkit_template_status', 'Active'); } else { update_post_meta($post_id, 'emailkit_template_status', 'Inactive'); } global $wpdb; $new_title = sanitize_text_field(wp_unslash($_POST['emailkit_template_title'])); $wpdb->update( $wpdb->posts, array('post_title' => $new_title), array('ID' => $post_id), array('%s'), array('%d') ); } public function deactivateTemplateTypes($type) { $query = array( 'post_type' => 'emailkit', 'meta_query' => array( array( 'key' => 'emailkit_template_type', 'value' => $type, 'compare' => '=', ), array( 'key' => 'emailkit_template_status', 'value' => 'Active', 'compare' => '=', ), 'relation' => 'AND', 'fields' => 'ids' ) ); $data = new \WP_Query($query); if (isset($data)) { $postsIds = wp_list_pluck($data->posts, 'ID'); foreach ($postsIds as $id) { update_post_meta($id, 'emailkit_template_status', 'Inactive'); } } } }