php - Widget options displayed under widget -
i made first wordpress widget today , works supposed on local wordpress installation(same version on server). uploaded server , options of widget displayed under widget on page instead of widget option place on admin side , can't figure out why.
here code:
// creating widget class wpb_widget extends wp_widget { function __construct() { parent::__construct( // base id of widget 'wpb_widget', // widget name appear in ui __('taxi prijs calculator', 'wpb_widget_domain'), // widget description array( 'description' => __( 'taxi prijs calculator', 'wpb_widget_domain' ), ) ); } // creating widget front-end // action happens public function widget( $args, $instance ) { $title = apply_filters( 'widget_title', $instance['title'] ); $shadow = $instance['shadow']; $maincolor = $instance['maincolor']; $textcolor = $instance['textcolor']; $shadowcolor = $instance['shadowcolor']; // before , after widget arguments defined themes echo $args['before_widget']; if ( ! empty( $title ) ) echo $args['before_title'] . $title . $args['after_title']; //here code widget took out save space. echo $args['after_widget']; } // widget backend public function form( $instance ) { if ( isset( $instance[ 'title' ] ) ) { $title = $instance[ 'title' ]; } else { $title = __( 'new title', 'wpb_widget_domain' ); } if ( isset( $instance[ 'shadow' ] ) ) { $shadow = $instance[ 'shadow' ]; } else { $shadow = __( 'new shadow', 'wpb_widget_domain' ); } if ( isset( $instance[ 'maincolor' ] ) ) { $maincolor = $instance[ 'maincolor' ]; } else { $maincolor = __( 'new maincolor', 'wpb_widget_domain' ); } if ( isset( $instance[ 'textcolor' ] ) ) { $textcolor = $instance[ 'textcolor' ]; } else { $textcolor = __( 'new textcolor', 'wpb_widget_domain' ); } if ( isset( $instance[ 'shadowcolor' ] ) ) { $shadowcolor = $instance[ 'shadowcolor' ]; } else { $shadowcolor = __( 'new shadowcolor', 'wpb_widget_domain' ); } // widget admin form ?> <p> <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'title:' ); ?></label> <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> </p> <p> <label for="<?php echo $this->get_field_id( 'shadow' ); ?>"><?php _e( 'display shadow:' ); ?></label> <br> <input type="radio" id="<?php echo $this->get_field_id( 'shadow' ); ?>" name="<?php echo $this->get_field_name( 'shadow' ); ?>" value="yes" <?php if($shadow == "yes" || $shadow = "new shadow"){ echo "checked";}?>>yes <input type="radio" id="<?php echo $this->get_field_id( 'shadow' ); ?>" name="<?php echo $this->get_field_name( 'shadow' ); ?>" value="no" <?php if($shadow == "no"){ echo "checked";}?>>no </p> <p> <label for="<?php echo $this->get_field_id( 'shadowcolor' ); ?>"><?php _e( 'shadow color:' ); ?></label><br> <input type="color" id="<?php echo $this->get_field_id( 'shadowcolor' ); ?>" name="<?php echo $this->get_field_name( 'shadowcolor' ); ?>" value="<?php if(empty($shadowcolor) || $shadowcolor == "new shadowcolor") { echo "#323232";}else{echo esc_attr( $shadowcolor );} ?>"> </p> <p> <label for="<?php echo $this->get_field_id( 'maincolor' ); ?>"><?php _e( 'main color:' ); ?></label><br> <input type="color" id="<?php echo $this->get_field_id( 'maincolor' ); ?>" name="<?php echo $this->get_field_name( 'maincolor' ); ?>" value="<?php if(empty($maincolor) || $maincolor == "new maincolor") { echo "#fdd017";}else{echo esc_attr( $maincolor );} ?>"> </p> <p> <label for="<?php echo $this->get_field_id( 'textcolor' ); ?>"><?php _e( 'text color:' ); ?></label><br> <input type="color" id="<?php echo $this->get_field_id( 'textcolor' ); ?>" name="<?php echo $this->get_field_name( 'textcolor' ); ?>" value="<?php if(empty($textcolor) || $textcolor == "new textcolor") { echo "#000000";}else{echo esc_attr( $textcolor );} ?>"> </p> <?php } // updating widget replacing old instances new public function update( $new_instance, $old_instance ) { $instance = array(); $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : ''; $instance['shadow'] = ( ! empty( $new_instance['shadow'] ) ) ? strip_tags( $new_instance['shadow'] ) : ''; $instance['maincolor'] = ( ! empty( $new_instance['maincolor'] ) ) ? strip_tags( $new_instance['maincolor'] ) : ''; $instance['textcolor'] = ( ! empty( $new_instance['textcolor'] ) ) ? strip_tags( $new_instance['textcolor'] ) : ''; $instance['shadowcolor'] = ( ! empty( $new_instance['shadowcolor'] ) ) ? strip_tags( $new_instance['shadowcolor'] ) : ''; return $instance; } } // class wpb_widget ends here // register , load widget function wpb_load_widget() { register_widget( 'wpb_widget' ); } function prefix_add_my_stylesheet() { // respects ssl, style.css relative current file wp_register_style( 'prefix-style', plugins_url('css/taxi.css', __file__) ); wp_enqueue_style( 'prefix-style' ); } add_action( 'wp_enqueue_scripts', 'prefix_add_my_stylesheet' ); add_action( 'widgets_init', 'wpb_load_widget' );
this happens:
Comments
Post a Comment