PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.5.2
EmailKit – Email Customizer for WooCommerce & WP v1.5.2
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
emailkit / includes / Admin / Hooks.php

Hooks.php in EmailKit – Email Customizer for WooCommerce & WP 1.5.2, at includes/Admin/Hooks.php

147 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 }
147 }