wppaste
WordPress

twentytwelve_comment( WP_Comment $comment, array $args, int $depth )

Since
Twenty Twelve 1.0
Source
wp-content/themes/twentytwelve/functions.php:472
Template for comments and pingbacks.

Description

To override this walker in a child theme without modifying the comments template simply create your own twentytwelve_comment(), and that function will be used instead.

Used as a callback by wp_list_comments() for displaying the comments.

Compatibility

WordPress
since Twenty Twelve 1.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$commentWP_Comment
The comment object.
$argsarray
An array of comment arguments. @see get_comment_reply_link()
$depthint
The depth of the comment.

Performance profile

How much work a call to twentytwelve_comment() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Moderate

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
35–127

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 159.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()one call below twentytwelve_comment()
  • optionoption read or writeget_option()one call below twentytwelve_comment()

Further down the call graph this can also reach query, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 3 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost twentytwelve_comment() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always35–39comment_class(), comment_ID(), _e(), comment_author_link(), __(), edit_comment_link()
always113–121comment_class(), comment_ID(), comment_ID(), get_avatar(), get_comment_author_link(), printf(), get_comment_link(), esc_url(), get_comment_time(), __(), get_comment_date(), get_comment_time(), sprintf(), printf(), wp_get_current_commenter(), __(), comment_text(), __(), edit_comment_link(), __(), reply_text(), array_merge()
always119–127comment_class(), comment_ID(), comment_ID(), get_avatar(), get_comment_author_link(), __(), printf(), get_comment_link(), esc_url(), get_comment_time(), __(), get_comment_date(), get_comment_time(), sprintf(), printf(), wp_get_current_commenter(), __(), comment_text(), __(), edit_comment_link(), __(), reply_text(), array_merge()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev15935–1276
8.515935–1276
8.415935–1276
8.315935–1276
8.215935–1276
8.115935–12762 fewer instructions than PHP 7.4
7.416136–1296

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 15

Show all 15

Source code

	function twentytwelve_comment( $comment, $args, $depth ) {		$GLOBALS['comment'] = $comment;		switch ( $comment->comment_type ) :			case 'pingback':			case 'trackback':				// Display trackbacks differently than normal comments.				?>		<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">		<p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>				<?php				break;			default:				// Proceed with normal comments.				global $post;				?>		<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">		<article id="comment-<?php comment_ID(); ?>" class="comment">			<header class="comment-meta comment-author vcard">				<?php					echo get_avatar( $comment, 44 );					printf(						'<cite><b class="fn">%1$s</b> %2$s</cite>',						get_comment_author_link(),						// If current post author is also comment author, make it known visually.						( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''					);					printf(						'<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',						esc_url( get_comment_link( $comment->comment_ID ) ),						get_comment_time( 'c' ),						/* translators: 1: Date, 2: Time. */						sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )					);				?>				</header><!-- .comment-meta --> 				<?php				$commenter = wp_get_current_commenter();				if ( $commenter['comment_author_email'] ) {					$moderation_note = __( 'Your comment is awaiting moderation.', 'twentytwelve' );				} else {					$moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.', 'twentytwelve' );				}				?> 				<?php if ( '0' === $comment->comment_approved ) : ?>				<p class="comment-awaiting-moderation"><?php echo $moderation_note; ?></p>				<?php endif; ?> 				<section class="comment-content comment">				<?php comment_text(); ?>				<?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>				</section><!-- .comment-content --> 				<div class="reply">				<?php				comment_reply_link(					array_merge(						$args,						array(							'reply_text' => __( 'Reply', 'twentytwelve' ),							'after'      => ' <span>&darr;</span>',							'depth'      => $depth,							'max_depth'  => $args['max_depth'],						)					)				);				?>				</div><!-- .reply -->			</article><!-- #comment-## -->				<?php				break;		endswitch; // End comment_type check.	}

Changelog

Introduced in Twenty Twelve 1.0. 3 changes between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

7.1.0
Parameter $comment retyped from untyped to WP_Comment.verified against source
7.1.0
Parameter $args retyped from untyped to array.verified against source
7.1.0
Parameter $depth retyped from untyped to int.verified against source
Twenty Twelve 1.0
Twenty Twelve 1.0from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-content/themes/twentytwelve/functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.