From 7ba7224246e51cc7fa8e18200f29bb2789e7aeb8 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Mon, 13 Nov 2017 11:09:20 -0500 Subject: [PATCH] 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) --- ...ass-displayfeaturedimagegenesis-common.php | 18 ++++- ...ass-displayfeaturedimagegenesis-output.php | 2 +- ...s-displayfeaturedimagegenesis-postmeta.php | 76 ++++++++++++++++--- 3 files changed, 83 insertions(+), 13 deletions(-) diff --git a/includes/class-displayfeaturedimagegenesis-common.php b/includes/class-displayfeaturedimagegenesis-common.php index c74967a..518de02 100644 --- a/includes/class-displayfeaturedimagegenesis-common.php +++ b/includes/class-displayfeaturedimagegenesis-common.php @@ -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; + } } diff --git a/includes/class-displayfeaturedimagegenesis-output.php b/includes/class-displayfeaturedimagegenesis-output.php index b1e3926..b3a7f9b 100644 --- a/includes/class-displayfeaturedimagegenesis-output.php +++ b/includes/class-displayfeaturedimagegenesis-output.php @@ -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; } diff --git a/includes/class-displayfeaturedimagegenesis-postmeta.php b/includes/class-displayfeaturedimagegenesis-postmeta.php index 26a9ef3..3f82fa9 100644 --- a/includes/class-displayfeaturedimagegenesis-postmeta.php +++ b/includes/class-displayfeaturedimagegenesis-postmeta.php @@ -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( '

%1$s

'; + + 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'] ] ) ); + } } /**