PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 1.6.4
Kubio AI Page Builder v1.6.4
2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / filters.php
kubio / lib Last commit date
admin-pages 3 years ago api 3 years ago blog 3 years ago customizer 3 years ago filters 3 years ago full-site-editing 3 years ago importer 4 years ago integrations 3 years ago menu 3 years ago polyfills 4 years ago preview 4 years ago shapes 4 years ago shortcodes 3 years ago src 3 years ago add-edit-in-kubio.php 3 years ago editor-assets.php 3 years ago env.php 4 years ago filters.php 3 years ago frontend.php 4 years ago global-data.php 3 years ago init.php 4 years ago kubio-block-library.php 4 years ago kubio-editor.php 3 years ago load.php 3 years ago
filters.php
278 lines
1 <?php
2
3 use IlluminateAgnostic\Arr\Support\Arr;
4 use Kubio\Core\LodashBasic;
5 use Kubio\Core\Utils;
6
7
8 add_filter(
9 'kubio/preview/template_part_blocks',
10 function ( $parts = array() ) {
11 return array_merge(
12 (array) $parts,
13 array(
14 'core/template-part',
15 'kubio/header',
16 'kubio/footer',
17 'kubio/sidebar',
18 )
19 );
20 },
21 5,
22 1
23 );
24
25
26 function kubio_blocks_update_template_parts_theme( $parsed_blocks, $theme ) {
27 $parts_block_names = apply_filters( 'kubio/preview/template_part_blocks', array() );
28
29 Utils::walkBlocks(
30 $parsed_blocks,
31 function ( &$block ) use ( $theme, $parts_block_names ) {
32
33 $block_name = Arr::get( $block, 'blockName' );
34 $current_theme = Arr::get( $block, 'attrs.theme' );
35 $is_template_part = in_array( $block_name, $parts_block_names );
36
37 if ( $block_name && ( $current_theme || $is_template_part ) ) {
38 Arr::set( $block, 'attrs.theme', $theme );
39 }
40
41 }
42 );
43
44 return $parsed_blocks;
45 }
46
47 //this code is not required for the attributes to work. But it could be a problem in the future if we don't register the
48 //anchor attribute
49 function kubio_register_anchor_attribute( $metaData ) {
50 $supportsAnchor = LodashBasic::get( $metaData, array( 'supports', 'anchor' ), false );
51 if ( $supportsAnchor ) {
52 $hasAnchorAttribute = LodashBasic::get( $metaData, array( 'attributes', 'anchor' ), false );
53 if ( ! $hasAnchorAttribute ) {
54 $anchorData = array(
55 'type' => 'string',
56 );
57 LodashBasic::set( $metaData, array( 'attributes', 'anchor' ), $anchorData );
58 }
59 }
60
61 return $metaData;
62 }
63
64 add_filter(
65 'kubio/blocks/register_block_type',
66 'kubio_register_anchor_attribute'
67 );
68
69
70 function kubio_add_full_hd_image_size() {
71 add_image_size( 'kubio-fullhd', 1920, 1080 );
72 }
73
74 add_filter( 'after_setup_theme', 'kubio_add_full_hd_image_size' );
75
76
77 function kubio_url_import_cdn_files( $url ) {
78
79 if ( strpos( $url, 'wp-content/uploads' ) !== false ) {
80
81 if ( \_\startsWith( $url, site_url() ) ) {
82 return $url;
83 }
84
85 return str_replace( 'https://demos.kubiobuilder.com', 'https://static-assets.kubiobuilder.com/demos', $url );
86 }
87
88 return $url;
89 }
90
91 add_filter( 'kubio/importer/kubio-source-url', 'kubio_url_import_cdn_files' );
92
93
94 //load full width template if the page is empty
95 add_action(
96 'wp',
97 function () {
98 /** @var WP_Query $wp_query */
99
100 $isKubioTheme = kubio_theme_has_kubio_block_support();
101
102 //only apply to pages
103 if ( is_page() && ! is_front_page() && $isKubioTheme ) {
104 global $post;
105
106 if ( ! $post ) {
107 return;
108 }
109 $template = get_page_template_slug( $post->ID );
110 $referer = Arr::get( $_SERVER, 'HTTP_REFERER', '' );
111 $callFromKubio = strpos( $referer, 'page=kubio' ) !== false && strpos( $referer, admin_url() ) !== false;
112 if ( empty( trim( $post->post_content ) ) && isset( $_GET['_wp-find-template'] ) && $callFromKubio && empty( $template ) ) {
113 /**
114 * The locate_block_template function has a check if the get parameter the _wp-find-template is set it
115 * returns wp_send_json_success( $block_template ) with the template provided;
116 * the wp_send_json_success( $block_template );
117 *
118 * If the full width template is found the wp_send_json_success will return the full width tempalte then die
119 * the request. If the full width template is not found then the function will return the 'full-width' text
120 * and we do nothing with it. But the code will run normally and return the normal template that should be
121 * Page.
122 */
123 locate_block_template( 'full-width', 'page', array( 'full-width.php' ) );
124 locate_block_template( 'kubio-full-width', 'page', array( 'kubio-full-width.php' ) );
125 }
126 }
127
128 },
129 5
130 );
131
132 //show index when on latest posts page. It's weird but 2022 theme also shows front page when you click edit and latest
133 //posts is your homepage which is wrong.
134 add_action(
135 'wp',
136 function () {
137 /** @var WP_Query $wp_query */
138
139 //when the front page is the latest posts load the index template
140 if ( is_front_page() && is_home() ) {
141
142 $referer = Arr::get( $_SERVER, 'HTTP_REFERER', '' );
143 $callFromKubio = strpos( $referer, 'page=kubio' ) !== false && strpos( $referer, admin_url() ) !== false;
144 if ( isset( $_GET['_wp-find-template'] ) && $callFromKubio ) {
145 locate_block_template( 'index', 'page', array( 'index.php' ) );
146 }
147 }
148
149 },
150 5
151 );
152 function kubio_change_customize_link_to_open_kubio_editor() {
153 $kubio_url = add_query_arg( array( 'page' => 'kubio' ), admin_url( 'admin.php' ) );
154 ?>
155 <script>
156 (function () {
157 var button = document.querySelector('.button.load-customize');
158
159 if (button) {
160 button.href = "<?php echo esc_url( $kubio_url ); ?>";
161 }
162 })();
163 </script>
164 <?php
165 }
166
167 add_action( 'welcome_panel', 'kubio_change_customize_link_to_open_kubio_editor', 20 );
168
169 function kubio_plugin_meta( $plugin_meta, $plugin_file ) {
170 $plugins_dir = trailingslashit( wp_normalize_path( WP_CONTENT_DIR . '/plugins/' ) );
171 $kubio_file = str_replace( $plugins_dir, '', wp_normalize_path( KUBIO_ENTRY_FILE ) );
172 if ( $plugin_file === $kubio_file ) {
173 $plugin_meta[0] = "{$plugin_meta[0]} (build: " . KUBIO_BUILD_NUMBER . ')';
174 }
175
176 return $plugin_meta;
177 }
178
179 add_filter( 'plugin_row_meta', 'kubio_plugin_meta', 10, 4 );
180
181 add_filter(
182 'kubio/importer/kubio-url-placeholder-replacement',
183 function () {
184 $stylesheet = get_stylesheet();
185
186 return "https://static-assets.kubiobuilder.com/themes/{$stylesheet}/assets/";
187 },
188 5
189 );
190
191 add_action(
192 'plugins_loaded',
193 function() {
194 // init the hasEnoughRemainingTime static variable
195 Utils::hasEnoughRemainingTime();
196 }
197 );
198
199 /**
200 * This filter checks the attributes for every imported block and replaces the link values stored on the demo site like
201 * `https://support-work.kubiobuilder.com` with the site url.
202 *
203 * @param $parsed_blocks
204 * @param $demo_url
205 * @return mixed
206 */
207 function kubio_blocks_update_block_links( $parsed_blocks, $demo_url ) {
208 $replace = site_url();
209
210 Utils::walkBlocks(
211 $parsed_blocks,
212 function ( &$block ) use ( $demo_url, $replace ) {
213
214 $old_url = Arr::get( $block, 'attrs.link.value' );
215
216 if ( $old_url !== null && ! empty( $old_url ) ) {
217 $next_url = $old_url;
218
219 if ( strpos( $old_url, 'http://wpsites.' ) === 0 ) {
220 // replace internal ( extendstudio links )
221 $next_url = preg_replace( '#^http://wpsites\.(.*?)\.(.*?)/(.*?)/(.*?)/([a-zA-Z0-9-]+)#', $replace, $old_url );
222 } else {
223 $next_url = str_replace( $demo_url, $replace, $old_url );
224 }
225
226 if ( $old_url !== $next_url ) {
227 Arr::set( $block, 'attrs.link.value', $next_url );
228 }
229 }
230 }
231 );
232
233 return $parsed_blocks;
234 }
235
236 //This is added for woocomerce but it fixes a general issue. If the page that we preview is being redirected we need to
237 //add our flag to the redirected page or the editor will not work.
238 function kubio_add_flags_to_redirects( $location ) {
239 $kubioFlags = array(
240 '_wp-find-template',
241 '__kubio-rendered-content',
242 '__kubio-rendered-styles',
243 '__kubio-site-edit-iframe-preview',
244 '__kubio-site-edit-iframe-classic-template',
245 '__kubio-body-class',
246 '__kubio-page-title',
247 '__kubio-page-query',
248 );
249
250 foreach ( $kubioFlags as $flag ) {
251 if ( isset( $_GET[ $flag ] ) && ! empty( $_GET[ $flag ] ) ) {
252
253 $location = add_query_arg( $flag, $_GET[ $flag ], $location );
254 }
255 }
256
257 return $location;
258 }
259 add_filter( 'wp_redirect', 'kubio_add_flags_to_redirects' );
260
261
262 // deactivate new block editor
263 function kubio_remove_widget_block_editor() {
264 remove_theme_support( 'widgets-block-editor' );
265 }
266 add_action( 'after_setup_theme', 'kubio_remove_widget_block_editor' );
267
268 require_once __DIR__ . '/filters/kubio-fresh-site.php';
269 require_once __DIR__ . '/filters/dismissable-notice.php';
270 require_once __DIR__ . '/filters/svg-kses.php';
271 require_once __DIR__ . '/filters/post-insert.php';
272 require_once __DIR__ . '/filters/gutenerg-plugin-check.php';
273 require_once __DIR__ . '/filters/default-editor-overlay.php';
274 require_once __DIR__ . '/filters/requirements-notices.php';
275 require_once __DIR__ . '/filters/site-urls.php';
276 require_once __DIR__ . '/filters/after-kubio-activation.php';
277 require_once __DIR__ . '/filters/wp-import.php';
278