/wp-content/themes/astrid/inc/framework/widgets/front-testimonials.php
PHP | 165 lines | 138 code | 22 blank | 5 comment | 18 complexity | c9ad5b362d881663c3500c0b83b30cdc MD5 | raw file
Possible License(s): GPL-2.0
- <?php
- /**
- * Testimonials widget
- *
- * @package Astrid
- */
- class Atframework_Testimonials extends WP_Widget {
- public function __construct() {
- $widget_ops = array('classname' => 'atframework_testimonials_widget', 'description' => __( 'Display your testimonials.', 'astrid') );
- parent::__construct(false, $name = __('Astrid FP: Testimonials', 'astrid'), $widget_ops);
- $this->alt_option_name = 'atframework_testimonials_widget';
-
- }
-
- function form($instance) {
- $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
- $number = isset( $instance['number'] ) ? intval( $instance['number'] ) : -1;
- $offset = isset( $instance['offset'] ) ? intval( $instance['offset'] ) : 0;
- $see_all = isset( $instance['see_all'] ) ? esc_url( $instance['see_all'] ) : '';
- $see_all_text = isset( $instance['see_all_text'] ) ? esc_html( $instance['see_all_text'] ) : '';
- $pageids = isset( $instance['pageids'] ) ? esc_html( $instance['pageids'] ) : '';
- ?>
- <p><?php _e('This widget displays all pages that have the Single Testimonial page template assigned to them.', 'astrid'); ?></p>
- <p><em><?php _e('Tip: to rearrange the testimonials order, edit each testimonial page and add a value in Page Attributes > Order', 'astrid'); ?></em></p>
- <p>
- <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'astrid'); ?></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 testimonials to show (-1 shows all of them):', 'astrid' ); ?></label>
- <input 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><label for="<?php echo $this->get_field_id( 'offset' ); ?>"><?php _e( 'Offset (number of testimonials needs to be different than -1 for this option to work):', 'astrid' ); ?></label>
- <input id="<?php echo $this->get_field_id( 'offset' ); ?>" name="<?php echo $this->get_field_name( 'offset' ); ?>" type="text" value="<?php echo $offset; ?>" size="3" /></p>
- <p><label for="<?php echo $this->get_field_id( 'pageids' ); ?>"><?php _e( 'Page IDs to display in this widget (separated by commas, example: 14,810,220). Note: you can find the page ID in the URL bar while editing your page.', 'astrid' ); ?></label>
- <input id="<?php echo $this->get_field_id( 'pageids' ); ?>" name="<?php echo $this->get_field_name( 'pageids' ); ?>" type="text" value="<?php echo $pageids; ?>" size="3" /></p>
- <p><label for="<?php echo $this->get_field_id('see_all'); ?>"><?php _e('The URL for your button [In case you want a button below your testimonials block]', 'astrid'); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'see_all' ); ?>" name="<?php echo $this->get_field_name( 'see_all' ); ?>" type="text" value="<?php echo $see_all; ?>" size="3" /></p>
- <p><label for="<?php echo $this->get_field_id('see_all_text'); ?>"><?php _e('The text for the button [Defaults to <em>See all our testimonials</em> if left empty]', 'astrid'); ?></label>
- <input class="widefat" id="<?php echo $this->get_field_id( 'see_all_text' ); ?>" name="<?php echo $this->get_field_name( 'see_all_text' ); ?>" type="text" value="<?php echo $see_all_text; ?>" size="3" /></p>
- <?php
- }
- function update($new_instance, $old_instance) {
- $instance = $old_instance;
- $instance['title'] = sanitize_text_field($new_instance['title']);
- $instance['number'] = sanitize_text_field($new_instance['number']);
- $instance['offset'] = sanitize_text_field($new_instance['offset']);
- $instance['see_all'] = esc_url_raw( $new_instance['see_all'] );
- $instance['see_all_text'] = sanitize_text_field($new_instance['see_all_text']);
- $instance['pageids'] = sanitize_text_field($new_instance['pageids']);
-
- $alloptions = wp_cache_get( 'alloptions', 'options' );
- if ( isset($alloptions['atframework_testimonials']) )
- delete_option('atframework_testimonials');
-
- return $instance;
- }
-
- function widget($args, $instance) {
- $cache = array();
- if ( ! $this->is_preview() ) {
- $cache = wp_cache_get( 'atframework_testimonials', 'widget' );
- }
- if ( ! is_array( $cache ) ) {
- $cache = array();
- }
- if ( ! isset( $args['widget_id'] ) ) {
- $args['widget_id'] = $this->id;
- }
- if ( isset( $cache[ $args['widget_id'] ] ) ) {
- echo $cache[ $args['widget_id'] ];
- return;
- }
- ob_start();
- extract($args);
- $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : '';
- $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
- $see_all = isset( $instance['see_all'] ) ? esc_url($instance['see_all']) : '';
- $see_all_text = isset( $instance['see_all_text'] ) ? esc_html($instance['see_all_text']) : '';
- $number = ( ! empty( $instance['number'] ) ) ? intval( $instance['number'] ) : -1;
- if ( ! $number )
- $number = -1;
- $offset = ( ! empty( $instance['offset'] ) ) ? intval( $instance['offset'] ) : 0;
- $pageids = isset( $instance['pageids'] ) ? esc_html($instance['pageids']) : '';
- if ($pageids) {
- $ids = explode(',', $pageids);
- } else {
- $ids = '';
- }
- $testimonials = new WP_Query( array(
- 'post_type' => 'page',
- 'no_found_rows' => true,
- 'post_status' => 'publish',
- 'orderby' => 'menu_order',
- 'order' => 'ASC',
- 'posts_per_page' => $number,
- 'post__in' => $ids,
- 'offset' => $offset,
- 'meta_query' => array(
- array(
- 'key' => '_wp_page_template',
- 'value' => 'page-templates/single-testimonial.php',
- )
- )
- ) );
- echo $args['before_widget'];
- if ($testimonials->have_posts()) :
- ?>
- <?php if ( $title ) echo $before_title . $title . $after_title; ?>
- <div class="testimonial-area clearfix">
- <?php while ( $testimonials->have_posts() ) : $testimonials->the_post(); ?>
- <div class="testimonial astrid-3col">
- <div class="testimonial-content">
- <?php the_content(); ?>
- </div>
- <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="40" height="20">
- <g transform="translate(0,-1032.3622)">
- <path d="M 0,0 20,20 40,0" transform="translate(0,1032.3622)"/>
- </g>
- </svg>
- <?php if ( has_post_thumbnail() ) : ?>
- <div class="testimonial-thumb">
- <?php the_post_thumbnail('astrid-testimonial-thumb'); ?>
- </div>
- <?php endif; ?>
- <h3 class="testimonial-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
- </div>
- <?php endwhile; ?>
- </div>
- <?php if ($see_all != '') : ?>
- <a href="<?php echo esc_url($see_all); ?>" class="button centered-button">
- <?php if ($see_all_text) : ?>
- <?php echo $see_all_text; ?>
- <?php else : ?>
- <?php echo __('See all our testimonials', 'astrid'); ?>
- <?php endif; ?>
- </a>
- <?php endif; ?>
- <?php
- wp_reset_postdata();
- endif;
- echo $args['after_widget'];
- if ( ! $this->is_preview() ) {
- $cache[ $args['widget_id'] ] = ob_get_flush();
- wp_cache_set( 'atframework_testimonials', $cache, 'widget' );
- } else {
- ob_end_flush();
- }
- }
-
- }