Advertisement
anapatrice

fp-employees.php

Feb 22nd, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.23 KB | None | 0 0
  1. <?php
  2.  
  3. class Moesia_Employees extends WP_Widget {
  4.  
  5. // constructor
  6. function moesia_employees() {
  7. $widget_ops = array('classname' => 'moesia_employees_widget', 'description' => __( 'Display your team members in a stylish way.', 'moesia') );
  8. parent::__construct(false, $name = __('Moesia FP: Employees', 'moesia'), $widget_ops);
  9. $this->alt_option_name = 'moesia_employees_widget';
  10.  
  11. add_action( 'save_post', array($this, 'flush_widget_cache') );
  12. add_action( 'deleted_post', array($this, 'flush_widget_cache') );
  13. add_action( 'switch_theme', array($this, 'flush_widget_cache') );
  14. }
  15.  
  16. // widget form creation
  17. function form($instance) {
  18.  
  19. // Check values
  20. $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
  21. $image_uri = isset( $instance['image_uri'] ) ? esc_url_raw( $instance['image_uri'] ) : '';
  22. $number = isset( $instance['number'] ) ? intval( $instance['number'] ) : -1;
  23. $category = isset( $instance['category'] ) ? esc_attr( $instance['category'] ) : '';
  24. $see_all = isset( $instance['see_all'] ) ? esc_url_raw( $instance['see_all'] ) : '';
  25. $see_all_text = isset( $instance['see_all_text'] ) ? esc_html( $instance['see_all_text'] ) : '';
  26. ?>
  27.  
  28. <p><?php _e('In order to display this widget, you must first add some employees from the dashboard. Add as many as you want and the theme will automatically display them all.', 'moesia'); ?></p>
  29. <p>
  30. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'moesia'); ?></label>
  31. <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; ?>" />
  32. </p>
  33.  
  34. <?php
  35. if ( $image_uri != '' ) :
  36. echo '<p><img class="custom_media_image" src="' . $image_uri . '" style="max-width:100px;" /></p>';
  37. endif;
  38. ?>
  39. <p><label for="<?php echo $this->get_field_id('image_uri'); ?>"><?php _e('[DEPRECATED - Go to Edit Row > Theme > Background image] Upload an image for the background if you want. It will get a parallax effect.', 'moesia'); ?></label></p>
  40. <p><input type="button" class="button button-primary custom_media_button" id="custom_media_button" name="<?php echo $this->get_field_name('image_uri'); ?>" value="Upload Image" style="margin-top:5px;" /></p>
  41. <p><input class="widefat custom_media_url" id="<?php echo $this->get_field_id( 'image_uri' ); ?>" name="<?php echo $this->get_field_name( 'image_uri' ); ?>" type="text" value="<?php echo $image_uri; ?>" size="3" /></p>
  42. <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of employees to show (-1 shows all of them):', 'moesia' ); ?></label>
  43. <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>
  44. <p><label for="<?php echo $this->get_field_id('see_all'); ?>"><?php _e('Enter the URL for your employees page. Useful if you want to show here just a few employees, then send your visitors to a page that uses the employees page template.', 'moesia'); ?></label>
  45. <input class="widefat custom_media_url" 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>
  46. <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 employees</em> if left empty]', 'moesia'); ?></label>
  47. <input class="widefat custom_media_url" 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>
  48.  
  49. <p><label for="<?php echo $this->get_field_id( 'category' ); ?>"><?php _e( 'Enter the slug for your category or leave empty to show all employees.', 'moesia' ); ?></label>
  50. <input class="widefat" id="<?php echo $this->get_field_id( 'category' ); ?>" name="<?php echo $this->get_field_name( 'category' ); ?>" type="text" value="<?php echo $category; ?>" size="3" /></p>
  51.  
  52. <?php
  53. }
  54.  
  55. // update widget
  56. function update($new_instance, $old_instance) {
  57. $instance = $old_instance;
  58. $instance['title'] = strip_tags($new_instance['title']);
  59. $instance['number'] = strip_tags($new_instance['number']);
  60. $instance['image_uri'] = esc_url_raw( $new_instance['image_uri'] );
  61. $instance['see_all'] = esc_url_raw( $new_instance['see_all'] );
  62. $instance['see_all_text'] = strip_tags($new_instance['see_all_text']);
  63. $instance['category'] = strip_tags($new_instance['category']);
  64.  
  65. $this->flush_widget_cache();
  66.  
  67. $alloptions = wp_cache_get( 'alloptions', 'options' );
  68. if ( isset($alloptions['moesia_employees']) )
  69. delete_option('moesia_employees');
  70.  
  71. return $instance;
  72. }
  73.  
  74. function flush_widget_cache() {
  75. wp_cache_delete('moesia_employees', 'widget');
  76. }
  77.  
  78. // display widget
  79. function widget($args, $instance) {
  80. $cache = array();
  81. if ( ! $this->is_preview() ) {
  82. $cache = wp_cache_get( 'moesia_employees', 'widget' );
  83. }
  84.  
  85. if ( ! is_array( $cache ) ) {
  86. $cache = array();
  87. }
  88.  
  89. if ( ! isset( $args['widget_id'] ) ) {
  90. $args['widget_id'] = $this->id;
  91. }
  92.  
  93. if ( isset( $cache[ $args['widget_id'] ] ) ) {
  94. echo $cache[ $args['widget_id'] ];
  95. return;
  96. }
  97.  
  98. ob_start();
  99. extract($args);
  100.  
  101. $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Our Employees', 'moesia' );
  102.  
  103. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  104. $image_uri = isset( $instance['image_uri'] ) ? esc_url($instance['image_uri']) : '';
  105. $see_all = isset( $instance['see_all'] ) ? esc_url($instance['see_all']) : '';
  106. $see_all_text = isset( $instance['see_all_text'] ) ? esc_html($instance['see_all_text']) : '';
  107. $number = ( ! empty( $instance['number'] ) ) ? intval( $instance['number'] ) : -1;
  108. if ( ! $number )
  109. $number = -1;
  110. $category = isset( $instance['category'] ) ? esc_attr($instance['category']) : '';
  111.  
  112. $r = new WP_Query( apply_filters( 'widget_posts_args', array(
  113. 'no_found_rows' => true,
  114. 'post_status' => 'publish',
  115. 'post_type' => 'employees',
  116. 'posts_per_page' => $number,
  117. 'category_name' => $category
  118. ) ) );
  119.  
  120. if ($r->have_posts()) :
  121. ?>
  122.  
  123. <section id="employees" class="employees-area">
  124. <div class="container">
  125. <?php if ( $title ) echo $before_title . '<span class="wow bounce">' . $title . '</span>' . $after_title; ?>
  126. <?php while ( $r->have_posts() ) : $r->the_post(); ?>
  127. <?php //Get the custom field values
  128. $photo = get_post_meta( get_the_ID(), 'wpcf-photo', true );
  129. $position = get_post_meta( get_the_ID(), 'wpcf-position', true );
  130. $facebook = get_post_meta( get_the_ID(), 'wpcf-facebook', true );
  131. $twitter = get_post_meta( get_the_ID(), 'wpcf-twitter', true );
  132. $google = get_post_meta( get_the_ID(), 'wpcf-google-plus', true );
  133. $linkedin = get_post_meta( get_the_ID(), 'wpcf-linkedin', true );
  134. $custom_link = get_post_meta( get_the_ID(), 'wpcf-custom-link', true );
  135. ?>
  136. <div class="employee col-md-4 col-sm-6 col-xs-6">
  137. <?php if ($photo != '') : ?>
  138. <a href="<?php echo esc_url($custom_link); ?>">
  139. <?php endif; ?>
  140.  
  141.  
  142. <img class="employee-photo wow zoomInDown" src="<?php echo esc_url($photo); ?>" alt="<?php the_title(); ?>">
  143. <?php if ( $custom_link != '' ) : ?>
  144. </a>
  145. <?php endif; ?>
  146.  
  147. <?php elseif ( has_post_thumbnail() ) : ?>
  148.  
  149. <?php if ( $custom_link != '' ) : ?>
  150. <a href="<?php echo esc_url($custom_link); ?>">
  151. <?php endif; ?>
  152.  
  153. <div class="employee-photo wow zoomInDown"><?php the_post_thumbnail('moesia-employees-thumb'); ?></div>
  154.  
  155. <?php if ( $custom_link != '' ) : ?>
  156. </a>
  157. <?php endif; ?>
  158.  
  159. <?php endif; ?>
  160. <h4 class="employee-name wow fadeInUp"><?php the_title(); ?></h4>
  161. <?php if ($position != '') : ?>
  162. <span class="employee-position wow fadeInUp"><?php echo esc_html($position); ?></span>
  163. <?php endif; ?>
  164. <div class="employee-desc wow fadeInUp"><?php the_content(); ?></div>
  165. <?php if ( ($facebook != '') || ($twitter != '') || ($google != '') || ($linkedin != '') ) : ?>
  166. <div class="employee-social wow fadeInUp">
  167. <?php if ($facebook != '') : ?>
  168. <a href="<?php echo esc_url($facebook); ?>" target="_blank"><i class="fa fa-facebook"></i></a>
  169. <?php endif; ?>
  170. <?php if ($twitter != '') : ?>
  171. <a href="<?php echo esc_url($twitter); ?>" target="_blank"><i class="fa fa-twitter"></i></a>
  172. <?php endif; ?>
  173. <?php if ($google != '') : ?>
  174. <a href="<?php echo esc_url($google); ?>" target="_blank"><i class="fa fa-google-plus"></i></a>
  175. <?php endif; ?>
  176. <?php if ($linkedin != '') : ?>
  177. <a href="<?php echo esc_url($linkedin); ?>" target="_blank"><i class="fa fa-linkedin"></i></a>
  178. <?php endif; ?>
  179. </div>
  180. <?php endif; ?>
  181. </div>
  182. <?php endwhile; ?>
  183. </div>
  184. <?php if ($see_all != '') : ?>
  185. <a href="<?php echo esc_url($see_all); ?>" class="all-news">
  186. <?php if ($see_all_text) : ?>
  187. <?php echo $see_all_text; ?>
  188. <?php else : ?>
  189. <?php echo __('See all our employees', 'moesia'); ?>
  190. <?php endif; ?>
  191. </a>
  192. <?php endif; ?>
  193. </section>
  194. <?php if ($image_uri != '') : ?>
  195. <style type="text/css">
  196. .employees-area {
  197. display: block;
  198. background: url(<?php echo $image_uri; ?>) no-repeat;
  199. background-position: center top;
  200. background-attachment: fixed;
  201. background-size: cover;
  202. z-index: -1;
  203. }
  204. .employee {
  205. background-color: rgba(0,0,0,0.6);
  206. border-right: 1px solid #5E5E5E;
  207. }
  208. .employee:nth-of-type(3),
  209. .employee:nth-of-type(6),
  210. .employee:nth-of-type(7) {
  211. border-right: 0;
  212. }
  213. </style>
  214. <?php endif; ?>
  215.  
  216. <?php
  217. // Reset the global $the_post as this query will have stomped on it
  218. wp_reset_postdata();
  219.  
  220. endif;
  221.  
  222. if ( ! $this->is_preview() ) {
  223. $cache[ $args['widget_id'] ] = ob_get_flush();
  224. wp_cache_set( 'moesia_employees', $cache, 'widget' );
  225. } else {
  226. ob_end_flush();
  227. }
  228. }
  229.  
  230. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement