mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-06-05 15:08:20 +09:00
Add fallback setting for custom content types
This commit is contained in:
@@ -160,11 +160,13 @@ class Display_Featured_Image_Genesis_Common {
|
||||
}
|
||||
}
|
||||
|
||||
$thumb_metadata = wp_get_attachment_metadata( get_post_thumbnail_id( get_the_ID() ) ); // needed only for the next line
|
||||
$width = $thumb_metadata ? $thumb_metadata['width'] : '';
|
||||
$medium = (int) apply_filters( 'displayfeaturedimagegenesis_set_medium_width', get_option( 'medium_size_w' ) );
|
||||
if ( has_post_thumbnail() && $width > $medium ) {
|
||||
$image_id = get_post_thumbnail_id( get_the_ID() );
|
||||
if ( isset( $setting['fallback'][ $post_type ] ) && ! $setting['fallback'][ $post_type ] ) {
|
||||
$thumb_metadata = wp_get_attachment_metadata( get_post_thumbnail_id( get_the_ID() ) ); // needed only for the next line
|
||||
$width = $thumb_metadata ? $thumb_metadata['width'] : '';
|
||||
$medium = (int) apply_filters( 'displayfeaturedimagegenesis_set_medium_width', get_option( 'medium_size_w' ) );
|
||||
if ( has_post_thumbnail() && $width > $medium ) {
|
||||
$image_id = get_post_thumbnail_id( get_the_ID() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -89,16 +89,35 @@ class Display_Featured_Image_Genesis_Helper {
|
||||
* @since 2.3.0
|
||||
*/
|
||||
public function do_checkbox( $args ) {
|
||||
$setting = isset( $this->displaysetting[ $args['setting'] ] ) ? $this->displaysetting[ $args['setting'] ] : 0;
|
||||
printf( '<input type="hidden" name="displayfeaturedimagegenesis[%s]" value="0" />', esc_attr( $args['setting'] ) );
|
||||
printf( '<label for="displayfeaturedimagegenesis[%1$s]"><input type="checkbox" name="displayfeaturedimagegenesis[%1$s]" id="displayfeaturedimagegenesis[%1$s]" value="1" %2$s class="code" />%3$s</label>',
|
||||
echo '<p>';
|
||||
$setting = $this->get_checkbox_setting( $args );
|
||||
printf( '<input type="hidden" name="%s[%s]" value="0" />', esc_attr( $this->page ), esc_attr( $args['setting'] ) );
|
||||
printf( '<label for="%4$s[%1$s]"><input type="checkbox" name="%4$s[%1$s]" id="%4$s[%1$s]" value="1" %2$s class="code" />%3$s</label>',
|
||||
esc_attr( $args['setting'] ),
|
||||
checked( 1, esc_attr( $setting ), false ),
|
||||
esc_attr( $args['label'] )
|
||||
esc_attr( $args['label'] ),
|
||||
esc_attr( $this->page )
|
||||
);
|
||||
echo '</p>';
|
||||
$this->do_description( $args['setting'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current value for the checkbox.
|
||||
* @param $args
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function get_checkbox_setting( $args ) {
|
||||
$setting = isset( $this->setting[ $args['setting'] ] ) ? $this->setting[ $args['setting'] ] : 0;
|
||||
if ( isset( $args['setting_name'] ) ) {
|
||||
if ( isset( $this->setting[ $args['setting_name'] ][ $args['name'] ] ) ) {
|
||||
$setting = $this->setting[ $args['setting_name'] ][ $args['name'] ];
|
||||
}
|
||||
}
|
||||
return $setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic callback to display a field description.
|
||||
* @param string $args setting name used to identify description callback
|
||||
|
||||
@@ -324,6 +324,15 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
$this->setting['post_type'][ $post_type ] = $id = '';
|
||||
}
|
||||
|
||||
if ( is_object( $args['post_type'] ) ) {
|
||||
$fallback_args = array(
|
||||
'setting' => "fallback][{$post_type}",
|
||||
'label' => sprintf( __( 'Always use a fallback image for %s.', 'display-featured-image-genesis' ), esc_attr( $args['post_type']->label ) ),
|
||||
'setting_name' => 'fallback',
|
||||
'name' => $post_type,
|
||||
);
|
||||
$this->do_checkbox( $fallback_args );
|
||||
}
|
||||
$id = $this->setting['post_type'][ $post_type ];
|
||||
$name = 'displayfeaturedimagegenesis[post_type][' . esc_attr( $post_type ) . ']';
|
||||
if ( $id ) {
|
||||
@@ -393,6 +402,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
|
||||
|
||||
// sanitize
|
||||
$new_value['post_type'][ $object->name ] = $this->validate_image( $new_value['post_type'][ $object->name ], $old_value, $label, $size_to_check );
|
||||
$new_value['fallback'][ $object->name ] = $this->one_zero( $new_value['fallback'][ $object->name ] );
|
||||
}
|
||||
|
||||
return $new_value;
|
||||
|
||||
Reference in New Issue
Block a user