diff --git a/includes/settings/class-displayfeaturedimagegenesis-helper.php b/includes/settings/class-displayfeaturedimagegenesis-helper.php index 8a66e0e..97b73ea 100644 --- a/includes/settings/class-displayfeaturedimagegenesis-helper.php +++ b/includes/settings/class-displayfeaturedimagegenesis-helper.php @@ -33,7 +33,7 @@ class Display_Featured_Image_Genesis_Helper extends DisplayFeaturedImageGenesisG $this->page . '_' . $section['id'], $section['title'], array( $this, 'section_description' ), - $this->page . '_' . $section['id'] + $this->page . '_' . $section['tab'] ); } } @@ -49,10 +49,10 @@ class Display_Featured_Image_Genesis_Helper extends DisplayFeaturedImageGenesisG protected function add_fields( $fields, $sections ) { foreach ( $fields as $field ) { add_settings_field( - '[' . $field['id'] . ']', - sprintf( '', $field['id'], $field['title'] ), + $field['id'], + sprintf( '', $this->page, $field['id'], $field['title'] ), array( $this, $field['callback'] ), - $this->page . '_' . $sections[ $field['section'] ]['id'], + $this->page . '_' . $sections[ $field['section'] ]['tab'], $this->page . '_' . $sections[ $field['section'] ]['id'], $field ); @@ -93,12 +93,12 @@ class Display_Featured_Image_Genesis_Helper extends DisplayFeaturedImageGenesisG * @param $args */ public function do_number( $args ) { - printf( '', + printf( '%6$s', (int) $args['min'], (int) $args['max'], - esc_attr( $args['id'] ), - esc_attr( $this->setting[ $args['id'] ] ), - esc_attr( $this->page ), + esc_attr( $this->get_field_id( $args ) ), + esc_attr( $this->get_field_value( $args ) ), + esc_attr( $this->get_field_name( $args ) ), esc_attr( $args['label'] ) ); $this->do_description( $args ); @@ -113,48 +113,43 @@ class Display_Featured_Image_Genesis_Helper extends DisplayFeaturedImageGenesisG * @param $args */ public function do_checkbox( $args ) { - $setting = $this->get_checkbox_setting( $args ); - printf( '', esc_attr( $this->page ), esc_attr( $args['id'] ) ); - printf( '', - esc_attr( $args['id'] ), - checked( 1, esc_attr( $setting ), false ), + $name = $this->get_field_name( $args ); + $value = $this->get_field_value( $args ); + printf( '', esc_attr( $name ) ); + printf( '', + esc_attr( $this->get_field_id( $args ) ), + checked( 1, esc_attr( $value ), false ), esc_attr( $args['label'] ), - esc_attr( $this->page ) + esc_attr( $name ) ); $this->do_description( $args ); } - /** - * Get the current value for the checkbox. - * - * @param $args - * - * @return int - */ - protected function get_checkbox_setting( $args ) { - $setting = isset( $this->setting[ $args['id'] ] ) ? $this->setting[ $args['id'] ] : 0; - if ( isset( $args['setting_name'] ) && isset( $this->setting[ $args['setting_name'] ][ $args['name'] ] ) ) { - $setting = $this->setting[ $args['setting_name'] ][ $args['name'] ]; - } - - return $setting; - } - /** * Build a checkbox array. * * @param $args */ public function do_checkbox_array( $args ) { - foreach ( $args['options'] as $key => $value ) { - $type_args = array( - 'id' => "{$args['id']}][{$key}", - 'label' => $value, - 'setting_name' => $args['id'], - 'name' => $key, + echo '
'; + $name = $this->get_field_name( $args ); + $id = $this->get_field_id( $args ); + $value = $this->get_field_value( $args ); + foreach ( $args['options'] as $choice => $label ) { + $check = isset( $value[ $choice ] ) ? $value[ $choice ] : 0; + printf( '', + esc_attr( $name ), + esc_attr( $choice ) + ); + printf( '', + esc_attr( $choice ), + checked( 1, $check, false ), + esc_html( $label ), + esc_attr( $name ), + esc_attr( $id ) ); - $this->do_checkbox( $type_args ); } + echo '
'; $this->do_description( $args ); } @@ -166,14 +161,17 @@ class Display_Featured_Image_Genesis_Helper extends DisplayFeaturedImageGenesisG */ public function do_radio_buttons( $args ) { echo '
'; + $name = $this->get_field_name( $args ); + $id = $this->get_field_id( $args ); + $value = $this->get_field_value( $args ); printf( '%s', esc_html( $args['legend'] ) ); - foreach ( $args['buttons'] as $key => $button ) { - printf( ' ', - esc_attr( $args['id'] ), - esc_attr( $key ), - checked( $key, $this->setting[ $args['id'] ], false ), - esc_attr( $button ), - esc_attr( $this->page ) + foreach ( $args['buttons'] as $choice => $label ) { + printf( ' ', + esc_attr( $id ), + esc_attr( $choice ), + checked( $choice, $value, false ), + esc_attr( $label ), + esc_attr( $name ) ); } echo '
'; @@ -185,14 +183,15 @@ class Display_Featured_Image_Genesis_Helper extends DisplayFeaturedImageGenesisG * @param $args */ public function do_select( $args ) { - printf( '', + esc_attr( $this->get_field_id( $args ) ), + esc_attr( $this->get_field_name( $args ) ) ); foreach ( (array) $args['options'] as $option => $label ) { printf( '', esc_attr( $option ), - selected( $option, $this->setting[ $args['id'] ], false ), + selected( $option, $value, false ), esc_attr( $label ) ); } @@ -295,6 +294,48 @@ class Display_Featured_Image_Genesis_Helper extends DisplayFeaturedImageGenesisG return array_merge( $built_in, $post_types ); } + /** + * Get the current field name. + * + * @param $args + * + * @return string + */ + public function get_field_name( $args ) { + return isset( $args['key'] ) && $args['key'] ? $this->page . '[' . $args['key'] . '][' . $args['setting'] . ']' : $this->page . '[' . $args['id'] . ']'; + } + + /** + * Get the current field id. + * + * @param $args + * + * @return string + * + */ + public function get_field_id( $args ) { + return isset( $args['key'] ) && $args['key'] ? $this->page . '-' . $args['key'] . '-' . $args['setting'] : $this->page . '-' . $args['id']; + } + + /** + * Get the current field value. + * + * @param $args + * + * @return mixed + * @internal param $setting + * + */ + public function get_field_value( $args ) { + if ( isset( $args['key'] ) && $args['key'] ) { + $value = isset( $this->setting[ $args['key'] ][ $args['setting'] ] ) ? $this->setting[ $args['key'] ][ $args['setting'] ] : 0; + } else { + $value = isset( $this->setting[ $args['id'] ] ) ? $this->setting[ $args['id'] ] : ''; + } + + return $value; + } + /** * Determines if the user has permission to save the information from the submenu * page. diff --git a/includes/settings/class-displayfeaturedimagegenesis-settings-validate.php b/includes/settings/class-displayfeaturedimagegenesis-settings-validate.php index 85e6899..7dfb147 100644 --- a/includes/settings/class-displayfeaturedimagegenesis-settings-validate.php +++ b/includes/settings/class-displayfeaturedimagegenesis-settings-validate.php @@ -93,13 +93,6 @@ class Display_Featured_Image_Genesis_Settings_Validate extends Display_Featured_ if ( isset( $new_value['post_type'][ $post_type ] ) ) { $new_value['post_type'][ $post_type ] = $this->validate_image( $new_value['post_type'][ $post_type ], $old_value, $label, $size_to_check ); } - if ( isset( $new_value['fallback'][ $post_type ] ) ) { - $new_value['fallback'][ $post_type ] = $this->one_zero( $new_value['fallback'][ $post_type ] ); - } - } - $post_types = $this->get_content_types_built_in(); - foreach ( $post_types as $post_type ) { - $new_value['skip'][ $post_type ] = isset( $new_value['skip'][ $post_type ] ) ? $this->one_zero( $new_value['skip'][ $post_type ] ) : 0; } return $new_value;