11<?php
22
3+ use WP_CLI \Utils ;
4+
35/**
46 * Adds, gets, and deletes entries in the WordPress Transient Cache.
57 *
@@ -74,7 +76,7 @@ class Transient_Command extends WP_CLI_Command {
7476 public function get ( $ args , $ assoc_args ) {
7577 list ( $ key ) = $ args ;
7678
77- $ func = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'network ' ) ? 'get_site_transient ' : 'get_transient ' ;
79+ $ func = Utils \get_flag_value ( $ assoc_args , 'network ' ) ? 'get_site_transient ' : 'get_transient ' ;
7880 $ value = $ func ( $ key );
7981
8082 if ( false === $ value ) {
@@ -117,9 +119,9 @@ public function get( $args, $assoc_args ) {
117119 public function set ( $ args , $ assoc_args ) {
118120 list ( $ key , $ value ) = $ args ;
119121
120- $ expiration = \ WP_CLI \ Utils \get_flag_value ( $ args , 2 , 0 );
122+ $ expiration = Utils \get_flag_value ( $ args , 2 , 0 );
121123
122- $ func = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'network ' ) ? 'set_site_transient ' : 'set_transient ' ;
124+ $ func = Utils \get_flag_value ( $ assoc_args , 'network ' ) ? 'set_site_transient ' : 'set_transient ' ;
123125 if ( $ func ( $ key , $ value , $ expiration ) ) {
124126 WP_CLI ::success ( 'Transient added. ' );
125127 } else {
@@ -166,8 +168,8 @@ public function set( $args, $assoc_args ) {
166168 public function delete ( $ args , $ assoc_args ) {
167169 $ key = ( ! empty ( $ args ) ) ? $ args [0 ] : NULL ;
168170
169- $ all = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'all ' );
170- $ expired = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'expired ' );
171+ $ all = Utils \get_flag_value ( $ assoc_args , 'all ' );
172+ $ expired = Utils \get_flag_value ( $ assoc_args , 'expired ' );
171173
172174 if ( true === $ all ) {
173175 $ this ->delete_all ();
@@ -182,12 +184,12 @@ public function delete( $args, $assoc_args ) {
182184 WP_CLI ::error ( 'Please specify transient key, or use --all or --expired. ' );
183185 }
184186
185- $ func = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'network ' ) ? 'delete_site_transient ' : 'delete_transient ' ;
187+ $ func = Utils \get_flag_value ( $ assoc_args , 'network ' ) ? 'delete_site_transient ' : 'delete_transient ' ;
186188
187189 if ( $ func ( $ key ) ) {
188190 WP_CLI ::success ( 'Transient deleted. ' );
189191 } else {
190- $ func = \ WP_CLI \ Utils \get_flag_value ( $ assoc_args , 'network ' ) ? 'get_site_transient ' : 'get_transient ' ;
192+ $ func = Utils \get_flag_value ( $ assoc_args , 'network ' ) ? 'get_site_transient ' : 'get_transient ' ;
191193 if ( $ func ( $ key ) )
192194 WP_CLI ::error ( 'Transient was not deleted even though the transient appears to exist. ' );
193195 else
@@ -235,8 +237,8 @@ private function delete_expired() {
235237 AND a.option_name NOT LIKE %s
236238 AND b.option_name = CONCAT( '_transient_timeout_', SUBSTRING( a.option_name, 12 ) )
237239 AND b.option_value < %d " ,
238- \ WP_CLI \ Utils \esc_like ( '_transient_ ' ) . '% ' ,
239- \ WP_CLI \ Utils \esc_like ( '_transient_timeout_ ' ) . '% ' ,
240+ Utils \esc_like ( '_transient_ ' ) . '% ' ,
241+ Utils \esc_like ( '_transient_timeout_ ' ) . '% ' ,
240242 time ()
241243 )
242244 );
@@ -250,8 +252,8 @@ private function delete_expired() {
250252 AND a.option_name NOT LIKE %s
251253 AND b.option_name = CONCAT( '_site_transient_timeout_', SUBSTRING( a.option_name, 17 ) )
252254 AND b.option_value < %d " ,
253- \ WP_CLI \ Utils \esc_like ( '_site_transient_ ' ) . '% ' ,
254- \ WP_CLI \ Utils \esc_like ( '_site_transient_timeout_ ' ) . '% ' ,
255+ Utils \esc_like ( '_site_transient_ ' ) . '% ' ,
256+ Utils \esc_like ( '_site_transient_timeout_ ' ) . '% ' ,
255257 time ()
256258 )
257259 );
@@ -264,8 +266,8 @@ private function delete_expired() {
264266 AND a.meta_key NOT LIKE %s
265267 AND b.meta_key = CONCAT( '_site_transient_timeout_', SUBSTRING( a.meta_key, 17 ) )
266268 AND b.meta_value < %d " ,
267- \ WP_CLI \ Utils \esc_like ( '_site_transient_ ' ) . '% ' ,
268- \ WP_CLI \ Utils \esc_like ( '_site_transient_timeout_ ' ) . '% ' ,
269+ Utils \esc_like ( '_site_transient_ ' ) . '% ' ,
270+ Utils \esc_like ( '_site_transient_timeout_ ' ) . '% ' ,
269271 time ()
270272 )
271273 );
@@ -298,7 +300,7 @@ private function delete_all() {
298300 $ count = $ wpdb ->query (
299301 $ wpdb ->prepare (
300302 "DELETE FROM $ wpdb ->options WHERE option_name LIKE %s " ,
301- \ WP_CLI \ Utils \esc_like ( '_transient_ ' ) . '% '
303+ Utils \esc_like ( '_transient_ ' ) . '% '
302304 )
303305 );
304306
@@ -307,14 +309,14 @@ private function delete_all() {
307309 $ count += $ wpdb ->query (
308310 $ wpdb ->prepare (
309311 "DELETE FROM $ wpdb ->options WHERE option_name LIKE %s " ,
310- \ WP_CLI \ Utils \esc_like ( '_site_transient_ ' ) . '% '
312+ Utils \esc_like ( '_site_transient_ ' ) . '% '
311313 )
312314 );
313315 } elseif ( is_multisite () && is_main_site () && is_main_network () ) {
314316 // Multisite stores site transients in the sitemeta table.
315317 $ count += $ wpdb ->prepare (
316318 "DELETE FROM $ wpdb ->sitemeta WHERE option_name LIKE %s " ,
317- \ WP_CLI \ Utils \esc_like ( '_site_transient_ ' ) . '% '
319+ Utils \esc_like ( '_site_transient_ ' ) . '% '
318320 );
319321 }
320322
0 commit comments