就我个人而言,我不明白为什么textarea没有保存textarea内部的值,而是在前端显示值。我也检查了这个问题-question 但我似乎找不到我的小部件有什么问题。任何帮助都将不胜感激
//register widget backend
class resumee_experience1_widget extends WP_Widget{
public function __construct(){
parent::__construct(\'experience_one_widget\', __(\'Resume Experience Widget\', \'resumee\'), array(
\'description\' => __(\'Resume Experience Widget\', \'resumee\'),
\'customize_selective_refresh\' => true
));
}
/**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
public function widget($args, $instance){
$title = apply_filters(\'widget_title\', $instance[\'title\'] );
$exp1 = $instance[\'exp1\'];
$jd1 = $instance[\'jd1\'];
$exp2 = $instance[\'exp2\'];
$jd2 = $instance[\'jd2\'];
$exp3 = $instance[\'exp3\'];
$jd3 = $instance[\'jd3\'];
/* Before widget (defined by themes). */
echo $args[\'before_widget\'] ;
echo \'<div class="container experience">
<div class="col-md-12">\';
if(isset($title) && !empty($title)){
echo \'<h3 class="timeline">\'. esc_html__($title) .\'</h3>\';
}
echo \'<ul class="timeline">
<li class="timeline-inverted">
<div class="timeline-badge warning">●</div>
<div class="timeline-panel">
<div class="timeline-heading">\';
if(isset($exp1) && !empty($exp1)){
echo \'<h4 class="timeline-title">\'. esc_html__($exp1) .\'</h4>\';
}
echo \'</div><div class="timeline-body">\';
if(isset($jd1) && !empty($jd1)){
echo \'<p>\'. esc_html__($jd1) .\'</p>\';
}
echo \'</div></div></li>
<li class="timeline-inverted">
<div class="timeline-badge warning">●</div>
<div class="timeline-panel">
<div class="timeline-heading">\';
if(isset($exp2) && !empty($exp2)){
echo \'<h4 class="timeline-title">\'. esc_html__($exp2) .\'</h4>\';
}
echo \'</div><div class="timeline-body">\';
if(isset($jd2) && !empty($jd2)){
echo \'<p>\'. esc_html__($jd2) .\'</p>\';
}
echo \'</div></div></li>
<li class="timeline-inverted">
<div class="timeline-badge warning">●</div>
<div class="timeline-panel">
<div class="timeline-heading">\';
if(isset($exp3) && !empty($exp3)){
echo \'<h4 class="timeline-title">\'. esc_html__($exp3) .\'</h4>\';
}
echo \'</div><div class="timeline-body">\';
if(isset($jd3) && !empty($jd3)){
echo \'<p>\'. esc_html__($jd3) .\'</p>\';
}
echo \'</div></div></li></ul></div></div>\';
/* After widget (defined by themes). */
echo $args[\'after_widget\'] ;
}
/**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
public function form($instance){
/* Set up some default widget settings. */
$defaults = array(
\'title\' => __(\'Work Experience\', \'resumee\'),
\'exp1\' => __(\'Company Name, Jan, 2015 - present\', \'resumee\'),
\'jd1\' => __(\'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porttitor dapibus ipsum ut efficitur. Aliquam feugiat nec sem dapibus blandit. Nam non faucibus urna, at pulvinar nisl. Aliquam erat volutpat. Ut eget aliquet diam. In et Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porttitor dapibus ipsum ut efficitur.\', \'resumee\'),
\'exp2\' => __(\'Company Name, Feb, 2013 - 2015\', \'resumee\'),
\'jd2\' => __(\'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porttitor dapibus ipsum ut efficitur. Aliquam feugiat nec sem dapibus blandit. Nam non faucibus urna, at pulvinar nisl. Aliquam erat volutpat. Ut eget aliquet diam. In et Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porttitor dapibus ipsum ut efficitur.\', \'resumee\'),
\'exp3\' => __(\'Company Name, March, 2011 - 2013\', \'resumee\'),
\'jd3\' => __(\'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porttitor dapibus ipsum ut efficitur. Aliquam feugiat nec sem dapibus blandit. Nam non faucibus urna, at pulvinar nisl. Aliquam erat volutpat. Ut eget aliquet diam. In et Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam porttitor dapibus ipsum ut efficitur.\', \'resumee\')
);
$instance = wp_parse_args( (array) $instance, $defaults );
?>
<!-- title field -->
<label for="<?php echo $this->get_field_id(\'title\'); ?>"><?php _e(\'Title:\' , \'resumee\'); ?></label>
<br>
<input class="widefat" id="<?php echo $this->get_field_id(\'title\'); ?>" name="<?php echo $this->get_field_name(\'title\'); ?>" value="<?php echo esc_attr( $instance[\'title\'] ); ?>" type="text">
<br>
<br>
<!-- exp1 field -->
<label for="<?php echo $this->get_field_id(\'exp1\'); ?>"><?php _e(\'Company:\' , \'resumee\'); ?></label>
<br>
<input class="widefat" id="<?php echo $this->get_field_id(\'exp1\'); ?>" name="<?php echo $this->get_field_name(\'exp1\'); ?>" value="<?php echo esc_attr( $instance[\'exp1\'] ); ?>" type="text">
<br>
<br>
<!-- jd1 field -->
<label for="<?php echo $this->get_field_id(\'jd1\'); ?>"><?php _e(\'Job Description:\' , \'resumee\'); ?></label>
<br>
<textarea class="widefat" rows="10" cols="20" id="<?php echo $this->get_field_id(\'jd1\'); ?>" name="<?php echo $this->get_field_name(\'jd1\'); ?>" ><?php echo ($instance[\'$jd1\']); ?></textarea>
<br>
<br>
<!-- exp2 field -->
<label for="<?php echo $this->get_field_id(\'exp2\'); ?>"><?php _e(\'Company:\' , \'resumee\'); ?></label>
<br>
<input class="widefat" id="<?php echo $this->get_field_id(\'exp2\'); ?>" name="<?php echo $this->get_field_name(\'exp2\'); ?>" value="<?php echo esc_attr( $instance[\'exp2\'] ); ?>" type="text">
<br>
<br>
<!-- jd2 field -->
<label for="<?php echo $this->get_field_id(\'jd2\'); ?>"><?php _e(\'Job Description:\' , \'resumee\'); ?></label>
<br>
<textarea class="widefat" rows="10" cols="20" id="<?php echo $this->get_field_id(\'jd2\'); ?>" name="<?php echo $this->get_field_name(\'jd2\'); ?>" ><?php echo ($instance[\'$jd2\']); ?></textarea>
<br>
<br>
<!-- exp3 field -->
<label for="<?php echo $this->get_field_id(\'exp3\'); ?>"><?php _e(\'Company:\' , \'resumee\'); ?></label>
<br>
<input class="widefat" id="<?php echo $this->get_field_id(\'exp3\'); ?>" name="<?php echo $this->get_field_name(\'exp3\'); ?>" value="<?php echo esc_attr( $instance[\'exp3\'] ); ?>" type="text">
<br>
<br>
<!-- jd3 field -->
<label for="<?php echo $this->get_field_id(\'jd3\'); ?>"><?php _e(\'Job Description:\' , \'resumee\'); ?></label>
<br>
<textarea class="widefat" rows="10" cols="20" id="<?php echo $this->get_field_id(\'jd3\'); ?>" name="<?php echo $this->get_field_name(\'jd3\'); ?>" ><?php echo ($instance[\'$jd3\']); ?></textarea>
<br>
<br>
<?php
}
/**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance[ \'title\' ] = strip_tags( $new_instance[ \'title\' ] );
$instance[ \'exp1\' ] = strip_tags( $new_instance[ \'exp1\' ] );
$instance[ \'jd1\' ] = strip_tags( $new_instance[ \'jd1\' ] );
$instance[ \'exp2\' ] = strip_tags( $new_instance[ \'exp2\' ] );
$instance[ \'jd2\' ] = strip_tags( $new_instance[ \'jd2\' ] );
$instance[ \'exp3\' ] = strip_tags( $new_instance[ \'exp3\' ] );
$instance[ \'jd3\' ] = strip_tags( $new_instance[ \'jd3\' ] );
return $instance;
}
}
//regoster widget with hook
function register_experience_one_widget(){
register_widget( \'resumee_experience1_widget\' );
}
add_action( \'widgets_init\', \'register_experience_one_widget\');