PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/astrid/inc/framework/widgets/front-testimonials.php

https://bitbucket.org/EduardoEMD/exclusive
PHP | 165 lines | 138 code | 22 blank | 5 comment | 18 complexity | c9ad5b362d881663c3500c0b83b30cdc MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Testimonials widget
  4. *
  5. * @package Astrid
  6. */
  7. class Atframework_Testimonials extends WP_Widget {
  8. public function __construct() {
  9. $widget_ops = array('classname' => 'atframework_testimonials_widget', 'description' => __( 'Display your testimonials.', 'astrid') );
  10. parent::__construct(false, $name = __('Astrid FP: Testimonials', 'astrid'), $widget_ops);
  11. $this->alt_option_name = 'atframework_testimonials_widget';
  12. }
  13. function form($instance) {
  14. $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
  15. $number = isset( $instance['number'] ) ? intval( $instance['number'] ) : -1;
  16. $offset = isset( $instance['offset'] ) ? intval( $instance['offset'] ) : 0;
  17. $see_all = isset( $instance['see_all'] ) ? esc_url( $instance['see_all'] ) : '';
  18. $see_all_text = isset( $instance['see_all_text'] ) ? esc_html( $instance['see_all_text'] ) : '';
  19. $pageids = isset( $instance['pageids'] ) ? esc_html( $instance['pageids'] ) : '';
  20. ?>
  21. <p><?php _e('This widget displays all pages that have the Single Testimonial page template assigned to them.', 'astrid'); ?></p>
  22. <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>
  23. <p>
  24. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'astrid'); ?></label>
  25. <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; ?>" />
  26. </p>
  27. <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of testimonials to show (-1 shows all of them):', 'astrid' ); ?></label>
  28. <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>
  29. <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>
  30. <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>
  31. <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>
  32. <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>
  33. <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>
  34. <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>
  35. <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>
  36. <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>
  37. <?php
  38. }
  39. function update($new_instance, $old_instance) {
  40. $instance = $old_instance;
  41. $instance['title'] = sanitize_text_field($new_instance['title']);
  42. $instance['number'] = sanitize_text_field($new_instance['number']);
  43. $instance['offset'] = sanitize_text_field($new_instance['offset']);
  44. $instance['see_all'] = esc_url_raw( $new_instance['see_all'] );
  45. $instance['see_all_text'] = sanitize_text_field($new_instance['see_all_text']);
  46. $instance['pageids'] = sanitize_text_field($new_instance['pageids']);
  47. $alloptions = wp_cache_get( 'alloptions', 'options' );
  48. if ( isset($alloptions['atframework_testimonials']) )
  49. delete_option('atframework_testimonials');
  50. return $instance;
  51. }
  52. function widget($args, $instance) {
  53. $cache = array();
  54. if ( ! $this->is_preview() ) {
  55. $cache = wp_cache_get( 'atframework_testimonials', 'widget' );
  56. }
  57. if ( ! is_array( $cache ) ) {
  58. $cache = array();
  59. }
  60. if ( ! isset( $args['widget_id'] ) ) {
  61. $args['widget_id'] = $this->id;
  62. }
  63. if ( isset( $cache[ $args['widget_id'] ] ) ) {
  64. echo $cache[ $args['widget_id'] ];
  65. return;
  66. }
  67. ob_start();
  68. extract($args);
  69. $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : '';
  70. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  71. $see_all = isset( $instance['see_all'] ) ? esc_url($instance['see_all']) : '';
  72. $see_all_text = isset( $instance['see_all_text'] ) ? esc_html($instance['see_all_text']) : '';
  73. $number = ( ! empty( $instance['number'] ) ) ? intval( $instance['number'] ) : -1;
  74. if ( ! $number )
  75. $number = -1;
  76. $offset = ( ! empty( $instance['offset'] ) ) ? intval( $instance['offset'] ) : 0;
  77. $pageids = isset( $instance['pageids'] ) ? esc_html($instance['pageids']) : '';
  78. if ($pageids) {
  79. $ids = explode(',', $pageids);
  80. } else {
  81. $ids = '';
  82. }
  83. $testimonials = new WP_Query( array(
  84. 'post_type' => 'page',
  85. 'no_found_rows' => true,
  86. 'post_status' => 'publish',
  87. 'orderby' => 'menu_order',
  88. 'order' => 'ASC',
  89. 'posts_per_page' => $number,
  90. 'post__in' => $ids,
  91. 'offset' => $offset,
  92. 'meta_query' => array(
  93. array(
  94. 'key' => '_wp_page_template',
  95. 'value' => 'page-templates/single-testimonial.php',
  96. )
  97. )
  98. ) );
  99. echo $args['before_widget'];
  100. if ($testimonials->have_posts()) :
  101. ?>
  102. <?php if ( $title ) echo $before_title . $title . $after_title; ?>
  103. <div class="testimonial-area clearfix">
  104. <?php while ( $testimonials->have_posts() ) : $testimonials->the_post(); ?>
  105. <div class="testimonial astrid-3col">
  106. <div class="testimonial-content">
  107. <?php the_content(); ?>
  108. </div>
  109. <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="40" height="20">
  110. <g transform="translate(0,-1032.3622)">
  111. <path d="M 0,0 20,20 40,0" transform="translate(0,1032.3622)"/>
  112. </g>
  113. </svg>
  114. <?php if ( has_post_thumbnail() ) : ?>
  115. <div class="testimonial-thumb">
  116. <?php the_post_thumbnail('astrid-testimonial-thumb'); ?>
  117. </div>
  118. <?php endif; ?>
  119. <h3 class="testimonial-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
  120. </div>
  121. <?php endwhile; ?>
  122. </div>
  123. <?php if ($see_all != '') : ?>
  124. <a href="<?php echo esc_url($see_all); ?>" class="button centered-button">
  125. <?php if ($see_all_text) : ?>
  126. <?php echo $see_all_text; ?>
  127. <?php else : ?>
  128. <?php echo __('See all our testimonials', 'astrid'); ?>
  129. <?php endif; ?>
  130. </a>
  131. <?php endif; ?>
  132. <?php
  133. wp_reset_postdata();
  134. endif;
  135. echo $args['after_widget'];
  136. if ( ! $this->is_preview() ) {
  137. $cache[ $args['widget_id'] ] = ob_get_flush();
  138. wp_cache_set( 'atframework_testimonials', $cache, 'widget' );
  139. } else {
  140. ob_end_flush();
  141. }
  142. }
  143. }