Current Path : /var/test/www/ya/wp-content/themes/youthy/framework/widgets/ |
Current File : /var/test/www/ya/wp-content/themes/youthy/framework/widgets/widget-event.php |
<?php // MeanThemes Homepage Widget for Event. /* * * This widget uses the Custom post type for meanthemes_event (via the MeanThemes tools plugin) * */ // Register widget add_action('widgets_init', 'meanthemes_home_event_widget'); function meanthemes_home_event_widget() { register_widget( 'meanthemes_home_event' ); } // Setup widget class class meanthemes_home_event extends WP_Widget { function __construct() { $widget_name = __( 'MT Homepage: Event' , 'meanthemes' ); $widget_classname = "meanthemes_home_event"; $widget_description = __('This widget includes the event you have set up via "Posts", with a few extra options.', 'meanthemes'); // Set widget classname and description from above $widget_ops = array( 'classname' => $widget_classname, 'description' => $widget_description, ); parent::__construct('meanthemes_home_event-widget', $widget_name, $widget_ops); } // Setup widget output function widget($args, $instance) { extract($args); // Variables from the widget settings. if ( isset( $instance[ 'title' ] ) ) { $title = $instance[ 'title' ]; } else { $title = ""; } if ( isset( $instance[ 'description' ] ) ) { $description = $instance[ 'description' ]; } else { $description = ""; } if ( isset( $instance[ 'button_text' ] ) ) { $button_text = $instance[ 'button_text' ]; } else { $button_text = ""; } if ( isset( $instance[ 'button_url' ] ) ) { $button_url = $instance[ 'button_url' ]; } else { $button_url = ""; } if ( isset( $instance[ 'button_color' ] ) ) { $button_color = $instance[ 'button_color' ]; } else { $button_color = ""; } if ( isset( $instance[ 'post_amount' ] ) ) { $post_amount = $instance[ 'post_amount' ]; } else { $post_amount = ""; } if ( $post_amount === "" ) { $posts_per_page = 4; } else { $posts_per_page = $post_amount; } if ( isset( $instance[ 'show_future' ] ) ) { $show_future = $instance[ 'show_future' ]; } else { $show_future = ""; } if ( $show_future === "" ) { $show_future = '1'; } if ( $show_future === "1" ) { $post_status = 'future'; $post_order = 'asc'; } else { $post_status = 'publish,future'; $post_order = 'desc'; } if ( isset( $instance[ 'bg_color' ] ) ) { $bg_color = $instance[ 'bg_color' ]; } else { $bg_color = ""; } if ( isset( $instance[ 'text_color' ] ) ) { $text_color = $instance[ 'text_color' ]; } else { $text_color = ""; } if ( $button_color || $bg_color || $text_color ) { ?> <style type="text/css"> <?php if ( $button_color ) { ?> .home-widget#<?php echo esc_attr( $this->id ); ?> .btn.info-btn, .home-widget#<?php echo esc_attr( $this->id ); ?> .btn.info-btn:hover { background-color: <?php echo esc_html( $button_color ); ?> !important; } <?php } ?> <?php if ( $bg_color ) { ?> .home-widget#<?php echo esc_attr( $this->id ); ?> { background-color: <?php echo esc_html( $bg_color ); ?> !important; } <?php } ?> <?php if ( $text_color ) { ?> .home-widget#<?php echo esc_attr( $this->id ); ?> .widget-info { color: <?php echo esc_html( $text_color ); ?> !important; } <?php } ?> </style> <?php } // Widget HTML output ?> <section class="home-widget widget-event" id="<?php echo esc_attr( $this->id ); ?>"> <?php // Get All Event Posts // This is done via get_posts to avoid pagination issues. // Reset post data wp_reset_postdata(); global $post; // Set a global post to return actual posts $args = array( 'post_type' => 'event', 'order' => $post_order, 'posts_per_page' => $posts_per_page, 'post_status' => $post_status ); $postslist = get_posts( $args ); if ( $postslist ) { ?> <div class="loop"> <?php if ( $title || $description ) { ?> <div class="widget-info"> <?php if ( $title ) { ?> <h2><?php echo esc_html( $title ); ?></h2> <?php } ?> <?php if ( $description ) { ?> <div class="widget-description"> <?php echo balanceTags( apply_filters( 'the_content', $description ) ); ?> </div> <?php } ?> </div> <?php } ?> <?php } foreach ( $postslist as $post ): setup_postdata($post); get_template_part('event/item'); endforeach; if ( $postslist ) { ?> <?php if ( $button_text && $button_url ) { ?> <div class="widget-buttons"> <a class="btn info-btn" href="<?php echo esc_url( $button_url ); ?>" title="<?php echo esc_html( $button_text ); ?>"><?php echo esc_html( $button_text ); ?> <i class="fa fa-arrow-right"></i></a> </div> <?php } ?> </div> <?php } ?> </section> <?php wp_reset_postdata(); } // Variables for updating widget, these should match above but use santization methods function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = esc_html( $new_instance['title'] ); $instance['description'] = esc_attr( $new_instance['description'] ); $instance['button_text'] = esc_html( $new_instance['button_text'] ); $instance['button_url'] = esc_url( $new_instance['button_url'] ); $instance['button_color'] = esc_html( $new_instance['button_color'] ); $instance['bg_color'] = esc_html( $new_instance['bg_color'] ); $instance['text_color'] = esc_html( $new_instance['text_color'] ); $instance['post_amount'] = esc_attr( $new_instance['post_amount'] ); $instance['show_future'] = esc_attr( $new_instance['show_future'] ); return $instance; } // Setup widget form that appears in Appearance > Widgets function form($instance) { // Again set the variables... again! $defaults = array( "title" => "", "description" => "", "button_text" => "", "button_url" => "", "button_color" => "", "bg_color" => "", "text_color" => "", "post_amount" => "", "show_future" => "" ); $instance = wp_parse_args( (array) $instance, $defaults ); ?> <p> <label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php _e( 'Title:' , 'meanthemes' ); ?></label><br /> <input type="text" name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('description') ); ?>"><?php _e( 'Short description:' , 'meanthemes' ); ?></label><br /> <textarea name="<?php echo esc_attr( $this->get_field_name('description') ); ?>" rows="6" style="width: 100%;" id="<?php echo esc_attr( $this->get_field_id('description') ); ?>"><?php echo balanceTags( $instance['description'] ); ?></textarea> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('button_text') ); ?>"><?php _e( 'Button Text:' , 'meanthemes' ); ?></label><br /> <input type="text" name="<?php echo esc_attr( $this->get_field_name('button_text') ); ?>" id="<?php echo esc_attr( $this->get_field_id('button_text') ); ?>" value="<?php echo esc_attr( $instance['button_text'] ); ?>" class="widefat" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('button_url') ); ?>"><?php _e( 'Button URL:' , 'meanthemes' ); ?></label><br /> <input type="text" name="<?php echo esc_attr( $this->get_field_name('button_url' ) ); ?>" id="<?php echo esc_attr( $this->get_field_id('button_url') ); ?>" value="<?php echo esc_url( $instance['button_url'] ); ?>" class="widefat" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('button_color') ); ?>"><?php _e( 'Button Color:' , 'meanthemes' ); ?></label><br /> <input type="text" name="<?php echo esc_attr( $this->get_field_name('button_color') ); ?>" id="<?php echo esc_attr( $this->get_field_id('button_color') ); ?>" value="<?php echo esc_attr( $instance['button_color'] ); ?>" class="widefat color-field" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('post_amount') ); ?>"><?php _e( 'Show this number of posts:' , 'meanthemes' ); ?></label><br /> <input type="number" name="<?php echo esc_attr( $this->get_field_name('post_amount') ); ?>" id="<?php echo esc_attr( $this->get_field_id('post_amount') ); ?>" value="<?php if ( $instance['post_amount'] === '' ) { echo '4'; } else { echo esc_attr( $instance['post_amount'] ); } ?>" class="widefat" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('show_future') ); ?>"><?php _e( 'Show Future events only:' , 'meanthemes' ); ?></label><br /> <select name="<?php echo esc_attr( $this->get_field_name('show_future') ); ?>" id="<?php echo esc_attr( $this->get_field_id('show_future') ); ?>"> <option value="0" <?php if ( $instance['show_future'] !== '1' ) { ?>selected<?php } ?>>No</option> <option value="1" <?php if ( $instance['show_future'] !== '0' ) { ?>selected<?php } ?>>Yes</option> </select> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('bg_color') ); ?>"><?php _e( 'Background Color:' , 'meanthemes' ); ?></label><br /> <input type="text" name="<?php echo esc_attr( $this->get_field_name('bg_color') ); ?>" id="<?php echo esc_attr( $this->get_field_id('bg_color') ); ?>" value="<?php echo esc_attr( $instance['bg_color'] ); ?>" class="widefat color-field" /> </p> <p> <label for="<?php echo esc_attr( $this->get_field_id('text_color') ); ?>"><?php _e( 'Text Color:' , 'meanthemes' ); ?></label><br /> <input type="text" name="<?php echo esc_attr( $this->get_field_name('text_color') ); ?>" id="<?php echo esc_attr( $this->get_field_id('text_color') ); ?>" value="<?php echo esc_attr( $instance['text_color'] ); ?>" class="widefat color-field" /> </p> <?php } } ?>