it doesn’t this work (Set Checkbox as checked by default)

Question

it doesn’t this work (Set Checkbox as checked by default)

class p30code_widget_genre_widget extends WP_Widget {
    public function __construct() {
        $widget_ops = array( 
            'classname' => 'p30code_widget_genre_widget',
            'description' => 'نمایش پست های براساس ژانر',
        );
        parent::__construct( 'p30code_widget_genre_widget', 'پست ها به صورت ژانر', $widget_ops );
    }
    public function widget( $args, $instance ) {
    if($instance['widget_movie_genres'] == "0" && $instance['widget_serie_genres'] == "0"){
        return; 
    }
?>
<div class="box">
    <div class="title">
        <h5 class="title-text text-orange"> ژانر بر اساس <?php if ($instance['widget_movie_genres'] == "1") { ?><span class="text-danger movie-genres active" onclick="javascript:$(this).addClass('active').parents('.box').find('ul.inline-list:nth-of-type(1)').addClass('active').parents('.box').find('ul.inline-list:nth-of-type(2), .title-text span.text-danger:nth-of-type(2)').removeClass('active');"> فیلم</span><?php } ?><?php if ($instance['widget_serie_genres'] == "1") { ?><span class="text-danger serie-genres" onclick="javascript:$(this).addClass('active').parents('.box').find('ul.inline-list:nth-of-type(2)').addClass('active').parents('.box').find('ul.inline-list:nth-of-type(1), .title-text span.text-danger:nth-of-type(1)').removeClass('active');"> سریال</span><span class="img-icon video-options"></span><?php } ?></h5>
    </div>
<?php if ($instance['widget_movie_genres'] == "1") { ?>
<ul class="genre-list inline-list two-col movie-genres active">
<?php
    $taxonomy = 'movie_genres';
    $show_count = 1;
    $hide_empty = false;
    $title_li = '';
    $depth = 1;
    $args = array(
        'taxonomy' => $taxonomy,
        'show_count' => $show_count,
        'hide_empty' => $hide_empty,
        'title_li' => $title_li,
        'depth' => $depth,
        'echo' => 0
    );
    $links = wp_list_categories($args);
    $links = str_replace('</a> (', '<span class="count">', $links);
    $links = str_replace(')', '</span></a>', $links);
    echo $links;
?>
</ul>
<?php } ?>
<?php if ($instance['widget_serie_genres'] == "1") { ?>
<ul class="genre-list inline-list two-col serie-genres">
<?php
    $taxonomy = 'serie_genres';
    $show_count = 1;
    $hide_empty = false;
    $title_li = '';
    $depth = 1;
    $args = array(
        'taxonomy' => $taxonomy,
        'show_count' => $show_count,
        'hide_empty' => $hide_empty,
        'title_li' => $title_li,
        'depth' => $depth,
        'echo' => 0
    );
    $links = wp_list_categories($args);
    $links = str_replace('</a> (', '<span class="count">', $links);
    $links = str_replace(')', '</span></a>', $links);
    echo $links;
?>
</ul>
<?php } ?>
</div>
    <?php }
    public function form( $instance ) {

    ?>
<div class="widget-body">
    <p>
        <label for="<?php echo $this->get_field_id( 'widget_movie_genres' ); ?>"><?php _e('نمایش فیلم'); ?>
            <input class="widefat" id="<?php echo $this->get_field_id( 'widget_movie_genres' ); ?>" name="<?php echo $this->get_field_name( 'widget_movie_genres' ); ?>" type="checkbox" value="1" <?php echo ($instance['widget_movie_genres'] == 1 ? "checked":"" ); ?> />
        </label>
    </p>
    <p>
        <label for="<?php echo $this->get_field_id( 'widget_serie_genres' ); ?>"><?php _e('نمایش سریال'); ?>
            <input class="widefat" id="<?php echo $this->get_field_id( 'widget_serie_genres' ); ?>" name="<?php echo $this->get_field_name( 'widget_serie_genres' ); ?>" type="checkbox" value="1" <?php echo ($instance['widget_serie_genres'] == 1 ? "checked":"" ); ?> />
        </label>
    </p>
</div>
    <?php }
    public function update( $new_instance ) {
        $instance = array();
        $instance['widget_movie_genres'] = (!empty($new_instance['widget_movie_genres']) ? $new_instance['widget_movie_genres'] : 0);
        $instance['widget_serie_genres'] = (!empty($new_instance['widget_serie_genres']) ? $new_instance['widget_serie_genres'] : 0);
        return $instance;
    }
}
0
ali 3 years 2020-04-07T16:51:09-05:00 0 Answers 84 views 0

Leave an answer

Browse
Browse