Change post_meta disable

Initial work to change `_displayfeaturedimagegenesis_disable` to a select with image size options instead of being a checkbox. Options will be:
* 0: default (consistent with checkbox)
* 1: disable (consistent with checkbox)
* 2: backstretch (new)
* 3: large (new)
This commit is contained in:
Robin Cornett
2017-11-13 11:09:20 -05:00
parent ce25026ae0
commit 7ba7224246
3 changed files with 83 additions and 13 deletions
@@ -366,17 +366,29 @@ class Display_Featured_Image_Genesis_Common {
*/
public static function image_size() {
$image_size = 'displayfeaturedimage_backstretch';
$setting = displayfeaturedimagegenesis_get_setting();
$post_type = get_post_type();
$post_meta = (int) get_post_meta( get_the_ID(), '_displayfeaturedimagegenesis_disable', true );
if ( 2 === $post_meta ) {
return $image_size;
}
/**
* Creates display_featured_image_genesis_use_large_image filter to check
* whether get_post_type array should use large image instead of backstretch.
* @uses is_in_array()
*/
if ( self::is_in_array( 'use_large_image' ) || ( is_singular() && isset( $setting['large'][ $post_type ] ) && $setting['large'][ $post_type ] ) ) {
if ( self::is_in_array( 'use_large_image' ) || self::get_singular_image_size() ) {
return 'large';
}
return apply_filters( 'displayfeaturedimagegenesis_image_size', $image_size );
}
protected static function get_singular_image_size() {
if ( ! is_singular() ) {
return false;
}
$setting = displayfeaturedimagegenesis_get_setting();
$post_type = get_post_type();
$post_meta = (int) get_post_meta( get_the_ID(), '_displayfeaturedimagegenesis_disable', true );
return ( isset( $setting['large'][ $post_type ] ) && $setting['large'][ $post_type ] ) || 3 === $post_meta;
}
}
@@ -350,7 +350,7 @@ class Display_Featured_Image_Genesis_Output {
$post_type = get_post_type();
$skip_singular = is_singular() && isset( $this->setting['skip'][ $post_type ] ) && $this->setting['skip'][ $post_type ] ? true : false;
if ( $this->get_skipped_posttypes() || $skip_singular || $exclude_front || $this->check_post_meta( '_displayfeaturedimagegenesis_disable' ) ) {
if ( $this->get_skipped_posttypes() || $skip_singular || $exclude_front || 1 === (int) $this->check_post_meta( '_displayfeaturedimagegenesis_disable' ) ) {
$disable = true;
}
@@ -25,13 +25,26 @@ class Display_Featured_Image_Genesis_Post_Meta {
/**
* Build the metabox with the checkbox setting.
* @since 2.5.0
*
* @param $content
* @param $post_id
*
* @return string
*/
public function meta_box( $content, $post_id ) {
$output = wp_nonce_field( 'displayfeaturedimagegenesis_post_save', 'displayfeaturedimagegenesis_post_nonce', true, false );
$output = wp_nonce_field( 'displayfeaturedimagegenesis_post_save', 'displayfeaturedimagegenesis_post_nonce', true, false );
$select = $this->get_select();
if ( $select ) {
foreach ( $select as $s ) {
$output .= $this->do_select( $s, $post_id );
}
}
$checkboxes = $this->get_checkboxes();
foreach ( $checkboxes as $checkbox ) {
$output .= $this->do_checkbox( $checkbox, $post_id );
if ( $checkboxes ) {
foreach ( $checkboxes as $checkbox ) {
$output .= $this->do_checkbox( $checkbox, $post_id );
}
}
return $output . $content;
@@ -43,12 +56,7 @@ class Display_Featured_Image_Genesis_Post_Meta {
* @since 2.5.2
*/
protected function get_checkboxes() {
$checkboxes = array(
array(
'setting' => $this->disable,
'label' => __( 'Don\'t show the featured image on this post', 'display-featured-image-genesis' ),
),
);
$checkboxes = array();
$setting = displayfeaturedimagegenesis_get_setting();
if ( ! $setting['keep_titles'] ) {
$checkboxes[] = array(
@@ -59,10 +67,31 @@ class Display_Featured_Image_Genesis_Post_Meta {
return $checkboxes;
}
/**
* @return array
*/
protected function get_select() {
return array(
array(
'setting' => $this->disable,
'label' => __( 'Featured Image Size:', 'display-featured-image-genesis' ),
'options' => array(
0 => __( 'Content type default', 'display-featured-image-genesis' ),
1 => __( 'Don\'t display the featured image', 'display-featured-image-genesis' ),
2 => __( 'Use a backstretch image if it exists', 'display-featured-image-genesis' ),
3 => __( 'Use a large (not backstretch) image', 'display-featured-image-genesis' ),
),
),
);
}
/**
* Generic function to add a post_meta checkbox
*
* @param $args array includes setting and label
*
* @param $post_id
*
* @return string checkbox label/input
* @since 2.5.2
*/
@@ -77,6 +106,30 @@ class Display_Featured_Image_Genesis_Post_Meta {
return $output;
}
/**
* @param $args
* @param $post_id
*
* @return string
*/
protected function do_select( $args, $post_id ) {
$value = get_post_meta( $post_id, $args['setting'], true );
$output = sprintf( '<p>%1$s<select id="%2$s" name="%2$s">',
esc_attr( $args['label'] ),
esc_attr( $args['setting'] )
);
foreach ( (array) $args['options'] as $option => $field_label ) {
$output .= sprintf( '<option value="%s" %s>%s</option>',
esc_attr( $option ),
selected( $option, $value, false ),
esc_attr( $field_label )
);
}
$output .= '</select></p>';
return $output;
}
/**
* Update the post meta.
* @param $post_id
@@ -107,6 +160,11 @@ class Display_Featured_Image_Genesis_Post_Meta {
delete_post_meta( $post_id, $checkbox['setting'] );
}
}
$select = $this->get_select();
foreach ( $select as $s ) {
update_post_meta( $post_id, $s['setting'], (int) ( $_POST[ $s['setting'] ] ) );
}
}
/**