File tree Expand file tree Collapse file tree 4 files changed +73
-0
lines changed
Expand file tree Collapse file tree 4 files changed +73
-0
lines changed Original file line number Diff line number Diff line change @@ -304,6 +304,33 @@ Errors if the value can't be set.
304304
305305
306306
307+ ### wp cache supports
308+
309+ Determines whether the object cache implementation supports a particular feature.
310+
311+ ~~~
312+ wp cache supports <feature>
313+ ~~~
314+
315+ ** OPTIONS**
316+
317+ <feature>
318+ Name of the feature to check for.
319+
320+ ** EXAMPLES**
321+
322+ # Check whether is add_multiple supported.
323+ $ wp cache supports add_multiple
324+ $ echo $?
325+ 0
326+
327+ # Bash script for checking whether for support like this:
328+ if ! wp cache supports non_existing; then
329+ echo 'non_existing is not supported'
330+ fi
331+
332+
333+
307334### wp cache type
308335
309336Attempts to determine which object cache is being used.
Original file line number Diff line number Diff line change 4141 " cache incr" ,
4242 " cache replace" ,
4343 " cache set" ,
44+ " cache supports" ,
4445 " cache type" ,
4546 " transient" ,
4647 " transient delete" ,
Original file line number Diff line number Diff line change @@ -147,3 +147,13 @@ Feature: Managed the WordPress object cache
147147 """
148148 Warning: Ignoring the --url=<url> argument because flushing the cache affects all sites on a multisite installation.
149149 """
150+
151+ @require-wp-6.1
152+ Scenario : Checking if the cache supports a feature
153+ Given a WP install
154+
155+ When I try `wp cache supports non_existing`
156+ Then the return code should be 1
157+
158+ When I run `wp cache supports set_multiple`
159+ Then the return code should be 0
Original file line number Diff line number Diff line change @@ -343,4 +343,39 @@ public function type( $args, $assoc_args ) {
343343 WP_CLI ::line ( $ message );
344344 }
345345
346+ /**
347+ * Determines whether the object cache implementation supports a particular feature.
348+ *
349+ * ## OPTIONS
350+ *
351+ * <feature>
352+ * : Name of the feature to check for.
353+ *
354+ * ## EXAMPLES
355+ *
356+ * # Check whether is add_multiple supported.
357+ * $ wp cache supports add_multiple
358+ * $ echo $?
359+ * 0
360+ *
361+ * # Bash script for checking whether for support like this:
362+ * if ! wp cache supports non_existing; then
363+ * echo 'non_existing is not supported'
364+ * fi
365+ */
366+ public function supports ( $ args , $ assoc_args ) {
367+ list ( $ feature ) = $ args ;
368+
369+ if ( ! function_exists ( 'wp_cache_supports ' ) ) {
370+ WP_CLI ::error ( 'Checking cache features is only available in WordPress 6.1 and higher ' );
371+ }
372+
373+ $ supports = wp_cache_supports ( $ feature );
374+
375+ if ( $ supports ) {
376+ WP_CLI ::halt ( 0 );
377+ }
378+ WP_CLI ::halt ( 1 );
379+ }
380+
346381}
You can’t perform that action at this time.
0 commit comments