Changeset 3174532
- Timestamp:
- 10/23/2024 06:21:00 PM (17 months ago)
- Location:
- content-update-scheduler
- Files:
-
- 2 edited
- 3 copied
-
tags/2.3.3 (copied) (copied from content-update-scheduler/trunk)
-
tags/2.3.3/content-update-scheduler.php (copied) (copied from content-update-scheduler/trunk/content-update-scheduler.php) (5 diffs)
-
tags/2.3.3/readme.txt (copied) (copied from content-update-scheduler/trunk/readme.txt) (2 diffs)
-
trunk/content-update-scheduler.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
content-update-scheduler/tags/2.3.3/content-update-scheduler.php
r3151025 r3174532 8 8 * Author: Infinitnet 9 9 * Author URI: https://infinitnet.io/ 10 * Version: 2.3. 210 * Version: 2.3.3 11 11 * License: GPLv3 12 12 * Text Domain: content-update-scheduler … … 824 824 * @return void 825 825 */ 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 826 854 public static function copy_meta_and_terms($source_post_id, $destination_post_id, $restore_references = false) 827 855 { 828 829 856 $source_post = get_post($source_post_id); 830 857 $destination_post = get_post($destination_post_id); … … 835 862 } 836 863 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 843 865 $meta = get_post_meta($source_post->ID); 844 866 foreach ($meta as $key => $values) { 845 delete_post_meta($destination_post->ID, $key); // Delete existing meta to avoid duplicates867 delete_post_meta($destination_post->ID, $key); 846 868 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 ); 861 878 } 862 879 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); 868 881 } 869 882 } … … 924 937 error_log("Date components: Year: $year, Month: $month, Day: $day, Time: $time"); 925 938 939 // Get WordPress timezone 926 940 $tz = wp_timezone(); 941 942 // Create date string and explicitly set timezone 927 943 $date_string = sprintf('%04d-%02d-%02d %s', $year, $month, $day, $time); 928 944 $date_time = DateTime::createFromFormat('Y-m-d H:i', $date_string, $tz); … … 933 949 } 934 950 951 // Convert to UTC before getting timestamp 952 $date_time->setTimezone(new DateTimeZone('UTC')); 935 953 $stamp = $date_time->getTimestamp(); 936 954 -
content-update-scheduler/tags/2.3.3/readme.txt
r3151025 r3174532 4 4 Requires at least: 5.0 5 5 Tested up to: 6.6.1 6 Stable tag: 2.3. 26 Stable tag: 2.3.3 7 7 Requires PHP: 7.3 8 8 License: GPLv3 … … 50 50 51 51 == 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 52 56 53 57 = 2.3.2 = -
content-update-scheduler/trunk/content-update-scheduler.php
r3151025 r3174532 8 8 * Author: Infinitnet 9 9 * Author URI: https://infinitnet.io/ 10 * Version: 2.3. 210 * Version: 2.3.3 11 11 * License: GPLv3 12 12 * Text Domain: content-update-scheduler … … 824 824 * @return void 825 825 */ 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 826 854 public static function copy_meta_and_terms($source_post_id, $destination_post_id, $restore_references = false) 827 855 { 828 829 856 $source_post = get_post($source_post_id); 830 857 $destination_post = get_post($destination_post_id); … … 835 862 } 836 863 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 843 865 $meta = get_post_meta($source_post->ID); 844 866 foreach ($meta as $key => $values) { 845 delete_post_meta($destination_post->ID, $key); // Delete existing meta to avoid duplicates867 delete_post_meta($destination_post->ID, $key); 846 868 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 ); 861 878 } 862 879 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); 868 881 } 869 882 } … … 924 937 error_log("Date components: Year: $year, Month: $month, Day: $day, Time: $time"); 925 938 939 // Get WordPress timezone 926 940 $tz = wp_timezone(); 941 942 // Create date string and explicitly set timezone 927 943 $date_string = sprintf('%04d-%02d-%02d %s', $year, $month, $day, $time); 928 944 $date_time = DateTime::createFromFormat('Y-m-d H:i', $date_string, $tz); … … 933 949 } 934 950 951 // Convert to UTC before getting timestamp 952 $date_time->setTimezone(new DateTimeZone('UTC')); 935 953 $stamp = $date_time->getTimestamp(); 936 954 -
content-update-scheduler/trunk/readme.txt
r3151025 r3174532 4 4 Requires at least: 5.0 5 5 Tested up to: 6.6.1 6 Stable tag: 2.3. 26 Stable tag: 2.3.3 7 7 Requires PHP: 7.3 8 8 License: GPLv3 … … 50 50 51 51 == 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 52 56 53 57 = 2.3.2 =
Note: See TracChangeset
for help on using the changeset viewer.