W3cubDocs

/WordPress

WP_Object_Cache::incr( int|string $key, int $offset = 1, string $group = ‘default’ ): int|false

Increments numeric cache item’s value.

Parameters

$keyint|stringrequired
The cache key to increment.
$offsetintoptional
The amount by which to increment the item’s value.

Default:1

$groupstringoptional
The group the key is in. Default 'default'.

Default:'default'

Return

int|false The item’s new value on success, false on failure.

Source

public function incr( $key, $offset = 1, $group = 'default' ) {
	if ( ! $this->is_valid_key( $key ) ) {
		return false;
	}

	if ( empty( $group ) ) {
		$group = 'default';
	}

	if ( $this->multisite && ! isset( $this->global_groups[ $group ] ) ) {
		$key = $this->blog_prefix . $key;
	}

	if ( ! $this->_exists( $key, $group ) ) {
		return false;
	}

	if ( ! is_numeric( $this->cache[ $group ][ $key ] ) ) {
		$this->cache[ $group ][ $key ] = 0;
	}

	$offset = (int) $offset;

	$this->cache[ $group ][ $key ] += $offset;

	if ( $this->cache[ $group ][ $key ] < 0 ) {
		$this->cache[ $group ][ $key ] = 0;
	}

	return $this->cache[ $group ][ $key ];
}

Changelog

Version Description
3.3.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_object_cache/incr