0

We utilize WooCommerce and a WooCommerce plugin called Product Documents (https://woocommerce.com/products/product-documents/) to associate PDF media files with products in my online store.

Our client then uses a plugin called Enable Media Replace (https://wordpress.org/plugins/enable-media-replace/) to swap out media files when a new version of a PDF is released. We want all of the product document links to be updated as well.

This works fine if we allow the plugin to rename the new file to match the old file name. However, if we request that the plugin change old links to match the new file name, it only works within the product content itself, not within the links for the product documents. In fact, it wipes out the product document link data COMPLETELY.

It took some time for us to figure out the culprit, but we finally did, and I'm not sure where to turn for assistance or how to code this in myself.

The Product Documents plugin allows us to link any number of documents to a WooCommerce plugin, and it stores the information in a meta record along with the document such as the sample that follows this post. The plugin uses a WP standard serialization method to serialize the document data into something such as this (single document):

{s:5:"label";s:19:"WAW-2322 Spec Sheet";s:13:"file_location";s:75:"https://dc2willoughbyc.wpengine.com/wp-content/uploads/2018/01/WAW-2322.pdf";}

The "Enable Media Replace" plugin, when we ask it to replace one media file with another (with a different name), DOES change the file name (in the example above, from WAW-2322.pdf to ABCD.pdf, would be an example). However, it does not update the "s:75" section of the serialized object that represents the length of the string to follow. Since the length of the file changed (reduced by 4 characters), WP can no longer deserialize the string into an object and our data is list.

Our request is that "Enable Media Replace" take into account object serialization in WPMeta fields and not only update the file name, but also the string length in the serialized object. Other search/replace plugins (such as "Better Search and Replace" https://wordpress.org/plugins/search-and-replace/) properly care for this replacement, but the UI of "Enable Media Replace" is much better for our client to use (and MUCH less dangerous!)

We would appreciate your feedback and assistance to this issue.

Full Sample data below. The plugin will replace the file name, but does not change the string length of the file name accordingly.

a:1:{i:0;a:3:{s:4:"name";s:0:"";s:7:"default";b:1;s:9:"documents";a:7:{i:0;a:2:{s:5:"label";s:19:"WAW-2322 Spec Sheet";s:13:"file_location";s:75:"https://dc2willoughbyc.wpengine.com/wp-content/uploads/2018/01/WAW-2322.pdf";}i:1;a:2:{s:5:"label";s:32:"WORD formatted CSI specification";s:13:"file_location";s:99:"https://dc2willoughbyc.wpengine.com/wp-content/uploads/2017/09/224233_Willoughby_Washfountains.docx";}i:2;a:2:{s:5:"label";s:16:"AutoCAD DWG file";s:13:"file_location";s:75:"https://dc2willoughbyc.wpengine.com/wp-content/uploads/2017/09/Aquasurf.dwg";}i:3;a:2:{s:5:"label";s:16:"DXF drawing file";s:13:"file_location";s:83:"https://dc2willoughbyc.wpengine.com/wp-content/uploads/2018/01/DWG_DXF/Aquasurf.dxf";}i:4;a:2:{s:5:"label";s:37:"Install and maintenance documentation";s:13:"file_location";s:86:"https://dc2willoughbyc.wpengine.com/wp-content/uploads/2018/01/WAW-2322-Series-IOM.pdf";}i:5;a:2:{s:5:"label";s:22:"AquaSurf® color chart";s:13:"file_location";s:88:"https://dc2willoughbyc.wpengine.com/wp-content/uploads/2017/05/Aqua-Surf-Color-Table.pdf";}i:6;a:2:{s:5:"label";s:11:"REVIT files";s:13:"file_location";s:114:"https://dc2willoughbyc.wpengine.com/wp-content/uploads/2018/01/AquaWave-Lavatory-2_Station-Willoughby-WAW-2322.rfa";}}}}
  • Welcome to WPSE! We assist with custom code rather than plugins. I would recommend you contact the developer or support team of Enable Media Replace directly to resolve the issue. – WebElaine Nov 13 at 21:12
  • I have, but I'm also willing to tinker around the code if need be. Thought I'd see if anyone knew of ways to get these serialized strings to clean themselves up when altered. – Chet at C2IT Nov 14 at 13:43
  • It sounds like the problem is specific to the plugin. Trying to clean up data after something runs is more risky than fixing the place where it's running and creating the problem. It shouldn't be too difficult for the plugin author to unserialize and re-serialize instead of doing just a search and replace. – WebElaine Nov 14 at 16:24
  • Sounds like the plugin creator is on it - they are aware of the issue and working on it, just no ETA... – Chet at C2IT Nov 18 at 16:35
0

Plugin creator knows of the problem and is working on a resolution...

Details here: https://wordpress.org/support/topic/replacing-media-paths-in-serialized-wpmeta-data/#post-12146774

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.