PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 1.7.2
Kubio AI Page Builder v1.7.2
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 / api / colibri.php
kubio / lib / api Last commit date
colibri.php 4 years ago contact-form.php 4 years ago entity.php 4 years ago get-body-class.php 4 years ago get-classic-page-template.php 4 years ago get-page-query.php 4 years ago get-page-title.php 4 years ago get-post-content.php 4 years ago get-post-styles.php 4 years ago index.php 3 years ago page-templates.php 4 years ago save-template-parts-filter.php 4 years ago subscribe-form.php 4 years ago typekit.php 4 years ago update-ui-version.php 3 years ago
colibri.php
136 lines
1 <?php
2
3 use IlluminateAgnostic\Arr\Support\Arr;
4
5 add_action(
6 'rest_api_init',
7 function () {
8 $namespace = 'kubio/v1';
9
10 register_rest_route(
11 $namespace,
12 '/enable-theme',
13 array(
14 'methods' => 'GET',
15 'callback' => 'kubio_enable_theme',
16 'permission_callback' => function () {
17 return current_user_can( 'edit_theme_options' );
18 },
19 )
20 );
21
22 register_rest_route(
23 $namespace,
24 '/colibri-data-export',
25 array(
26 'methods' => 'GET',
27 'callback' => 'kubio_colibri_data_export',
28 'permission_callback' => function () {
29 return current_user_can( 'edit_theme_options' );
30 },
31 )
32 );
33
34 register_rest_route(
35 $namespace,
36 '/colibri-data-export-done',
37 array(
38 'methods' => 'GET',
39 'callback' => 'kubio_colibri_data_export_done',
40 'permission_callback' => function () {
41 return current_user_can( 'edit_theme_options' );
42 },
43 )
44 );
45 }
46 );
47
48 function kubio_get_installed_theme() {
49 $themes = wp_get_themes();
50 $kubio_themes = array( 'kubio', 'elevate-wp' );
51 $intersect = array_values( array_intersect( array_keys( $themes ), $kubio_themes ) );
52 $theme = Arr::get( $intersect, 0, null );
53 return $theme;
54 }
55
56 function kubio_enable_theme( WP_REST_Request $data ) {
57 switch_theme( $data['name'] );
58 return wp_send_json( array( 'switched' => $data['name'] ) );
59 }
60
61 function kubio_colibri_data_export_done() {
62
63 // copy menus location from colibri to kubio;
64 $colibri_options = get_option( 'theme_mods_colibri-wp', array() );
65 $kubio_options = get_option( 'theme_mods_kubio', array() );
66
67 $colibri_locations = Arr::get( $colibri_options, 'nav_menu_locations', array() );
68 $kubio_locations = Arr::get( $kubio_options, 'nav_menu_locations', array() );
69
70 $locations_map = array(
71 'header-menu' => 'header-menu',
72 'footer-menu' => 'footer-menu',
73 'footer-menu-1' => 'footer-menu-secondary',
74 'header-menu-1' => 'header-menu-secondary',
75 );
76
77 foreach ( $colibri_locations as $location => $menu ) {
78 $location = Arr::get( $locations_map, $location, $location );
79 $kubio_locations[ $location ] = $menu;
80 }
81
82 Arr::set( $kubio_options, 'nav_menu_locations', $kubio_locations );
83
84 if ( $theme = kubio_get_installed_theme() ) {
85 update_option( "theme_mods_{$theme}", $kubio_options );
86 switch_theme( $theme );
87
88 flush_rewrite_rules();
89 update_option( 'theme_switched', false );
90 }
91
92 wp_send_json_success();
93 }
94
95 function kubio_colibri_data_export() {
96
97 $theme = kubio_get_installed_theme();
98
99 if ( $theme ) {
100 ob_clean();
101
102 // templates are created with colibri-wp theme on kubio activation //
103 foreach ( get_block_templates( array(), 'wp_template' ) as $template ) {
104 wp_set_post_terms( $template->wp_id, $theme, 'wp_theme' );
105 }
106
107 echo wp_json_encode(
108 \ExtendBuilder\export_colibri_data(
109 array( 'exclude_generated' => true ),
110 false
111 )
112 );
113 switch_theme( $theme );
114 } else {
115 wp_send_json_error(
116 array(
117 'error' => 'kubio-not-installed',
118 )
119 );
120 }
121 }
122
123 add_filter(
124 'colibri_page_builder/get_partial_details',
125 function ( $data ) {
126 $post = get_post( $data['id'] );
127 $new_data = array(
128 'title' => $post->post_title,
129 'page_template' => $post->page_template,
130 'parent' => $post->post_parent,
131 );
132 return array_merge( $data, $new_data );
133 },
134 100
135 );
136