Plugin Directory

Changeset 3326697


Ignore:
Timestamp:
07/12/2025 10:20:15 AM (9 months ago)
Author:
kp4coder
Message:

V 1.9.1 Featured image duplication

Location:
sync-post-with-other-site
Files:
24 added
4 edited

Legend:

Unmodified
Added
Removed
  • sync-post-with-other-site/trunk/SyncPostWithOtherSite.php

    r3324964 r3326697  
    44Plugin URI: https://kp4coder.com/
    55Description: Allows user to sync post with multiple websites.
    6 Version: 1.9
     6Version: 1.9.1
    77Author: kp4coder
    88Author URI: https://kp4coder.com/
     
    5252
    5353global $sps_version;
    54 $sps_version = '1.9';
     54$sps_version = '1.9.1';
    5555
    5656class SyncPostWithOtherSite {
  • sync-post-with-other-site/trunk/includes/sps_post_meta.class.php

    r3324986 r3326697  
    88            add_action('admin_init', array( $this, 'register_meta_settings' ) );
    99               
    10             add_action('save_post', array( $this, 'save_meta_fields' ) );
     10            add_action('save_post', array( $this, 'save_meta_fields' ), 11 );
    1111                   
    1212        }
     
    6161
    6262        function save_meta_fields( $post_id ) {
     63            $sps_websites = array();
    6364            if( isset($_REQUEST['sps_website']) && !empty($_REQUEST['sps_website']) ) {
    64                 $sps_websites = array();
    6565                foreach( $_REQUEST['sps_website'] as $sps_webkey => $sps_webvalue ) {
    6666                    $sps_websites[$sps_webkey] = esc_url_raw($sps_webvalue);
    6767                }
    68                 update_post_meta($post_id, 'sps_website', $sps_websites);
    6968            }
     69            update_post_meta($post_id, 'sps_website', $sps_websites);
    7070        }
    7171       
  • sync-post-with-other-site/trunk/includes/sps_sync.class.php

    r3324964 r3326697  
    1313            add_action( "rest_insert_post", array( $this, "sps_rest_insert_post" ), 10 , 3 );
    1414           
    15             add_action( "save_post", array( $this, "sps_save_post" ), 10 , 3 );
     15            add_action( "save_post", array( $this, "sps_save_post" ), 12 , 3 );
    1616
    1717            add_action( "spsp_after_save_data", array( $this, "spsp_grab_content_images" ), 10, 2 );
     
    8989            $args = apply_filters( 'spsp_before_send_data_args', $args );
    9090            $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";
    9292            $return = wp_remote_post( $url, array( 'body' => $args ));
    9393            return $return;
     
    269269                $post_action = 'edit';
    270270                $sps_sync_data['ID'] = $post_id;
     271                $sps_sync_data['existing_featured_image_id'] = get_post_thumbnail_id($post_id);
    271272                $post_id = wp_update_post( $sps_sync_data );
    272273            } else {
    273274                $post_action = 'add';
     275                $sps_sync_data['existing_featured_image_id'] = 0;
    274276                $post_id = wp_insert_post( $sps_sync_data );
    275277            }
     
    320322
    321323            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'];;
    333328                } 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                }
    362371
    363372                // And finally assign featured image to post
  • sync-post-with-other-site/trunk/readme.txt

    r3324964 r3326697  
    55Requires at least: 4.5
    66Tested up to: 6.6.1
    7 Stable tag: 1.9
     7Stable tag: 1.9.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    117117* Fix: Security Update
    118118
     119= 1.9.1 - July 12, 2025 =
     120* Fix: Featured image duplication
     121
    119122== Upgrade notice ==
    120123
Note: See TracChangeset for help on using the changeset viewer.