PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.2.0
Kubio AI Page Builder v2.2.0
2.8.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
AI 2 years ago admin-pages 2 years ago api 2 years ago blog 3 years ago customizer 2 years ago filters 2 years ago full-site-editing 2 years ago importer 4 years ago integrations 2 years ago menu 3 years ago polyfills 3 years ago preview 2 years ago shapes 2 years ago shortcodes 3 years ago src 2 years ago add-edit-in-kubio.php 2 years ago editor-assets.php 2 years ago env.php 2 years ago filters.php 2 years ago frontend.php 4 years ago global-data.php 2 years ago init.php 2 years ago kubio-block-library.php 2 years ago kubio-editor.php 2 years ago load.php 2 years ago
filters.php
287 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 $is_kubio_theme = kubio_theme_has_kubio_block_support();
101
102 //only apply to pages
103 if ( is_page() && ! is_front_page() && $is_kubio_theme ) {
104 /** @var \WP_Post $post */
105 global $post;
106
107 if ( ! $post ) {
108 return;
109 }
110
111 $saved_in_kubio = get_post_meta( $post->ID, 'saved_in_kubio', true );
112 if ( Utils::isTrue( $saved_in_kubio ) ) {
113 return;
114 }
115
116 $template = get_page_template_slug( $post->ID );
117 $is_from_kubio = Utils::hasKubioEditorReferer();
118 if ( empty( trim( $post->post_content ) ) && isset( $_GET['_wp-find-template'] ) && $is_from_kubio && empty( $template ) ) {
119 /**
120 * The locate_block_template function has a check if the get parameter the _wp-find-template is set it
121 * returns wp_send_json_success( $block_template ) with the template provided;
122 * the wp_send_json_success( $block_template );
123 *
124 * If the full width template is found the wp_send_json_success will return the full width tempalte then die
125 * the request. If the full width template is not found then the function will return the 'full-width' text
126 * and we do nothing with it. But the code will run normally and return the normal template that should be
127 * Page.
128 */
129 locate_block_template( 'full-width', 'page', array( 'full-width.php' ) );
130 locate_block_template( 'kubio-full-width', 'page', array( 'kubio-full-width.php' ) );
131 }
132 }
133
134 },
135 5
136 );
137
138 //show index when on latest posts page. It's weird but 2022 theme also shows front page when you click edit and latest
139 //posts is your homepage which is wrong.
140 add_action(
141 'wp',
142 function () {
143 /** @var WP_Query $wp_query */
144
145 //when the front page is the latest posts load the home or index template
146 if ( is_front_page() && is_home() ) {
147
148 $referer = Arr::get( $_SERVER, 'HTTP_REFERER', '' );
149 $callFromKubio = strpos( $referer, 'page=kubio' ) !== false && strpos( $referer, admin_url() ) !== false;
150 if ( isset( $_GET['_wp-find-template'] ) && $callFromKubio ) {
151 locate_block_template( 'home', 'page', array( 'home.php' ) );
152 locate_block_template( 'index', 'page', array( 'index.php' ) );
153 }
154 }
155
156 },
157 5
158 );
159 function kubio_change_customize_link_to_open_kubio_editor() {
160 $kubio_url = Utils::kubioGetEditorURL();
161 ?>
162 <script>
163 (function () {
164 var button = document.querySelector('.button.load-customize,#welcome-panel .load-customize');
165
166 if (button) {
167 button.href = "<?php echo esc_url( $kubio_url ); ?>";
168 }
169 })();
170 </script>
171 <?php
172 }
173
174 add_action( 'welcome_panel', 'kubio_change_customize_link_to_open_kubio_editor', 20 );
175
176 function kubio_plugin_meta( $plugin_meta, $plugin_file ) {
177 $plugins_dir = trailingslashit( wp_normalize_path( WP_CONTENT_DIR . '/plugins/' ) );
178 $kubio_file = str_replace( $plugins_dir, '', wp_normalize_path( KUBIO_ENTRY_FILE ) );
179 if ( $plugin_file === $kubio_file ) {
180 $plugin_meta[0] = "{$plugin_meta[0]} (build: " . KUBIO_BUILD_NUMBER . ')';
181 }
182
183 return $plugin_meta;
184 }
185
186 add_filter( 'plugin_row_meta', 'kubio_plugin_meta', 10, 4 );
187
188 add_filter(
189 'kubio/importer/kubio-url-placeholder-replacement',
190 function () {
191 $stylesheet = get_stylesheet();
192
193 return "https://static-assets.kubiobuilder.com/themes/{$stylesheet}/assets/";
194 },
195 5
196 );
197
198 add_action(
199 'plugins_loaded',
200 function() {
201 // init the hasEnoughRemainingTime static variable
202 Utils::hasEnoughRemainingTime();
203 }
204 );
205
206 /**
207 * This filter checks the attributes for every imported block and replaces the link values stored on the demo site like
208 * `https://support-work.kubiobuilder.com` with the site url.
209 *
210 * @param $parsed_blocks
211 * @param $demo_url
212 * @return mixed
213 */
214 function kubio_blocks_update_block_links( $parsed_blocks, $demo_url ) {
215 $replace = site_url();
216
217 Utils::walkBlocks(
218 $parsed_blocks,
219 function ( &$block ) use ( $demo_url, $replace ) {
220
221 $old_url = Arr::get( $block, 'attrs.link.value' );
222
223 if ( $old_url !== null && ! empty( $old_url ) ) {
224 $next_url = $old_url;
225
226 if ( strpos( $old_url, 'http://wpsites.' ) === 0 ) {
227 // replace internal ( extendstudio links )
228 $next_url = preg_replace( '#^http://wpsites\.(.*?)\.(.*?)/(.*?)/(.*?)/([a-zA-Z0-9-]+)#', $replace, $old_url );
229 } else {
230 $next_url = str_replace( $demo_url, $replace, $old_url );
231 }
232
233 if ( $old_url !== $next_url ) {
234 Arr::set( $block, 'attrs.link.value', $next_url );
235 }
236 }
237 }
238 );
239
240 return $parsed_blocks;
241 }
242
243 //This is added for woocomerce but it fixes a general issue. If the page that we preview is being redirected we need to
244 //add our flag to the redirected page or the editor will not work.
245 function kubio_add_flags_to_redirects( $location ) {
246 $kubioFlags = array(
247 '_wp-find-template',
248 '__kubio-rendered-content',
249 '__kubio-rendered-styles',
250 '__kubio-site-edit-iframe-preview',
251 '__kubio-site-edit-iframe-classic-template',
252 '__kubio-body-class',
253 '__kubio-page-title',
254 '__kubio-page-query',
255 );
256
257 foreach ( $kubioFlags as $flag ) {
258 if ( isset( $_GET[ $flag ] ) && ! empty( $_GET[ $flag ] ) ) {
259 $location = add_query_arg( $flag, $_GET[ $flag ], $location );
260 }
261 }
262
263 return $location;
264 }
265 add_filter( 'wp_redirect', 'kubio_add_flags_to_redirects' );
266
267
268 // deactivate new block editor
269 function kubio_remove_widget_block_editor() {
270 remove_theme_support( 'widgets-block-editor' );
271 }
272 add_action( 'after_setup_theme', 'kubio_remove_widget_block_editor' );
273
274 require_once __DIR__ . '/filters/kubio-fresh-site.php';
275 require_once __DIR__ . '/filters/dismissable-notice.php';
276 require_once __DIR__ . '/filters/svg-kses.php';
277 require_once __DIR__ . '/filters/post-insert.php';
278 require_once __DIR__ . '/filters/gutenerg-plugin-check.php';
279 require_once __DIR__ . '/filters/default-editor-overlay.php';
280 require_once __DIR__ . '/filters/requirements-notices.php';
281 require_once __DIR__ . '/filters/site-urls.php';
282 require_once __DIR__ . '/filters/after-kubio-activation.php';
283 require_once __DIR__ . '/filters/wp-import.php';
284 require_once __DIR__ . '/filters/starter-sites-feature.php';
285 require_once __DIR__ . '/filters/register-meta-fields.php';
286 require_once __DIR__ . '/filters/allow-kubio-blog-override.php';
287