PageRenderTime 34ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/wordpress/wp-content/themes/sydney/widgets/fp-employees.php

https://bitbucket.org/Tasfeq/web-admin
PHP | 197 lines | 162 code | 35 blank | 0 comment | 26 complexity | 6fba05171d47a9fea91e00e9cd3de3a9 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. class Sydney_Employees extends WP_Widget {
  3. public function __construct() {
  4. $widget_ops = array('classname' => 'sydney_employees_widget', 'description' => __( 'Display your team members in a stylish way.', 'sydney') );
  5. parent::__construct(false, $name = __('Sydney FP: Employees', 'sydney'), $widget_ops);
  6. $this->alt_option_name = 'sydney_employees_widget';
  7. }
  8. function form($instance) {
  9. $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
  10. $number = isset( $instance['number'] ) ? intval( $instance['number'] ) : -1;
  11. $category = isset( $instance['category'] ) ? esc_attr( $instance['category'] ) : '';
  12. $see_all = isset( $instance['see_all'] ) ? esc_url_raw( $instance['see_all'] ) : '';
  13. $see_all_text = isset( $instance['see_all_text'] ) ? esc_html( $instance['see_all_text'] ) : '';
  14. $center_content = isset( $instance['center_content'] ) ? (bool) $instance['center_content'] : false;
  15. ?>
  16. <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.', 'sydney'); ?></p>
  17. <p>
  18. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'sydney'); ?></label>
  19. <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; ?>" />
  20. </p>
  21. <p><label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of employees to show (-1 shows all of them):', 'sydney' ); ?></label>
  22. <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>
  23. <p><label for="<?php echo $this->get_field_id('see_all'); ?>"><?php _e('Enter an URL here if you want to section to link somewhere.', 'sydney'); ?></label>
  24. <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>
  25. <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]', 'sydney'); ?></label>
  26. <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>
  27. <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.', 'sydney' ); ?></label>
  28. <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>
  29. <p><input class="checkbox" type="checkbox" <?php checked( $center_content ); ?> id="<?php echo $this->get_field_id( 'center_content' ); ?>" name="<?php echo $this->get_field_name( 'center_content' ); ?>" />
  30. <label for="<?php echo $this->get_field_id( 'center_content' ); ?>"><?php _e( 'Center the employees? (use only if you have 1 or 2 employees)', 'sydney' ); ?></label></p>
  31. <?php
  32. }
  33. function update($new_instance, $old_instance) {
  34. $instance = $old_instance;
  35. $instance['title'] = strip_tags($new_instance['title']);
  36. $instance['number'] = strip_tags($new_instance['number']);
  37. $instance['see_all'] = esc_url_raw( $new_instance['see_all'] );
  38. $instance['see_all_text'] = strip_tags($new_instance['see_all_text']);
  39. $instance['category'] = strip_tags($new_instance['category']);
  40. $instance['center_content'] = isset( $new_instance['center_content'] ) ? (bool) $new_instance['center_content'] : false;
  41. $alloptions = wp_cache_get( 'alloptions', 'options' );
  42. if ( isset($alloptions['sydney_employees']) )
  43. delete_option('sydney_employees');
  44. return $instance;
  45. }
  46. function widget($args, $instance) {
  47. $cache = array();
  48. if ( ! $this->is_preview() ) {
  49. $cache = wp_cache_get( 'sydney_employees', 'widget' );
  50. }
  51. if ( ! is_array( $cache ) ) {
  52. $cache = array();
  53. }
  54. if ( ! isset( $args['widget_id'] ) ) {
  55. $args['widget_id'] = $this->id;
  56. }
  57. if ( isset( $cache[ $args['widget_id'] ] ) ) {
  58. echo $cache[ $args['widget_id'] ];
  59. return;
  60. }
  61. ob_start();
  62. extract($args);
  63. $title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : '';
  64. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
  65. $see_all = isset( $instance['see_all'] ) ? esc_url($instance['see_all']) : '';
  66. $see_all_text = isset( $instance['see_all_text'] ) ? esc_html($instance['see_all_text']) : '';
  67. $number = ( ! empty( $instance['number'] ) ) ? intval( $instance['number'] ) : -1;
  68. if ( ! $number )
  69. $number = -1;
  70. $category = isset( $instance['category'] ) ? esc_attr($instance['category']) : '';
  71. $center_content = isset( $instance['center_content'] ) ? $instance['center_content'] : false;
  72. $r = new WP_Query(array(
  73. 'no_found_rows' => true,
  74. 'post_status' => 'publish',
  75. 'post_type' => 'employees',
  76. 'posts_per_page' => $number,
  77. 'category_name' => $category
  78. ) );
  79. echo $args['before_widget'];
  80. if ($r->have_posts()) :
  81. ?>
  82. <?php if ( $title ) echo $before_title . $title . $after_title; ?>
  83. <div class="roll-team carousel owl-carousel" data-widgetid="employees-<?php echo $args['widget_id']; ?>">
  84. <?php while ( $r->have_posts() ) : $r->the_post(); ?>
  85. <?php //Get the custom field values
  86. $position = get_post_meta( get_the_ID(), 'wpcf-position', true );
  87. $facebook = get_post_meta( get_the_ID(), 'wpcf-facebook', true );
  88. $twitter = get_post_meta( get_the_ID(), 'wpcf-twitter', true );
  89. $google = get_post_meta( get_the_ID(), 'wpcf-google-plus', true );
  90. $link = get_post_meta( get_the_ID(), 'wpcf-custom-link', true );
  91. ?>
  92. <div class="team-item">
  93. <div class="team-inner">
  94. <div class="pop-overlay">
  95. <div class="team-pop">
  96. <div class="team-info">
  97. <div class="name"><?php the_title(); ?></div>
  98. <div class="pos"><?php echo esc_html($position); ?></div>
  99. <ul class="team-social">
  100. <?php if ($facebook != '') : ?>
  101. <li><a class="facebook" href="<?php echo esc_url($facebook); ?>" target="_blank"><i class="fa fa-facebook"></i></a></li>
  102. <?php endif; ?>
  103. <?php if ($twitter != '') : ?>
  104. <li><a class="twitter" href="<?php echo esc_url($twitter); ?>" target="_blank"><i class="fa fa-twitter"></i></a></li>
  105. <?php endif; ?>
  106. <?php if ($google != '') : ?>
  107. <li><a class="google" href="<?php echo esc_url($google); ?>" target="_blank"><i class="fa fa-google-plus"></i></a></li>
  108. <?php endif; ?>
  109. </ul>
  110. </div>
  111. </div>
  112. </div>
  113. <?php if ( has_post_thumbnail() ) : ?>
  114. <div class="avatar">
  115. <?php the_post_thumbnail('sydney-medium-thumb'); ?>
  116. </div>
  117. <?php endif; ?>
  118. </div>
  119. <div class="team-content">
  120. <div class="name">
  121. <?php if ($link == '') : ?>
  122. <?php the_title(); ?>
  123. <?php else : ?>
  124. <a href="<?php echo esc_url($link); ?>"><?php the_title(); ?></a>
  125. <?php endif; ?>
  126. </div>
  127. <div class="pos"><?php echo esc_html($position); ?></div>
  128. </div>
  129. </div><!-- /.team-item -->
  130. <?php endwhile; ?>
  131. </div>
  132. <?php if ($see_all != '') : ?>
  133. <a href="<?php echo esc_url($see_all); ?>" class="roll-button more-button">
  134. <?php if ($see_all_text) : ?>
  135. <?php echo $see_all_text; ?>
  136. <?php else : ?>
  137. <?php echo __('See all our employees', 'sydney'); ?>
  138. <?php endif; ?>
  139. </a>
  140. <?php endif; ?>
  141. <?php
  142. wp_reset_postdata();
  143. if ($center_content) :
  144. echo '<style>';
  145. echo '@media only screen and (min-width: 971px) {';
  146. echo '[data-widgetid="employees-' . $args['widget_id'] . '"].roll-team .owl-wrapper { text-align: center; width: 100% !important; }';
  147. echo '[data-widgetid="employees-' . $args['widget_id'] . '"].roll-team.owl-carousel .owl-item { float: none; display: inline-block; }';
  148. echo '}';
  149. echo '</style>';
  150. ?>
  151. <?php
  152. endif;
  153. endif;
  154. echo $args['after_widget'];
  155. if ( ! $this->is_preview() ) {
  156. $cache[ $args['widget_id'] ] = ob_get_flush();
  157. wp_cache_set( 'sydney_employees', $cache, 'widget' );
  158. } else {
  159. ob_end_flush();
  160. }
  161. }
  162. }