init(); } /** * Initialize class features. */ protected function init() { add_action('enqueue_block_editor_assets', array( $this, 'wpfnl_checkout_block_editor_assets' )); add_action( 'init', array( $this, 'register_assets' ) ); add_action( 'init', array( $this, 'register_blocks' ) ); add_action( 'wp_footer', array( $this, 'wpfnl_inline_footer_scripts' ) ); add_action( 'wp_head', array( $this, 'add_block_inline_css' ), 100 ); add_filter( 'block_categories_all', array( $this, 'register_block_category' ), 10, 2 ); new Wpfnl_Gutenberg_Editor(); } /** * Inline jquery for editor-end floating label checkout. */ public function wpfnl_checkout_block_editor_assets() { wp_enqueue_script( 'wpfunnels-editor-script', plugins_url( 'block/wpfunnels-editor-script.js', __DIR__ ), ['jquery'], WPFNL_VERSION, true ); $this->enqueue_imported_template_inline_css(); $post_id = get_the_ID(); if ( ! $post_id && isset($_GET['post']) ) { $post_id = intval($_GET['post']); } if ( 'yes' === (get_post_meta($post_id, '_wpfnl_enhanced_phone_field_enabled', true) ? get_post_meta($post_id, '_wpfnl_enhanced_phone_field_enabled', true) : 'no') ) { wp_enqueue_style('intl-tel-input-style', WPFNL_URL . 'public/assets/phone/css/intlTelInput.css', array(), WPFNL_VERSION); wp_enqueue_script('intl-tel-input-script', WPFNL_URL . 'public/assets/phone/js/intlTelInput.min.js', array('jquery'), WPFNL_VERSION, true); wp_enqueue_script('intl-tel-input-utils', WPFNL_URL . 'public/assets/phone/js/utils.js', array('intl-tel-input-script'), WPFNL_VERSION, true); wp_localize_script( 'wpfunnels-editor-script', 'wpfnl_obj', [ 'phone_utils_url' => WPFNL_URL . 'public/assets/phone/js/utils.js', 'phone_help_text' => get_post_meta($post_id, '_wpfnl_phone_help_text', true) ? get_post_meta($post_id, '_wpfnl_phone_help_text', true) : '', ] ); } } /** * Enqueue imported Gutenberg template inline CSS in editor mode. */ private function enqueue_imported_template_inline_css() { $post_id = get_the_ID(); if ( ! $post_id && isset( $_GET['post'] ) ) { $post_id = intval( $_GET['post'] ); } if ( ! $post_id ) { return; } $custom_css = get_post_meta( $post_id, 'rex_gutenberg_css', true ); if ( ! $custom_css ) { return; } wp_register_style( 'rex-gutenberg-css', false ); wp_enqueue_style( 'rex-gutenberg-css' ); wp_add_inline_style( 'rex-gutenberg-css', $custom_css ); } /** * Register blocks, hooking up assets and render functions as needed. */ public function register_blocks() { $block_types = $this->get_block_types(); foreach ( $block_types as $block_type ) { $block_type_class = __NAMESPACE__ . '\\BlockTypes\\' . $block_type; $block_type_instance = new $block_type_class(); } } /** * Get list of block types. * * @return array */ protected function get_block_types() { $block_types = array( 'NextStepButton', 'CheckoutForm', 'OrderDetails', 'OptinForm', ); // Add OfferButton only if Pro is not active if ( ! Wpfnl_functions::is_wpfnl_pro_activated() ) { $block_types[] = 'OfferButton'; } return apply_filters('wpfunnels/gutenberg_block_types', $block_types); } /** * Register assets for gutenberg * * @since 2.0.3 */ public function register_assets() { wp_register_style( 'wpfnl-blocks-editor-style', plugins_url( 'block/assets/dist/wpfnl-blocks-editor-style.css', __DIR__ ), [], '2.0.3', 'all' ); wp_register_style( 'wpfnl-blocks-style',plugins_url( 'block/assets/dist/wpfnl-blocks-style.css', __DIR__ ), [], '2.0.3', 'all' ); } /** * Load Inline Footer Script * * @since 1.3.0 */ public function wpfnl_inline_footer_scripts() { global $wp_query; $is_previewing= $wp_query->is_preview(); $can_edit= current_user_can( 'edit_posts' ); if($is_previewing || $can_edit){ ?> ' . $blockCss . ''; } else { echo ''; } } } /** * Register WPFunnels block category * * @param array $categories Block categories. * @param object $post Post object. * @return array Modified block categories. */ public function register_block_category( $categories, $post ) { return array_merge( $categories, array( array( 'slug' => 'wpfunnels', 'title' => __( 'WPFunnels', 'wpfnl' ), 'icon' => null, ), ) ); } }