PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.4
Kubio AI Page Builder v2.8.4
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 / api / save-template-parts-filter.php
kubio / lib / api Last commit date
multilanguage 1 year ago recommendations 6 days ago colibri.php 1 year ago contact-form.php 1 year ago entity.php 4 years ago get-body-class.php 1 year ago get-classic-page-template.php 1 year ago get-page-query.php 1 year ago get-page-title.php 1 year ago get-post-content.php 1 year ago get-post-styles.php 1 year ago index.php 11 months ago kubio-cloud.php 1 year ago page-templates.php 4 years ago save-template-parts-filter.php 1 year ago subscribe-form.php 4 years ago typekit.php 4 years ago update-settings-flags.php 1 year ago
save-template-parts-filter.php
71 lines
1 <?php
2
3 use Kubio\Core\Importer;
4
5 function kubio_template_autosave( $post_data, $type = 'preview' ) {
6
7 $id = $post_data->wp_id ? $post_data->wp_id : $post_data->id;
8
9 //TODO make a query that gets the autosave with the correct type so there are not made multiple autosaves for the same
10 //post and type
11 $old_autosave = wp_get_post_autosave( $id );
12 $same_autosave_type = true;
13 $autosave_meta_key = 'kubio_template_autosave_type';
14 if ( $old_autosave ) {
15 $autosave_type = get_post_meta( $id, $autosave_meta_key, true );
16
17 //no meta is present or if the meta is present is the same type
18 $same_autosave_type = ! $autosave_type || ( $autosave_type && $autosave_type === $type );
19 }
20 if ( $old_autosave && $same_autosave_type ) {
21 wp_update_post(
22 array(
23 'ID' => $old_autosave->ID,
24 'post_content' => wp_slash( $post_data->content ),
25 )
26 );
27 update_post_meta( $old_autosave->ID, $autosave_meta_key, $type );
28 return $old_autosave;
29 } else {
30
31 // if possible save the post with initial value and then create the autosave
32 if ( ! is_numeric( $id ) && property_exists( $post_data, 'slug' ) && property_exists( $post_data, 'content' ) ) {
33 $id = Importer::createTemplate( $post_data->slug, $post_data->content, false );
34 }
35
36 $new_data = get_post( $id );
37 $new_data->post_content = $post_data->content;
38
39 $autosave_id = _wp_put_post_revision( $new_data, true );
40
41 if ( ! is_wp_error( $autosave_id ) ) {
42 update_post_meta( $autosave_id, $autosave_meta_key, $type );
43 return get_post( $autosave_id );
44 }
45
46 return $autosave_id;
47 }
48
49 return $post_data;
50 }
51
52
53 register_post_meta(
54 'revision',
55 'kubio_template_autosave_type',
56 array(
57 'show_in_rest' => true,
58 'single' => true,
59 'type' => 'string',
60 'auth_callback' => function () {
61 return current_user_can( 'edit_posts' );
62 },
63 )
64 );
65
66
67
68 add_filter( 'kubio/save-template-entity/page/autosave', 'kubio_template_autosave', 10, 2 );
69 add_filter( 'kubio/save-template-entity/wp_template/autosave', 'kubio_template_autosave', 10, 2 );
70 add_filter( 'kubio/save-template-entity/wp_template_part/autosave', 'kubio_template_autosave', 10, 2 );
71