admin管理员组

文章数量:1410706

We utilize WooCommerce and a WooCommerce plugin called Product Documents (/) to associate PDF media files with products in my online store.

Our client then uses a plugin called 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:".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" /) 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:".pdf";}i:1;a:2:{s:5:"label";s:32:"WORD formatted CSI specification";s:13:"file_location";s:99:".docx";}i:2;a:2:{s:5:"label";s:16:"AutoCAD DWG file";s:13:"file_location";s:75:".dwg";}i:3;a:2:{s:5:"label";s:16:"DXF drawing file";s:13:"file_location";s:83:".dxf";}i:4;a:2:{s:5:"label";s:37:"Install and maintenance documentation";s:13:"file_location";s:86:".pdf";}i:5;a:2:{s:5:"label";s:22:"AquaSurf® color chart";s:13:"file_location";s:88:".pdf";}i:6;a:2:{s:5:"label";s:11:"REVIT files";s:13:"file_location";s:114:".rfa";}}}}

We utilize WooCommerce and a WooCommerce plugin called Product Documents (https://woocommerce/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/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/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/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/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/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/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/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/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/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/wp-content/uploads/2018/01/AquaWave-Lavatory-2_Station-Willoughby-WAW-2322.rfa";}}}}
Share Improve this question asked Nov 13, 2019 at 20:56 Chet at C2ITChet at C2IT 1611 silver badge3 bronze badges 4
  • 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 Commented Nov 13, 2019 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 Commented Nov 14, 2019 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 Commented Nov 14, 2019 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 Commented Nov 18, 2019 at 16:35
Add a comment  | 

1 Answer 1

Reset to default 0

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

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

本文标签: quotEnable Media Replacequot plugin does not update serialized object in WPMeta