-
Notifications
You must be signed in to change notification settings - Fork 142
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
Use WP Rest API infrastructure for previews #583
base: master
Are you sure you want to change the base?
Conversation
'thumbnailImage' => wp_create_nonce( 'shortcode-ui-get-thumbnail-image' ), | ||
), | ||
'urls' => array( | ||
'preview' => home_url( '/wp-json/shortcode-ui/v1/preview' ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use rest_url()
here, to accommodate non-pretty permalinks as well.
Looks pretty good!
Modernization is the key benefit, I think. Also, when batch
Given we aren't performing a write operation, I think we should be using |
add_action( 'wp_enqueue_editor', 'shortcode_ui_action_wp_enqueue_editor' ); | ||
add_action( 'media_buttons', 'shortcode_ui_action_media_buttons' ); | ||
add_action( 'wp_ajax_bulk_do_shortcode', 'shortcode_ui_handle_ajax_bulk_do_shortcode' ); | ||
add_filter( 'wp_editor_settings', 'shortcode_ui_filter_wp_editor_settings', 10, 2 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we removing the singleton then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this somewhere... but this is for a separate PR ;)
Removed some stuff I committed by accident. Updated PR to use |
Yeah that would be really neat |
@@ -68,9 +68,34 @@ private function setup_actions() { | |||
add_action( 'admin_enqueue_scripts', array( $this, 'action_admin_enqueue_scripts' ) ); | |||
add_action( 'wp_enqueue_editor', array( $this, 'action_wp_enqueue_editor' ) ); | |||
add_action( 'wp_ajax_bulk_do_shortcode', array( $this, 'handle_ajax_bulk_do_shortcode' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this registration, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yep
@mattheu Can you fix the failed build? Looks good to me otherwise. |
|
||
$responses = array(); | ||
public function handle_shortcode_preview( WP_REST_Request $request ) { | ||
return $this->get_shortcode_preview( $request->get_param( 'query' ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what this function is doing, but we don't currently have a get_shortcode_preview()
method here...
I think this functionality might be vestigial anyways, currently all previews are bulk requests even if they're only for one shortcode.
This looks much cleaner than before. I like all the changes here, and doing this through the REST API makes it potentially discoverable for other uses. |
Added a permission callback to the requests to check the user has the cap to edit the post. |
TODO
|
I've added some tests for this. Should be good to go. @danielbachhuber would be good if you could give this a once over. |
I have a concern about using the REST API for this. Namely, shortcodes may render differently depending on the URL that the shortcode appears on. In the Customizer, the Selective Refresh API makes requests to render partials by making an Ajax request to the actual URL that the partial (e.g. widget) appears on, and a |
Hmm thats a good point - and sounds like a good workaround. This would affect the current implementation too. |
Lets push this to a future release. Too big for 0.7.0 |
How about using the rest API infrastructure in core for previews?
get preview
does feel a bit odd. Any issues using GET instead?Also deleted the legacy 'fetch' code which is no longer used - including tests. Becomes apparent that we don't have tests for the fetcher which we probably should - but this can be handled separately.