Changeset 2310548
- Timestamp:
- 05/23/2020 02:01:56 AM (6 years ago)
- Location:
- pinecast-wp-sync
- Files:
-
- 4 edited
- 1 copied
-
tags/1.0.5/trunk (copied) (copied from pinecast-wp-sync/trunk)
-
tags/1.0.5/trunk/includes/ajax-functions.php (modified) (1 diff)
-
tags/1.0.5/trunk/includes/class-podcast.php (modified) (9 diffs)
-
trunk/includes/ajax-functions.php (modified) (1 diff)
-
trunk/includes/class-podcast.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pinecast-wp-sync/tags/1.0.5/trunk/includes/ajax-functions.php
r2264272 r2310548 18 18 if ( $podcast = get_podcast( wp_unslash($_POST['podcast']) ) ) { 19 19 $result = $podcast->sync_episodes(); 20 if ( !$result) {20 if ($result) { 21 21 wp_send_json( array( 22 22 'success' => false, 23 23 'error' => 'could not sync', 24 'result' => $result, 25 'feed_url' => $podcast->get_feed_url(), 24 26 ) ); 25 27 return; -
pinecast-wp-sync/tags/1.0.5/trunk/includes/class-podcast.php
r2264272 r2310548 187 187 $response = wp_remote_get( 188 188 $this->feed_url, 189 ['user-agent' => 'WordPress ']189 ['user-agent' => 'WordPress; Pinecast Sync Plugin'] 190 190 ); 191 191 $body = wp_remote_retrieve_body( $response ); … … 293 293 * Synchronize the podcast episodes, create new posts if they don't exist yet. 294 294 * 295 * @return int[]|bool List of post IDs created on success (can be empty), false on failure.295 * @return string|bool Returns an error or false 296 296 */ 297 297 public function sync_episodes() { … … 299 299 300 300 if ( empty( $feed->items ) ) { 301 return false;301 return 'Feed was empty'; 302 302 } 303 303 … … 315 315 } 316 316 317 return $created_posts;317 return false; 318 318 } 319 319 … … 337 337 'meta_input' => array( 338 338 '_pinecast_id' => $data->id, 339 '_pinecast_image' => $data->image,340 339 '_pinecast_feed' => $this->feed_url, 341 340 ), … … 362 361 } 363 362 364 if ( $this->use_featured_image() && ! empty( $data->image ) ) {365 if ( $attachment_id = $this->import_episode_image( $data->image, $post_id ) ) {363 if ( $this->use_featured_image() && !empty( $data->image ) ) { 364 if ( $attachment_id = $this->import_episode_image( $data->image, $post_id, true ) ) { 366 365 set_post_thumbnail( $post_id, $attachment_id ); 367 366 } … … 397 396 if (has_post_thumbnail($post_id)) { 398 397 delete_post_thumbnail($post_id); 399 delete_ metadata('post',$post_id, '_pinecast_image');398 delete_post_metadata($post_id, '_pinecast_image'); 400 399 } 401 400 } … … 416 415 * @return bool|int Attachment ID on success, false otherwise. 417 416 */ 418 private function import_episode_image( $image_url, $post_id ) {417 private function import_episode_image( $image_url, $post_id, $override = false ) { 419 418 require_once ABSPATH . 'wp-includes/post.php'; 420 419 require_once ABSPATH . 'wp-admin/includes/image.php'; 421 420 require_once ABSPATH . 'wp-admin/includes/file.php'; 422 421 require_once ABSPATH . 'wp-admin/includes/media.php'; 422 423 if (!$override) { 424 $existing_image = get_post_meta($post_id, '_pinecast_image', true); 425 if ($existing_image === $image_url) { 426 // Don't update if it hasn't changed. 427 return false; 428 } elseif ($existing_image) { 429 // If there was an existing image that's not the current image, delete it. 430 delete_post_thumbnail($post_id); 431 delete_post_metadata($post_id, '_pinecast_image'); 432 } elseif (has_post_thumbnail($post_id)) { 433 // If there was an existing image that's not from Pinecast, 434 // don't overwrite it. 435 return false; 436 } 437 } 423 438 424 439 // Download file to temp dir … … 437 452 $attachment_id = media_handle_sideload( $file, $post_id ); 438 453 454 update_post_meta($post_id, '_pinecast_image', $image_url); 455 439 456 return $attachment_id; 440 457 } -
pinecast-wp-sync/trunk/includes/ajax-functions.php
r2264272 r2310548 18 18 if ( $podcast = get_podcast( wp_unslash($_POST['podcast']) ) ) { 19 19 $result = $podcast->sync_episodes(); 20 if ( !$result) {20 if ($result) { 21 21 wp_send_json( array( 22 22 'success' => false, 23 23 'error' => 'could not sync', 24 'result' => $result, 25 'feed_url' => $podcast->get_feed_url(), 24 26 ) ); 25 27 return; -
pinecast-wp-sync/trunk/includes/class-podcast.php
r2264272 r2310548 187 187 $response = wp_remote_get( 188 188 $this->feed_url, 189 ['user-agent' => 'WordPress ']189 ['user-agent' => 'WordPress; Pinecast Sync Plugin'] 190 190 ); 191 191 $body = wp_remote_retrieve_body( $response ); … … 293 293 * Synchronize the podcast episodes, create new posts if they don't exist yet. 294 294 * 295 * @return int[]|bool List of post IDs created on success (can be empty), false on failure.295 * @return string|bool Returns an error or false 296 296 */ 297 297 public function sync_episodes() { … … 299 299 300 300 if ( empty( $feed->items ) ) { 301 return false;301 return 'Feed was empty'; 302 302 } 303 303 … … 315 315 } 316 316 317 return $created_posts;317 return false; 318 318 } 319 319 … … 337 337 'meta_input' => array( 338 338 '_pinecast_id' => $data->id, 339 '_pinecast_image' => $data->image,340 339 '_pinecast_feed' => $this->feed_url, 341 340 ), … … 362 361 } 363 362 364 if ( $this->use_featured_image() && ! empty( $data->image ) ) {365 if ( $attachment_id = $this->import_episode_image( $data->image, $post_id ) ) {363 if ( $this->use_featured_image() && !empty( $data->image ) ) { 364 if ( $attachment_id = $this->import_episode_image( $data->image, $post_id, true ) ) { 366 365 set_post_thumbnail( $post_id, $attachment_id ); 367 366 } … … 397 396 if (has_post_thumbnail($post_id)) { 398 397 delete_post_thumbnail($post_id); 399 delete_ metadata('post',$post_id, '_pinecast_image');398 delete_post_metadata($post_id, '_pinecast_image'); 400 399 } 401 400 } … … 416 415 * @return bool|int Attachment ID on success, false otherwise. 417 416 */ 418 private function import_episode_image( $image_url, $post_id ) {417 private function import_episode_image( $image_url, $post_id, $override = false ) { 419 418 require_once ABSPATH . 'wp-includes/post.php'; 420 419 require_once ABSPATH . 'wp-admin/includes/image.php'; 421 420 require_once ABSPATH . 'wp-admin/includes/file.php'; 422 421 require_once ABSPATH . 'wp-admin/includes/media.php'; 422 423 if (!$override) { 424 $existing_image = get_post_meta($post_id, '_pinecast_image', true); 425 if ($existing_image === $image_url) { 426 // Don't update if it hasn't changed. 427 return false; 428 } elseif ($existing_image) { 429 // If there was an existing image that's not the current image, delete it. 430 delete_post_thumbnail($post_id); 431 delete_post_metadata($post_id, '_pinecast_image'); 432 } elseif (has_post_thumbnail($post_id)) { 433 // If there was an existing image that's not from Pinecast, 434 // don't overwrite it. 435 return false; 436 } 437 } 423 438 424 439 // Download file to temp dir … … 437 452 $attachment_id = media_handle_sideload( $file, $post_id ); 438 453 454 update_post_meta($post_id, '_pinecast_image', $image_url); 455 439 456 return $attachment_id; 440 457 }
Note: See TracChangeset
for help on using the changeset viewer.