wppaste
WordPress

get_lastcommentmodified( string $timezone = 'server' ): string|false

Since
1.5.0, 4.7.0
Source
wp-includes/comment.php:410
Retrieves the date the last comment was modified.

Compatibility

WordPress
since 4.7.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

$timezonestringoptional
Which timezone to use in reference to 'gmt', 'blog', or 'server' locations.Default: 'server'

Return value

string|false
Last comment modified date on success, false on failure.

Performance profile

How much work a call to get_lastcommentmodified() 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
Heavy

Reaches the database via ->get_var().

Scaling
Constant

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

Instructions
15–44

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • cacheobject cachewp_cache_get()called directly
  • sqldatabase query->get_var()called directly

What one call costs · 6 distinct outcomes

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

WhenInstructionsCalls it makes
always15–24strtolower(), wp_cache_get()
$comment_modified_date === false22–29strtolower(), wp_cache_get(), wp_cache_set()
$comment_modified_date === false26–30strtolower(), wp_cache_get(), ->get_var()
$comment_modified_date === false31–35strtolower(), wp_cache_get(), ->get_var(), wp_cache_set()
$comment_modified_date === false33–39strtolower(), wp_cache_get(), gmdate(), ->prepare(), ->get_var()
$comment_modified_date === false38–44strtolower(), wp_cache_get(), gmdate(), ->prepare(), ->get_var(), wp_cache_set()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev6515–446
8.56515–446
8.46515–446
8.36515–446
8.26515–4461 more instruction than PHP 8.1
8.16415–446
7.46415–446

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 · 2

Used by · 1

Source code

function get_lastcommentmodified( $timezone = 'server' ) {	global $wpdb; 	$timezone = strtolower( $timezone );	$key      = "lastcommentmodified:$timezone"; 	$comment_modified_date = wp_cache_get( $key, 'timeinfo' );	if ( false !== $comment_modified_date ) {		return $comment_modified_date;	} 	switch ( $timezone ) {		case 'gmt':			$comment_modified_date = $wpdb->get_var( "SELECT comment_date_gmt FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" );			break;		case 'blog':			$comment_modified_date = $wpdb->get_var( "SELECT comment_date FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1" );			break;		case 'server':			$add_seconds_server = gmdate( 'Z' ); 			$comment_modified_date = $wpdb->get_var( $wpdb->prepare( "SELECT DATE_ADD(comment_date_gmt, INTERVAL %s SECOND) FROM $wpdb->comments WHERE comment_approved = '1' ORDER BY comment_date_gmt DESC LIMIT 1", $add_seconds_server ) );			break;	} 	if ( $comment_modified_date ) {		wp_cache_set( $key, $comment_modified_date, 'timeinfo' ); 		return $comment_modified_date;	} 	return false;}

Changelog

Introduced in 1.5.0. Unchanged from 6.7.7 through 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.

4.7.0
Replaced caching the modified date in a local static variable with the Object Cache API.from the docblock
1.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/comment.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.