// // {$OBJECT_TYPE} meta functions // /** * Add meta data field to a {$OBJECT_TYPE}. * * This meta data function mirrors a corresponding wordpress post meta function. * * @since 3.8.12 * * @param int ${$OBJECT_TYPE}_id {$OBJECT_TYPE} ID. * @param string $meta_key Metadata name. * @param mixed $meta_value Metadata value. * @param bool $unique Optional, default is false. Whether the same key should not be added. * @return bool False for failure. True for success. */ function wpsc_add_{$OBJECT_TYPE}_meta( ${$OBJECT_TYPE}_id, $meta_key, $meta_value, $unique = false ) { return add_metadata( '{$OBJECT_TYPE}' , ${$OBJECT_TYPE}_id, $meta_key , $meta_value, $unique ); } /** * Remove metadata matching criteria from a {$OBJECT_TYPE}. * * You can match based on the key, or key and value. Removing based on key and * value, will keep from removing duplicate metadata with the same key. It also * allows removing all metadata matching key, if needed. * This meta data function mirrors a corresponding wordpress post meta function. * * @since 3.8.12 * * @param int ${$OBJECT_TYPE}_id {$OBJECT_TYPE} ID * @param string $meta_key Metadata name. * @param mixed $meta_value Optional. Metadata value. * @return bool False for failure. True for success. */ function wpsc_delete_{$OBJECT_TYPE}_meta( ${$OBJECT_TYPE}_id, $meta_key, $meta_value = '' ) { return delete_metadata( '{$OBJECT_TYPE}' , ${$OBJECT_TYPE}_id , $meta_key , $meta_value ); } /** * Retrieve {$OBJECT_TYPE} meta field for a {$OBJECT_TYPE}. * * @since 3.8.12 * * @param int ${$OBJECT_TYPE}_id {$OBJECT_TYPE} ID. * @param string $key Optional. The meta key to retrieve. By default, returns data for all keys. * @param bool $single Whether to return a single value. * @return mixed Will be an array if $single is false. Will be value of meta data field if $single * is true. */ function wpsc_get_{$OBJECT_TYPE}_meta( ${$OBJECT_TYPE}_id, $key = '', $single = false ) { return get_metadata( '{$OBJECT_TYPE}' , ${$OBJECT_TYPE}_id , $key, $single ); } /** * Determine if a meta key is set for a given {$OBJECT_TYPE}. * * @since 3.8.12 * * @param int ${$OBJECT_TYPE}_id {$OBJECT_TYPE} ID. * @param string $key Optional. The meta key to retrieve. By default, returns data for all keys. * @return boolean true of the key is set, false if not. * is true. */ function wpsc_{$OBJECT_TYPE}_meta_exists( ${$OBJECT_TYPE}_id, $meta_key ) { return metadata_exists( '{$OBJECT_TYPE}' , ${$OBJECT_TYPE}_id , $meta_key ); } /** * Update {$OBJECT_TYPE} meta field based on {$OBJECT_TYPE} ID. * * Use the $prev_value parameter to differentiate between meta fields with the * same key and {$OBJECT_TYPE} ID. * * If the meta field for the {$OBJECT_TYPE} does not exist, it will be added. * This meta data function mirrors a corresponding wordpress post meta function. * * @since 3.8.12 * * @param int ${$OBJECT_TYPE}_id ${$OBJECT_TYPE} ID. * @param string $meta_key Metadata key. * @param mixed $meta_value Metadata value. * @param mixed $prev_value Optional. Previous value to check before removing. * @return bool False on failure, true if success. */ function wpsc_update_{$OBJECT_TYPE}_meta( ${$OBJECT_TYPE}_id, $meta_key, $meta_value, $prev_value = '' ) { return update_metadata( '{$OBJECT_TYPE}' , ${$OBJECT_TYPE}_id , $meta_key , $meta_value , $prev_value ); } /** * Delete everything from {$OBJECT_TYPE} meta matching meta key. * This meta data function mirrors a corresponding wordpress post meta function. * @since 3.8.12 * * @param string ${$OBJECT_TYPE}_meta_key Key to search for when deleting. * @return bool Whether the {$OBJECT_TYPE} meta key was deleted from the database */ function wpsc_delete_{$OBJECT_TYPE}_meta_by_key( ${$OBJECT_TYPE}_meta_key ) { return delete_metadata( '{$OBJECT_TYPE}' , null , ${$OBJECT_TYPE}_meta_key , '' , true ); } /** * Retrieve {$OBJECT_TYPE} meta fields, based on {$OBJECT_TYPE} ID. * * The {$OBJECT_TYPE} meta fields are retrieved from the cache where possible, * so the function is optimized to be called more than once. * This meta data function mirrors a corresponding wordpress post meta function. * * @since 3.8.12 * * @param int ${$OBJECT_TYPE}_id {$OBJECT_TYPE} ID. * @return array */ function wpsc_get_{$OBJECT_TYPE}_custom( ${$OBJECT_TYPE}_id = 0 ) { ${$OBJECT_TYPE}_id = absint( ${$OBJECT_TYPE}_id ); return get_{$OBJECT_TYPE}_meta( ${$OBJECT_TYPE}_id ); } /** * Retrieve meta field names for a {$OBJECT_TYPE}. * * If there are no meta fields, then nothing(null) will be returned. * This meta data function mirrors a corresponding wordpress post meta function. * * @since 3.8.12 * * @param int ${$OBJECT_TYPE}_id {$OBJECT_TYPE} ID * @return array|null Either array of the keys, or null if keys could not be retrieved. */ function wpsc_get_{$OBJECT_TYPE}_custom_keys( ${$OBJECT_TYPE}_id = 0 ) { $custom = get_{$OBJECT_TYPE}_custom( ${$OBJECT_TYPE}_id ); if ( ! is_array( $custom ) ) return; if ( $keys = array_keys( $custom ) ) return $keys; } /** * Retrieve values for a custom {$OBJECT_TYPE} field. * * The parameters must not be considered optional. All of the {$OBJECT_TYPE} meta fields * will be retrieved and only the meta field key values returned. * This meta data function mirrors a corresponding wordpress post meta function. * * @since 3.8.12 * * @param string $metakey Meta field key. * @param int ${$OBJECT_TYPE}_id {$OBJECT_TYPE} ID * @return array Meta field values. */ function wpsc_get_{$OBJECT_TYPE}_custom_values( $metakey = '', ${$OBJECT_TYPE}_id = 0 ) { if ( ! $key ) return null; $custom = get_{$OBJECT_TYPE}_custom( ${$OBJECT_TYPE}_id ); return isset( $custom[$key] ) ? $custom[$key] : null; } /** * Calls function for each meta matching the timestamp criteria. Callback function * will get a single parameter that is an object representing the meta. * * @since 3.8.12 * * @param function $callback function to invoke once for each meta matching criteria * @param int|string $timestamp timestamp to compare meta items against, if int a unix timestamp is assumed, * if string a mysql timestamp is assumed * @param string $comparison any one of the supported comparison operators,(=,>=,>,<=,<,<>,!=) * @param string $meta_key restrict testing of meta to the values with the specified meta key * @return int count of meta items matching the criteria */ function wpsc_get_{$OBJECT_TYPE}_meta_by_timestamp( $callback = null, $timestamp = 0, $comparison = '>', $metakey = '' ) { return wpsc_get_meta_by_timestamp( '{$OBJECT_TYPE}', $callback , $timestamp , $comparison , $metakey ); }