mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-06-05 15:08:20 +09:00
Refactor taxonomy widget
Adds new widget form class, which all three widgets can share.
This commit is contained in:
@@ -212,7 +212,6 @@ class Display_Featured_Image_Genesis {
|
||||
|
||||
/**
|
||||
* check existing settings array to see if a setting is in the array
|
||||
* @return updated setting updates to default (0)
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public function check_settings() {
|
||||
@@ -253,6 +252,8 @@ class Display_Featured_Image_Genesis {
|
||||
*
|
||||
* @param string|array $new New settings. Can be a string, or an array.
|
||||
* @param string $setting Optional. Settings field name. Default is displayfeaturedimagegenesis.
|
||||
*
|
||||
* @return mixed updated option
|
||||
*/
|
||||
protected function update_settings( $new = '', $setting = 'displayfeaturedimagegenesis' ) {
|
||||
return update_option( $setting, wp_parse_args( $new, get_option( $setting ) ) );
|
||||
@@ -264,12 +265,11 @@ class Display_Featured_Image_Genesis {
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public function load_textdomain() {
|
||||
load_plugin_textdomain( 'display-featured-image-genesis', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
||||
load_plugin_textdomain( 'display-featured-image-genesis' );
|
||||
}
|
||||
|
||||
/**
|
||||
* enqueue admin scripts
|
||||
* @return scripts to use image uploader
|
||||
*
|
||||
* @since 1.2.1
|
||||
*/
|
||||
@@ -301,41 +301,41 @@ class Display_Featured_Image_Genesis {
|
||||
|
||||
if ( in_array( $screen->id, array( 'widgets', 'customize' ), true ) ) {
|
||||
wp_enqueue_script( 'widget_selector' );
|
||||
wp_localize_script( 'widget_selector', 'displayfeaturedimagegenesis_ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
|
||||
wp_localize_script( 'widget_selector', 'displayfeaturedimagegenesis_ajax_object', array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Register widgets for plugin
|
||||
* @return widgets Taxonomy/term, CPT, and Author widgets
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public function register_widgets() {
|
||||
|
||||
$files = array(
|
||||
'author',
|
||||
'cpt-archive',
|
||||
'taxonomy',
|
||||
);
|
||||
|
||||
foreach ( $files as $file ) {
|
||||
require_once plugin_dir_path( __FILE__ ) . 'widgets/displayfeaturedimagegenesis-' . $file . '-widget.php';
|
||||
}
|
||||
|
||||
if ( function_exists( 'is_customize_preview' ) && is_customize_preview() && ! function_exists( 'genesis' ) ) {
|
||||
return;
|
||||
}
|
||||
register_widget( 'Display_Featured_Image_Genesis_Author_Widget' );
|
||||
register_widget( 'Display_Featured_Image_Genesis_Widget_Taxonomy' );
|
||||
register_widget( 'Display_Featured_Image_Genesis_Widget_CPT' );
|
||||
|
||||
$widgets = array(
|
||||
'author' => 'Display_Featured_Image_Genesis_Author_Widget',
|
||||
'cpt-archive' => 'Display_Featured_Image_Genesis_Widget_CPT',
|
||||
'taxonomy' => 'Display_Featured_Image_Genesis_Widget_Taxonomy',
|
||||
);
|
||||
|
||||
require_once plugin_dir_path( __FILE__ ) . 'widgets/class-displayfeaturedimagegenesis-widgets.php';
|
||||
foreach ( $widgets as $file => $widget ) {
|
||||
require_once plugin_dir_path( __FILE__ ) . 'widgets/displayfeaturedimagegenesis-' . $file . '-widget.php';
|
||||
register_widget( $widget );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add link to plugin settings page in plugin table
|
||||
* @param $links link to settings page
|
||||
* @param $links array link to settings page
|
||||
* @return array
|
||||
*
|
||||
* @since 2.3.0
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$value = isset( $instance[ $args['id'] ] ) ? $instance[ $args['id'] ] : $this->parent->defaults[ $args['id'] ];
|
||||
echo '<p>';
|
||||
printf( '<input type="hidden" name="%s" value="0" />', esc_attr( $this->parent->get_field_name( $args['id'] ) ) );
|
||||
printf( '<input id="%s" type="checkbox" name="%s" value="1" %s/>', esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $this->parent->get_field_name( $args['id'] ) ), checked( 1, esc_attr( $value ), false ) );
|
||||
printf( '<label for="%s">%s</label>', esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $args['label'] ) );
|
||||
echo '</p>';
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$after = isset( $args['after'] ) ? $args['after'] : '';
|
||||
$flex = isset( $args['flex'] ) && $args['flex'] ? ' class="flex"' : '';
|
||||
printf( '<p%s>', wp_kses( $flex, array( 'class' ) ) );
|
||||
printf( '<label for="%s">%s </label>', esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $args['label'] ) );
|
||||
printf( '<input type="number" min="%s" max="%s" id="%s" name="%s" value="%s" />%s', intval( $args['min'] ), intval( $args['max'] ), esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $this->parent->get_field_name( $args['id'] ) ), esc_attr( $instance[ $args['id'] ] ), esc_attr( $after ) );
|
||||
echo '</p>';
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
$onchange = isset( $args['onchange'] ) ? sprintf( ' onchange="%s"', $args['onchange'] ) : '';
|
||||
$class = isset( $args['class'] ) ? sprintf( ' class="%s"', $args['class'] ) : '';
|
||||
$flex = isset( $args['flex'] ) && $args['flex'] ? ' class="flex"' : '';
|
||||
printf( '<p%s>', wp_kses( $flex, array( 'class' ) ) );
|
||||
printf( '<label for="%1$s">%2$s </label>', esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $args['label'] ) );
|
||||
printf( '<select id="%1$s" name="%2$s"%3$s%4$s style="max-width:220px;">', esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $this->parent->get_field_name( $args['id'] ) ), $class, $onchange );
|
||||
$function = "get_{$args['id']}";
|
||||
$options = method_exists( $this->parent, $function ) ? $this->parent->$function( $instance ) : $args['choices'];
|
||||
foreach ( $options as $option => $label ) {
|
||||
printf( '<option value="%1$s" %2$s>%3$s</option>', $option, selected( $option, $instance[ $args['id'] ], false ), $label );
|
||||
}
|
||||
echo '</select>';
|
||||
echo '</p>';
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
$class = isset( $args['class'] ) ? sprintf( ' class="%s"', esc_attr( $args['class'] ) ) : '';
|
||||
$label_class = isset( $args['label_class'] ) ? sprintf( ' class="%s"', esc_attr( $args['label_class'] ) ) : '';
|
||||
echo '<p>';
|
||||
printf( '<label for="%s"%s>%s </label>', esc_attr( $this->parent->get_field_id( $args['id'] ) ), $label_class, esc_attr( $args['label'] ) );
|
||||
printf( '<input type="text" id="%s" name="%s" value="%s"%s />', esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $this->parent->get_field_name( $args['id'] ) ), esc_attr( $instance[ $args['id'] ] ), $class );
|
||||
echo '</p>';
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
echo '<p>';
|
||||
$rows = isset( $args['rows'] ) ? $args['rows'] : 3;
|
||||
printf( '<label for="%s">%s</label>', esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $args['label'] ) );
|
||||
printf( '<textarea class="large-text" rows="%s" id="%s" name="%s">%s</textarea>', absint( $rows ), esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $this->parent->get_field_name( $args['id'] ) ), esc_attr( $instance[ $args['id'] ] ) );
|
||||
echo '</p>';
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
class DisplayFeaturedImageGenesisWidgets {
|
||||
|
||||
protected $parent;
|
||||
|
||||
public $instance;
|
||||
|
||||
public function __construct( $parent, $instance ) {
|
||||
$this->parent = $parent;
|
||||
$this->instance = $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function get_image_size() {
|
||||
$sizes = genesis_get_image_sizes();
|
||||
$options = array();
|
||||
foreach ( (array) $sizes as $name => $size ) {
|
||||
$options[ $name ] = sprintf( '%s ( %s x %s )', esc_html( $name ), (int) $size['width'], (int) $size['height'] );
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build boxes with fields.
|
||||
*
|
||||
* @param $boxes
|
||||
* @param string $class
|
||||
*/
|
||||
public function do_boxes( $boxes, $class = '' ) {
|
||||
foreach ( $boxes as $box => $value ) {
|
||||
if ( ! $value ) {
|
||||
continue;
|
||||
}
|
||||
$box_class = ! $class ? 'genesis-widget-column-box' : 'genesis-widget-column-box ' . $class;
|
||||
printf( '<div class="%s">', esc_attr( $box_class ) );
|
||||
echo wp_kses_post( wpautop( $this->box_description( $box ) ) );
|
||||
$this->do_fields( $this->instance, $value );
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a description to a widget settings box.
|
||||
* @param $box
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function box_description( $box ) {
|
||||
$method = "describe_{$box}";
|
||||
return method_exists( $this, $method ) ? $this->$method() : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Cycle through the fields for a given box, pick the appropriate method, and go.
|
||||
* @param $instance
|
||||
* @param $fields
|
||||
*/
|
||||
public function do_fields( $instance, $fields ) {
|
||||
foreach ( $fields as $field ) {
|
||||
$method = "do_{$field['method']}";
|
||||
if ( method_exists( $this, $method ) ) {
|
||||
$this->$method( $instance, $field['args'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic function to build a text input for the widget form.
|
||||
* @param $instance
|
||||
* @param $args
|
||||
*/
|
||||
public function do_text( $instance, $args ) {
|
||||
include $this->path( 'text' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic function to build a select input for the widget form.
|
||||
* @param $instance
|
||||
* @param $args
|
||||
*/
|
||||
public function do_select( $instance, $args ) {
|
||||
include $this->path( 'select' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic function to build a number input.
|
||||
* @param $instance
|
||||
* @param $args
|
||||
*/
|
||||
public function do_number( $instance, $args ) {
|
||||
include $this->path( 'number' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic function to build a checkbox input.
|
||||
* @param $instance
|
||||
* @param $args
|
||||
*/
|
||||
public function do_checkbox( $instance, $args ) {
|
||||
include $this->path( 'checkbox' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic function to build a textarea input
|
||||
* @param $instance
|
||||
* @param $args
|
||||
*/
|
||||
public function do_textarea( $instance, $args ) {
|
||||
include $this->path( 'textarea' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get path for included files.
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function path( $file ) {
|
||||
return trailingslashit( plugin_dir_path( __FILE__ ) . 'admin' ) . $file . '.php';
|
||||
}
|
||||
}
|
||||
@@ -70,9 +70,7 @@ class Display_Featured_Image_Genesis_Widget_Taxonomy extends WP_Widget {
|
||||
* @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
|
||||
* @param array $instance The settings for the particular instance of the widget
|
||||
*/
|
||||
function widget( $args, $instance ) {
|
||||
|
||||
global $wp_query, $_genesis_displayed_ids;
|
||||
public function widget( $args, $instance ) {
|
||||
|
||||
// Merge with defaults
|
||||
$instance = wp_parse_args( (array) $instance, $this->defaults );
|
||||
@@ -170,107 +168,143 @@ class Display_Featured_Image_Genesis_Widget_Taxonomy extends WP_Widget {
|
||||
*
|
||||
* @param array $instance Current settings
|
||||
*/
|
||||
function form( $instance ) {
|
||||
public function form( $instance ) {
|
||||
|
||||
// Merge with defaults
|
||||
$instance = wp_parse_args( (array) $instance, $this->defaults );
|
||||
$form = new DisplayFeaturedImageGenesisWidgets( $this, $instance );
|
||||
|
||||
?>
|
||||
<p>
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_attr_e( 'Title:', 'display-featured-image-genesis' ); ?> </label>
|
||||
<input type="text" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" />
|
||||
</p>
|
||||
$form->do_text( $instance, array(
|
||||
'id' => 'title',
|
||||
'label' => __( 'Title:', 'display-featured-image-genesis' ),
|
||||
'class' => 'widefat',
|
||||
) );
|
||||
|
||||
<div class="genesis-widget-column">
|
||||
echo '<div class="genesis-widget-column">';
|
||||
|
||||
<div class="genesis-widget-column-box genesis-widget-column-box-top">
|
||||
$form->do_boxes( array(
|
||||
'taxonomy' => array(
|
||||
array(
|
||||
'method' => 'select',
|
||||
'args' => array(
|
||||
'id' => 'taxonomy',
|
||||
'label' => __( 'Taxonomy:', 'display-featured-image-genesis' ),
|
||||
'flex' => true,
|
||||
'onchange' => sprintf( 'term_postback(\'%s\', this.value );', esc_attr( $this->get_field_id( 'term' ) ) ),
|
||||
'choices' => $this->get_taxonomies(),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'method' => 'select',
|
||||
'args' => array(
|
||||
'id' => 'term',
|
||||
'label' => __( 'Term:', 'display-featured-image-genesis' ),
|
||||
'flex' => true,
|
||||
'choices' => $this->get_term_lists( $instance, false ),
|
||||
),
|
||||
),
|
||||
),
|
||||
), 'genesis-widget-column-box-top' );
|
||||
|
||||
<p>
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'taxonomy' ) ); ?>"><?php esc_attr_e( 'Taxonomy:', 'display-featured-image-genesis' ); ?> </label>
|
||||
<select id="<?php echo esc_attr( $this->get_field_id( 'taxonomy' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'taxonomy' ) ); ?>" onchange="term_postback('<?php echo esc_attr( $this->get_field_id( 'term' ) ); ?>', this.value);" >
|
||||
<?php
|
||||
$args = array(
|
||||
'public' => true,
|
||||
'show_ui' => true,
|
||||
);
|
||||
$taxonomies = get_taxonomies( $args, 'objects' );
|
||||
$form->do_boxes( array(
|
||||
'words' => array(
|
||||
array(
|
||||
'method' => 'checkbox',
|
||||
'args' => array(
|
||||
'id' => 'show_title',
|
||||
'label' => __( 'Show Term Title', 'display-featured-image-genesis' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'method' => 'checkbox',
|
||||
'args' => array(
|
||||
'id' => 'show_content',
|
||||
'label' => __( 'Show Term Intro Text', 'display-featured-image-genesis' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
) );
|
||||
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
echo '<option value="' . esc_attr( $taxonomy->name ) . '"' . selected( esc_attr( $taxonomy->name ), $instance['taxonomy'], false ) . '>' . esc_attr( $taxonomy->label ) . '</option>';
|
||||
} ?>
|
||||
</select>
|
||||
</p>
|
||||
echo '</div>';
|
||||
echo '<div class="genesis-widget-column genesis-widget-column-right">';
|
||||
|
||||
<p>
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'term' ) ); ?>"><?php esc_attr_e( 'Term:', 'display-featured-image-genesis' ); ?> </label>
|
||||
<select id="<?php echo esc_attr( $this->get_field_id( 'term' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'term' ) ); ?>" >
|
||||
<?php
|
||||
$args = array(
|
||||
'orderby' => 'name',
|
||||
'order' => 'ASC',
|
||||
'hide_empty' => false,
|
||||
);
|
||||
$terms = get_terms( $instance['taxonomy'], $args );
|
||||
echo '<option value="none"' . selected( 'none', $instance['term'], false ) . '>--</option>';
|
||||
foreach ( $terms as $term ) {
|
||||
echo '<option value="' . esc_attr( $term->term_id ) . '"' . selected( esc_attr( $term->term_id ), $instance['term'], false ) . '>' . esc_attr( $term->name ) . '</option>';
|
||||
} ?>
|
||||
</select>
|
||||
</p>
|
||||
$form->do_boxes( array(
|
||||
'image' => array(
|
||||
array(
|
||||
'method' => 'checkbox',
|
||||
'args' => array(
|
||||
'id' => 'show_image',
|
||||
'label' => __( 'Show Featured Image', 'display-featured-image-genesis' ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'method' => 'select',
|
||||
'args' => array(
|
||||
'id' => 'image_size',
|
||||
'label' => __( 'Image Size:', 'display-featured-image-genesis' ),
|
||||
'flex' => true,
|
||||
'choices' => $form->get_image_size(),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'method' => 'select',
|
||||
'args' => array(
|
||||
'id' => 'image_alignment',
|
||||
'label' => __( 'Image Alignment', 'display-featured-image-genesis' ),
|
||||
'flex' => true,
|
||||
'choices' => array(
|
||||
'alignnone' => __( 'None', 'display-featured-image-genesis' ),
|
||||
'alignleft' => __( 'Left', 'display-featured-image-genesis' ),
|
||||
'alignright' => __( 'Right', 'display-featured-image-genesis' ),
|
||||
'aligncenter' => __( 'Center', 'display-featured-image-genesis' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
), 'genesis-widget-column-box-top' );
|
||||
|
||||
</div>
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
<div class="genesis-widget-column-box">
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function get_taxonomies() {
|
||||
$args = array(
|
||||
'public' => true,
|
||||
'show_ui' => true,
|
||||
);
|
||||
$taxonomies = get_taxonomies( $args, 'objects' );
|
||||
$options = array();
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
$options[ $taxonomy->name ] = $taxonomy->label;
|
||||
}
|
||||
|
||||
<p>
|
||||
<input id="<?php echo esc_attr( $this->get_field_id( 'show_title' ) ); ?>" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_title' ) ); ?>" value="1" <?php checked( $instance['show_title'] ); ?>/>
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'show_title' ) ); ?>"><?php esc_attr_e( 'Show Term Title', 'display-featured-image-genesis' ); ?></label>
|
||||
</p>
|
||||
return $options;
|
||||
}
|
||||
|
||||
<p>
|
||||
<input id="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_content' ) ); ?>" value="1" <?php checked( $instance['show_content'] ); ?>/>
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'show_content' ) ); ?>"><?php esc_attr_e( 'Show Term Intro Text', 'display-featured-image-genesis' ); ?></label>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="genesis-widget-column genesis-widget-column-right">
|
||||
|
||||
<div class="genesis-widget-column-box genesis-widget-column-box-top">
|
||||
|
||||
<p>
|
||||
<input id="<?php echo esc_attr( $this->get_field_id( 'show_image' ) ); ?>" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'show_image' ) ); ?>" value="1" <?php checked( $instance['show_image'] ); ?>/>
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'show_image' ) ); ?>"><?php esc_attr_e( 'Show Featured Image', 'display-featured-image-genesis' ); ?></label>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'image_size' ) ); ?>"><?php esc_attr_e( 'Image Size:', 'display-featured-image-genesis' ); ?> </label>
|
||||
<select id="<?php echo esc_attr( $this->get_field_id( 'image_size' ) ); ?>" class="genesis-image-size-selector" name="<?php echo esc_attr( $this->get_field_name( 'image_size' ) ); ?>">
|
||||
<?php
|
||||
$sizes = genesis_get_image_sizes();
|
||||
foreach ( (array) $sizes as $name => $size ) {
|
||||
printf( '<option value="%s"%s>%s ( %s x %s )</option>', esc_attr( $name ), selected( $name, $instance['image_size'], false ), esc_html( $name ), (int) $size['width'], (int) $size['height'] );
|
||||
} ?>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'image_alignment' ) ); ?>"><?php esc_attr_e( 'Image Alignment:', 'display-featured-image-genesis' ); ?></label>
|
||||
<select id="<?php echo esc_attr( $this->get_field_id( 'image_alignment' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'image_alignment' ) ); ?>">
|
||||
<option value="alignnone">- <?php esc_attr_e( 'None', 'display-featured-image-genesis' ); ?> -</option>
|
||||
<option value="alignleft" <?php selected( 'alignleft', $instance['image_alignment'] ); ?>><?php esc_attr_e( 'Left', 'display-featured-image-genesis' ); ?></option>
|
||||
<option value="alignright" <?php selected( 'alignright', $instance['image_alignment'] ); ?>><?php esc_attr_e( 'Right', 'display-featured-image-genesis' ); ?></option>
|
||||
<option value="aligncenter" <?php selected( 'aligncenter', $instance['image_alignment'] ); ?>><?php esc_attr_e( 'Center', 'display-featured-image-genesis' ); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?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 ? sanitize_text_field( $_POST['taxonomy'] ) : $instance['taxonomy'];
|
||||
$terms = get_terms( $taxonomy, $args );
|
||||
$options['none'] = '--';
|
||||
foreach ( $terms as $term ) {
|
||||
if ( is_object( $term ) ) {
|
||||
$options[ $term->term_id ] = $term->name;
|
||||
}
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,26 +314,10 @@ class Display_Featured_Image_Genesis_Widget_Taxonomy extends WP_Widget {
|
||||
*/
|
||||
function term_action_callback() {
|
||||
|
||||
$args = array(
|
||||
'orderby' => 'name',
|
||||
'order' => 'ASC',
|
||||
'hide_empty' => false,
|
||||
);
|
||||
$terms = get_terms( $_POST['taxonomy'], $args );
|
||||
|
||||
// Build an appropriate JSON response containing this info
|
||||
$list['none'] = '--';
|
||||
foreach ( $terms as $term ) {
|
||||
$list[ $term->term_id ] = esc_attr( $term->name );
|
||||
}
|
||||
$list = $this->get_term_lists( array(), true );
|
||||
|
||||
// And emit it
|
||||
$emit = json_encode( $list );
|
||||
if ( function_exists( 'wp_json_encode' ) ) {
|
||||
$emit = wp_json_encode( $list );
|
||||
}
|
||||
echo $emit;
|
||||
echo wp_json_encode( $list );
|
||||
die();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user