Plugin Directory

Changeset 3174532


Ignore:
Timestamp:
10/23/2024 06:21:00 PM (17 months ago)
Author:
infinitnet
Message:

2.3.3 release

Location:
content-update-scheduler
Files:
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • content-update-scheduler/tags/2.3.3/content-update-scheduler.php

    r3151025 r3174532  
    88 * Author: Infinitnet
    99 * Author URI: https://infinitnet.io/
    10  * Version: 2.3.2
     10 * Version: 2.3.3
    1111 * License: GPLv3
    1212 * Text Domain: content-update-scheduler
     
    824824     * @return void
    825825     */
     826    /**
     827     * Helper method to properly copy meta values while preserving their format
     828     *
     829     * @param mixed $value The meta value to process
     830     * @return mixed The processed meta value
     831     */
     832    private static function copy_meta_value($value) {
     833        // If the value is serialized, handle it carefully
     834        if (is_serialized($value)) {
     835            $unserialized = maybe_unserialize($value);
     836            if ($unserialized === false) {
     837                return $value; // Return original if unserialization fails
     838            }
     839            return $unserialized;
     840        }
     841
     842        // Check if value is JSON encoded (Elementor uses this)
     843        if (is_string($value) && substr($value, 0, 1) === '{' && substr($value, -1) === '}') {
     844            $json_decoded = json_decode($value, true);
     845            if (json_last_error() === JSON_ERROR_NONE) {
     846                // If it's valid JSON, store the raw value to preserve Unicode escapes
     847                return $value;
     848            }
     849        }
     850
     851        return $value;
     852    }
     853
    826854    public static function copy_meta_and_terms($source_post_id, $destination_post_id, $restore_references = false)
    827855    {
    828 
    829856        $source_post = get_post($source_post_id);
    830857        $destination_post = get_post($destination_post_id);
     
    835862        }
    836863
    837         /*
    838          * remove all meta from the destination,
    839          * initialize to emptyarray if not set to prevent error in foreach loop
    840          */
    841 
    842         // now for copying the metadata to the new post.
     864        // Copy meta
    843865        $meta = get_post_meta($source_post->ID);
    844866        foreach ($meta as $key => $values) {
    845             delete_post_meta($destination_post->ID, $key); // Delete existing meta to avoid duplicates
     867            delete_post_meta($destination_post->ID, $key);
    846868            foreach ($values as $value) {
    847                 if (is_serialized($value)) {
    848                     $value = preg_replace_callback('/O:\d+:"([^"]+)"/', function ($matches) {
    849                         return class_exists($matches[1]) ? $matches[0] : 'O:8:"stdClass"';
    850                     }, $value);
    851                    
    852                     $unserialized_value = maybe_unserialize($value);
    853                    
    854                     if (is_string($unserialized_value) && strpos($unserialized_value, 'O:8:"stdClass"') !== false) {
    855                         // Skip this meta entry if it contains undefined objects
    856                         error_log('Skipping meta entry for key: ' . $key . '. Unserialized value contains undefined objects.');
    857                         continue 2;
    858                     }
    859                 } else {
    860                     $unserialized_value = $value;
     869                $processed_value = self::copy_meta_value($value);
     870               
     871                if ($restore_references && is_string($processed_value) &&
     872                    strpos($processed_value, (string)$source_post->ID) !== false) {
     873                    $processed_value = str_replace(
     874                        (string)$source_post->ID,
     875                        (string)$destination_post->ID,
     876                        $processed_value
     877                    );
    861878                }
    862879               
    863                 if ($restore_references && is_string($unserialized_value) && strpos($unserialized_value, (string)$source_post->ID) !== false) {
    864                     $unserialized_value = str_replace((string)$source_post->ID, (string)$destination_post->ID, $unserialized_value);
    865                 }
    866                
    867                 add_post_meta($destination_post->ID, $key, $unserialized_value);
     880                add_post_meta($destination_post->ID, $key, $processed_value);
    868881            }
    869882        }
     
    924937                error_log("Date components: Year: $year, Month: $month, Day: $day, Time: $time");
    925938
     939                // Get WordPress timezone
    926940                $tz = wp_timezone();
     941               
     942                // Create date string and explicitly set timezone
    927943                $date_string = sprintf('%04d-%02d-%02d %s', $year, $month, $day, $time);
    928944                $date_time = DateTime::createFromFormat('Y-m-d H:i', $date_string, $tz);
     
    933949                }
    934950
     951                // Convert to UTC before getting timestamp
     952                $date_time->setTimezone(new DateTimeZone('UTC'));
    935953                $stamp = $date_time->getTimestamp();
    936954
  • content-update-scheduler/tags/2.3.3/readme.txt

    r3151025 r3174532  
    44Requires at least: 5.0
    55Tested up to: 6.6.1
    6 Stable tag: 2.3.2
     6Stable tag: 2.3.3
    77Requires PHP: 7.3
    88License: GPLv3
     
    5050
    5151== Changelog ==
     52
     53= 2.3.3 =
     54* fix: Properly handle timezone when saving publication date
     55* refactor: Improve copy_meta_and_terms method to handle serialized and JSON data
    5256
    5357= 2.3.2 =
  • content-update-scheduler/trunk/content-update-scheduler.php

    r3151025 r3174532  
    88 * Author: Infinitnet
    99 * Author URI: https://infinitnet.io/
    10  * Version: 2.3.2
     10 * Version: 2.3.3
    1111 * License: GPLv3
    1212 * Text Domain: content-update-scheduler
     
    824824     * @return void
    825825     */
     826    /**
     827     * Helper method to properly copy meta values while preserving their format
     828     *
     829     * @param mixed $value The meta value to process
     830     * @return mixed The processed meta value
     831     */
     832    private static function copy_meta_value($value) {
     833        // If the value is serialized, handle it carefully
     834        if (is_serialized($value)) {
     835            $unserialized = maybe_unserialize($value);
     836            if ($unserialized === false) {
     837                return $value; // Return original if unserialization fails
     838            }
     839            return $unserialized;
     840        }
     841
     842        // Check if value is JSON encoded (Elementor uses this)
     843        if (is_string($value) && substr($value, 0, 1) === '{' && substr($value, -1) === '}') {
     844            $json_decoded = json_decode($value, true);
     845            if (json_last_error() === JSON_ERROR_NONE) {
     846                // If it's valid JSON, store the raw value to preserve Unicode escapes
     847                return $value;
     848            }
     849        }
     850
     851        return $value;
     852    }
     853
    826854    public static function copy_meta_and_terms($source_post_id, $destination_post_id, $restore_references = false)
    827855    {
    828 
    829856        $source_post = get_post($source_post_id);
    830857        $destination_post = get_post($destination_post_id);
     
    835862        }
    836863
    837         /*
    838          * remove all meta from the destination,
    839          * initialize to emptyarray if not set to prevent error in foreach loop
    840          */
    841 
    842         // now for copying the metadata to the new post.
     864        // Copy meta
    843865        $meta = get_post_meta($source_post->ID);
    844866        foreach ($meta as $key => $values) {
    845             delete_post_meta($destination_post->ID, $key); // Delete existing meta to avoid duplicates
     867            delete_post_meta($destination_post->ID, $key);
    846868            foreach ($values as $value) {
    847                 if (is_serialized($value)) {
    848                     $value = preg_replace_callback('/O:\d+:"([^"]+)"/', function ($matches) {
    849                         return class_exists($matches[1]) ? $matches[0] : 'O:8:"stdClass"';
    850                     }, $value);
    851                    
    852                     $unserialized_value = maybe_unserialize($value);
    853                    
    854                     if (is_string($unserialized_value) && strpos($unserialized_value, 'O:8:"stdClass"') !== false) {
    855                         // Skip this meta entry if it contains undefined objects
    856                         error_log('Skipping meta entry for key: ' . $key . '. Unserialized value contains undefined objects.');
    857                         continue 2;
    858                     }
    859                 } else {
    860                     $unserialized_value = $value;
     869                $processed_value = self::copy_meta_value($value);
     870               
     871                if ($restore_references && is_string($processed_value) &&
     872                    strpos($processed_value, (string)$source_post->ID) !== false) {
     873                    $processed_value = str_replace(
     874                        (string)$source_post->ID,
     875                        (string)$destination_post->ID,
     876                        $processed_value
     877                    );
    861878                }
    862879               
    863                 if ($restore_references && is_string($unserialized_value) && strpos($unserialized_value, (string)$source_post->ID) !== false) {
    864                     $unserialized_value = str_replace((string)$source_post->ID, (string)$destination_post->ID, $unserialized_value);
    865                 }
    866                
    867                 add_post_meta($destination_post->ID, $key, $unserialized_value);
     880                add_post_meta($destination_post->ID, $key, $processed_value);
    868881            }
    869882        }
     
    924937                error_log("Date components: Year: $year, Month: $month, Day: $day, Time: $time");
    925938
     939                // Get WordPress timezone
    926940                $tz = wp_timezone();
     941               
     942                // Create date string and explicitly set timezone
    927943                $date_string = sprintf('%04d-%02d-%02d %s', $year, $month, $day, $time);
    928944                $date_time = DateTime::createFromFormat('Y-m-d H:i', $date_string, $tz);
     
    933949                }
    934950
     951                // Convert to UTC before getting timestamp
     952                $date_time->setTimezone(new DateTimeZone('UTC'));
    935953                $stamp = $date_time->getTimestamp();
    936954
  • content-update-scheduler/trunk/readme.txt

    r3151025 r3174532  
    44Requires at least: 5.0
    55Tested up to: 6.6.1
    6 Stable tag: 2.3.2
     6Stable tag: 2.3.3
    77Requires PHP: 7.3
    88License: GPLv3
     
    5050
    5151== Changelog ==
     52
     53= 2.3.3 =
     54* fix: Properly handle timezone when saving publication date
     55* refactor: Improve copy_meta_and_terms method to handle serialized and JSON data
    5256
    5357= 2.3.2 =
Note: See TracChangeset for help on using the changeset viewer.