# emailkit/1.5.2/includes/Admin/Hooks.php

EmailKit – Email Customizer for WooCommerce &amp; WP, version 1.5.2. 147 lines.

- Page: https://pluginprobe.com/plugins/emailkit/1.5.2/code/includes/Admin/Hooks.php
- Raw: https://pluginprobe.com/plugins/emailkit/1.5.2/raw/includes/Admin/Hooks.php
- Modified: 2024-02-28T05:00:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/emailkit/1.5.2/code/includes/Admin/Hooks.php#L10-L20`.

```php
<?php 

namespace Emailkit\Admin;
use EmailKit\Admin\Emails\Helpers\Utils;
use EmailKit\Admin\Emails\EmailLists;

defined("ABSPATH") || exit;

class Hooks
{

    public function __construct()
    {
        add_filter('manage_emailkit_posts_columns', [$this, 'set_columns']);
        add_action('manage_emailkit_posts_custom_column', [$this, 'add_column_content'], 10, 2);
        add_action('admin_init', [$this, 'add_author_support'], 10);
        add_action('admin_footer', [$this, 'modal_view']);
        add_filter('emailkit_shortcode_filter', [$this, 'replace']);
        add_filter('post_row_actions', [$this, 'custom_post_row_actions'], 10, 2);
        add_filter('emailkit_shortcode_filter', [$this, 'mail_shortcode_replace'], 10, 1);
    }
    function custom_post_row_actions($actions, $post) {
   
         // Remove the Quick Edit link
        if ( isset( $actions['inline hide-if-no-js'] ) ) {
            unset( $actions['inline hide-if-no-js'] );
        }


        if ($post->post_type === 'emailkit') {
            $edit_url = admin_url("post.php?post={$post->ID}&action=emailkit-builder");
            $actions['emailkit-builder'] = "<a href='$edit_url'>Edit with Emailkit</a>";
            // unset($actions['edit']);
        }
        return $actions;
    }

    public function replace($input){

        // Define the regular expression pattern
        $pattern = '/<span data-shortcode="{{([\w]+)}}">([\w]+)<\/span>/';

        // Use preg_match_all to find all matches in the input
        preg_match_all($pattern, $input, $matches, PREG_SET_ORDER);

        // Loop through each match and replace the content inside the span tag
        foreach ($matches as $match) {
            $shortcode = $match[1]; // Content inside the data-shortcode attribute

            // Create the replacement string and replace the match in the input
            $replacement = '<span data-shortcode="{{' . $shortcode . '}}">{{' . $shortcode . '}}</span>';
            $input = str_replace($match[0], $replacement, $input);
        }

        return $input;
    }
    

    public function add_author_support()
    {
        remove_post_type_support('emailkit', 'author');
        remove_post_type_support('emailkit', 'title');
    }


    public function set_columns($columns)
    {

        $date_column = $columns['date'];
        unset($columns['title']);
        unset($columns['date']);
        unset($columns['author']);

        $columns['title'] = esc_html__('Template Title', 'emailkit');
        $columns['type']     = esc_html__('Templates Type', 'emailkit');
        $columns['status']   = esc_html__('Templates Status', 'emailkit');
        $columns['author']   = esc_html__('Author', 'emailkit');
        $columns['date']     = esc_html($date_column);

        return $columns;
    }

    public function add_column_content($col, $post_id)
    {

        $type      = get_post_meta($post_id, 'emailkit_template_type', true);
        $status    = get_post_meta($post_id, 'emailkit_template_status', true);

        switch ($col) {
            case 'type':
                echo esc_html(
                    $col === 'type'
                        ? (
                            isset(EmailLists::woocommerce_email()[$type])
                                ? EmailLists::woocommerce_email()[$type]
                                : (
                                    isset(EmailLists::wordpress_email()[$type])
                                        ? EmailLists::wordpress_email()[$type]
                                        : $type
                                )
                        )
                        : ''
                );
            break;

            case 'status':
                $temple_type = str_replace(' ', '-', strtolower($type));
                $isStatus = $status;
                    echo wp_kses('<div class="column-content-container">', Utils::get_kses_array());
        
                    if (!empty($status)) {
                        ?>
                        <div class="emailkit-admin-template-switch">
                            <div class="emailkit-admin-template-switch-inactive">Active</div>
                            <div class="emailkit-admin-template-switch-main">
                            <div class="switch-container">
                            <label class="switch" for="emailkit-template-status-switch-<?php echo esc_attr($post_id) ?>">
                                <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' : '';?> />
                                <span class="slider"><span class="slider-active-text"></span></span>
                            </label>
                        </div>
                            </div>
                            <!-- <div class="emailkit-admin-template-switch-active <?php //echo esc_attr($isStatus=== 'active' ? 'emailkit-slider-active' : '' );?>">Enabled</div> -->
                        </div>
                        
                        <?php
                    }
        
                echo wp_kses('</div>', Utils::get_kses_array());
            break;
        }
    }

    function mail_shortcode_replace($mail_content){
        return Utils::mail_shortcode_filter($mail_content);
    }
    public function modal_view(){

        $screen = get_current_screen();

        if($screen->id == 'edit-emailkit' ){

            include_once EMAILKIT_DIR . 'includes/views/modal-add-new-email.php';
            include_once EMAILKIT_DIR . 'includes/views/modal-editor.php';
        }
    }
}
```
