Make WordPress Core

Opened 21 months ago

Last modified 21 months ago

#57095 new defect (bug)

Shortcode's query are executing at backend because of the_content filter

Reported by: vijayhardaha's profile 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)

callers-tracks.png (312.2 KB) - added by vijayhardaha 21 months ago.
Callers functions stack
xhr-requests-default.png (254.7 KB) - added by vijayhardaha 21 months ago.
Default XHR requests when I don't edit the code.
xhr-requests-after-code-change.png (172.3 KB) - added by vijayhardaha 21 months ago.
XHR Requests after changing the code as described in issue description

Download all attachments as: .zip

Change History (7)

@vijayhardaha
21 months ago

Callers functions stack

@vijayhardaha
21 months ago

Default XHR requests when I don't edit the code.

@vijayhardaha
21 months ago

XHR Requests after changing the code as described in issue description

#1 @TimothyBlynJacobs
21 months 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 @vijayhardaha
21 months 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 @ocean90
21 months 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.

#4 @krupalpanchal
21 months ago

  • Keywords has-screenshots added
Note: See TracTickets for help on using tickets.