plugin_file = $plugin_file; $this->settings = $settings; } public function hook() { add_action( 'init', array( $this, 'register' ) ); add_action( 'wp_ajax_hf_form_submit', array( $this, 'listen_for_submit' ) ); add_action( 'wp_ajax_nopriv_hf_form_submit', array( $this, 'listen_for_submit' ) ); add_action( 'init', array( $this, 'register_assets' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_assets' ) ); add_action( 'parse_request', array( $this, 'listen_for_preview' ) ); add_filter( 'hf_form_markup', 'hf_template' ); } public function register() { // register post type register_post_type( 'html-form', array( 'labels' => array( 'name' => 'HTML Forms', 'singular_name' => 'HTML Form', ), 'public' => false, 'capability_type' => 'form', ) ); if ( function_exists( 'register_block_type' ) ) { register_block_type( 'html-forms/form', array( 'render_callback' => array( $this, 'shortcode' ), ) ); } add_shortcode( 'hf_form', array( $this, 'shortcode' ) ); } public function register_assets() { $assets_url = plugins_url( 'assets/', $this->plugin_file ); wp_register_script( 'html-forms', $assets_url . 'js/public.js', array(), HTML_FORMS_VERSION, true ); wp_localize_script( 'html-forms', 'hf_js_vars', array( 'ajax_url' => admin_url( 'admin-ajax.php?action=hf_form_submit' ), ) ); wp_register_style( 'html-forms', $assets_url . 'css/forms.css', array(), HTML_FORMS_VERSION ); add_filter( 'script_loader_tag', array( $this, 'add_defer_attribute' ), 10, 2 ); } public function enqueue_assets() { if ( $this->settings['load_stylesheet'] ) { wp_enqueue_style( 'html-forms' ); } } /** * Adds defer attribute to our