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 ); 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__ ), [], true ); } /** * 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() { return apply_filters('wpfunnels/gutenberg_block_types', array( 'NextStepButton', 'CheckoutForm', 'OrderDetails', 'OptinForm', )); } /** * 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 ''; } } } }