Php 扩展WP_小部件复选框不工作
我的插件坏了! 我使用了两个ceheckbox和不同的名称和id,但它不起作用,不能保存和更新 请在下面输入我的代码:Php 扩展WP_小部件复选框不工作,php,wordpress,widget,Php,Wordpress,Widget,我的插件坏了! 我使用了两个ceheckbox和不同的名称和id,但它不起作用,不能保存和更新 请在下面输入我的代码: function update( $new_instance, $old_instance ) { $instance = $old_instance; $instance['title'] = strip_tags($new_instance['title']); $instance['number'] =
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['number'] = (int) $new_instance['number'];
$instance['show_date'] = (isset($new_instance['show_date']) AND $new_instance['show_date'] == 1) ? 1 : 0;
$instance['show_img'] = (isset($new_instance['show_img']) AND $new_instance['show_img'] == 1) ? 1 : 0;
return $instance;
}
function form( $instance ) {
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 5;
$show_date = (isset($instance['show_date']) AND $instance['show_date'] == 1) ? 1 : 0;
$show_img = (isset($instance['show_img']) AND $instance['show_img'] == 1) ? 1 : 0;
$wp_theme = wp_get_theme();
$wp_theme = $wp_theme->get('TextDomain');
?>
<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 $title; ?>" /></p>
<p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts to display:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="text" value="<?php echo $number; ?>" size="3" /></p>
<p><input id="<?php echo ( $this->get_field_id('show_img') ); ?>" name="<?php echo ( $this->get_field_name('show_img') ); ?>" type="checkbox" value="1" <?php if($show_img) echo ' checked="checked"'; ?> />
<label for="<?php echo ( $this->get_field_id('show_img') ); ?>"><?php _e( 'Display feature image?' ); ?></label></p>
<p><input id="<?php echo ( $this->get_field_id('show_date') ); ?>" name="<?php echo ( $this->get_field_name('show_date') ); ?>" type="checkbox" value="1" <?php if($show_date) echo ' checked="checked"'; ?> />
<label for="<?php echo ( $this->get_field_id('show_date') ); ?>"><?php _e( 'Display post date?' ); ?></label></p>
<?php
}
函数更新($new\u实例,$old\u实例){
$instance=$old_实例;
$instance['title']=strip_标记($new_instance['title']);
$instance['number']=(int)$new_instance['number'];
$instance['show_date']=(isset($new_instance['show_date'])和$new_instance['show_date']==1)?1:0;
$instance['show_img']=(isset($new_instance['show_img'])和$new_instance['show_img']==1)?1:0;
返回$instance;
}
函数形式($instance){
$title=isset($instance['title'])?esc_attr($instance['title']):“”;
$number=isset($instance['number'])?absint($instance['number']):5;
$show_date=(isset($instance['show_date'])和$instance['show_date']==1)?1:0;
$show_img=(isset($instance['show_img'])和$instance['show_img']==1)?1:0;
$wp_theme=wp_get_theme();
$wp_theme=$wp_theme->get('TextDomain');
?>