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

114 lines 3.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
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__('Email Subject', 'emailkit');
74 $columns['type'] = esc_html__('Templates Type', 'emailkit');
75 $columns['status'] = esc_html__('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
95 echo esc_html(ucfirst($status));
96 break;
97 }
98 }
99
100 function mail_shortcode_replace($mail_content){
101 return Utils::mail_shortcode_filter($mail_content);
102 }
103 public function modal_view(){
104
105 $screen = get_current_screen();
106
107 if($screen->id == 'edit-emailkit' ){
108 //include_once 'views/modal-editor.php';
109
110 // Include new modal for add new form
111 include_once EMAILKIT_DIR. 'includes/views/modal-add-new-email.php';
112 }
113 }
114 }