WP_Object_Cache::decr() WordPress Method

The WP_Object_Cache::decr() method decreases a stored value by the specified amount.

WP_Object_Cache::decr( int|string $key, int $offset = 1, string $group = 'default' ) #

Decrements numeric cache item’s value.


Parameters

$key

(int|string)(Required)The cache key to decrement.

$offset

(int)(Optional) The amount by which to decrement the item's value.

Default value: 1

$group

(string)(Optional) The group the key is in.

Default value: 'default'


Top ↑

Return

(int|false) The item's new value on success, false on failure.


Top ↑

Source

File: wp-includes/class-wp-object-cache.php

	public function decr( $key, $offset = 1, $group = 'default' ) {
		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 ];
	}


Top ↑

Changelog

Changelog
VersionDescription
3.3.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.