WP_Object_Cache::decr

Advertisement

Summery Summery

Decrements numeric cache item’s value.

Syntax Syntax

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

Parameters Parameters

$key

(Required) The cache key to decrement.

$offset

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

Default value: 1

$group

(Optional) The group the key is in. Default 'default'.

Default value: 'default'

Return Return

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

Source 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 ];
	}

Advertisement

Changelog Changelog

Changelog
Version Description
3.3.0 Introduced.

Advertisement

Leave a Reply