Opened 2 years ago
Last modified 2 years ago
#57095 new defect (bug)
Shortcode's query are executing at backend because of the_content filter
Reported by: | vijayhardaha | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.1 |
Component: | Editor | Keywords: | has-screenshots |
Focuses: | Cc: |
Description
Steps to reproduce the issue & main issue description are available on this GitHub issue https://github.com/WordPress/gutenberg/issues/45732
I investigated this issue more and found a couple of new things.
So if you'll check the callers-tracks image, you'll see block_editor_rest_api_preload
is being called, then from REST_API call apply_filters('the_content')
being used and which I think executes the shortcode.
In file wp-admin/edit-form-blocks.php
, I removed the add_query_arg( 'context', 'edit', $rest_path )
on line no 65, after this change I don't see the issue.
After and before this change, I see changes in XHR requests, I am attaching both screenshots.
Attachments (3)
Change History (7)
#1
@
2 years ago
Thanks for the ticket @vijayhardaha!
Could you explain more what the issue is? Shortcodes should be able to be called in any context, be that the admin or the REST API.
#2
@
2 years ago
Thanks for the reply @TimothyBlynJacobs
For example, if we use [products limit=4]
shortcode in the classic editor so this shortcode is a simple text that should be transformed into something on the front end. so putting the shortcode tag in the classic editor doesn't execute the code inside the shortcode.
the same behavior should be applied with the block editor as well, if I am putting a shortcode in page/post content, the shortcode code should be executed in the front only not in the backend.
In my original issue and GitHub issue, you'll see that WC_Shortcodes:products()
and other functions are being called, but in general when we add a shortcode in the backend, we don't render any preview, so it should not execute the queries and functions which is in a shortcode callback function.
#3
@
2 years ago
This is a bit related to #55151 and the notes from @gziolo in https://github.com/WordPress/gutenberg/issues/33542#issuecomment-1036465478.
The REST API includes a rendered version of the content which means shortcodes are rendered too. And since the preloading runs in the same request you'll get the extra queries and such.
Callers functions stack