Changeset 3326697
- Timestamp:
- 07/12/2025 10:20:15 AM (9 months ago)
- Location:
- sync-post-with-other-site
- Files:
-
- 24 added
- 4 edited
-
tags/1.9.1 (added)
-
tags/1.9.1/Post Add or Edit Select Website.PNG (added)
-
tags/1.9.1/Setting page.PNG (added)
-
tags/1.9.1/SyncPostWithOtherSite.php (added)
-
tags/1.9.1/SyncPostWithOtherSite.png (added)
-
tags/1.9.1/assets (added)
-
tags/1.9.1/assets/css (added)
-
tags/1.9.1/assets/css/sps_admin_style.css (added)
-
tags/1.9.1/assets/css/sps_front_style.css (added)
-
tags/1.9.1/assets/images (added)
-
tags/1.9.1/assets/js (added)
-
tags/1.9.1/assets/js/sps_admin_js.js (added)
-
tags/1.9.1/assets/js/sps_front_js.js (added)
-
tags/1.9.1/includes (added)
-
tags/1.9.1/includes/sps_post_meta.class.php (added)
-
tags/1.9.1/includes/sps_settings.class.php (added)
-
tags/1.9.1/includes/sps_settings.view.php (added)
-
tags/1.9.1/includes/sps_sync.class.php (added)
-
tags/1.9.1/languages (added)
-
tags/1.9.1/languages/sps_text_domain-en_US.mo (added)
-
tags/1.9.1/languages/sps_text_domain-en_US.po (added)
-
tags/1.9.1/log (added)
-
tags/1.9.1/log/sps_log.txt (added)
-
tags/1.9.1/readme.txt (added)
-
trunk/SyncPostWithOtherSite.php (modified) (2 diffs)
-
trunk/includes/sps_post_meta.class.php (modified) (2 diffs)
-
trunk/includes/sps_sync.class.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sync-post-with-other-site/trunk/SyncPostWithOtherSite.php
r3324964 r3326697 4 4 Plugin URI: https://kp4coder.com/ 5 5 Description: Allows user to sync post with multiple websites. 6 Version: 1.9 6 Version: 1.9.1 7 7 Author: kp4coder 8 8 Author URI: https://kp4coder.com/ … … 52 52 53 53 global $sps_version; 54 $sps_version = '1.9 ';54 $sps_version = '1.9.1'; 55 55 56 56 class SyncPostWithOtherSite { -
sync-post-with-other-site/trunk/includes/sps_post_meta.class.php
r3324986 r3326697 8 8 add_action('admin_init', array( $this, 'register_meta_settings' ) ); 9 9 10 add_action('save_post', array( $this, 'save_meta_fields' ) );10 add_action('save_post', array( $this, 'save_meta_fields' ), 11 ); 11 11 12 12 } … … 61 61 62 62 function save_meta_fields( $post_id ) { 63 $sps_websites = array(); 63 64 if( isset($_REQUEST['sps_website']) && !empty($_REQUEST['sps_website']) ) { 64 $sps_websites = array();65 65 foreach( $_REQUEST['sps_website'] as $sps_webkey => $sps_webvalue ) { 66 66 $sps_websites[$sps_webkey] = esc_url_raw($sps_webvalue); 67 67 } 68 update_post_meta($post_id, 'sps_website', $sps_websites);69 68 } 69 update_post_meta($post_id, 'sps_website', $sps_websites); 70 70 } 71 71 -
sync-post-with-other-site/trunk/includes/sps_sync.class.php
r3324964 r3326697 13 13 add_action( "rest_insert_post", array( $this, "sps_rest_insert_post" ), 10 , 3 ); 14 14 15 add_action( "save_post", array( $this, "sps_save_post" ), 1 0, 3 );15 add_action( "save_post", array( $this, "sps_save_post" ), 12 , 3 ); 16 16 17 17 add_action( "spsp_after_save_data", array( $this, "spsp_grab_content_images" ), 10, 2 ); … … 89 89 $args = apply_filters( 'spsp_before_send_data_args', $args ); 90 90 $args['sps_action'] = $action; 91 $url = $args['sps']['host_name']."/ wp-json/sps/v1/data";91 $url = $args['sps']['host_name']."/index.php?rest_route=/sps/v1/data"; // "/wp-json/sps/v1/data"; 92 92 $return = wp_remote_post( $url, array( 'body' => $args )); 93 93 return $return; … … 269 269 $post_action = 'edit'; 270 270 $sps_sync_data['ID'] = $post_id; 271 $sps_sync_data['existing_featured_image_id'] = get_post_thumbnail_id($post_id); 271 272 $post_id = wp_update_post( $sps_sync_data ); 272 273 } else { 273 274 $post_action = 'add'; 275 $sps_sync_data['existing_featured_image_id'] = 0; 274 276 $post_id = wp_insert_post( $sps_sync_data ); 275 277 } … … 320 322 321 323 if( isset($sps_sync_data['featured_image']) && !empty($sps_sync_data['featured_image']) ) { 322 323 $image_url = $sps_sync_data['featured_image']; 324 $image_arr = explode( '/', $sps_sync_data['featured_image'] ); 325 $image_name = end($image_arr); 326 $upload_dir = wp_upload_dir(); 327 $unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); 328 $filename = basename( $unique_file_name ); 329 330 // Check folder permission and define file location 331 if( wp_mkdir_p( $upload_dir['path'] ) ) { 332 $file = $upload_dir['path'] . '/' . $filename; 324 325 $actual_fimage_url = get_post_meta($sps_sync_data['existing_featured_image_id'], 'sps_featured_image_url', true); 326 if( $actual_fimage_url == $sps_sync_data['featured_image'] ) { // compare existing featured image url with new url 327 $attach_id = $sps_sync_data['existing_featured_image_id'];; 333 328 } else { 334 $file = $upload_dir['basedir'] . '/' . $filename; 335 } 336 337 // Create the image file on the server 338 $this->grab_image( $image_url, $file); 339 340 // Check image file type 341 $wp_filetype = wp_check_filetype( $filename, null ); 342 343 // Set attachment data 344 $attachment = array( 345 'post_mime_type' => $wp_filetype['type'], 346 'post_title' => sanitize_file_name( $filename ), 347 'post_content' => '', 348 'post_status' => 'inherit' 349 ); 350 351 // Create the attachment 352 $attach_id = wp_insert_attachment( $attachment, $file, $post_id ); 353 354 // Include image.php 355 require_once(ABSPATH . 'wp-admin/includes/image.php'); 356 357 // Define attachment metadata 358 $attach_data = wp_generate_attachment_metadata( $attach_id, $file ); 359 360 // Assign metadata to attachment 361 wp_update_attachment_metadata( $attach_id, $attach_data ); 329 $image_url = $sps_sync_data['featured_image']; 330 $image_arr = explode( '/', $sps_sync_data['featured_image'] ); 331 $image_name = end($image_arr); 332 $upload_dir = wp_upload_dir(); 333 $unique_file_name = wp_unique_filename( $upload_dir['path'], $image_name ); 334 $filename = basename( $unique_file_name ); 335 336 // Check folder permission and define file location 337 if( wp_mkdir_p( $upload_dir['path'] ) ) { 338 $file = $upload_dir['path'] . '/' . $filename; 339 } else { 340 $file = $upload_dir['basedir'] . '/' . $filename; 341 } 342 343 // Create the image file on the server 344 $this->grab_image( $image_url, $file); 345 346 // Check image file type 347 $wp_filetype = wp_check_filetype( $filename, null ); 348 349 // Set attachment data 350 $attachment = array( 351 'post_mime_type' => $wp_filetype['type'], 352 'post_title' => sanitize_file_name( $filename ), 353 'post_content' => '', 354 'post_status' => 'inherit' 355 ); 356 357 // Create the attachment 358 $attach_id = wp_insert_attachment( $attachment, $file, $post_id ); 359 360 361 // Include image.php 362 require_once(ABSPATH . 'wp-admin/includes/image.php'); 363 364 // Define attachment metadata 365 $attach_data = wp_generate_attachment_metadata( $attach_id, $file ); 366 367 // Assign metadata to attachment 368 wp_update_attachment_metadata( $attach_id, $attach_data ); 369 update_post_meta($attach_id, 'sps_featured_image_url', $sps_sync_data['featured_image']); // Store Featured Image URL for check next time 370 } 362 371 363 372 // And finally assign featured image to post -
sync-post-with-other-site/trunk/readme.txt
r3324964 r3326697 5 5 Requires at least: 4.5 6 6 Tested up to: 6.6.1 7 Stable tag: 1.9 7 Stable tag: 1.9.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 117 117 * Fix: Security Update 118 118 119 = 1.9.1 - July 12, 2025 = 120 * Fix: Featured image duplication 121 119 122 == Upgrade notice == 120 123
Note: See TracChangeset
for help on using the changeset viewer.