mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-07-19 14:33:32 +09:00
Move the ajax callback
This commit is contained in:
@@ -73,6 +73,44 @@ class DisplayFeaturedImageGenesisWidgetsForm {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $instance
|
||||
* @param bool $ajax
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_term_lists( $instance, $ajax = false ) {
|
||||
$args = array(
|
||||
'orderby' => 'name',
|
||||
'order' => 'ASC',
|
||||
'hide_empty' => false,
|
||||
);
|
||||
$taxonomy = $ajax ? filter_input( INPUT_POST, 'taxonomy', FILTER_SANITIZE_STRING ) : $instance['taxonomy'];
|
||||
$terms = get_terms( $taxonomy, $args );
|
||||
$options[''] = '--';
|
||||
foreach ( $terms as $term ) {
|
||||
if ( is_object( $term ) ) {
|
||||
$options[ $term->term_id ] = $term->name;
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the callback to populate the custom term dropdown. The
|
||||
* selected post type is provided in $_POST['taxonomy'], and the
|
||||
* calling script expects a JSON array of term objects.
|
||||
*/
|
||||
public function term_action_callback() {
|
||||
|
||||
$list = $this->get_term_lists( array(), true );
|
||||
|
||||
// And emit it
|
||||
echo wp_json_encode( $list );
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build boxes with fields.
|
||||
*
|
||||
|
||||
@@ -39,7 +39,8 @@ class Display_Featured_Image_Genesis_Widget_Taxonomy extends WP_Widget {
|
||||
|
||||
parent::__construct( 'featured-taxonomy', __( 'Display Featured Term Image', 'display-featured-image-genesis' ), $widget_ops, $control_ops );
|
||||
|
||||
add_action( 'wp_ajax_widget_selector', array( $this, 'term_action_callback' ) );
|
||||
$form = new DisplayFeaturedImageGenesisWidgetsForm( $this, array() );
|
||||
add_action( 'wp_ajax_widget_selector', array( $form, 'term_action_callback' ) );
|
||||
|
||||
}
|
||||
|
||||
@@ -153,42 +154,4 @@ class Display_Featured_Image_Genesis_Widget_Taxonomy extends WP_Widget {
|
||||
'archive' => include 'fields/archive.php',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $instance
|
||||
* @param bool $ajax
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function get_term_lists( $instance, $ajax = false ) {
|
||||
$args = array(
|
||||
'orderby' => 'name',
|
||||
'order' => 'ASC',
|
||||
'hide_empty' => false,
|
||||
);
|
||||
$taxonomy = $ajax ? filter_input( INPUT_POST, 'taxonomy', FILTER_SANITIZE_STRING ) : $instance['taxonomy'];
|
||||
$terms = get_terms( $taxonomy, $args );
|
||||
$options[''] = '--';
|
||||
foreach ( $terms as $term ) {
|
||||
if ( is_object( $term ) ) {
|
||||
$options[ $term->term_id ] = $term->name;
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the callback to populate the custom term dropdown. The
|
||||
* selected post type is provided in $_POST['taxonomy'], and the
|
||||
* calling script expects a JSON array of term objects.
|
||||
*/
|
||||
public function term_action_callback() {
|
||||
|
||||
$list = $this->get_term_lists( array(), true );
|
||||
|
||||
// And emit it
|
||||
echo wp_json_encode( $list );
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ return array(
|
||||
'id' => 'term',
|
||||
'label' => __( 'Term:', 'display-featured-image-genesis' ),
|
||||
'flex' => true,
|
||||
'choices' => $this->get_term_lists( $instance, false ),
|
||||
'choices' => $form->get_term_lists( $instance, false ),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user