Skip to main content

key

key

pb.plugin.key(name)

Returns a key object for a given key name. The object provides synchronous and asynchronous functions to manipulate stored key data.

ParamTypeDescription
namestringThe plugin key name

Key

The corresponding key object is returned when using the "key" function. This key object contains functions to manipulate the stored data for that key.

Methods

async

The async object contains asynchronous versions of the same key manipulation functions.

Properties

NameType
asyncObject

Methods

get

keyInstance.async.get([object_id])

A function that returns a promise to retrieve the most up to date value for the given object id from the server.

Returns: Promise - Promise object that represents the value for the given object id.

ParamTypeDescription
[object_id]numberThe ID of the object.

set

keyInstance.async.set(options)

A function that returns a promise to set the plugin key to a given value.

Returns: Promise - Promise object that represents the new value.

ParamTypeDescription
optionsObjectAdditional options:
options.valueObject | string | numberThe value to be assigned to this key.
[options.object_id]numberThe ID of the object.
[options.metadata]Array.<PageMetadataKey>An array of strings where each string represents a page data property. This data is added to the value as an object key/value pair.

append

keyInstance.async.append(options)

A function that returns a promise to concatenate a given value to the end of the existing key value. The promise will resolve successfully with the updated value.

Returns: Promise - Promise object that represents the updated value.

ParamTypeDescription
optionsObjectAdditional options:
[options.object_id]numberThe ID of the object.
options.valuestring | numberThe value to be added to the end of the existing value.

prepend

keyInstance.async.prepend(options)

A function that returns a promise to insert a given value in front of the existing key value. The promise will resolve successfully with the updated value.

Returns: Promise - Promise object that represents the updated value.

ParamTypeDescription
optionsObjectAdditional options:
[options.object_id]numberThe ID of the object.
options.valuestring | numberThe value to be added to the beginning of the existing value.

increment

keyInstance.async.increment([options])

A function that returns a promise to increment a key value. If the key is an integer, increases the key's value by one, or you can optionally supply a different amount to increment by. The promise will resolve successfully with the updated value.

Returns: Promise - Promise object that represents the updated value.

ParamTypeDefaultDescription
[options]ObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.value]string | number1The amount by which to increment.

decrement

keyInstance.async.decrement([options])

A function that returns a promise to decrement a key value. If the key is an integer, decreases the key's value by one, or you can optionally supply a different amount to decrement by. The promise will resolve successfully with the updated value.

Returns: Promise - Promise object that represents the updated value.

ParamTypeDefaultDescription
[options]ObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.value]string | number1The amount by which to increment.

push

keyInstance.async.push(options)

A function that returns a promise to add one or more values to the end of an array. You must supply either options.value or options.values. If both are supplied, options.values will be ignored in favor of options.value.

Returns: Promise - Promise object that represents the updated array.

ParamTypeDescription
optionsObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.value]string | numberThe value to be pushed onto the array.
[options.values]ArrayAn array of values to be pushed onto the array.
[options.metadata]Array.<PageMetadataKey>An array of strings where each string represents a page data property. This data is added to the value as an object key/value pair. It can only use it when pushing a single item. It cannot be used with the 'values' option.

pop

keyInstance.async.pop([options])

A function that returns a promise to remove the last item in the array. You can supply an options.num_items value to pop multiple items off. The promise will resolve successfully with the item(s) that were removed.

Returns: Promise - Promise object that represents the item(s) popped off from the array.

ParamTypeDefaultDescription
[options]ObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.num_items]number1The number of items to pop.

unshift

keyInstance.async.unshift(options)

A function that returns a promise to add one or more values to the front of an array. You must supply either options.value or options.values. If both are supplied, options.values will be ignored in favor of options.value.

Returns: Promise - Promise object that represents the updated array.

ParamTypeDescription
optionsObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.value]string | numberThe value to be unshifted onto the array.
[options.values]ArrayAn array of values to be unshifted onto the array.

shift

keyInstance.async.shift([options])

A function that returns a promise to remove the first item in the array. You can supply an options.num_items value to shift multiple items off. The promise will resolve successfully with the item(s) that were removed.

Returns: Promise - Promise object that represents the item(s) shifted off from the array.

ParamTypeDefaultDescription
[options]ObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.num_items]number1The number of items to shift.

type

keyInstance.type()

Returns the type code of this plugin key. The reference function pb.plugin.key_types() may be handy when used in conjunction with this function.

Returns: number - The numeric code that represents this key type.

get

keyInstance.get([object_id])

Returns the value associated with this plugin key for the passed-in object_id.

Returns: string | number | Array | Object - The value of this plugin key stored under this object_id.

ParamTypeDescription
[object_id]numberThe ID of the object.

set

keyInstance.set(options)

Sets the plugin key.

ParamTypeDescription
optionsObjectAdditional options:
options.valueObject | string | numberThe value to be assigned to this key.
[options.object_id]numberThe ID of the object.
[options.success]functionThe success callback function.
[options.metadata]Array.<PageMetadataKey>An array of strings where each string represents a page data property. This data is added to the value as an object key/value pair.
[options.error]functionThe error callback function.
[options.complete]functionThe complete callback function.

unset

keyInstance.unset(options)

Sets the plugin key value to undefined. Object ID must be explicitly defined.

