Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected HTML returned in JSON #15

Open
bobbingwide opened this issue Nov 2, 2016 · 2 comments
Open

Unexpected HTML returned in JSON #15

bobbingwide opened this issue Nov 2, 2016 · 2 comments
Assignees

Comments

@bobbingwide
Copy link
Owner

bobbingwide commented Nov 2, 2016

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 bobbingwide added the bug label Nov 2, 2016
@bobbingwide bobbingwide self-assigned this Nov 2, 2016
@bobbingwide
Copy link
Owner Author

bobbingwide commented Nov 2, 2016

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:

  • wp_ajax_nopriv_oik_clone_post,
  • shutdown,
  • jetpack_sync_before_send_wp_insert_post,
  • the_content

@bobbingwide
Copy link
Owner Author

bobbingwide commented Nov 2, 2016

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 Trace shutdown processing needs to be after other shutdown processing oik-bwtrace#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 bobbingwide/oik#57

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant