bobbingwide / oik-clone

Clone content between sites
https://www.oik-plugins.com/oik-plugins/oik-clone-clone-your-wordpress-content/
GNU General Public License v2.0
5 stars 0 forks source link

Unexpected HTML returned in JSON #15

Open bobbingwide opened 7 years ago

bobbingwide commented 7 years ago

For a couple of posts which have been cloned, the ID for a slave's entry has been set to 0. This can happen when the slave returned in the JSON cannot be determined due to the JSON being malformed.

A particular instance is qw/oikcom/oik-plugins/oik-testimonials, ID 7975, which had failed to clone to oik-plugins.com. The returned JSON includes the JavaScript generated for the [bw_testimonials] shortcode, which was part of the post's content.

This problem does not happen when the post is cloned to oik-plugins.co.uk, nor locally.

Workaround

Disable the shortcodes before cloning and re-enable after. Either edit the code so that it's not expanded or deactivate the https://github.com/bobbingwide/oik-testimonials plugin.

Problem explanation

The problem is caused by 'the_content' filter being run during shutdown processing. See below

Proposed solution

tbc

bobbingwide commented 7 years ago

On a hunch I attempted to reproduce in a local env with Yoast SEO 3.4.2. oik-plugins.co.uk has 3.5. Current latest version of Yoast SEO is 3.7.1

This didn't produce the expected results ( in qw/wordpress). This is most likely due to the fact that cloning had previously succeeded.

So I tried the deactivate oik-testimonials plugin method. The result of this was that the post was cloned to post ID 1. Another rather unexpected result! I manually corrected the id in the post meta data and tried another clone. It worked. And with oik-testimonials reactivated the cloning continued to work but the result returned contained the unexpected JavaScript

[body] => {"narrative":"blah blah","slave":7975}
<script type="text/javascript">jQuery(document).ready(function() { jQuery( "#bw_testimonial-1" ).cycle( {"width":"100%","fit":1} ); });</script> 
<script type="text/javascript">jQuery(document).ready(function() { jQuery( "#bw_testimonial-2" ).cycle( {"width":"100%","fit":1} ); });</script>
<script type="text/javascript">jQuery(document).ready(function() { jQuery( "#bw_testimonial-3" ).cycle( {"width":"100%","fit":1} ); });</script>
<script type="text/javascript">jQuery(document).ready(function() { jQuery( "#bw_testimonial-4" ).cycle( {"width":"100%","fit":1} ); });</script>

Trace output on the server does not show this being returned in the JSON ( see oik_clone_reply_with_json ). But we do see the_content being invoked during shutdown processing. The post being processed is the revision 20485. The hook nesting is:

bobbingwide commented 7 years ago

Analysis of the functions attached to 'shutdown' is enlightening.

/home/oikplugi/public_html/wp-content/plugins/oik-bwtrace/includes/bwtrace-actions.php(426:0) bw_trace_attached_hooks(3) 269 2016-11-02T12:16:36+00:00 0.453553 0.000070 cf=wp_ajax_nopriv_oik_clone_post,shutdown 184 0 10485760/10485760 128M F=629 shutdown 
: 0   bw_trace_attached_hooks;9
: 1   wp_ob_end_flush_all;1
: 10   bw_trace_count_report;1 
bw_trace_included_files;1 
bw_trace_saved_queries;1 
bw_trace_output_buffer;1 
bw_trace_functions_traced;1 
bw_trace_status_report;1 
Yoast_Notification_Center::update_storage;1 
WPSEO_Sitemaps_Cache::clear_queued;1 
Jetpack_Sync_Sender::do_sync;1

Clearly there's a lot going on during shutdown. What I realise is.

  1. trace shutdown functions should be added at a higher priority - 11 or higher ... seems I already knew that. See https://github.com/bobbingwide/oik-bwtrace/issues/31
  2. it must be the shortcode's execution that's producing the unwanted side effects.

It appears that bw_jq_flush() shouldn't be echoing its output in AJAX processing. See https://github.com/bobbingwide/oik/issues/57