diff --git a/includes/class-displayfeaturedimagegenesis.php b/includes/class-displayfeaturedimagegenesis.php index d2301a6..afadc01 100644 --- a/includes/class-displayfeaturedimagegenesis.php +++ b/includes/class-displayfeaturedimagegenesis.php @@ -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 */ diff --git a/includes/widgets/admin/checkbox.php b/includes/widgets/admin/checkbox.php new file mode 100644 index 0000000..3b707b3 --- /dev/null +++ b/includes/widgets/admin/checkbox.php @@ -0,0 +1,8 @@ +parent->defaults[ $args['id'] ]; +echo '
'; +printf( '', esc_attr( $this->parent->get_field_name( $args['id'] ) ) ); +printf( '', 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( '', esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $args['label'] ) ); +echo '
'; diff --git a/includes/widgets/admin/number.php b/includes/widgets/admin/number.php new file mode 100644 index 0000000..f5aa788 --- /dev/null +++ b/includes/widgets/admin/number.php @@ -0,0 +1,8 @@ +', wp_kses( $flex, array( 'class' ) ) ); +printf( '', esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $args['label'] ) ); +printf( '%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 ''; diff --git a/includes/widgets/admin/select.php b/includes/widgets/admin/select.php new file mode 100644 index 0000000..8113738 --- /dev/null +++ b/includes/widgets/admin/select.php @@ -0,0 +1,15 @@ +', wp_kses( $flex, array( 'class' ) ) ); +printf( '', esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $args['label'] ) ); +printf( ''; +echo ''; diff --git a/includes/widgets/admin/text.php b/includes/widgets/admin/text.php new file mode 100644 index 0000000..f367361 --- /dev/null +++ b/includes/widgets/admin/text.php @@ -0,0 +1,8 @@ +'; +printf( '', esc_attr( $this->parent->get_field_id( $args['id'] ) ), $label_class, esc_attr( $args['label'] ) ); +printf( '', 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 ''; diff --git a/includes/widgets/admin/textarea.php b/includes/widgets/admin/textarea.php new file mode 100644 index 0000000..939c616 --- /dev/null +++ b/includes/widgets/admin/textarea.php @@ -0,0 +1,7 @@ +'; +$rows = isset( $args['rows'] ) ? $args['rows'] : 3; +printf( '', esc_attr( $this->parent->get_field_id( $args['id'] ) ), esc_attr( $args['label'] ) ); +printf( '', 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 ''; diff --git a/includes/widgets/class-displayfeaturedimagegenesis-widgets.php b/includes/widgets/class-displayfeaturedimagegenesis-widgets.php new file mode 100644 index 0000000..c235799 --- /dev/null +++ b/includes/widgets/class-displayfeaturedimagegenesis-widgets.php @@ -0,0 +1,126 @@ +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( '- - -
+ $form->do_text( $instance, array( + 'id' => 'title', + 'label' => __( 'Title:', 'display-featured-image-genesis' ), + 'class' => 'widefat', + ) ); - - - - '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(); } - }