fields as $id => $field ): $field[ 'id' ] = $id; ?>


get_html_dropdown_posts( $field ); break; case 'dropdown-pages': $this->get_html_dropdown_pages( $field ); break; case 'dropdown-menus': $this->get_html_dropdown_menus( $field ); break; case 'dropdown-categories': $this->get_html_dropdown_categories( $field ); break; case 'text': case 'number': case 'email': case 'file': case 'url': $this->get_html_text( $field ); break; case 'select': $this->get_html_select( $field ); break; case 'radio': $this->get_html_radio( $field ); break; case 'checkbox': $this->get_html_checkbox( $field ); break; case 'textarea': $this->get_html_textarea( $field ); break; case 'description': $this->get_html_description( $field ); break; default: echo esc_html__( 'Type Not Supported.', 'blogberg' ); break; } ?>

'dropdown-categories-' . $this->get_field_id( $field[ 'id' ] ), 'echo' => 0, 'show_option_none' => esc_html__( '— Select —', 'blogberg' ), 'option_none_value' => '0', 'selected' => esc_html( $field[ 'current_value' ] ), ) ); # Hackily add in the data link parameter. $dropdown = str_replace( '

> $value ): ?> > id="get_field_id( $field[ 'id' ] ) ); ?>" value="" > $this->get_field_name( $field[ 'id' ] ), 'id' => $this->get_field_id( $field[ 'id' ] ), 'class' => 'widefat', 'selected' => $field[ 'current_value' ] ); wp_dropdown_pages( $args ); } public function get_html_dropdown_posts( $field, $post_type = 'post' ){ $posts = get_posts( array( 'posts_per_page' => -1, 'post_type' => $post_type, 'post_status' => 'publish' ) ); ?> '', 'menu' => $nav_menu, 'echo' => false ); return wp_nav_menu( apply_filters( 'blogberg_widget_nav_menu_args', $nav_menu_args, $nav_menu, $id ) ); } public function update( $new_instance, $old_instance ) { $instance = array(); foreach( $this->fields as $id => $field ): $instance[ $id ] = $this->sanitize( $field, $new_instance[ $id ] ); endforeach; return $instance; } public function form( $instance ){ foreach( $this->fields as $key => $field ){ $this->fields[ $key ][ 'default' ] = isset( $field[ 'default' ] ) ? $field[ 'default' ] : null; $this->fields[ $key ][ 'current_value' ] = isset( $instance[ $key ] ) ? $instance[ $key ] : $this->fields[ $key ][ 'default' ]; } $this->generate_fields(); } public function sanitize( $field, $value ){ if ( isset( $field[ 'sanitize_callback' ] ) && is_callable( $field[ 'sanitize_callback' ] ) ) { $value = call_user_func( $field[ 'sanitize_callback' ], $field, $value ); return $value; } if( ! isset( $field[ 'default' ] ) ){ $field[ 'default' ] = null; } switch( $field[ 'type' ] ){ case 'dropdown-posts': case 'dropdown-pages': case 'dropdown-categories': $value = absint( $value ); break; case 'image': case 'url': $value = esc_url_raw( $value ); break; case 'email': $value = sanitize_email( $value ); break; case 'text': $value = sanitize_text_field( $value ); break; case 'number': if( is_numeric( $value ) ){ if( isset( $field[ 'max' ] ) ){ if( $value > $field[ 'max' ] ){ $value = $field[ 'default' ]; } } if( isset( $field[ 'min' ] ) ){ if( $value < $field[ 'min' ] ){ $value = $field[ 'default' ]; } } }else{ $value = $field[ 'default' ]; } break; case 'select': case 'radio': $value = esc_attr( $value ); $value = array_key_exists( $value, $field[ 'choices' ] ) ? $value : $field[ 'default' ]; break; case 'checkbox': $value = ! empty( $value ); break; case 'textarea': $value = wp_kses_post( $value ); break; } return $value; } public function init_defaults( $instance ){ if( ! is_array( $instance ) ){ $instance = array(); } foreach( $this->fields as $id => $field ){ if( !isset( $instance[ $id ] ) ){ $instance[ $id ] = isset( $field[ 'default' ] ) ? $field[ 'default' ] : null; } $instance[ $id ] = $this->sanitize( $field, $instance[ $id ] ); } return $instance; } } endif;