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

/public_html/wp-content/themes/genesis/lib/structure/comments.php

https://gitlab.com/hop23typhu/list-theme
PHP | 465 lines | 218 code | 88 blank | 159 comment | 36 complexity | e63e24e63ba53793b3730c8facb84fae MD5 | raw file
  1. <?php
  2. /**
  3. * Genesis Framework.
  4. *
  5. * WARNING: This file is part of the core Genesis Framework. DO NOT edit this file under any circumstances.
  6. * Please do all modifications in the form of a child theme.
  7. *
  8. * @package Genesis\Comments
  9. * @author StudioPress
  10. * @license GPL-2.0+
  11. * @link http://my.studiopress.com/themes/genesis/
  12. */
  13. add_action( 'genesis_after_post', 'genesis_get_comments_template' );
  14. add_action( 'genesis_after_entry', 'genesis_get_comments_template' );
  15. /**
  16. * Output the comments at the end of entries.
  17. *
  18. * Load comments only if we are on a post, page, or CPT that supports comments, and only if comments or trackbacks are enabled.
  19. *
  20. * @since 1.1.0
  21. *
  22. * @uses genesis_get_option() Get theme setting value.
  23. *
  24. * @return null Return early if post type does not support comments.
  25. */
  26. function genesis_get_comments_template() {
  27. if ( ! post_type_supports( get_post_type(), 'comments' ) )
  28. return;
  29. if ( is_singular() && ! in_array( get_post_type(), array( 'post', 'page' ) ) ) {
  30. comments_template( '', true );
  31. } elseif ( is_singular( 'post' ) && ( genesis_get_option( 'trackbacks_posts' ) || genesis_get_option( 'comments_posts' ) ) ) {
  32. comments_template( '', true );
  33. } elseif ( is_singular( 'page' ) && ( genesis_get_option( 'trackbacks_pages' ) || genesis_get_option( 'comments_pages' ) ) ) {
  34. comments_template( '', true );
  35. }
  36. }
  37. add_action( 'genesis_comments', 'genesis_do_comments' );
  38. /**
  39. * Echo Genesis default comment structure.
  40. *
  41. * Does the `genesis_list_comments` action.
  42. *
  43. * Applies the `genesis_title_comments`, `genesis_prev_comments_link_text`, `genesis_next_comments_link_text`, and
  44. * `genesis_comments_closed_text` filters.
  45. *
  46. * @since 1.1.2
  47. *
  48. * @uses genesis_get_option() Get theme setting value.
  49. *
  50. * @global WP_Query $wp_query Query object.
  51. *
  52. * @return null Return early if on a page with Genesis pages comments off, or on a post with Genesis posts comments off.
  53. */
  54. function genesis_do_comments() {
  55. global $wp_query;
  56. //* Bail if comments are off for this post type
  57. if ( ( is_page() && ! genesis_get_option( 'comments_pages' ) ) || ( is_single() && ! genesis_get_option( 'comments_posts' ) ) )
  58. return;
  59. if ( have_comments() && ! empty( $wp_query->comments_by_type['comment'] ) ) {
  60. genesis_markup( array(
  61. 'html5' => '<div %s>',
  62. 'xhtml' => '<div id="comments">',
  63. 'context' => 'entry-comments',
  64. ) );
  65. echo apply_filters( 'genesis_title_comments', __( '<h3>Comments</h3>', 'genesis' ) );
  66. printf( '<ol %s>', genesis_attr( 'comment-list' ) );
  67. do_action( 'genesis_list_comments' );
  68. echo '</ol>';
  69. //* Comment Navigation
  70. $prev_link = get_previous_comments_link( apply_filters( 'genesis_prev_comments_link_text', '' ) );
  71. $next_link = get_next_comments_link( apply_filters( 'genesis_next_comments_link_text', '' ) );
  72. if ( $prev_link || $next_link ) {
  73. genesis_markup( array(
  74. 'html5' => '<div %s>',
  75. 'xhtml' => '<div class="navigation">',
  76. 'context' => 'comments-pagination',
  77. ) );
  78. printf( '<div class="pagination-previous alignleft">%s</div>', $prev_link );
  79. printf( '<div class="pagination-next alignright">%s</div>', $next_link );
  80. echo '</div>';
  81. }
  82. echo '</div>';
  83. }
  84. //* No comments so far
  85. elseif ( 'open' === get_post()->comment_status && $no_comments_text = apply_filters( 'genesis_no_comments_text', '' ) ) {
  86. if ( genesis_html5() )
  87. echo sprintf( '<div %s>', genesis_attr( 'entry-comments' ) ) . $no_comments_text . '</div>';
  88. else
  89. echo '<div id="comments">' . $no_comments_text . '</div>';
  90. }
  91. elseif ( $comments_closed_text = apply_filters( 'genesis_comments_closed_text', '' ) ) {
  92. if ( genesis_html5() )
  93. echo sprintf( '<div %s>', genesis_attr( 'entry-comments' ) ) . $comments_closed_text . '</div>';
  94. else
  95. echo '<div id="comments">' . $comments_closed_text . '</div>';
  96. }
  97. }
  98. add_action( 'genesis_pings', 'genesis_do_pings' );
  99. /**
  100. * Echo Genesis default trackback structure.
  101. *
  102. * Does the `genesis_list_args` action.
  103. *
  104. * Applies the `genesis_no_pings_text` filter.
  105. *
  106. * @since 1.1.2
  107. *
  108. * @uses genesis_get_option() Get theme setting value.
  109. *
  110. * @global WP_Query $wp_query Query object.
  111. *
  112. * @return null Return early if on a page with Genesis pages trackbacks off, or on a post with Genesis posts trackbacks off.
  113. */
  114. function genesis_do_pings() {
  115. global $wp_query;
  116. //* Bail if trackbacks are off for this post type
  117. if ( ( is_page() && ! genesis_get_option( 'trackbacks_pages' ) ) || ( is_single() && ! genesis_get_option( 'trackbacks_posts' ) ) )
  118. return;
  119. //* If have pings
  120. if ( have_comments() && !empty( $wp_query->comments_by_type['pings'] ) ) {
  121. genesis_markup( array(
  122. 'html5' => '<div %s>',
  123. 'xhtml' => '<div id="pings">',
  124. 'context' => 'entry-pings',
  125. ) );
  126. echo apply_filters( 'genesis_title_pings', __( '<h3>Trackbacks</h3>', 'genesis' ) );
  127. echo '<ol class="ping-list">';
  128. do_action( 'genesis_list_pings' );
  129. echo '</ol>';
  130. echo '</div>';
  131. } else {
  132. echo apply_filters( 'genesis_no_pings_text', '' );
  133. }
  134. }
  135. add_action( 'genesis_list_comments', 'genesis_default_list_comments' );
  136. /**
  137. * Output the list of comments.
  138. *
  139. * Applies the `genesis_comment_list_args` filter.
  140. *
  141. * @since 1.0.0
  142. *
  143. * @see genesis_html5_comment_callback() HTML5 callback.
  144. * @see genesis_comment_callback() XHTML callback.
  145. *
  146. * @uses genesis_html5() Check for HTML5 support.
  147. */
  148. function genesis_default_list_comments() {
  149. $defaults = array(
  150. 'type' => 'comment',
  151. 'avatar_size' => 48,
  152. 'format' => 'html5', //* Not necessary, but a good example
  153. 'callback' => genesis_html5() ? 'genesis_html5_comment_callback' : 'genesis_comment_callback',
  154. );
  155. $args = apply_filters( 'genesis_comment_list_args', $defaults );
  156. wp_list_comments( $args );
  157. }
  158. add_action( 'genesis_list_pings', 'genesis_default_list_pings' );
  159. /**
  160. * Output the list of trackbacks.
  161. *
  162. * Applies the `genesis_ping_list_args` filter.
  163. *
  164. * @since 1.0.0
  165. */
  166. function genesis_default_list_pings() {
  167. $args = apply_filters( 'genesis_ping_list_args', array(
  168. 'type' => 'pings',
  169. ) );
  170. wp_list_comments( $args );
  171. }
  172. /**
  173. * Comment callback for {@link genesis_default_list_comments()} if HTML5 is not active.
  174. *
  175. * Does `genesis_before_comment` and `genesis_after_comment` actions.
  176. *
  177. * Applies `comment_author_says_text` and `genesis_comment_awaiting_moderation` filters.
  178. *
  179. * @since 1.0.0
  180. *
  181. * @param stdClass $comment Comment object.
  182. * @param array $args Comment args.
  183. * @param integer $depth Depth of current comment.
  184. */
  185. function genesis_comment_callback( $comment, array $args, $depth ) {
  186. $GLOBALS['comment'] = $comment; ?>
  187. <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
  188. <?php do_action( 'genesis_before_comment' ); ?>
  189. <div class="comment-header">
  190. <div class="comment-author vcard">
  191. <?php echo get_avatar( $comment, $args['avatar_size'] ); ?>
  192. <?php printf( __( '<cite class="fn">%s</cite> <span class="says">%s:</span>', 'genesis' ), get_comment_author_link(), apply_filters( 'comment_author_says_text', __( 'says', 'genesis' ) ) ); ?>
  193. </div>
  194. <div class="comment-meta commentmetadata">
  195. <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>"><?php printf( __( '%1$s at %2$s', 'genesis' ), get_comment_date(), get_comment_time() ); ?></a>
  196. <?php edit_comment_link( __( '(Edit)', 'genesis' ), '' ); ?>
  197. </div>
  198. </div>
  199. <div class="comment-content">
  200. <?php if ( ! $comment->comment_approved ) : ?>
  201. <p class="alert"><?php echo apply_filters( 'genesis_comment_awaiting_moderation', __( 'Your comment is awaiting moderation.', 'genesis' ) ); ?></p>
  202. <?php endif; ?>
  203. <?php comment_text(); ?>
  204. </div>
  205. <div class="reply">
  206. <?php comment_reply_link( array_merge( $args, array( 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
  207. </div>
  208. <?php do_action( 'genesis_after_comment' );
  209. //* No ending </li> tag because of comment threading
  210. }
  211. /**
  212. * Comment callback for {@link genesis_default_list_comments()} if HTML5 is active.
  213. *
  214. * Does `genesis_before_comment` and `genesis_after_comment` actions.
  215. *
  216. * Applies `comment_author_says_text` and `genesis_comment_awaiting_moderation` filters.
  217. *
  218. * @since 2.0.0
  219. *
  220. * @param stdClass $comment Comment object.
  221. * @param array $args Comment args.
  222. * @param integer $depth Depth of current comment.
  223. */
  224. function genesis_html5_comment_callback( $comment, array $args, $depth ) {
  225. $GLOBALS['comment'] = $comment; ?>
  226. <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
  227. <article <?php echo genesis_attr( 'comment' ); ?>>
  228. <?php do_action( 'genesis_before_comment' ); ?>
  229. <header <?php echo genesis_attr( 'comment-header' ); ?>>
  230. <p <?php echo genesis_attr( 'comment-author' ); ?>>
  231. <?php
  232. echo get_avatar( $comment, $args['avatar_size'] );
  233. $author = get_comment_author();
  234. $url = get_comment_author_url();
  235. if ( ! empty( $url ) && 'http://' !== $url ) {
  236. $author = sprintf( '<a href="%s" %s>%s</a>', esc_url( $url ), genesis_attr( 'comment-author-link' ), $author );
  237. }
  238. /**
  239. * Filter the "comment author says" text.
  240. *
  241. * Allows developer to filter the "comment author says" text so it can say something different, or nothing at all.
  242. *
  243. * @since unknown
  244. *
  245. * @param string $text Comment author says text.
  246. */
  247. $comment_author_says_text = apply_filters( 'comment_author_says_text', __( 'says', 'genesis' ) );
  248. printf( '<span itemprop="name">%s</span> <span class="says">%s</span>', $author, $comment_author_says_text );
  249. ?>
  250. </p>
  251. <p <?php echo genesis_attr( 'comment-meta' ); ?>>
  252. <?php
  253. printf( '<time %s>', genesis_attr( 'comment-time' ) );
  254. printf( '<a href="%s" %s>', esc_url( get_comment_link( $comment->comment_ID ) ), genesis_attr( 'comment-time-link' ) );
  255. echo esc_html( get_comment_date() ) . ' ' . __( 'at', 'genesis' ) . ' ' . esc_html( get_comment_time() );
  256. echo '</a></time>';
  257. edit_comment_link( __( '(Edit)', 'genesis' ), ' ' );
  258. ?>
  259. </p>
  260. </header>
  261. <div <?php echo genesis_attr( 'comment-content' ); ?>>
  262. <?php if ( ! $comment->comment_approved ) : ?>
  263. <?php
  264. /**
  265. * Filter the "comment awaiting moderation" text.
  266. *
  267. * Allows developer to filter the "comment awaiting moderation" text so it can say something different, or nothing at all.
  268. *
  269. * @since unknown
  270. *
  271. * @param string $text Comment awaiting moderation text.
  272. */
  273. $comment_awaiting_moderation_text = apply_filters( 'genesis_comment_awaiting_moderation', __( 'Your comment is awaiting moderation.', 'genesis' ) );
  274. ?>
  275. <p class="alert"><?php echo $comment_awaiting_moderation_text; ?></p>
  276. <?php endif; ?>
  277. <?php comment_text(); ?>
  278. </div>
  279. <?php
  280. comment_reply_link( array_merge( $args, array(
  281. 'depth' => $depth,
  282. 'before' => sprintf( '<div %s>', genesis_attr( 'comment-reply' ) ),
  283. 'after' => '</div>',
  284. ) ) );
  285. ?>
  286. <?php do_action( 'genesis_after_comment' ); ?>
  287. </article>
  288. <?php
  289. //* No ending </li> tag because of comment threading
  290. }
  291. add_action( 'genesis_comment_form', 'genesis_do_comment_form' );
  292. /**
  293. * Optionally show the comment form.
  294. *
  295. * Genesis asks WP for the HTML5 version of the comment form - it uses {@link genesis_comment_form_args()} to revert to
  296. * XHTML form fields when child theme doesn't support HTML5.
  297. *
  298. * @since 1.0.0
  299. *
  300. * @return null Return early if comments are closed via Genesis for this page or post.
  301. */
  302. function genesis_do_comment_form() {
  303. //* Bail if comments are closed for this post type
  304. if ( ( is_page() && ! genesis_get_option( 'comments_pages' ) ) || ( is_single() && ! genesis_get_option( 'comments_posts' ) ) )
  305. return;
  306. comment_form( array( 'format' => 'html5' ) );
  307. }
  308. add_filter( 'comment_form_defaults', 'genesis_comment_form_args' );
  309. /**
  310. * Filter the default comment form arguments, used by `comment_form()`.
  311. *
  312. * Applies only to XHTML child themes, since Genesis uses default HTML5 comment form where possible.
  313. *
  314. * Applies `genesis_comment_form_args` filter.
  315. *
  316. * @since 1.8.0
  317. *
  318. * @uses genesis_html5() Check for HTML5 support.
  319. *
  320. * @global string $user_identity Display name of the user.
  321. *
  322. * @param array $defaults Comment form defaults.
  323. *
  324. * @return array Filterable array.
  325. */
  326. function genesis_comment_form_args( array $defaults ) {
  327. //* Use WordPress default HTML5 comment form if themes supports HTML5
  328. if ( genesis_html5() )
  329. return $defaults;
  330. global $user_identity;
  331. $commenter = wp_get_current_commenter();
  332. $req = get_option( 'require_name_email' );
  333. $aria_req = ( $req ? ' aria-required="true"' : '' );
  334. $author = '<p class="comment-form-author">' .
  335. '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" tabindex="1"' . $aria_req . ' />' .
  336. '<label for="author">' . __( 'Name', 'genesis' ) . '</label> ' .
  337. ( $req ? '<span class="required">*</span>' : '' ) .
  338. '</p>';
  339. $email = '<p class="comment-form-email">' .
  340. '<input id="email" name="email" type="text" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" tabindex="2"' . $aria_req . ' />' .
  341. '<label for="email">' . __( 'Email', 'genesis' ) . '</label> ' .
  342. ( $req ? '<span class="required">*</span>' : '' ) .
  343. '</p>';
  344. $url = '<p class="comment-form-url">' .
  345. '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" tabindex="3" />' .
  346. '<label for="url">' . __( 'Website', 'genesis' ) . '</label>' .
  347. '</p>';
  348. $comment_field = '<p class="comment-form-comment">' .
  349. '<textarea id="comment" name="comment" cols="45" rows="8" tabindex="4" aria-required="true"></textarea>' .
  350. '</p>';
  351. $args = array(
  352. 'comment_field' => $comment_field,
  353. 'title_reply' => __( 'Speak Your Mind', 'genesis' ),
  354. 'comment_notes_before' => '',
  355. 'comment_notes_after' => '',
  356. 'fields' => array(
  357. 'author' => $author,
  358. 'email' => $email,
  359. 'url' => $url,
  360. ),
  361. );
  362. //* Merge $args with $defaults
  363. $args = wp_parse_args( $args, $defaults );
  364. //* Return filterable array of $args, along with other optional variables
  365. return apply_filters( 'genesis_comment_form_args', $args, $user_identity, get_the_ID(), $commenter, $req, $aria_req );
  366. }
  367. add_filter( 'get_comments_link', 'genesis_comments_link_filter', 10, 2 );
  368. /**
  369. * Filter the comments link. If post has comments, link to #comments div. If no, link to #respond div.
  370. *
  371. * @since 2.0.1
  372. */
  373. function genesis_comments_link_filter( $link, $post_id ) {
  374. if ( 0 == get_comments_number() )
  375. return get_permalink( $post_id ) . '#respond';
  376. return $link;
  377. }