Update CPT image settings

This commit is contained in:
Robin Cornett
2017-10-25 13:57:19 -04:00
parent 776aa0d192
commit 9fa9d96773
2 changed files with 39 additions and 51 deletions
@@ -2,7 +2,7 @@
/**
* Class Display_Featured_Image_Genesis_Settings_Define
* @package DisplayFeaturedImageGenesis
* @package DisplayFeaturedImageGenesis
* @copyright 2017 Robin Cornett
*/
class Display_Featured_Image_Genesis_Settings_Define extends Display_Featured_Image_Genesis_Helper {
@@ -183,20 +183,6 @@ class Display_Featured_Image_Genesis_Settings_Define extends Display_Featured_Im
*/
protected function define_cpt_fields() {
$fields = array(
array(
'id' => 'post_types][search',
'title' => __( 'Search Results', 'display-featured-image-genesis' ),
'callback' => 'set_cpt_image',
'section' => 'cpt',
'post_type' => 'search',
),
array(
'id' => 'post_types][fourohfour',
'title' => __( '404 Page', 'display-featured-image-genesis' ),
'callback' => 'set_cpt_image',
'section' => 'cpt',
'post_type' => 'fourohfour',
),
array(
'id' => 'skip',
'title' => __( 'Skip Content Types', 'display-featured-image-genesis' ),
@@ -206,22 +192,23 @@ class Display_Featured_Image_Genesis_Settings_Define extends Display_Featured_Im
),
);
$post_types = $this->get_post_types();
if ( $post_types ) {
$show_on_front = get_option( 'show_on_front' );
$posts_page = get_option( 'page_for_posts' );
if ( 'page' === $show_on_front && $posts_page ) {
unset( $post_types['post'] );
}
foreach ( $post_types as $post_type => $label ) {
$fields[] = array(
'id' => 'post_types][' . esc_attr( $post_type ),
'title' => esc_attr( $label ),
'callback' => 'set_cpt_image',
'section' => 'cpt',
'post_type' => $post_type,
);
}
$custom_pages = array(
'search' => __( 'Search Results', 'display-featured-image-genesis' ),
'fourohfour' => __( '404 Page', 'display-featured-image-genesis' ),
);
$post_types = array_merge( $custom_pages, $this->get_post_types() );
$show_on_front = get_option( 'show_on_front' );
$posts_page = get_option( 'page_for_posts' );
if ( 'page' === $show_on_front && $posts_page ) {
unset( $post_types['post'] );
}
foreach ( $post_types as $post_type => $label ) {
$fields[] = array(
'id' => esc_attr( $post_type ),
'title' => esc_attr( $label ),
'callback' => 'set_cpt_image',
'section' => 'cpt',
);
}
return $fields;
@@ -219,41 +219,42 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
* Custom Post Type image uploader
*
* @since 2.0.0
*
* @param $args
*/
public function set_cpt_image( $args ) {
$post_type = is_object( $args['post_type'] ) ? $args['post_type']->name : $args['post_type'];
if ( empty( $this->setting['post_type'][ $post_type ] ) ) {
$this->setting['post_type'][ $post_type ] = $id = '';
$id = isset( $this->setting['post_type'][ $args['id'] ] ) && $this->setting['post_type'][ $args['id'] ] ? $this->setting['post_type'][ $args['id'] ] : '';
$name = 'displayfeaturedimagegenesis[post_type][' . esc_attr( $args['id'] ) . ']';
if ( $id ) {
echo wp_kses_post( $this->render_image_preview( $id, $args['id'] ) );
}
if ( is_object( $args['post_type'] ) ) {
$this->render_buttons( $id, $name );
if ( ! in_array( $args['id'], array( 'search', 'fourohfour' ), true ) ) {
$fallback_args = array(
'id' => "fallback][{$post_type}",
'id' => "fallback][{$args['id']}",
/* translators: placeholder is the post type label. */
'label' => sprintf( __( 'Always use a fallback image for %s.', 'display-featured-image-genesis' ), esc_attr( $args['post_type']->label ) ),
'label' => sprintf( __( 'Always use a fallback image for %s.', 'display-featured-image-genesis' ), esc_attr( $args['title'] ) ),
'setting_name' => 'fallback',
'name' => $post_type,
'name' => $args['id'],
);
echo '<p>';
$this->do_checkbox( $fallback_args );
echo '</p>';
}
$id = $this->setting['post_type'][ $post_type ];
$name = 'displayfeaturedimagegenesis[post_type][' . esc_attr( $post_type ) . ']';
if ( $id ) {
echo wp_kses_post( $this->render_image_preview( $id, $post_type ) );
if ( empty( $id ) || in_array( $args['id'], array( 'search', 'fourohfour', 'post' ), true ) ) {
return;
}
$this->render_buttons( $id, $name );
if ( empty( $id ) || ! is_object( $args['post_type'] ) ) {
$archive_link = get_post_type_archive_link( $args['id'] );
if ( ! $archive_link ) {
return;
}
/* translators: placeholder is the post type name. */
$description = sprintf( __( 'View your <a href="%1$s" target="_blank">%2$s</a> archive.', 'display-featured-image-genesis' ),
esc_url( get_post_type_archive_link( $post_type ) ),
esc_attr( $args['post_type']->label )
esc_url( $archive_link ),
esc_attr( $args['title'] )
);
printf( '<p class="description">%s</p>', wp_kses_post( $description ) );
}
@@ -269,8 +270,8 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
*/
public function do_validation_things( $new_value ) {
$action = 'displayfeaturedimagegenesis_save-settings';
$nonce = 'displayfeaturedimagegenesis_nonce';
$action = $this->page . '_save-settings';
$nonce = $this->page . '_nonce';
// If the user doesn't have permission to save, then display an error message
if ( ! $this->user_can_save( $action, $nonce ) ) {
wp_die( esc_attr__( 'Something unexpected happened. Please try again.', 'display-featured-image-genesis' ) );
@@ -294,7 +295,7 @@ class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Gen
* @since 2.4.0
*/
protected function terms_have_been_updated() {
$updated = get_option( 'displayfeaturedimagegenesis_updatedterms', false );
$updated = get_option( $this->page . '_updatedterms', false );
return (bool) $updated;
}