@@ -216,7 +216,7 @@ private function doReplaceQuery($base_url, $search_urls, $replace_urls)
216216
217217 $ post_content = $ rows ["post_content " ];
218218 $ post_id = $ rows ['ID ' ];
219- $ replaced_content = $ this ->replaceContent ($ post_content , $ search_urls , $ replace_urls );
219+ $ replaced_content = $ this ->replaceContent ($ post_content , $ search_urls , $ replace_urls, false , true );
220220
221221 if ($ replaced_content !== $ post_content )
222222 {
@@ -311,14 +311,25 @@ private function handleMetaData($url, $search_urls, $replace_urls)
311311 * @param $search String Search string
312312 * @param $replace String Replacement String
313313 * @param $in_deep Boolean. This is use to prevent serialization of sublevels. Only pass back serialized from top.
314+ * @param $strict_check Boolean . If true, remove all classes from serialization check and fail. This should be done on post_content, not on metadata.
314315 */
315- private function replaceContent ($ content , $ search , $ replace , $ in_deep = false )
316+ private function replaceContent ($ content , $ search , $ replace , $ in_deep = false , $ strict_check = false )
316317 {
317318 //$is_serial = false;
318319 if ( true === is_serialized ($ content ))
319320 {
320321 $ serialized_content = $ content ; // use to return content back if incomplete classes are found, prevent destroying the original information
321- $ content = Unserialize::unserialize ($ content , array ('allowed_classes ' => false ));
322+
323+ if (true === $ strict_check )
324+ {
325+ $ args = array ('allowed_classes ' => false );
326+ }
327+ else
328+ {
329+ $ args = array ('allowed_classes ' => true );
330+ }
331+
332+ $ content = Unserialize::unserialize ($ content , $ args );
322333 // bail directly on incomplete classes. In < PHP 7.2 is_object is false on incomplete objects!
323334 if (true === $ this ->checkIncomplete ($ content ))
324335 {
@@ -362,7 +373,14 @@ private function replaceContent($content, $search, $replace, $in_deep = false)
362373 // bail directly on incomplete classes.
363374 if (true === $ this ->checkIncomplete ($ content ))
364375 {
365- return $ serialized_content ;
376+ // if it was serialized, return the original as not to corrupt data.
377+ if (isset ($ serialized_content ))
378+ {
379+ return $ serialized_content ;
380+ }
381+ else { // else just return the content.
382+ return $ content ;
383+ }
366384 }
367385 foreach ($ content as $ key => $ value )
368386 {
@@ -493,7 +511,7 @@ private function findNearestSize($sizeName)
493511 /* Check if given content is JSON format. */
494512 private function isJSON ($ content )
495513 {
496- if (is_array ($ content ) || is_object ($ content ))
514+ if (is_array ($ content ) || is_object ($ content ) || is_null ( $ content ) )
497515 return false ; // can never be.
498516
499517 $ json = json_decode ($ content );
0 commit comments