diff --git a/display-featured-image-genesis.php b/display-featured-image-genesis.php
index 8e4631f..9ab905e 100644
--- a/display-featured-image-genesis.php
+++ b/display-featured-image-genesis.php
@@ -31,6 +31,7 @@ if ( ! defined( 'DISPLAYFEATUREDIMAGEGENESIS_BASENAME' ) ) {
function display_featured_image_genesis_require() {
$files = array(
'class-displayfeaturedimagegenesis',
+ 'class-displayfeaturedimagegenesis-helper',
'class-displayfeaturedimagegenesis-admin',
'class-displayfeaturedimagegenesis-author',
'class-displayfeaturedimagegenesis-common',
@@ -48,6 +49,7 @@ function display_featured_image_genesis_require() {
display_featured_image_genesis_require();
// Instantiate dependent classes
+$displayfeaturedimagegenesis_helper = new Display_Featured_Image_Genesis_Helper();
$displayfeaturedimagegenesis_admin = new Display_Featured_Image_Genesis_Admin();
$displayfeaturedimagegenesis_author = new Display_Featured_Image_Genesis_Author();
$displayfeaturedimagegenesis_common = new Display_Featured_Image_Genesis_Common();
diff --git a/includes/class-displayfeaturedimagegenesis-author.php b/includes/class-displayfeaturedimagegenesis-author.php
index e2dcaae..679fcf2 100644
--- a/includes/class-displayfeaturedimagegenesis-author.php
+++ b/includes/class-displayfeaturedimagegenesis-author.php
@@ -1,6 +1,6 @@
name, $user->ID );
@@ -33,10 +33,10 @@ class Display_Featured_Image_Genesis_Author {
echo '
';
if ( $id ) {
- echo wp_kses_post( $this->settings->render_image_preview( $id ) );
+ echo wp_kses_post( $this->render_image_preview( $id ) );
}
- $this->settings->render_buttons( $id, $this->name );
+ $this->render_buttons( $id, $this->name );
echo ' Upload an image to use as your author page featured image. ';
echo ' | ';
echo '';
@@ -44,7 +44,7 @@ class Display_Featured_Image_Genesis_Author {
echo '';
}
- function save_profile_fields( $user_id ) {
+ public function save_profile_fields( $user_id ) {
if ( ! current_user_can( 'edit_user', $user_id ) ) {
return false;
@@ -57,10 +57,57 @@ class Display_Featured_Image_Genesis_Author {
$new_value = $_POST[ $this->name ];
$old_value = get_the_author_meta( $this->name, $user_id );
if ( $old_value !== $new_value ) {
- $new_value = $this->settings->validate_author_image( $new_value, $old_value );
+ $new_value = $this->validate_author_image( $new_value, $old_value );
update_user_meta( $user_id, $this->name, $new_value );
}
}
+ /**
+ * Returns old value for author image if not correct file type/size
+ * @param string $new_value New value
+ * @return string New value or old, depending on allowed image size.
+ * @since 2.3.0
+ */
+ public function validate_author_image( $new_value, $old_value ) {
+
+ $medium = get_option( 'medium_size_w' );
+ $source = wp_get_attachment_image_src( $new_value, 'full' );
+ $valid = $this->is_valid_img_ext( $source[0] );
+ $width = $source[1];
+
+ if ( ! $new_value || ( $new_value && $valid && $width > $medium ) ) {
+ return $new_value;
+ }
+
+ add_filter( 'user_profile_update_errors', array( $this, 'user_profile_error_message' ), 10, 3 );
+
+ return $old_value;
+
+ }
+
+ /**
+ * User profile error message
+ * @param var $errors error message depending on what's wrong
+ * @param var $update whether or not to update
+ * @param var $user user being updated
+ * @return error message
+ *
+ * @since 2.3.0
+ */
+ public function user_profile_error_message( $errors, $update, $user ) {
+ $new_value = (int) $_POST['displayfeaturedimagegenesis'];
+ $medium = get_option( 'medium_size_w' );
+ $source = wp_get_attachment_image_src( $new_value, 'full' );
+ $valid = $this->is_valid_img_ext( $source[0] );
+ $width = $source[1];
+ $reset = sprintf( __( ' The %s Featured Image has been reset to the last valid setting.', 'display-featured-image-genesis' ), $user->display_name );
+
+ if ( ! $valid ) {
+ $error = __( 'Sorry, that is an invalid file type.', 'display-featured-image-genesis' );
+ } elseif ( $width <= $medium ) {
+ $error = __( 'Sorry, your image is too small.', 'display-featured-image-genesis' );
+ }
+ $errors->add( 'profile_error', $error . $reset );
+ }
}
diff --git a/includes/class-displayfeaturedimagegenesis-helper.php b/includes/class-displayfeaturedimagegenesis-helper.php
new file mode 100644
index 0000000..640e7f4
--- /dev/null
+++ b/includes/class-displayfeaturedimagegenesis-helper.php
@@ -0,0 +1,255 @@
+
+ * @license GPL-2.0+
+ * @link http://robincornett.com
+ * @copyright 2014 Robin Cornett Creative, LLC
+ */
+
+class Display_Featured_Image_Genesis_Helper {
+
+ /**
+ * Generic function to add settings sections
+ *
+ * @since x.y.z
+ */
+ protected function add_sections( $sections ) {
+
+ foreach ( $sections as $section ) {
+ add_settings_section(
+ $section['id'],
+ $section['title'],
+ array( $this, $section['id'] . '_section_description' ),
+ $this->page
+ );
+ }
+ }
+
+ /**
+ * Generic function to add settings fields
+ * @param array $sections registered sections
+ * @return array all settings fields
+ *
+ * @since x.y.z
+ */
+ protected function add_fields( $fields, $sections ) {
+
+ foreach ( $fields as $field ) {
+ add_settings_field(
+ '[' . $field['id'] . ']',
+ sprintf( '', $field['id'], $field['title'] ),
+ array( $this, $field['callback'] ),
+ $this->page,
+ $sections[ $field['section'] ]['id'],
+ empty( $field['args'] ) ? array() : $field['args']
+ );
+ }
+
+ }
+
+ /**
+ * Echoes out the section description.
+ * @param string $description text string for description
+ * @return string as paragraph and escaped
+ *
+ * @since 2.3.0
+ */
+ protected function print_section_description( $description ) {
+ echo wp_kses_post( wpautop( $description ) );
+ }
+
+ /**
+ * Generic callback to create a number field setting.
+ *
+ * @since 2.3.0
+ */
+ public function do_number( $args ) {
+
+ printf( '', esc_attr( $this->page ),esc_attr( $args['setting'] ), esc_attr( $args['label'] ) );
+ printf( '',
+ (int) $args['min'],
+ (int) $args['max'],
+ esc_attr( $args['setting'] ),
+ esc_attr( $this->displaysetting[ $args['setting'] ] ),
+ esc_attr( $this->page )
+ );
+ $this->do_description( $args['setting'] );
+
+ }
+
+ /**
+ * generic checkbox function (for all checkbox settings)
+ * @return 0 1 checkbox
+ *
+ * @since 2.3.0
+ */
+ public function do_checkbox( $args ) {
+ printf( '', esc_attr( $args['setting'] ) );
+ printf( '',
+ esc_attr( $args['setting'] ),
+ checked( 1, esc_attr( $this->displaysetting[ $args['setting'] ] ), false ),
+ esc_attr( $args['label'] )
+ );
+ $this->do_description( $args['setting'] );
+ }
+
+ /**
+ * Generic callback to display a field description.
+ * @param string $args setting name used to identify description callback
+ * @return string Description to explain a field.
+ *
+ * @since 2.3.0
+ */
+ protected function do_description( $args ) {
+ $function = $args . '_description';
+ if ( ! method_exists( $this, $function ) ) {
+ return;
+ }
+ $description = $this->$function();
+ printf( '%s
', wp_kses_post( $description ) );
+ }
+
+ /**
+ * display image preview
+ * @param variable $id featured image ID
+ * @return $image image preview
+ *
+ * @since 2.3.0
+ */
+ public function render_image_preview( $id ) {
+ if ( empty( $id ) ) {
+ return;
+ }
+
+ $id = displayfeaturedimagegenesis_check_image_id( $id );
+ $preview = wp_get_attachment_image_src( (int) $id, 'medium' );
+ $image = sprintf( '', $preview[0] );
+ return $image;
+ }
+
+ /**
+ * show image select/delete buttons
+ * @param variable $id image ID
+ * @param varable $name name for value/ID/class
+ * @return $buttons select/delete image buttons
+ *
+ * @since 2.3.0
+ */
+ public function render_buttons( $id, $name ) {
+ $id = displayfeaturedimagegenesis_check_image_id( $id );
+ $id = $id ? (int) $id : '';
+ printf( '', esc_attr( $name ), esc_attr( $id ) );
+ printf( '',
+ esc_attr( $name ),
+ esc_attr__( 'Select Image', 'display-featured-image-genesis' )
+ );
+ if ( ! empty( $id ) ) {
+ printf( ' ',
+ esc_attr__( 'Delete Image', 'display-featured-image-genesis' )
+ );
+ }
+ }
+
+ /**
+ * Determines if the user has permission to save the information from the submenu
+ * page.
+ *
+ * @since 2.3.0
+ * @access protected
+ *
+ * @param string $action The name of the action specified on the submenu page
+ * @param string $nonce The nonce specified on the submenu page
+ *
+ * @return bool True if the user has permission to save; false, otherwise.
+ * @author Tom McFarlin (https://tommcfarlin.com/save-wordpress-submenu-page-options/)
+ */
+ protected function user_can_save( $action, $nonce ) {
+ $is_nonce_set = isset( $_POST[ $nonce ] );
+ $is_valid_nonce = false;
+
+ if ( $is_nonce_set ) {
+ $is_valid_nonce = wp_verify_nonce( $_POST[ $nonce ], $action );
+ }
+ return ( $is_nonce_set && $is_valid_nonce );
+ }
+
+ /**
+ * Returns previous value for image if not correct file type/size
+ * @param string $new_value New value
+ * @return string New or previous value, depending on allowed image size.
+ * @since 1.2.2
+ */
+ protected function validate_image( $new_value, $old_value, $label, $size_to_check ) {
+
+ $new_value = displayfeaturedimagegenesis_check_image_id( $new_value );
+ $old_value = displayfeaturedimagegenesis_check_image_id( $old_value );
+ $source = wp_get_attachment_image_src( $new_value, 'full' );
+ $valid = $this->is_valid_img_ext( $source[0] );
+ $width = $source[1];
+ $reset = sprintf( __( ' The %s Featured Image has been reset to the last valid setting.', 'display-featured-image-genesis' ), $label );
+
+ // ok for field to be empty
+ if ( ! $new_value ) {
+ return '';
+ }
+
+ if ( $valid && $width > $size_to_check ) {
+ return (int) $new_value;
+ }
+
+ $new_value = $old_value;
+ if ( ! $valid ) {
+ $message = __( 'Sorry, that is an invalid file type.', 'display-featured-image-genesis' );
+ $class = 'invalid';
+ } elseif ( $width <= $size_to_check ) {
+ $message = __( 'Sorry, your image is too small.', 'display-featured-image-genesis' );
+ $class = 'weetiny';
+ }
+
+ add_settings_error(
+ $old_value,
+ esc_attr( $class ),
+ esc_attr( $message . $reset ),
+ 'error'
+ );
+
+ return (int) $new_value;
+ }
+
+ /**
+ * returns file extension
+ * @since 1.2.2
+ */
+ protected function get_file_ext( $file ) {
+ $parsed = @parse_url( $file, PHP_URL_PATH );
+ return $parsed ? strtolower( pathinfo( $parsed, PATHINFO_EXTENSION ) ) : false;
+ }
+
+ /**
+ * check if file type is image
+ * @return file check file extension against list
+ * @since 1.2.2
+ */
+ protected function is_valid_img_ext( $file ) {
+ $file_ext = $this->get_file_ext( $file );
+
+ $is_valid_types = (array) apply_filters( 'displayfeaturedimage_valid_img_types', array( 'jpg', 'jpeg', 'png', 'gif' ) );
+
+ return ( $file_ext && in_array( $file_ext, $is_valid_types ) );
+ }
+
+ /**
+ * Returns a 1 or 0, for all truthy / falsy values.
+ *
+ * Uses double casting. First, we cast to bool, then to integer.
+ *
+ * @since 1.3.0
+ *
+ * @param mixed $new_value Should ideally be a 1 or 0 integer passed in
+ * @return integer 1 or 0.
+ */
+ protected function one_zero( $new_value ) {
+ return (int) (bool) $new_value;
+ }
+}
diff --git a/includes/class-displayfeaturedimagegenesis-settings.php b/includes/class-displayfeaturedimagegenesis-settings.php
index ecd6e21..faf47cb 100644
--- a/includes/class-displayfeaturedimagegenesis-settings.php
+++ b/includes/class-displayfeaturedimagegenesis-settings.php
@@ -7,7 +7,7 @@
* @copyright 2014 Robin Cornett Creative, LLC
*/
-class Display_Featured_Image_Genesis_Settings {
+class Display_Featured_Image_Genesis_Settings extends Display_Featured_Image_Genesis_Helper {
/**
* variable set for featured image option
@@ -31,7 +31,7 @@ class Display_Featured_Image_Genesis_Settings {
add_theme_page(
__( 'Display Featured Image for Genesis', 'display-featured-image-genesis' ),
- __( 'Display Featured Image Settings', 'display-featured-image-genesis' ),
+ __( 'Display Featured Image for Genesis', 'display-featured-image-genesis' ),
'manage_options',
$this->page,
array( $this, 'do_settings_form' )
@@ -132,15 +132,7 @@ class Display_Featured_Image_Genesis_Settings {
);
}
- foreach ( $sections as $section ) {
- add_settings_section(
- $section['id'],
- $section['title'],
- array( $this, $section['id'] . '_section_description' ),
- $this->page
- );
- }
-
+ $this->add_sections( $sections );
$this->register_fields( $sections );
}
@@ -217,17 +209,7 @@ class Display_Featured_Image_Genesis_Settings {
}
}
- foreach ( $this->fields as $field ) {
- add_settings_field(
- '[' . $field['id'] . ']',
- sprintf( '', $field['id'], $field['title'] ),
- array( $this, $field['callback'] ),
- $this->page,
- $sections[ $field['section'] ]['id'],
- empty( $field['args'] ) ? array() : $field['args']
- );
- }
-
+ $this->add_fields( $this->fields, $sections );
}
/**
@@ -252,36 +234,6 @@ class Display_Featured_Image_Genesis_Settings {
$this->print_section_description( $description );
}
- /**
- * Echoes out the section description.
- * @param string $description text string for description
- * @return string as paragraph and escaped
- *
- * @since 2.3.0
- */
- protected function print_section_description( $description ) {
- echo wp_kses_post( wpautop( $description ) );
- }
-
- /**
- * Generic callback to create a number field setting.
- *
- * @since 2.3.0
- */
- public function do_number( $args ) {
-
- printf( '', esc_attr( $this->page ),esc_attr( $args['setting'] ), esc_attr( $args['label'] ) );
- printf( '',
- (int) $args['min'],
- (int) $args['max'],
- esc_attr( $args['setting'] ),
- esc_attr( $this->displaysetting[ $args['setting'] ] ),
- esc_attr( $this->page )
- );
- $this->do_description( $args['setting'] );
-
- }
-
/**
* Description for less_header setting.
* @return string description
@@ -325,22 +277,6 @@ class Display_Featured_Image_Genesis_Settings {
);
}
- /**
- * generic checkbox function (for all checkbox settings)
- * @return 0 1 checkbox
- *
- * @since 2.3.0
- */
- public function do_checkbox( $args ) {
- printf( '', esc_attr( $args['setting'] ) );
- printf( '',
- esc_attr( $args['setting'] ),
- checked( 1, esc_attr( $this->displaysetting[ $args['setting'] ] ), false ),
- esc_attr( $args['label'] )
- );
- $this->do_description( $args['setting'] );
- }
-
/**
* Custom Post Type image uploader
*
@@ -375,96 +311,6 @@ class Display_Featured_Image_Genesis_Settings {
printf( '%s
', wp_kses_post( $description ) );
}
- /**
- * display image preview
- * @param variable $id featured image ID
- * @return $image image preview
- *
- * @since 2.3.0
- */
- public function render_image_preview( $id ) {
- if ( empty( $id ) ) {
- return;
- }
-
- $id = displayfeaturedimagegenesis_check_image_id( $id );
- $preview = wp_get_attachment_image_src( (int) $id, 'medium' );
- $image = sprintf( '', $preview[0] );
- return $image;
- }
-
- /**
- * show image select/delete buttons
- * @param variable $id image ID
- * @param varable $name name for value/ID/class
- * @return $buttons select/delete image buttons
- *
- * @since 2.3.0
- */
- public function render_buttons( $id, $name ) {
- $id = displayfeaturedimagegenesis_check_image_id( $id );
- $id = $id ? (int) $id : '';
- printf( '', esc_attr( $name ), esc_attr( $id ) );
- printf( '',
- esc_attr( $name ),
- esc_attr__( 'Select Image', 'display-featured-image-genesis' )
- );
- if ( ! empty( $id ) ) {
- printf( ' ',
- esc_attr__( 'Delete Image', 'display-featured-image-genesis' )
- );
- }
- }
-
- /**
- * Save extra taxonomy fields callback function.
- * @param term id $term_id the id of the term
- * @return updated option updated option for term featured image
- *
- * @since 2.0.0
- */
- public function save_taxonomy_custom_meta( $term_id ) {
-
- if ( isset( $_POST['displayfeaturedimagegenesis'] ) ) {
- $t_id = $term_id;
- $displaysetting = get_option( "displayfeaturedimagegenesis_$t_id" );
- $cat_keys = array_keys( $_POST['displayfeaturedimagegenesis'] );
- $is_updated = false;
- foreach ( $cat_keys as $key ) {
- if ( isset( $_POST['displayfeaturedimagegenesis'][ $key ] ) ) {
- $displaysetting[ $key ] = $_POST['displayfeaturedimagegenesis'][ $key ];
- if ( $_POST['displayfeaturedimagegenesis']['term_image'] === $displaysetting[ $key ] ) {
- $displaysetting[ $key ] = $this->validate_taxonomy_image( $_POST['displayfeaturedimagegenesis'][ $key ] );
- if ( false !== $displaysetting[ $key ] ) {
- $is_updated = true;
- }
- }
- }
- }
- // Save the option array.
- if ( $is_updated ) {
- update_option( "displayfeaturedimagegenesis_$t_id", $displaysetting );
- }
- }
-
- }
-
- /**
- * Generic callback to display a field description.
- * @param string $args setting name used to identify description callback
- * @return string Description to explain a field.
- *
- * @since 2.3.0
- */
- protected function do_description( $args ) {
- $function = $args . '_description';
- if ( ! method_exists( $this, $function ) ) {
- return;
- }
- $description = $this->$function();
- printf( '%s
', wp_kses_post( $description ) );
- }
-
/**
* validate all inputs
* @param string $new_value various settings
@@ -515,29 +361,6 @@ class Display_Featured_Image_Genesis_Settings {
}
- /**
- * Determines if the user has permission to save the information from the submenu
- * page.
- *
- * @since 2.3.0
- * @access private
- *
- * @param string $action The name of the action specified on the submenu page
- * @param string $nonce The nonce specified on the submenu page
- *
- * @return bool True if the user has permission to save; false, otherwise.
- * @author Tom McFarlin (https://tommcfarlin.com/save-wordpress-submenu-page-options/)
- */
- private function user_can_save( $action, $nonce ) {
- $is_nonce_set = isset( $_POST[ $nonce ] );
- $is_valid_nonce = false;
-
- if ( $is_nonce_set ) {
- $is_valid_nonce = wp_verify_nonce( $_POST[ $nonce ], $action );
- }
- return ( $is_nonce_set && $is_valid_nonce );
- }
-
/**
* Returns previous value for image if not correct file type/size
* @param string $new_value New value
@@ -581,113 +404,6 @@ class Display_Featured_Image_Genesis_Settings {
return (int) $new_value;
}
- /**
- * Returns false value for image if not correct file type/size
- * @param string $new_value New value
- * @return string New value or false, depending on allowed image size.
- * @since 2.0.0
- */
- protected function validate_taxonomy_image( $new_value ) {
-
- // if the image was selected using the old URL method
- $new_value = displayfeaturedimagegenesis_check_image_id( $new_value );
- $medium = get_option( 'medium_size_w' );
- $source = wp_get_attachment_image_src( $new_value, 'full' );
- $valid = $this->is_valid_img_ext( $source[0] );
- $width = $source[1];
-
- // ok for field to be empty
- if ( $new_value && ( ! $valid || $width <= $medium ) ) {
- $new_value = false;
- }
-
- return $new_value;
- }
-
- /**
- * Returns old value for author image if not correct file type/size
- * @param string $new_value New value
- * @return string New value or old, depending on allowed image size.
- * @since 2.3.0
- */
- public function validate_author_image( $new_value, $old_value ) {
-
- $medium = get_option( 'medium_size_w' );
- $source = wp_get_attachment_image_src( $new_value, 'full' );
- $valid = $this->is_valid_img_ext( $source[0] );
- $width = $source[1];
-
- if ( ! $new_value || ( $new_value && $valid && $width > $medium ) ) {
- return $new_value;
- }
-
- add_filter( 'user_profile_update_errors', array( $this, 'user_profile_error_message' ), 10, 3 );
-
- return $old_value;
-
- }
-
- /**
- * User profile error message
- * @param var $errors error message depending on what's wrong
- * @param var $update whether or not to update
- * @param var $user user being updated
- * @return error message
- *
- * @since 2.3.0
- */
- public function user_profile_error_message( $errors, $update, $user ) {
- $new_value = (int) $_POST['displayfeaturedimagegenesis'];
- $medium = get_option( 'medium_size_w' );
- $source = wp_get_attachment_image_src( $new_value, 'full' );
- $valid = $this->is_valid_img_ext( $source[0] );
- $width = $source[1];
- $reset = sprintf( __( ' The %s Featured Image has been reset to the last valid setting.', 'display-featured-image-genesis' ), $user->display_name );
-
- if ( ! $valid ) {
- $error = __( 'Sorry, that is an invalid file type.', 'display-featured-image-genesis' );
- } elseif ( $width <= $medium ) {
- $error = __( 'Sorry, your image is too small.', 'display-featured-image-genesis' );
- }
- $errors->add( 'profile_error', $error . $reset );
- }
-
- /**
- * returns file extension
- * @since 1.2.2
- */
- protected function get_file_ext( $file ) {
- $parsed = @parse_url( $file, PHP_URL_PATH );
- return $parsed ? strtolower( pathinfo( $parsed, PATHINFO_EXTENSION ) ) : false;
- }
-
- /**
- * check if file type is image
- * @return file check file extension against list
- * @since 1.2.2
- */
- protected function is_valid_img_ext( $file ) {
- $file_ext = $this->get_file_ext( $file );
-
- $is_valid_types = (array) apply_filters( 'displayfeaturedimage_valid_img_types', array( 'jpg', 'jpeg', 'png', 'gif' ) );
-
- return ( $file_ext && in_array( $file_ext, $is_valid_types ) );
- }
-
- /**
- * Returns a 1 or 0, for all truthy / falsy values.
- *
- * Uses double casting. First, we cast to bool, then to integer.
- *
- * @since 1.3.0
- *
- * @param mixed $new_value Should ideally be a 1 or 0 integer passed in
- * @return integer 1 or 0.
- */
- protected function one_zero( $new_value ) {
- return (int) (bool) $new_value;
- }
-
/**
* Help tab for media screen
* @return help tab with verbose information for plugin
diff --git a/includes/class-displayfeaturedimagegenesis-taxonomies.php b/includes/class-displayfeaturedimagegenesis-taxonomies.php
index 99bedbb..24b4666 100644
--- a/includes/class-displayfeaturedimagegenesis-taxonomies.php
+++ b/includes/class-displayfeaturedimagegenesis-taxonomies.php
@@ -7,7 +7,7 @@
*
* @since 2.0.0
*/
-class Display_Featured_Image_Genesis_Taxonomies {
+class Display_Featured_Image_Genesis_Taxonomies extends Display_Featured_Image_Genesis_Helper {
protected $settings;
@@ -17,8 +17,6 @@ class Display_Featured_Image_Genesis_Taxonomies {
*/
public function set_taxonomy_meta() {
- $this->settings = new Display_Featured_Image_Genesis_Settings();
-
$args = array(
'public' => true,
);
@@ -27,8 +25,8 @@ class Display_Featured_Image_Genesis_Taxonomies {
foreach ( $taxonomies as $taxonomy ) {
add_action( "{$taxonomy}_add_form_fields", array( $this, 'add_taxonomy_meta_fields' ), 5, 2 );
add_action( "{$taxonomy}_edit_form_fields", array( $this, 'edit_taxonomy_meta_fields' ), 5, 2 );
- add_action( "edited_{$taxonomy}", array( $this->settings, 'save_taxonomy_custom_meta' ), 10, 2 );
- add_action( "create_{$taxonomy}", array( $this->settings, 'save_taxonomy_custom_meta' ), 10, 2 );
+ add_action( "edited_{$taxonomy}", array( $this, 'save_taxonomy_custom_meta' ), 10, 2 );
+ add_action( "create_{$taxonomy}", array( $this, 'save_taxonomy_custom_meta' ), 10, 2 );
add_action( 'load-edit-tags.php', array( $this, 'help' ) );
}
@@ -75,9 +73,9 @@ class Display_Featured_Image_Genesis_Taxonomies {
$id = $displaysetting['term_image'];
$name = 'displayfeaturedimagegenesis[term_image]';
if ( ! empty( $id ) ) {
- echo wp_kses_post( $this->settings->render_image_preview( $id ) );
+ echo wp_kses_post( $this->render_image_preview( $id ) );
}
- $this->settings->render_buttons( $id, $name );
+ $this->render_buttons( $id, $name );
echo '';
printf(
esc_attr__( 'Set Featured Image for %1$s.', 'display-featured-image-genesis' ),
@@ -88,6 +86,62 @@ class Display_Featured_Image_Genesis_Taxonomies {
echo '';
}
+ /**
+ * Save extra taxonomy fields callback function.
+ * @param term id $term_id the id of the term
+ * @return updated option updated option for term featured image
+ *
+ * @since 2.0.0
+ */
+ public function save_taxonomy_custom_meta( $term_id ) {
+
+ if ( ! isset( $_POST['displayfeaturedimagegenesis'] ) ) {
+ return;
+ }
+ $t_id = $term_id;
+ $displaysetting = get_option( "displayfeaturedimagegenesis_$t_id" );
+ $cat_keys = array_keys( $_POST['displayfeaturedimagegenesis'] );
+ $is_updated = false;
+ foreach ( $cat_keys as $key ) {
+ if ( isset( $_POST['displayfeaturedimagegenesis'][ $key ] ) ) {
+ $displaysetting[ $key ] = $_POST['displayfeaturedimagegenesis'][ $key ];
+ if ( $_POST['displayfeaturedimagegenesis']['term_image'] === $displaysetting[ $key ] ) {
+ $displaysetting[ $key ] = $this->validate_taxonomy_image( $_POST['displayfeaturedimagegenesis'][ $key ] );
+ if ( false !== $displaysetting[ $key ] ) {
+ $is_updated = true;
+ }
+ }
+ }
+ }
+ // Save the option array.
+ if ( $is_updated ) {
+ update_option( "displayfeaturedimagegenesis_$t_id", $displaysetting );
+ }
+ }
+
+ /**
+ * Returns false value for image if not correct file type/size
+ * @param string $new_value New value
+ * @return string New value or false, depending on allowed image size.
+ * @since 2.0.0
+ */
+ protected function validate_taxonomy_image( $new_value ) {
+
+ // if the image was selected using the old URL method
+ $new_value = displayfeaturedimagegenesis_check_image_id( $new_value );
+ $medium = get_option( 'medium_size_w' );
+ $source = wp_get_attachment_image_src( $new_value, 'full' );
+ $valid = $this->is_valid_img_ext( $source[0] );
+ $width = $source[1];
+
+ // ok for field to be empty
+ if ( $new_value && ( ! $valid || $width <= $medium ) ) {
+ $new_value = false;
+ }
+
+ return $new_value;
+ }
+
/**
* Help tab for media screen
* @return help tab with verbose information for plugin