PHP Class RCP_Levels, restrict-content-pro

This class handles querying, inserting, updating, and removing subscription levels Also includes other discount helper functions
Since: 1.5
Show file Open project: restrictcontentpro/restrict-content-pro Class Usage Examples

Public Properties

Property Type Description
$db_name Holds the name of our levels database table
$db_version Holds the version number of our levels database table
$meta_db_name Holds the name of our level meta database table

Public Methods

Method Description
__construct ( ) Get things started
add_meta ( integer $level_id, string $meta_key = '', mixed $meta_value, boolean $unique = false ) : boolean Add meta data field to a subscription level.
delete_meta ( integer $level_id, string $meta_key = '', mixed $meta_value = '' ) : boolean Remove metadata matching criteria from a subscription level.
get_level ( $level_id ) Retrieve a specific subscription level from the database
get_level_by ( $field = 'name', $value = '' ) Retrieve a specific subscription level from the database
get_level_field ( $level_id, $field = '' ) Retrieve a field for a subscription level
get_levels ( $args = [] ) Retrieve all subscription levels from the database
get_meta ( integer $level_id, string $meta_key = '', boolean $single = false ) : mixed Retrieve level meta field for a subscription level.
insert ( $args = [] ) Insert a subscription level into the database
remove ( $level_id ) Delete a subscription level
remove_all_meta_for_level_id ( integer $level_id ) : integer | false Removes all metadata for the specified subscription level.
update ( $level_id, $args = [] ) Update an existing subscription level
update_meta ( integer $level_id, string $meta_key = '', mixed $meta_value, mixed $prev_value = '' ) : boolean Update level meta field based on Subscription level ID.

Private Methods

Method Description
valid_amount ( $amount ) : boolean Validates that the amount is a valid format.

Method Details

__construct() public method

Get things started
Since: 1.5
public __construct ( )

add_meta() public method

Add meta data field to a subscription level.
Since: 2.6
public add_meta ( integer $level_id, string $meta_key = '', mixed $meta_value, boolean $unique = false ) : boolean
$level_id integer Subscription level ID.
$meta_key string Metadata name.
$meta_value mixed Metadata value.
$unique boolean Optional, default is false. Whether the same key should not be added.
return boolean False for failure. True for success.

delete_meta() public method

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.
Since: 2.6
public delete_meta ( integer $level_id, string $meta_key = '', mixed $meta_value = '' ) : boolean
$level_id integer Subscription level ID.
$meta_key string Metadata name.
$meta_value mixed Optional. Metadata value.
return boolean False for failure. True for success.

get_level() public method

Retrieve a specific subscription level from the database
Since: 1.5
public get_level ( $level_id )

get_level_by() public method

Retrieve a specific subscription level from the database
Since: 1.8.2
public get_level_by ( $field = 'name', $value = '' )

get_level_field() public method

Retrieve a field for a subscription level
Since: 1.5
public get_level_field ( $level_id, $field = '' )

get_levels() public method

Retrieve all subscription levels from the database
Since: 1.5
public get_levels ( $args = [] )

get_meta() public method

Retrieve level meta field for a subscription level.
Since: 2.6
public get_meta ( integer $level_id, string $meta_key = '', boolean $single = false ) : mixed
$level_id integer Subscription level ID.
$meta_key string The meta key to retrieve.
$single boolean 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.

insert() public method

Insert a subscription level into the database
Since: 1.5
public insert ( $args = [] )

remove() public method

Delete a subscription level
Since: 1.5
public remove ( $level_id )

remove_all_meta_for_level_id() public method

Removes all metadata for the specified subscription level.
Since: 2.6.6
public remove_all_meta_for_level_id ( integer $level_id ) : integer | false
$level_id integer Subscription level ID.
return integer | false Number of rows affected/selected or false on error.

update() public method

Update an existing subscription level
Since: 1.5
public update ( $level_id, $args = [] )

update_meta() public method

Use the $prev_value parameter to differentiate between meta fields with the same key and Subscription level ID. If the meta field for the subscription level does not exist, it will be added.
Since: 2.6
public update_meta ( integer $level_id, string $meta_key = '', mixed $meta_value, mixed $prev_value = '' ) : boolean
$level_id integer Subscription level ID.
$meta_key string Metadata key.
$meta_value mixed Metadata value.
$prev_value mixed Optional. Previous value to check before removing.
return boolean False on failure, true if success.

Property Details

$db_name public property

Holds the name of our levels database table
Since: 1.5
public $db_name

$db_version public property

Holds the version number of our levels database table
Since: 1.5
public $db_version

$meta_db_name public property

Holds the name of our level meta database table
Since: 2.6
public $meta_db_name