PluginProbe
Send Users Email – Email Subscribers, Email Marketing Newsletter / trunk
Send Users Email – Email Subscribers, Email Marketing Newsletter vtrunk
2.0.3 2.0.2 2.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 All 51 releases
send-users-email / includes / class-custom-html-template.php

class-custom-html-template.php in Send Users Email – Email Subscribers, Email Marketing Newsletter trunk, at includes/class-custom-html-template.php

120 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Custom HTML Template Class
5 *
6 * This class handles the custom HTML template functionality for the Send Users Email plugin.
7 * It registers and enqueues CodeMirror for HTML editing in the WordPress admin area.
8 *
9 * @package Send_Users_Email
10 */
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15 /**
16 * Summary of SUE_Custom_Html_Template
17 * Handles the custom HTML template functionality for the Send Users Email plugin.
18 * Registers and enqueues CodeMirror for HTML editing in the WordPress admin area.
19 * */
20 class SUE_Custom_Html_Template
21 {
22 /**
23 * Summary of parse_template
24 * Parses the custom HTML template with provided email content.
25 * This method replaces placeholders in the custom HTML template with actual email content.
26 *
27 * @param mixed $email_title
28 * @param mixed $email_tagline
29 * @param mixed $email_body
30 * @param mixed $email_logo
31 * @return string
32 */
33 static public function parse_template($email_title, $email_tagline, $email_body, $email_logo = '' )
34 {
35 $content = SUE_Custom_Html_Template_Model::get_formatted_custom_html_template();
36
37 $str_replace = [
38 '{{email_title}}' => $email_title,
39 '{{email_tagline}}' => $email_tagline,
40 '{{email_content}}' => $email_body,
41 '{{email_logo}}' => $email_logo,
42 ];
43
44 $email_body = str_replace(
45 array_keys( $str_replace ),
46 array_values( $str_replace ),
47 $content
48 );
49
50 return $email_body;
51 }
52 static public function ajax_form_update()
53 {
54 // Handle AJAX requests related to custom HTML templates
55 // This method can be extended to handle specific AJAX actions if needed
56 $arr_response = [
57 'status' => 'error',
58 'message' => esc_html__('An error occurred while processing your request.', 'send-users-email'),
59 ];
60
61 $update = SUE_Custom_Html_Template_Model::form_process($_POST);
62
63 if ($update) {
64 $arr_response['status'] = 'success';
65 $arr_response['message'] = esc_html__('Custom HTML template updated successfully.', 'send-users-email');
66 } else {
67 $arr_response['message'] = esc_html__('Failed to update custom HTML template.', 'send-users-email');
68 }
69
70 wp_send_json($arr_response);
71 wp_die(); // Always call wp_die() to properly terminate the AJAX request
72 }
73
74 /**
75 * Register CodeMirror assets for HTML editing.
76 * This method registers the necessary scripts and styles for CodeMirror.
77 */
78 static public function register(): void
79 {
80 // Register CodeMirror assets (WordPress core handles dependencies)
81 wp_register_script('wp-codemirror', false, [], false, true);
82 wp_register_style('wp-codemirror', false, [], false);
83
84 }
85
86 /**
87 * Enqueue CodeMirror assets for HTML editing.
88 * This method enqueues the CodeMirror editor and styles for use in the admin area.
89 */
90 static public function enqueue(): void
91 {
92 // Enqueue CodeMirror editor for HTML
93 wp_enqueue_code_editor(['type' => 'text/html']);
94 wp_enqueue_script('wp-codemirror');
95 wp_enqueue_style('wp-codemirror');
96
97 wp_enqueue_script('sue-admin-custom-html-template-js');
98 wp_enqueue_style('sue-admin-custom-html-template-css');
99 }
100
101 /**
102 * Render the custom HTML template editor.
103 * This method outputs the HTML for the custom HTML template editor.
104 *
105 * @param array $args Optional arguments for rendering the template.
106 */
107 static public function render( $args = [] ): void
108 {
109 $defaults = [
110 'title' => esc_html__('Custom HTML Template', 'send-users-email'),
111 'data' => SUE_Custom_Html_Template_Model::get_formatted_custom_html_template(),
112 'is_default' => SUE_Custom_Html_Template_Model::is_default_custom_html_template(),
113 ];
114
115 $args = wp_parse_args( $args, $defaults );
116
117 require_once SEND_USERS_EMAIL_PLUGIN_BASE_PATH . '/admin/partials/custom-html-template.php';
118 }
119
120 }