PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / trunk
Kubio AI Page Builder vtrunk
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 / customizer / index.php
kubio / lib / customizer Last commit date
index.php 1 year ago
index.php
100 lines
1 <?php
2
3 use Kubio\Core\Utils;
4
5 function kubio_set_admin_bar_menu_customize_to_kubio_editor( WP_Admin_Bar &$admin_bar ) {
6
7 if ( ! is_user_logged_in() || ! kubio_theme_has_kubio_block_support() ) {
8 return;
9 }
10
11 $url = kubio_frontend_get_editor_url();
12 $appearance_node = $admin_bar->get_node( 'customize' );
13 if ( ! $appearance_node ) {
14 return;
15 }
16 $appearance_node->href = $url;
17 $admin_bar->add_node( $appearance_node );
18 }
19
20 function kubio_set_admin_bar_customize_to_kubio_editor() {
21 if ( ! kubio_theme_has_kubio_block_support() ) {
22 return;
23 }
24 global $submenu;
25 if ( ! isset( $submenu['themes.php'] ) ) {
26 return;
27 }
28
29 foreach ( $submenu['themes.php'] as $key => $theme_submenu ) {
30 $slug = $theme_submenu[1];
31 if ( $slug !== 'customize' ) {
32 continue;
33 }
34 $submenu['themes.php'][ $key ][2] = 'admin.php?page=kubio';
35 }
36 }
37
38 function kubio_update_theme_page_customize_url( $prepared_themes ) {
39 if ( ! kubio_theme_has_kubio_block_support() ) {
40 return $prepared_themes;
41 }
42 foreach ( $prepared_themes as $key => $theme ) {
43 if ( $theme['active'] === true ) {
44 $prepared_themes[ $key ]['actions']['customize'] = Utils::kubioGetEditorURL();
45 }
46 }
47
48 return $prepared_themes;
49 }
50
51 function kubio_update_dashboard_customizer_url() {
52
53 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
54 $request_uri = isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '';
55 $is_dashboard_admin_or_theme = str_contains( $request_uri, 'wp-admin/index.php' ) || str_contains( $request_uri, 'wp-admin/themes.php' );
56
57 //Dashboard page or theme page
58 if ( ! $is_dashboard_admin_or_theme ) {
59 return;
60 }
61
62 $kubio_url = Utils::kubioGetEditorURL();
63 ob_start();
64 ?>
65 <script>
66 (function($) {
67 $(document).ready(function(){
68
69 <?php if ( kubio_theme_has_kubio_block_support() ) : ?>
70 var customizeLink = document.querySelector('a.load-customize');
71 if(customizeLink) {
72 customizeLink.setAttribute('href', <?php echo wp_json_encode( $kubio_url ); ?>);
73 }
74 <?php endif; ?>
75
76
77 //in the active theme page replace the edit with kubio link
78 var themeSingleTemplate = document.querySelector('#tmpl-theme-single')
79 if(themeSingleTemplate) {
80 let innerHtml = themeSingleTemplate.innerHTML;
81 let newInnerHtml = innerHtml.replace(/href='([^']*page=kubio)'/, "href='" + <?php echo wp_json_encode( $kubio_url ); ?> + "'");
82 themeSingleTemplate.innerHTML = newInnerHtml;
83 }
84 })
85 })(jQuery)
86 </script>
87 <?php
88
89 // phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags
90 $script = strip_tags( ob_get_clean() );
91 wp_add_inline_script( 'jquery', $script );
92 return;
93 }
94
95 add_filter( 'admin_init', 'kubio_update_dashboard_customizer_url' );
96 add_action( 'wp_prepare_themes_for_js', 'kubio_update_theme_page_customize_url', 1000 );
97 add_action( 'admin_bar_menu', 'kubio_set_admin_bar_menu_customize_to_kubio_editor', 1000 );
98 add_action( 'admin_menu', 'kubio_set_admin_bar_customize_to_kubio_editor', 1000 );
99
100