PluginProbe
Assistant – Every Day Productivity Apps / 1.3.4
Assistant – Every Day Productivity Apps v1.3.4
1.5.5 trunk 0.1.0 0.2.0 0.2.1 0.2.2 0.3.0 0.3.1 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.6.0 0.7.0 0.7.0.2 0.7.0.3 0.7.0.4 0.7.0.5 0.7.0.6 0.7.0.7 0.7.0.8 0.7.0.9 0.7.1 1.0 All 71 releases
← All changes | backend/src/Controllers/Cloud/Libraries/LibraryItemPostController.php +52 -25 0.7.11.3.4 View file →
@@ -73,13 +73,13 @@
73 73 [
74 74 'methods' => \WP_REST_Server::CREATABLE,
75 75 'callback' => [ $this, 'sync_to_library' ],
76 76 'args' => [
77 - 'id' => [
77 + 'id' => [
78 78 'required' => true,
79 79 'type' => 'number',
80 80 ],
81 - 'item_id' => [
81 + 'item_id' => [
82 82 'required' => true,
83 83 'type' => 'number',
84 84 ],
85 85 ],
@@ -109,9 +109,9 @@
109 109 [
110 110 'methods' => \WP_REST_Server::CREATABLE,
111 111 'callback' => [ $this, 'import_post_thumb_from_library' ],
112 112 'args' => [
113 - 'post_id' => [
113 + 'post_id' => [
114 114 'required' => true,
115 115 'type' => 'number',
116 116 ],
117 117 ],
@@ -128,9 +128,9 @@
128 128 [
129 129 'methods' => \WP_REST_Server::CREATABLE,
130 130 'callback' => [ $this, 'import_post_media_from_library' ],
131 131 'args' => [
132 - 'post_id' => [
132 + 'post_id' => [
133 133 'required' => true,
134 134 'type' => 'number',
135 135 ],
136 136 ],
@@ -147,9 +147,9 @@
147 147 [
148 148 'methods' => \WP_REST_Server::CREATABLE,
149 149 'callback' => [ $this, 'sync_from_library' ],
150 150 'args' => [
151 - 'id' => [
151 + 'id' => [
152 152 'required' => true,
153 153 'type' => 'number',
154 154 ],
155 155 ],
@@ -228,12 +228,12 @@
228 228 * @param object $post
229 229 * @return array
230 230 */
231 231 public function get_save_data( $request, $post ) {
232 - return [
232 + $data = [
233 233 'name' => $post->post_title,
234 234 'type' => 'post',
235 - 'data' => [
235 + 'post_data' => [
236 236 'post' => [
237 237 'comment_status' => $post->comment_status,
238 238 'menu_order' => $post->menu_order,
239 239 'ping_status' => $post->ping_status,
@@ -248,13 +248,20 @@
248 248 'terms' => $this->get_post_terms( $post ),
249 249
250 250 ],
251 251 'media' => [
252 - 'thumb' => get_attached_file( get_post_thumbnail_id( $post ) ),
253 252 'attachments' => $this->get_post_image_paths( $post ),
254 253 ],
255 254 'screenshot' => $this->get_post_screenshot( $request, $post ),
256 255 ];
256 +
257 + $thumbnail = get_attached_file( get_post_thumbnail_id( $post ) );
258 +
259 + if ($thumbnail) {
260 + $data['media']['thumb'] = $thumbnail;
261 + }
262 +
263 + return $data;
257 264 }
258 265
259 266 /**
260 267 * Saves a post to a cloud library.
@@ -284,12 +291,13 @@
284 291 $id = $request->get_param( 'id' );
285 292 $item_id = $request->get_param( 'item_id' );
286 293 $post = get_post( $id );
287 294 $client = new CloudClient;
295 + $data = $this->get_save_data( $request, $post );
288 296
289 297 return $client->libraries->update_item(
290 298 $item_id,
291 - $this->get_save_data( $request, $post )
299 + $data
292 300 );
293 301 }
294 302
295 303 /**
@@ -309,9 +317,13 @@
309 317 ]
310 318 );
311 319 }
312 320
321 + $client = new CloudClient;
322 + $item = $client->libraries->get_item( $item->id );
313 323 $post_data = $item->data->post;
324 + $meta_data = $item->data->meta;
325 + $term_data = $item->data->terms;
314 326
315 327 $new_post_id = wp_insert_post(
316 328 [
317 329 'comment_status' => $post_data->comment_status,
@@ -335,11 +347,11 @@
335 347 ]
336 348 );
337 349 }
338 350
339 - $this->import_post_meta_from_library( $new_post_id, $item->data->meta );
340 - $this->import_post_terms_from_library( $new_post_id, $item->data->terms );
341 - $this->regenerate_builder_cache( $item );
351 + $this->import_post_meta_from_library( $new_post_id, $meta_data );
352 + $this->import_post_terms_from_library( $new_post_id, $term_data );
353 + $this->regenerate_builder_cache( $new_post_id, $item );
342 354
343 355 return rest_ensure_response(
344 356 $this->posts->transform(
345 357 get_post( $new_post_id )
@@ -365,12 +377,18 @@
365 377 ]
366 378 );
367 379 }
368 380
381 + $client = new CloudClient;
382 + $item = $client->libraries->get_item( $item->id );
383 + $post_data = $item->data->post;
384 + $meta_data = $item->data->meta;
385 + $term_data = $item->data->terms;
386 +
369 387 $updated = wp_update_post(
370 388 [
371 389 'ID' => $post_id,
372 - 'post_content' => $item->data->post->post_content,
390 + 'post_content' => $post_data->post_content,
373 391 ]
374 392 );
375 393
376 394 if ( is_wp_error( $updated ) ) {
@@ -380,11 +398,11 @@
380 398 ]
381 399 );
382 400 }
383 401
384 - $this->import_post_meta_from_library( $post_id, $item->data->meta );
385 - $this->import_post_terms_from_library( $post_id, $item->data->terms );
386 - $this->regenerate_builder_cache( $item );
402 + $this->import_post_meta_from_library( $post_id, $meta_data );
403 + $this->import_post_terms_from_library( $post_id, $term_data );
404 + $this->regenerate_builder_cache( $post_id, $item );
387 405
388 406 return rest_ensure_response(
389 407 $this->posts->transform(
390 408 get_post( $post_id )
@@ -405,18 +423,24 @@
405 423 if ( ! $meta || ! is_object( $meta ) ) {
406 424 return;
407 425 }
408 426
427 + if ( isset( $meta->_fl_builder_data ) ) {
428 + $meta->_fl_builder_draft = $meta->_fl_builder_data;
429 + $meta->_fl_builder_draft_settings = $meta->_fl_builder_data_settings;
430 + }
431 +
409 432 foreach ( $meta as $meta_key => $meta_value ) {
410 433 if ( metadata_exists( 'post', $post_id, $meta_key ) ) {
411 434 delete_metadata( 'post', $post_id, $meta_key );
412 435 }
413 -
414 - foreach ( $meta_value as $value ) {
415 - $value = addslashes( $value );
416 - // @codingStandardsIgnoreStart
417 - $wpdb->query( "INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value) values ({$post_id}, '{$meta_key}', '{$value}')" );
418 - // @codingStandardsIgnoreEnd
436 + if ( is_array( $meta_value ) && count( $meta_value ) !== 0 ) {
437 + foreach ( $meta_value as $value ) {
438 + $value = addslashes( $value );
439 + // @codingStandardsIgnoreStart
440 + $wpdb->query( "INSERT INTO {$wpdb->postmeta} (post_id, meta_key, meta_value) values ({$post_id}, '{$meta_key}', '{$value}')" );
441 + // @codingStandardsIgnoreEnd
442 + }
419 443 }
420 444 }
421 445 }
422 446
@@ -439,9 +463,9 @@
439 463
440 464 foreach ( $terms as $term ) {
441 465 if ( ! isset( $term->name ) || ! isset( $term->taxonomy ) ) {
442 466 continue;
443 - } else if ( ! taxonomy_exists( $term->taxonomy ) ) {
467 + } elseif ( ! taxonomy_exists( $term->taxonomy ) ) {
444 468 continue;
445 469 } elseif ( ! isset( $taxonomy_terms ) ) {
446 470 $taxonomy_terms[ $term->taxonomy ] = [];
447 471 }
@@ -462,9 +486,9 @@
462 486 );
463 487 $term_id = $is_hierarchical ? $new_term['term_taxonomy_id'] : $term->name;
464 488 }
465 489
466 - $taxonomy_terms[ $term->taxonomy ] = $term_id;
490 + $taxonomy_terms[ $term->taxonomy ][] = $term_id;
467 491 }
468 492
469 493 foreach ( $taxonomy_terms as $taxonomy => $terms ) {
470 494 wp_delete_object_term_relationships( $post_id, $taxonomy );
@@ -638,11 +662,14 @@
638 662 *
639 663 * @param object $item
640 664 * @return void
641 665 */
642 - public function regenerate_builder_cache( $item ) {
666 + public function regenerate_builder_cache( $post_id, $item ) {
643 667 $meta = (array) $item->data->meta;
644 668
669 + if ( isset( $meta['_fl_builder_data'] ) && class_exists( 'FLBuilderModel' ) ) {
670 + \FLBuilderModel::delete_all_asset_cache( $post_id );
671 + }
645 672 if ( isset( $meta['_elementor_data'] ) && class_exists( 'Elementor\Plugin' ) ) {
646 673 \Elementor\Plugin::$instance->files_manager->clear_cache();
647 674 }
648 675 }