Grunion_Contact_Form_Plugin::__construct PHP Метод

__construct() публичный Метод

public __construct ( )
    function __construct()
    {
        $this->add_shortcode();
        // While generating the output of a text widget with a contact-form shortcode, we need to know its widget ID.
        add_action('dynamic_sidebar', array($this, 'track_current_widget'));
        // Add a "widget" shortcode attribute to all contact-form shortcodes embedded in widgets
        add_filter('widget_text', array($this, 'widget_atts'), 0);
        // If Text Widgets don't get shortcode processed, hack ours into place.
        if (!has_filter('widget_text', 'do_shortcode')) {
            add_filter('widget_text', array($this, 'widget_shortcode_hack'), 5);
        }
        // Akismet to the rescue
        if (defined('AKISMET_VERSION') || function_exists('akismet_http_post')) {
            add_filter('jetpack_contact_form_is_spam', array($this, 'is_spam_akismet'), 10, 2);
            add_action('contact_form_akismet', array($this, 'akismet_submit'), 10, 2);
        }
        add_action('loop_start', array('Grunion_Contact_Form', '_style_on'));
        add_action('wp_ajax_grunion-contact-form', array($this, 'ajax_request'));
        add_action('wp_ajax_nopriv_grunion-contact-form', array($this, 'ajax_request'));
        // Export to CSV feature
        if (is_admin()) {
            add_action('admin_init', array($this, 'download_feedback_as_csv'));
            add_action('admin_footer-edit.php', array($this, 'export_form'));
            add_action('current_screen', array($this, 'unread_count'));
        }
        // custom post type we'll use to keep copies of the feedback items
        register_post_type('feedback', array('labels' => array('name' => __('Feedback', 'jetpack'), 'singular_name' => __('Feedback', 'jetpack'), 'search_items' => __('Search Feedback', 'jetpack'), 'not_found' => __('No feedback found', 'jetpack'), 'not_found_in_trash' => __('No feedback found', 'jetpack')), 'menu_icon' => 'dashicons-feedback', 'show_ui' => TRUE, 'show_in_admin_bar' => FALSE, 'public' => FALSE, 'rewrite' => FALSE, 'query_var' => FALSE, 'capability_type' => 'page', 'show_in_rest' => true, 'rest_controller_class' => 'Grunion_Contact_Form_Endpoint', 'capabilities' => array('create_posts' => false, 'publish_posts' => 'publish_pages', 'edit_posts' => 'edit_pages', 'edit_others_posts' => 'edit_others_pages', 'delete_posts' => 'delete_pages', 'delete_others_posts' => 'delete_others_pages', 'read_private_posts' => 'read_private_pages', 'edit_post' => 'edit_page', 'delete_post' => 'delete_page', 'read_post' => 'read_page'), 'map_meta_cap' => true));
        // Add to REST API post type whitelist
        add_filter('rest_api_allowed_post_types', array($this, 'allow_feedback_rest_api_type'));
        // Add "spam" as a post status
        register_post_status('spam', array('label' => 'Spam', 'public' => FALSE, 'exclude_from_search' => TRUE, 'show_in_admin_all_list' => FALSE, 'label_count' => _n_noop('Spam <span class="count">(%s)</span>', 'Spam <span class="count">(%s)</span>', 'jetpack'), 'protected' => TRUE, '_builtin' => FALSE));
        // POST handler
        if (isset($_SERVER['REQUEST_METHOD']) && 'POST' == strtoupper($_SERVER['REQUEST_METHOD']) && isset($_POST['action']) && 'grunion-contact-form' == $_POST['action'] && isset($_POST['contact-form-id'])) {
            add_action('template_redirect', array($this, 'process_form_submission'));
        }
        /* Can be dequeued by placing the following in wp-content/themes/yourtheme/functions.php
         *
         * 	function remove_grunion_style() {
         *		wp_deregister_style('grunion.css');
         *	}
         *	add_action('wp_print_styles', 'remove_grunion_style');
         */
        if (is_rtl()) {
            wp_register_style('grunion.css', GRUNION_PLUGIN_URL . 'css/rtl/grunion-rtl.css', array(), JETPACK__VERSION);
        } else {
            wp_register_style('grunion.css', GRUNION_PLUGIN_URL . 'css/grunion.css', array(), JETPACK__VERSION);
        }
    }