PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.6.9
EmailKit – Email Customizer for WooCommerce & WP v1.6.9
1.6.9 1.6.8 1.6.7 trunk 1.0.0 1.2.0 1.4.0 1.4.5 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6
← All changes | includes/Admin/Hooks.php +163 -146 1.5.21.6.9 View file →
@@ -1,147 +1,164 @@
1 -<?php
2 -
3 -namespace Emailkit\Admin;
4 -use EmailKit\Admin\Emails\Helpers\Utils;
5 -use EmailKit\Admin\Emails\EmailLists;
6 -
7 -defined("ABSPATH") || exit;
8 -
9 -class Hooks
10 -{
11 -
12 - public function __construct()
13 - {
14 - add_filter('manage_emailkit_posts_columns', [$this, 'set_columns']);
15 - add_action('manage_emailkit_posts_custom_column', [$this, 'add_column_content'], 10, 2);
16 - add_action('admin_init', [$this, 'add_author_support'], 10);
17 - add_action('admin_footer', [$this, 'modal_view']);
18 - add_filter('emailkit_shortcode_filter', [$this, 'replace']);
19 - add_filter('post_row_actions', [$this, 'custom_post_row_actions'], 10, 2);
20 - add_filter('emailkit_shortcode_filter', [$this, 'mail_shortcode_replace'], 10, 1);
21 - }
22 - function custom_post_row_actions($actions, $post) {
23 -
24 - // Remove the Quick Edit link
25 - if ( isset( $actions['inline hide-if-no-js'] ) ) {
26 - unset( $actions['inline hide-if-no-js'] );
27 - }
28 -
29 -
30 - if ($post->post_type === 'emailkit') {
31 - $edit_url = admin_url("post.php?post={$post->ID}&action=emailkit-builder");
32 - $actions['emailkit-builder'] = "<a href='$edit_url'>Edit with Emailkit</a>";
33 - // unset($actions['edit']);
34 - }
35 - return $actions;
36 - }
37 -
38 - public function replace($input){
39 -
40 - // Define the regular expression pattern
41 - $pattern = '/<span data-shortcode="{{([\w]+)}}">([\w]+)<\/span>/';
42 -
43 - // Use preg_match_all to find all matches in the input
44 - preg_match_all($pattern, $input, $matches, PREG_SET_ORDER);
45 -
46 - // Loop through each match and replace the content inside the span tag
47 - foreach ($matches as $match) {
48 - $shortcode = $match[1]; // Content inside the data-shortcode attribute
49 -
50 - // Create the replacement string and replace the match in the input
51 - $replacement = '<span data-shortcode="{{' . $shortcode . '}}">{{' . $shortcode . '}}</span>';
52 - $input = str_replace($match[0], $replacement, $input);
53 - }
54 -
55 - return $input;
56 - }
57 -
58 -
59 - public function add_author_support()
60 - {
61 - remove_post_type_support('emailkit', 'author');
62 - remove_post_type_support('emailkit', 'title');
63 - }
64 -
65 -
66 - public function set_columns($columns)
67 - {
68 -
69 - $date_column = $columns['date'];
70 - unset($columns['title']);
71 - unset($columns['date']);
72 - unset($columns['author']);
73 -
74 - $columns['title'] = esc_html__('Template Title', 'emailkit');
75 - $columns['type'] = esc_html__('Templates Type', 'emailkit');
76 - $columns['status'] = esc_html__('Templates Status', 'emailkit');
77 - $columns['author'] = esc_html__('Author', 'emailkit');
78 - $columns['date'] = esc_html($date_column);
79 -
80 - return $columns;
81 - }
82 -
83 - public function add_column_content($col, $post_id)
84 - {
85 -
86 - $type = get_post_meta($post_id, 'emailkit_template_type', true);
87 - $status = get_post_meta($post_id, 'emailkit_template_status', true);
88 -
89 - switch ($col) {
90 - case 'type':
91 - echo esc_html(
92 - $col === 'type'
93 - ? (
94 - isset(EmailLists::woocommerce_email()[$type])
95 - ? EmailLists::woocommerce_email()[$type]
96 - : (
97 - isset(EmailLists::wordpress_email()[$type])
98 - ? EmailLists::wordpress_email()[$type]
99 - : $type
100 - )
101 - )
102 - : ''
103 - );
104 - break;
105 -
106 - case 'status':
107 - $temple_type = str_replace(' ', '-', strtolower($type));
108 - $isStatus = $status;
109 - echo wp_kses('<div class="column-content-container">', Utils::get_kses_array());
110 -
111 - if (!empty($status)) {
112 - ?>
113 - <div class="emailkit-admin-template-switch">
114 - <div class="emailkit-admin-template-switch-inactive">Active</div>
115 - <div class="emailkit-admin-template-switch-main">
116 - <div class="switch-container">
117 - <label class="switch" for="emailkit-template-status-switch-<?php echo esc_attr($post_id) ?>">
118 - <input type="checkbox" id="emailkit-template-status-switch-<?php echo esc_attr($post_id)?>" class="change-status-btn <?php echo esc_html($temple_type)?>" data-template-id="<?php echo esc_attr($post_id)?>" <?php echo esc_attr($status === 'active') ? 'checked' : '';?> />
119 - <span class="slider"><span class="slider-active-text"></span></span>
120 - </label>
121 - </div>
122 - </div>
123 - <!-- <div class="emailkit-admin-template-switch-active <?php //echo esc_attr($isStatus=== 'active' ? 'emailkit-slider-active' : '' );?>">Enabled</div> -->
124 - </div>
125 -
126 - <?php
127 - }
128 -
129 - echo wp_kses('</div>', Utils::get_kses_array());
130 - break;
131 - }
132 - }
133 -
134 - function mail_shortcode_replace($mail_content){
135 - return Utils::mail_shortcode_filter($mail_content);
136 - }
137 - public function modal_view(){
138 -
139 - $screen = get_current_screen();
140 -
141 - if($screen->id == 'edit-emailkit' ){
142 -
143 - include_once EMAILKIT_DIR . 'includes/views/modal-add-new-email.php';
144 - include_once EMAILKIT_DIR . 'includes/views/modal-editor.php';
145 - }
146 - }
1 +<?php
2 +
3 +namespace Emailkit\Admin;
4 +use EmailKit\Admin\Emails\Helpers\Utils;
5 +use EmailKit\Admin\Emails\EmailLists;
6 +
7 +defined("ABSPATH") || exit;
8 +
9 +class Hooks
10 +{
11 +
12 + public function __construct()
13 + {
14 + add_filter('manage_emailkit_posts_columns', [$this, 'set_columns']);
15 + add_action('manage_emailkit_posts_custom_column', [$this, 'add_column_content'], 10, 2);
16 + add_action('admin_init', [$this, 'add_author_support'], 10);
17 + add_action('admin_footer', [$this, 'modal_view']);
18 + add_filter('emailkit_shortcode_filter', [$this, 'replace']);
19 + add_filter('post_row_actions', [$this, 'custom_post_row_actions'], 10, 2);
20 + add_filter('emailkit_shortcode_filter', [$this, 'mail_shortcode_replace'], 10, 1);
21 + }
22 + function custom_post_row_actions($actions, $post) {
23 +
24 + // Remove the Quick Edit link
25 + if ($post->post_type === 'emailkit' && isset( $actions['inline hide-if-no-js'] ) && !class_exists('EmailKit_Essentials') ) {
26 + unset( $actions['inline hide-if-no-js'] );
27 + }
28 +
29 +
30 + if ($post->post_type === 'emailkit') {
31 + $edit_url = admin_url("post.php?post={$post->ID}&action=emailkit-builder");
32 + $actions['emailkit-builder'] = sprintf("<a href='%s'>%s</a>",esc_url($edit_url),esc_html__('Edit with Emailkit', 'emailkit'));
33 + // unset($actions['edit']);
34 + }
35 + return $actions;
36 + }
37 +
38 + public function replace($input){
39 +
40 + // Define the regular expression pattern
41 + $pattern = '/<span data-shortcode="{{([\w]+)}}">([\w]+)<\/span>/';
42 +
43 + // Use preg_match_all to find all matches in the input
44 + preg_match_all($pattern, $input, $matches, PREG_SET_ORDER);
45 +
46 + // Loop through each match and replace the content inside the span tag
47 + foreach ($matches as $match) {
48 + $shortcode = $match[1]; // Content inside the data-shortcode attribute
49 +
50 + // Create the replacement string and replace the match in the input
51 + $replacement = '<span data-shortcode="{{' . $shortcode . '}}">{{' . $shortcode . '}}</span>';
52 + $input = str_replace($match[0], $replacement, $input);
53 + }
54 +
55 + return $input;
56 + }
57 +
58 +
59 + public function add_author_support()
60 + {
61 + remove_post_type_support('emailkit', 'author');
62 + remove_post_type_support('emailkit', 'title');
63 + }
64 +
65 +
66 + public function set_columns($columns)
67 + {
68 +
69 + $date_column = $columns['date'];
70 + $checkbox = $columns['cb'];
71 + unset($columns['title']);
72 + unset($columns['date']);
73 + unset($columns['author']);
74 + unset($columns['cb']);
75 +
76 + $columns = array_merge(
77 + array(
78 + 'cb' => esc_html($checkbox),
79 + 'title' => esc_html__('Template Title', 'emailkit'),
80 + 'type' => esc_html__('Templates Type', 'emailkit'),
81 + 'status' => esc_html__('Templates Status', 'emailkit'),
82 + 'author' => esc_html__('Author', 'emailkit'),
83 + 'date' => esc_html($date_column),
84 +
85 + ),
86 + $columns
87 + );
88 +
89 + return $columns;
90 + }
91 +
92 + public function add_column_content($col, $post_id)
93 + {
94 +
95 + $type = get_post_meta($post_id, 'emailkit_template_type', true);
96 + $status = get_post_meta($post_id, 'emailkit_template_status', true);
97 +
98 + switch ($col) {
99 + case 'type':
100 + if ($col === 'type') {
101 + // Check for MetForm type first (starts with 'metform_form_' or equals METFORM constant)
102 + if (strpos($type, 'metform_form_') === 0 || $type === EmailLists::METFORM) {
103 + echo esc_html__('Confirmation Mail To User', 'emailkit');
104 + }
105 + // Check for PopupKit type
106 + elseif (strpos($type, 'popupkit_popup_') === 0 || $type === EmailLists::POPUPKIT) {
107 + echo esc_html__('Popup Submission Mail', 'emailkit');
108 + }
109 + // Then check WooCommerce
110 + elseif (isset(EmailLists::woocommerce_email()[$type])) {
111 + echo esc_html(EmailLists::woocommerce_email()[$type]);
112 + }
113 + // Then check WordPress
114 + elseif (isset(EmailLists::wordpress_email()[$type])) {
115 + echo esc_html(EmailLists::wordpress_email()[$type]);
116 + }
117 + else {
118 + echo esc_html($type);
119 + }
120 + }
121 + break;
122 +
123 + case 'status':
124 + $temple_type = str_replace(' ', '-', strtolower($type));
125 + $isStatus = $status;
126 + echo wp_kses('<div class="column-content-container">', Utils::get_kses_array());
127 +
128 + if (!empty($status)) {
129 + ?>
130 + <div class="emailkit-admin-template-switch">
131 + <div class="emailkit-admin-template-switch-inactive"><?php esc_html_e( 'Active', 'emailkit' ); ?></div>
132 + <div class="emailkit-admin-template-switch-main">
133 + <div class="switch-container">
134 + <label class="switch" for="emailkit-template-status-switch-<?php echo esc_attr($post_id) ?>">
135 + <input type="checkbox" id="emailkit-template-status-switch-<?php echo esc_attr($post_id)?>" class="change-status-btn <?php echo esc_html($temple_type)?>" data-template-id="<?php echo esc_attr($post_id)?>" <?php echo esc_attr($status === 'active') ? 'checked' : '';?> />
136 + <span class="slider"><span class="slider-active-text"></span></span>
137 + </label>
138 + </div>
139 + </div>
140 + <!-- <div class="emailkit-admin-template-switch-active <?php //echo esc_attr($isStatus=== 'active' ? 'emailkit-slider-active' : '' );?>">Enabled</div> -->
141 + </div>
142 +
143 + <?php
144 + }
145 +
146 + echo wp_kses('</div>', Utils::get_kses_array());
147 + break;
148 + }
149 + }
150 +
151 + function mail_shortcode_replace($mail_content){
152 + return Utils::mail_shortcode_filter($mail_content);
153 + }
154 + public function modal_view(){
155 +
156 + $screen = get_current_screen();
157 +
158 + if($screen->id == 'edit-emailkit' ){
159 +
160 + include_once EMAILKIT_DIR . 'includes/views/modal-add-new-email.php';
161 + include_once EMAILKIT_DIR . 'includes/views/modal-editor.php';
162 + }
163 + }
147 164 }