ParamTypeDescription
optionsObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.success]functionThe success callback function.
[options.error]functionThe error callback function.
[options.complete]functionThe complete callback function.

setOn

keyInstance.setOn(hook, [objectId], [value])

Triggers a plugin key to be set when a specific hook event occurs.

ParamTypeDescription
hookstringThe name of the event. Limited to 'thread_new' and 'post_new'.
[objectId]numberThe ID of the object.
[value]string | numberThe value to be assigned to this key.

after

keyInstance.after(hook, callback)

Execute a callback after a specified hook event occurs.

ParamTypeDescription
hookstringThe name of the event. Limited to 'thread_new', 'thread_edit', 'post_new', 'post_edit', and 'user_edit'.
callbackfunctionA method to run after the hook event happens. The first parameter is the new id related to the event. The second parameter is the plugin key object. The owner of the method, 'this', is also the plugin key object.

canRead

keyInstance.canRead([object_id])

Check if the key can be read for the specified object_id.

Returns: Boolean - True if the key can be read from for the specified object_id

ParamTypeDefaultDescription
[object_id]numberuser_idThe ID of the object to be checked.

canWrite

keyInstance.canWrite([object_id])

Check if the key can be written to for the specified object_id.

Returns: Boolean - True if the key can be written to for the specified object_id

ParamTypeDefaultDescription
[object_id]numberuser_idThe ID of the object to be checked.

append

keyInstance.append(options)

Concatenates a given value to the end of the existing key value.

ParamTypeDescription
optionsObjectAdditional options:
[options.object_id]numberThe ID of the object.
options.valuestring | numberThe value to be added to the end of the existing value.
[options.success]functionThe success callback function.
[options.error]functionThe error callback function.
[options.complete]functionThe complete callback function.

prepend

keyInstance.prepend(options)

Inserts a given value in front of the existing key value.

ParamTypeDescription
optionsObjectAdditional options:
[options.object_id]numberThe ID of the object.
options.valuestring | numberThe value to be added to the beginning of the existing value.
[options.success]functionThe success callback function.
[options.error]functionThe error callback function.
[options.complete]functionThe complete callback function.

increment

keyInstance.increment([options])

If the key is an integer, increases the key's value by one, or you can optionally supply a different amount to increment by.

ParamTypeDefaultDescription
[options]ObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.value]string | number1The amount by which to increment.
[options.success]functionThe success callback function.
[options.error]functionThe error callback function.
[options.complete]functionThe complete callback function.

decrement

keyInstance.decrement([options])

If the key is an integer, decreases the key's value by one, or you can optionally supply a different amount to decrement by.

ParamTypeDefaultDescription
[options]ObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.value]string | number1The amount by which to decrement.
[options.success]functionThe success callback function.
[options.error]functionThe error callback function.
[options.complete]functionThe complete callback function.

push

keyInstance.push(options)

If the key is an array, adds the given value to the back of the array. You must supply either options.value or options.values. If both are supplied, options.values will be ignored in favor of options.value.

ParamTypeDescription
optionsObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.value]string | numberThe value to be pushed onto the array.
[options.values]ArrayAn array of values to be pushed onto the array.
[options.metadata]Array.<PageMetadataKey>An array of strings where each string represents a page data property. This data is added to the value as an object key/value pair. It can only use it when pushing a single item. It cannot be used with the 'values' option.
[options.success]functionThe success callback function.
[options.error]functionThe error callback function.
[options.complete]functionThe complete callback function.

pop

keyInstance.pop([options])

If the key is an array, removes the last options.num_items values and returns them.

Returns: string | number | Array | Object | undefined - The last options.num_items values of the array, before they were removed. If multiple items are returned, they will be returned in an array. If popping from a key that is not loaded on the page, nothing will be returned.

ParamTypeDefaultDescription
[options]ObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.num_items]number1The number of items to pop.
[options.success]functionThe success callback function.
[options.error]functionThe error callback function.
[options.complete]functionThe complete callback function.

shift

keyInstance.shift([options])

If the key is an array, removes the first options.num_items values and returns them.

Returns: string | number | Array | Object | undefined - The first options.num_items values of the array, before they were removed. If multiple items are returned, they will be returned in an array. If shifting from a key that is not loaded on the page, nothing will be returned.

ParamTypeDefaultDescription
[options]ObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.num_items]number1The number of items to shift.
[options.success]functionThe success callback function.
[options.error]functionThe error callback function.
[options.complete]functionThe complete callback function.

unshift

keyInstance.unshift(options)

If the key is an array, adds the given value to the front of the array. You must supply either options.value or options.values. If both are supplied, options.values will be ignored in favor of options.value.

ParamTypeDescription
optionsObjectAdditional options:
[options.object_id]numberThe ID of the object.
[options.value]string | numberThe value to be unshifted onto the array.
[options.values]ArrayAn array of values to be unshifted onto the array.
[options.success]functionThe success callback function.
[options.error]functionThe error callback function.
[options.complete]functionThe complete callback function.

PageMetadataKey

Depending on the page the user is on, there is various metadata about that page that can be accessed. This data can be viewed by using "pb.data.get('page')". PageMetadataKey is a string that acts as a key to access a specific metadata property. Use the function "pb.plugin.getAvailablePageMetadataKeys()" to see what PageMetadataKey values are available for the current page. Some pages may not have any metadata available.