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

Allow to filter query_args in post_select ajax call #744

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions inc/fields/class-shortcode-ui-field-post-select.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public function action_wp_ajax_shortcode_ui_post_field() {
$nonce = isset( $_GET['nonce'] ) ? sanitize_text_field( $_GET['nonce'] ) : null;
$requested_shortcode = isset( $_GET['shortcode'] ) ? sanitize_text_field( $_GET['shortcode'] ) : null;
$requested_attr = isset( $_GET['attr'] ) ? sanitize_text_field( $_GET['attr'] ) : null;
$postid = isset( $_GET['postid'] ) ? absint( $_GET['postid'] ) : 0;

$response = array(
'items' => array(),
Expand Down Expand Up @@ -135,6 +136,8 @@ public function action_wp_ajax_shortcode_ui_post_field() {
$query_args['ignore_sticky_posts'] = true;
}

$query_args = apply_filters( 'shortcode_ui_post_field_query_args', $query_args, $postid );

$query = new WP_Query( $query_args );

foreach ( $query->posts as $post_id ) {
Expand Down
5 changes: 3 additions & 2 deletions js/build/shortcode-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ sui.views.editAttributeFieldPostSelect = sui.views.editAttributeSelect2Field.ext

ajaxData: {
action : 'shortcode_ui_post_field',
nonce : shortcodeUiPostFieldData.nonce,
nonce : shortcodeUiPostFieldData.nonce
},

events: {
Expand Down Expand Up @@ -1774,7 +1774,8 @@ sui.views.editAttributeSelect2Field = sui.views.editAttributeField.extend( {
var request = {
include : _preselected,
shortcode : this.shortcode.get( 'shortcode_tag'),
attr : this.model.get( 'attr' )
attr : this.model.get( 'attr' ),
postid : $( '#post_ID' ).val()
};

$.get( ajaxurl, $.extend( request, this.ajaxData ),
Expand Down
2 changes: 1 addition & 1 deletion js/src/views/edit-attribute-field-post-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sui.views.editAttributeFieldPostSelect = sui.views.editAttributeSelect2Field.ext

ajaxData: {
action : 'shortcode_ui_post_field',
nonce : shortcodeUiPostFieldData.nonce,
nonce : shortcodeUiPostFieldData.nonce
},

events: {
Expand Down
3 changes: 2 additions & 1 deletion js/src/views/select2-field.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ sui.views.editAttributeSelect2Field = sui.views.editAttributeField.extend( {
var request = {
include : _preselected,
shortcode : this.shortcode.get( 'shortcode_tag'),
attr : this.model.get( 'attr' )
attr : this.model.get( 'attr' ),
postid : $( '#post_ID' ).val()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's actually one other place in select2-fields.js where we should be passing the post ID. Can we also add the postid argument to the search ajax request here?

(Sorry, I think I highlighted the wrong array in my earlier comment - this is the request for initially loading the preselected posts when opening a shortcode ui.)

};

$.get( ajaxurl, $.extend( request, this.ajaxData ),
Expand Down