PluginProbe
EmailKit – Email Customizer for WooCommerce & WP / 1.4.5
EmailKit – Email Customizer for WooCommerce & WP v1.4.5
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.4.5, at includes/Admin/Hooks.php

134 lines 5.1 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
6 defined("ABSPATH") || exit;
7
8 class Hooks
9 {
10
11 public function __construct()
12 {
13 add_filter('manage_emailkit_posts_columns', [$this, 'set_columns']);
14 add_action('manage_emailkit_posts_custom_column', [$this, 'add_column_content'], 10, 2);
15 add_action('admin_init', [$this, 'add_author_support'], 10);
16 add_action('admin_footer', [$this, 'modal_view']);
17 add_filter('emailkit_shortcode_filter', [$this, 'replace']);
18 add_filter('post_row_actions', [$this, 'custom_post_row_actions'], 10, 2);
19 add_filter('emailkit_shortcode_filter', [$this, 'mail_shortcode_replace'], 10, 1);
20 }
21 function custom_post_row_actions($actions, $post) {
22
23 // Remove the Quick Edit link
24 if ( isset( $actions['inline hide-if-no-js'] ) ) {
25 unset( $actions['inline hide-if-no-js'] );
26 }
27
28
29 if ($post->post_type === 'emailkit') {
30 $edit_url = admin_url("post.php?post={$post->ID}&action=emailkit-builder");
31 $actions['emailkit-builder'] = "<a href='$edit_url'>Edit with Emailkit</a>";
32 // unset($actions['edit']);
33 }
34 return $actions;
35 }
36
37 public function replace($input){
38
39 // Define the regular expression pattern
40 $pattern = '/<span data-shortcode="{{([\w]+)}}">([\w]+)<\/span>/';
41
42 // Use preg_match_all to find all matches in the input
43 preg_match_all($pattern, $input, $matches, PREG_SET_ORDER);
44
45 // Loop through each match and replace the content inside the span tag
46 foreach ($matches as $match) {
47 $shortcode = $match[1]; // Content inside the data-shortcode attribute
48
49 // Create the replacement string and replace the match in the input
50 $replacement = '<span data-shortcode="{{' . $shortcode . '}}">{{' . $shortcode . '}}</span>';
51 $input = str_replace($match[0], $replacement, $input);
52 }
53
54 return $input;
55 }
56
57
58 public function add_author_support()
59 {
60 remove_post_type_support('emailkit', 'author');
61 remove_post_type_support('emailkit', 'title');
62 }
63
64
65 public function set_columns($columns)
66 {
67
68 $date_column = $columns['date'];
69 unset($columns['title']);
70 unset($columns['date']);
71 unset($columns['author']);
72
73 $columns['title'] = esc_html__('Template Title', 'emailkit');
74 $columns['type'] = esc_html__('Templates Type', 'emailkit');
75 $columns['status'] = esc_html__('Templates Status', 'emailkit');
76 $columns['author'] = esc_html__('Author', 'emailkit');
77 $columns['date'] = esc_html($date_column);
78
79 return $columns;
80 }
81
82 public function add_column_content($col, $post_id)
83 {
84
85 $type = get_post_meta($post_id, 'emailkit_template_type', true);
86 $status = get_post_meta($post_id, 'emailkit_template_status', true);
87
88 switch ($col) {
89 case 'type':
90 echo esc_html($type);
91 break;
92
93 case 'status':
94 $temple_type = str_replace(' ', '-', strtolower($type));
95 $isStatus = $status;
96 echo wp_kses('<div class="column-content-container">', Utils::get_kses_array());
97
98 if (!empty($status)) {
99 ?>
100 <div class="emailkit-admin-template-switch">
101 <div class="emailkit-admin-template-switch-inactive <?php echo esc_attr($isStatus === 'active' ? '' : 'emailkit-slider-active'); ?>">Disabled</div>
102 <div class="emailkit-admin-template-switch-main">
103 <div class="switch-container">
104 <label class="switch" for="emailkit-template-status-switch-<?php echo esc_attr($post_id) ?>">
105 <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' : '';?> />
106 <span class="slider"></span>
107 </label>
108 </div>
109 </div>
110 <div class="emailkit-admin-template-switch-active <?php echo esc_attr($isStatus=== 'active' ? 'emailkit-slider-active' : '' );?>">Enabled</div>
111 </div>
112
113 <?php
114 }
115
116 echo wp_kses('</div>', Utils::get_kses_array());
117 break;
118 }
119 }
120
121 function mail_shortcode_replace($mail_content){
122 return Utils::mail_shortcode_filter($mail_content);
123 }
124 public function modal_view(){
125
126 $screen = get_current_screen();
127
128 if($screen->id == 'edit-emailkit' ){
129
130 include_once EMAILKIT_DIR . 'includes/views/modal-add-new-email.php';
131 include_once EMAILKIT_DIR . 'includes/views/modal-editor.php';
132 }
133 }
134 }