diff --git a/.gitignore b/.gitignore index aafa768..11f7ff4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -Thumbs.db \ No newline at end of file +Thumbs.db +languages/display-featured-image-genesis.mo diff --git a/includes/class-displayfeaturedimagegenesis-common.php b/includes/class-displayfeaturedimagegenesis-common.php index c8cda2d..eeacdb3 100644 --- a/includes/class-displayfeaturedimagegenesis-common.php +++ b/includes/class-displayfeaturedimagegenesis-common.php @@ -64,9 +64,8 @@ class Display_Featured_Image_Genesis_Common { elseif ( is_post_type_archive() ) { $object = get_queried_object(); $post_type = $object->name; - $meta = get_option( 'displayfeaturedimagegenesis-cpt' ); - if ( isset( $meta[$post_type] ) ) { - $image_id = self::get_image_id( $meta[$post_type] ); + if ( isset( $displaysetting['post_type'][$post_type] ) ) { + $image_id = self::get_image_id( $displaysetting['post_type'][$post_type] ); } } // taxonomy diff --git a/includes/class-displayfeaturedimagegenesis-customposttypes.php b/includes/class-displayfeaturedimagegenesis-customposttypes.php deleted file mode 100644 index d55e876..0000000 --- a/includes/class-displayfeaturedimagegenesis-customposttypes.php +++ /dev/null @@ -1,126 +0,0 @@ - true, - '_builtin' => false, - 'has_archive' => true, - ); - $output = 'names'; - - $post_types = get_post_types( $args, $output ); - - foreach ( $post_types as $post_type ) { - add_submenu_page( - "edit.php?post_type=$post_type", - __( 'Featured Image', 'display-featured-image-genesis' ), - __( 'Featured Image', 'display-featured-image-genesis' ), - 'manage_categories', - "displayfeaturedimagegenesis-$post_type", - array( $this, 'do_settings_form' ) - ); - - register_setting( 'displayfeaturedimagegenesis_cpt', 'displayfeaturedimagegenesis-cpt' /*, array( $this, 'do_validation_things' )*/ ); - - } - - add_action( 'admin_init', array( $this, 'settings' ) ); - - } - - /** - * create CPT settings form - * @return form Display Featured Image for Genesis for CPT - * - * @since x.y.z - */ - public function do_settings_form() { - $page_title = get_admin_page_title(); - - echo '
' . sprintf( - __( 'You may optionally set a featured image for the %s archive to use.', 'display-featured-image-genesis' ), - $post_type - ) . '
'; - - } - - /** - * Default image uploader - * - * @return image - * - * @since 1.2.1 - */ - public function set_cpt_image() { - - $item = Display_Featured_Image_Genesis_Common::get_image_variables(); - $screen = get_current_screen(); - $post_type = $screen->post_type; - $setting = get_option( 'displayfeaturedimagegenesis-cpt' ); - - if ( empty( $setting[$post_type] ) ) { - $setting[$post_type] = ''; - } - if ( ! empty( $setting[$post_type] ) ) { - $id = Display_Featured_Image_Genesis_Common::get_image_id( $setting[$post_type] ); - $preview = wp_get_attachment_image_src( $id, 'medium' ); - echo '' . sprintf( - __( 'If you would like to use a featured image for the custom post type archive, upload it here. Must be at least %1$s pixels wide.', 'display-featured-image-genesis' ), - absint( $item->large + 1 ) - ) . '
'; - - } - -} diff --git a/includes/class-displayfeaturedimagegenesis-settings.php b/includes/class-displayfeaturedimagegenesis-settings.php index 8a5c8a5..8766cfd 100644 --- a/includes/class-displayfeaturedimagegenesis-settings.php +++ b/includes/class-displayfeaturedimagegenesis-settings.php @@ -15,6 +15,10 @@ class Display_Featured_Image_Genesis_Settings { */ protected $displaysetting; + protected $post_types; + + public $post_type; + /** * add a submenu page under Appearance * @return submenu Display Featured image settings page @@ -132,6 +136,40 @@ class Display_Featured_Image_Genesis_Settings { 'display_featured_image_section' ); + $args = array( + 'public' => true, + '_builtin' => false, + 'has_archive' => true, + ); + $output = 'objects'; + + $this->post_types = get_post_types( $args, $output ); + + if ( $this->post_types ) { + add_settings_section( + 'display_featured_image_custom_post_types', + __( 'CPT Featured Images', 'display-featured-image-genesis' ), + array( $this, 'cpt_section_description' ), + 'displayfeaturedimagegenesis' + ); + + // foreach ( $this->post_types as $post_type ) { + + add_settings_field( + "displayfeaturedimagegenesis[post_types]", + __( ' Featured Image', 'display-featured-image-genesis' ), + array( $this, 'set_cpt_image' ), + 'displayfeaturedimagegenesis', + 'display_featured_image_custom_post_types' + // array( 'label for' => 'displayfeaturedimagegenesis' . $post_type->name ) + ); + + // $this->post_type = $post_type->name; + + // } + + } + } /** @@ -144,6 +182,16 @@ class Display_Featured_Image_Genesis_Settings { echo '' . __( 'The Display Featured Image for Genesis plugin has just a few optional settings. Check the Help tab for more information. ', 'display-featured-image-genesis' ) . '
'; } + /** + * Section description + * @return section description + * + * @since 1.1.0 + */ + public function cpt_section_description() { + echo '' . __( 'Since you have custom post types with archives, you might like to set a featured image for each of them.', 'display-featured-image-genesis' ) . '
'; + } + /** * Setting for reduction amount * @return number of pixels to remove in backstretch-set.js @@ -175,7 +223,7 @@ class Display_Featured_Image_Genesis_Settings { echo '' . sprintf( __( 'If you would like to use a default image for the featured image, upload it here. Must be at least %1$s pixels wide.', 'display-featured-image-genesis' ), @@ -183,6 +231,42 @@ class Display_Featured_Image_Genesis_Settings { ) . '
'; } + /** + * Default image uploader + * + * @return image + * + * @since 1.2.1 + */ + public function set_cpt_image() { + + $item = Display_Featured_Image_Genesis_Common::get_image_variables(); + + foreach ( $this->post_types as $post_type ) { + $post_type = $post_type->name; + if ( empty( $this->displaysetting['post_type'][$post_type] ) ) { + $this->displaysetting['post_type'][$post_type] = ''; + } + echo '' . sprintf( + __( 'If you would like to use a featured image for the %1$s archive, upload it here. Must be at least %2$s pixels wide.', 'display-featured-image-genesis' ), + $post_type, + absint( $item->large + 1 ) + ) . '
'; + + } + + } + /** * option to exclude featured image on front page * @return 0 1 checkbox @@ -254,6 +338,10 @@ class Display_Featured_Image_Genesis_Settings { $new_value['feed_image'] = $this->one_zero( $new_value['feed_image'] ); + foreach ( $this->post_types as $post_type ) { + $new_value['post_type'][$post_type->name] = $this->validate_image( $new_value['post_type'][$post_type->name] ); + } + return $new_value; } diff --git a/includes/js/settings-upload.js b/includes/js/settings-upload.js index bb409d4..db3708d 100644 --- a/includes/js/settings-upload.js +++ b/includes/js/settings-upload.js @@ -2,7 +2,9 @@ jQuery(document).ready(function($){ var custom_uploader; - $('#upload_default_image').click(function(e) { + $('.upload_default_image').click(function(e) { + + var target_input = $(this).prev('.upload_image_url'); e.preventDefault(); @@ -24,7 +26,8 @@ jQuery(document).ready(function($){ //When a file is selected, grab the URL and set it as the text field's value custom_uploader.on('select', function() { attachment = custom_uploader.state().get('selection').first().toJSON(); - $('#default_image_url').val(attachment.url); + // $('input[name=' + target_input + ']').val(attachment.url); + $(target_input).val(attachment.url); }); //Open the uploader dialog @@ -32,4 +35,4 @@ jQuery(document).ready(function($){ }); -}); \ No newline at end of file +});