@@ -248,6 +248,9 @@ public function type() {
248248 * [--fields=<fields>]
249249 * : Limit the output to specific object fields.
250250 *
251+ * [--human-readable]
252+ * : Human-readable output for expirations.
253+ *
251254 * [--format=<format>]
252255 * : The serialization format for the value.
253256 * ---
@@ -286,10 +289,11 @@ public function type() {
286289 public function _list ( $ args , $ assoc_args ) {
287290 global $ wpdb ;
288291
289- $ fields = array ( ' name ' , 'value ' , ' expiration ' );
290- $ network = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'network ' , false );
291- $ unserialize = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'unserialize ' , false );
292+ $ network = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'network ' , false );
293+ $ unserialize = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'unserialize ' , false );
294+ $ human_readable = \WP_CLI \Utils \get_flag_value ( $ assoc_args , 'human-readable ' , false );
292295
296+ $ fields = array ( 'name ' , 'value ' , 'expiration ' );
293297 if ( isset ( $ assoc_args ['fields ' ] ) ) {
294298 $ fields = explode ( ', ' , $ assoc_args ['fields ' ] );
295299 }
@@ -320,7 +324,7 @@ public function _list( $args, $assoc_args ) {
320324
321325 foreach ( $ results as $ result ) {
322326 $ result ->name = str_replace ( array ( '_site_transient_ ' , '_transient_ ' ), '' , $ result ->name );
323- $ result ->expiration = $ this ->get_transient_expiration ( $ result ->name , $ network );
327+ $ result ->expiration = $ this ->get_transient_expiration ( $ result ->name , $ network, $ human_readable );
324328
325329 if ( $ unserialize ) {
326330 $ result ->value = maybe_unserialize ( $ result ->value );
@@ -335,13 +339,15 @@ public function _list( $args, $assoc_args ) {
335339 }
336340
337341 /**
338- * Retrieves the human-friendly expiration time.
342+ * Retrieves the expiration time.
339343 *
340344 * @param string $name Transient name.
341345 * @param bool $is_site_transient Optional. Whether this is a site transient. Default false.
346+ * @param bool $human_readable Optional. Whether to return the difference between now and the
347+ * expiration time in a human-readable format. Default false.
342348 * @return string Expiration time string.
343349 */
344- private function get_transient_expiration ( $ name , $ is_site_transient = false ) {
350+ private function get_transient_expiration ( $ name , $ is_site_transient = false , $ human_readable = false ) {
345351 if ( $ is_site_transient ) {
346352 if ( is_multisite () ) {
347353 $ expiration = (int ) get_site_option ( '_site_transient_timeout_ ' . $ name );
@@ -353,7 +359,11 @@ private function get_transient_expiration( $name, $is_site_transient = false ) {
353359 }
354360
355361 if ( 0 === $ expiration ) {
356- return 'no expiration ' ;
362+ return $ human_readable ? 'never expires ' : 'false ' ;
363+ }
364+
365+ if ( ! $ human_readable ) {
366+ return $ expiration ;
357367 }
358368
359369 $ now = time ();
0 commit comments