PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / includes / core / widgets / block / class-manager.php

class-manager.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at includes/core/widgets/block/class-manager.php

167 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Gutenberg widgets manager
4 *
5 * @package
6 */
7 namespace WPFunnels\Widgets\Gutenberg;
8
9 use WPFunnels\Wpfnl;
10 use WPFunnels\Wpfnl_functions;
11
12 /**
13 * BlockTypesController class.
14 *
15 * @since 5.0.0
16 * @internal
17 */
18 final class Manager {
19
20 /**
21 * Instance
22 *
23 * @since 1.0.0
24 *
25 * @access private
26 * @static
27 *
28 * @var Gutenberg_Block The single instance of the class.
29 */
30 private static $_instance = null;
31
32
33 /**
34 * Instance
35 *
36 * Ensures only one instance of the class is loaded or can be loaded.
37 *
38 * @return Gutenberg_Block An instance of the class.
39 * @since 1.0.0
40 *
41 * @access public
42 * @static
43 */
44 public static function instance()
45 {
46
47 if (is_null(self::$_instance)) {
48 self::$_instance = new self();
49 }
50 return self::$_instance;
51
52 }
53
54 public function __construct( ) {
55 $this->init();
56 }
57
58 /**
59 * Initialize class features.
60 */
61 protected function init() {
62 add_action('enqueue_block_editor_assets', array( $this, 'wpfnl_checkout_block_editor_assets' ));
63 add_action( 'init', array( $this, 'register_assets' ) );
64 add_action( 'init', array( $this, 'register_blocks' ) );
65 add_action( 'wp_footer', array( $this, 'wpfnl_inline_footer_scripts' ) );
66 add_action( 'wp_head', array( $this, 'add_block_inline_css' ), 100 );
67 new Wpfnl_Gutenberg_Editor();
68 }
69
70 /**
71 * Inline jquery for editor-end floating label checkout.
72 */
73 public function wpfnl_checkout_block_editor_assets() {
74 wp_enqueue_script( 'wpfunnels-editor-script', plugins_url( 'block/wpfunnels-editor-script.js', __DIR__ ), [], true );
75 }
76
77
78 /**
79 * Register blocks, hooking up assets and render functions as needed.
80 */
81 public function register_blocks() {
82 $block_types = $this->get_block_types();
83
84 foreach ( $block_types as $block_type ) {
85 $block_type_class = __NAMESPACE__ . '\\BlockTypes\\' . $block_type;
86 $block_type_instance = new $block_type_class();
87 }
88 }
89
90
91 /**
92 * Get list of block types.
93 *
94 * @return array
95 */
96 protected function get_block_types() {
97 return apply_filters('wpfunnels/gutenberg_block_types', array(
98 'NextStepButton',
99 'CheckoutForm',
100 'OrderDetails',
101 'OptinForm',
102 ));
103 }
104
105
106 /**
107 * Register assets for gutenberg
108 *
109 * @since 2.0.3
110 */
111 public function register_assets() {
112 wp_register_style( 'wpfnl-blocks-editor-style', plugins_url( 'block/assets/dist/wpfnl-blocks-editor-style.css', __DIR__ ), [], '2.0.3', 'all' );
113 wp_register_style( 'wpfnl-blocks-style',plugins_url( 'block/assets/dist/wpfnl-blocks-style.css', __DIR__ ), [], '2.0.3', 'all' );
114 }
115
116
117 /**
118 * Load Inline Footer Script
119 *
120 * @since 1.3.0
121 */
122 public function wpfnl_inline_footer_scripts() {
123 global $wp_query;
124 $is_previewing= $wp_query->is_preview();
125 $can_edit= current_user_can( 'edit_posts' );
126 if($is_previewing || $can_edit){
127 ?>
128 <script>
129 // Set Preview CSS
130 document.addEventListener("DOMContentLoaded", function() {
131 const cussrent_url = window.location.href;
132 let cssInline = document.createElement('style');
133 cssInline.type = 'text/css';
134 cssInline.id = 'wpfnl-block-js-preview';
135 cssInline.innerHTML =JSON.parse( localStorage.getItem('qubelyCSS'));
136 window.document.getElementsByTagName("head")[0].appendChild(cssInline);
137 })
138
139 </script>
140 <?php
141 }
142 }
143
144
145 /**
146 * Check current post page open and css path exists
147 * Then read the css file content from css path
148 * Then add inline css to the header
149 */
150 public function add_block_inline_css() {
151 $upload_dir = wp_get_upload_dir();
152 $upload_css_dir = trailingslashit( $upload_dir['basedir'] );
153 $post_id = get_the_ID();
154 if ( $post_id ) {
155 $css_path = $upload_css_dir . "wpfunnels/css/wpfnl-css-{$post_id}.css";
156 $json_path = $upload_css_dir . "wpfunnels/css/wpfnl-json-{$post_id}.json";
157
158 if ( file_exists( $css_path ) ) {
159 $blockCss = file_get_contents( $css_path );
160 echo '<style type="text/css">' . $blockCss . '</style>';
161 } else {
162 echo '<style type="text/css">' . get_post_meta( get_the_ID(), '_wpfunnels_gb_css', true ) . '</style>';
163 }
164 }
165 }
166 }
167