mirror of
https://github.com/10h30/display-featured-image-genesis.git
synced 2026-07-18 14:03:20 +09:00
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:
@@ -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'] ] ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user