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

/wp-content/themes/news/library/classes/widget-authors.php

https://bitbucket.org/lgorence/quickpress
PHP | 211 lines | 134 code | 27 blank | 50 comment | 4 complexity | 9c9d8a7a4482b9dc33a7d57a7eff6c13 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * The authors widget was created to give users the ability to list the authors of their blog because
  4. * there was no equivalent WordPress widget that offered the functionality. This widget allows full
  5. * control over its output by giving access to the parameters of wp_list_authors().
  6. *
  7. * @package Hybrid
  8. * @subpackage Classes
  9. * @author Justin Tadlock <justin@justintadlock.com>
  10. * @copyright Copyright (c) 2008 - 2012, Justin Tadlock
  11. * @link http://themehybrid.com/hybrid-core
  12. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  13. */
  14. /**
  15. * Authors Widget Class
  16. *
  17. * @since 0.6.0
  18. */
  19. class Hybrid_Widget_Authors extends WP_Widget {
  20. /**
  21. * Set up the widget's unique name, ID, class, description, and other options.
  22. *
  23. * @since 1.2.0
  24. */
  25. function __construct() {
  26. /* Set up the widget options. */
  27. $widget_options = array(
  28. 'classname' => 'authors',
  29. 'description' => esc_html__( 'An advanced widget that gives you total control over the output of your author lists.', 'hybrid-core' )
  30. );
  31. /* Set up the widget control options. */
  32. $control_options = array(
  33. 'width' => 525,
  34. 'height' => 350
  35. );
  36. /* Create the widget. */
  37. $this->WP_Widget(
  38. 'hybrid-authors', // $this->id_base
  39. __( 'Authors', 'hybrid-core' ), // $this->name
  40. $widget_options, // $this->widget_options
  41. $control_options // $this->control_options
  42. );
  43. }
  44. /**
  45. * Outputs the widget based on the arguments input through the widget controls.
  46. *
  47. * @since 0.6.0
  48. */
  49. function widget( $sidebar, $instance ) {
  50. extract( $sidebar );
  51. /* Set the $args for wp_list_authors() to the $instance array. */
  52. $args = $instance;
  53. /* Overwrite the $echo argument and set it to false. */
  54. $args['echo'] = false;
  55. /* Output the theme's $before_widget wrapper. */
  56. echo $before_widget;
  57. /* If a title was input by the user, display it. */
  58. if ( !empty( $instance['title'] ) )
  59. echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
  60. /* Get the authors list. */
  61. $authors = str_replace( array( "\r", "\n", "\t" ), '', wp_list_authors( $args ) );
  62. /* If 'list' is the style and the output should be HTML, wrap the authors in a <ul>. */
  63. if ( 'list' == $args['style'] && $args['html'] )
  64. $authors = '<ul class="xoxo authors">' . $authors . '</ul><!-- .xoxo .authors -->';
  65. /* Display the authors list. */
  66. echo $authors;
  67. /* Close the theme's widget wrapper. */
  68. echo $after_widget;
  69. }
  70. /**
  71. * Updates the widget control options for the particular instance of the widget.
  72. *
  73. * @since 0.6.0
  74. */
  75. function update( $new_instance, $old_instance ) {
  76. $instance = $old_instance;
  77. $instance = $new_instance;
  78. $instance['title'] = strip_tags( $new_instance['title'] );
  79. $instance['feed'] = strip_tags( $new_instance['feed'] );
  80. $instance['order'] = strip_tags( $new_instance['order'] );
  81. $instance['orderby'] = strip_tags( $new_instance['orderby'] );
  82. $instance['number'] = strip_tags( $new_instance['number'] );
  83. $instance['html'] = ( isset( $new_instance['html'] ) ? 1 : 0 );
  84. $instance['optioncount'] = ( isset( $new_instance['optioncount'] ) ? 1 : 0 );
  85. $instance['exclude_admin'] = ( isset( $new_instance['exclude_admin'] ) ? 1 : 0 );
  86. $instance['show_fullname'] = ( isset( $new_instance['show_fullname'] ) ? 1 : 0 );
  87. $instance['hide_empty'] = ( isset( $new_instance['hide_empty'] ) ? 1 : 0 );
  88. return $instance;
  89. }
  90. /**
  91. * Displays the widget control options in the Widgets admin screen.
  92. *
  93. * @since 0.6.0
  94. */
  95. function form( $instance ) {
  96. /* Set up the default form values. */
  97. $defaults = array(
  98. 'title' => esc_attr__( 'Authors', 'hybrid-core' ),
  99. 'order' => 'ASC',
  100. 'orderby' => 'display_name',
  101. 'number' => '',
  102. 'optioncount' => false,
  103. 'exclude_admin' => false,
  104. 'show_fullname' => true,
  105. 'hide_empty' => true,
  106. 'style' => 'list',
  107. 'html' => true,
  108. 'feed' => '',
  109. 'feed_image' => ''
  110. );
  111. /* Merge the user-selected arguments with the defaults. */
  112. $instance = wp_parse_args( (array) $instance, $defaults );
  113. $order = array( 'ASC' => esc_attr__( 'Ascending', 'hybrid-core' ), 'DESC' => esc_attr__( 'Descending', 'hybrid-core' ) );
  114. $orderby = array( 'display_name' => esc_attr__( 'Display Name', 'hybrid-core' ), 'email' => esc_attr__( 'Email', 'hybrid-core' ), 'ID' => esc_attr__( 'ID', 'hybrid-core' ), 'nicename' => esc_attr__( 'Nice Name', 'hybrid-core' ), 'post_count' => esc_attr__( 'Post Count', 'hybrid-core' ), 'registered' => esc_attr__( 'Registered', 'hybrid-core' ), 'url' => esc_attr__( 'URL', 'hybrid-core' ), 'user_login' => esc_attr__( 'Login', 'hybrid-core' ) );
  115. ?>
  116. <div class="hybrid-widget-controls columns-2">
  117. <p>
  118. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'hybrid-core' ); ?></label>
  119. <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" />
  120. </p>
  121. <p>
  122. <label for="<?php echo $this->get_field_id( 'order' ); ?>"><code>order</code></label>
  123. <select class="widefat" id="<?php echo $this->get_field_id( 'order' ); ?>" name="<?php echo $this->get_field_name( 'order' ); ?>">
  124. <?php foreach ( $order as $option_value => $option_label ) { ?>
  125. <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['order'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
  126. <?php } ?>
  127. </select>
  128. </p>
  129. <p>
  130. <label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><code>orderby</code></label>
  131. <select class="widefat" id="<?php echo $this->get_field_id( 'orderby' ); ?>" name="<?php echo $this->get_field_name( 'orderby' ); ?>">
  132. <?php foreach ( $orderby as $option_value => $option_label ) { ?>
  133. <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['orderby'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
  134. <?php } ?>
  135. </select>
  136. </p>
  137. <p>
  138. <label for="<?php echo $this->get_field_id( 'number' ); ?>"><code>number</code></label>
  139. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" value="<?php echo esc_attr( $instance['number'] ); ?>" />
  140. </p>
  141. <p>
  142. <label for="<?php echo $this->get_field_id( 'style' ); ?>"><code>style</code></label>
  143. <select class="widefat" id="<?php echo $this->get_field_id( 'style' ); ?>" name="<?php echo $this->get_field_name( 'style' ); ?>">
  144. <?php foreach ( array( 'list' => esc_attr__( 'List', 'hybrid-core'), 'none' => esc_attr__( 'None', 'hybrid-core' ) ) as $option_value => $option_label ) { ?>
  145. <option value="<?php echo esc_attr( $option_value ); ?>" <?php selected( $instance['style'], $option_value ); ?>><?php echo esc_html( $option_label ); ?></option>
  146. <?php } ?>
  147. </select>
  148. </p>
  149. </div>
  150. <div class="hybrid-widget-controls columns-2 column-last">
  151. <p>
  152. <label for="<?php echo $this->get_field_id( 'feed' ); ?>"><code>feed</code></label>
  153. <input type="text" class="widefat code" id="<?php echo $this->get_field_id( 'feed' ); ?>" name="<?php echo $this->get_field_name( 'feed' ); ?>" value="<?php echo esc_attr( $instance['feed'] ); ?>" />
  154. </p>
  155. <p>
  156. <label for="<?php echo $this->get_field_id( 'feed_image' ); ?>"><code>feed_image</code></label>
  157. <input type="text" class="widefat code" id="<?php echo $this->get_field_id( 'feed_image' ); ?>" name="<?php echo $this->get_field_name( 'feed_image' ); ?>" value="<?php echo esc_attr( $instance['feed_image'] ); ?>" />
  158. </p>
  159. <p>
  160. <label for="<?php echo $this->get_field_id( 'html' ); ?>">
  161. <input class="checkbox" type="checkbox" <?php checked( $instance['html'], true ); ?> id="<?php echo $this->get_field_id( 'html' ); ?>" name="<?php echo $this->get_field_name( 'html' ); ?>" /> <?php _e( '<acronym title="Hypertext Markup Language">HTML</acronym>?', 'hybrid-core' ); ?> <code>html</code></label>
  162. </p>
  163. <p>
  164. <label for="<?php echo $this->get_field_id( 'optioncount' ); ?>">
  165. <input class="checkbox" type="checkbox" <?php checked( $instance['optioncount'], true ); ?> id="<?php echo $this->get_field_id( 'optioncount' ); ?>" name="<?php echo $this->get_field_name( 'optioncount' ); ?>" /> <?php _e( 'Show post count?', 'hybrid-core' ); ?> <code>optioncount</code></label>
  166. </p>
  167. <p>
  168. <label for="<?php echo $this->get_field_id( 'exclude_admin' ); ?>">
  169. <input class="checkbox" type="checkbox" <?php checked( $instance['exclude_admin'], true ); ?> id="<?php echo $this->get_field_id( 'exclude_admin' ); ?>" name="<?php echo $this->get_field_name( 'exclude_admin' ); ?>" /> <?php _e( 'Exclude admin?', 'hybrid-core' ); ?> <code>exclude_admin</code></label>
  170. </p>
  171. <p>
  172. <label for="<?php echo $this->get_field_id( 'show_fullname' ); ?>">
  173. <input class="checkbox" type="checkbox" <?php checked( $instance['show_fullname'], true ); ?> id="<?php echo $this->get_field_id( 'show_fullname' ); ?>" name="<?php echo $this->get_field_name( 'show_fullname' ); ?>" /> <?php _e( 'Show full name?', 'hybrid-core' ); ?> <code>show_fullname</code></label>
  174. </p>
  175. <p>
  176. <label for="<?php echo $this->get_field_id( 'hide_empty' ); ?>">
  177. <input class="checkbox" type="checkbox" <?php checked( $instance['hide_empty'], true ); ?> id="<?php echo $this->get_field_id( 'hide_empty' ); ?>" name="<?php echo $this->get_field_name( 'hide_empty' ); ?>" /> <?php _e( 'Hide empty?', 'hybrid-core' ); ?> <code>hide_empty</code></label>
  178. </p>
  179. </div>
  180. <div style="clear:both;">&nbsp;</div>
  181. <?php
  182. }
  183. }
  184. ?>