RCP_Levels::get_levels PHP Method

get_levels() public method

Retrieve all subscription levels from the database
Since: 1.5
public get_levels ( $args = [] )
    public function get_levels($args = array())
    {
        global $wpdb;
        $defaults = array('status' => 'all', 'limit' => null, 'orderby' => 'list_order');
        $args = wp_parse_args($args, $defaults);
        if ($args['status'] == 'active') {
            $where = "WHERE `status` !='inactive'";
        } elseif ($args['status'] == 'inactive') {
            $where = "WHERE `status` ='{$status}'";
        } else {
            $where = "";
        }
        if (!empty($args['limit'])) {
            $limit = " LIMIT={$args['limit']}";
        } else {
            $limit = '';
        }
        $cache_key = md5(implode('|', $args) . $where);
        $levels = wp_cache_get($cache_key, 'rcp');
        if (false === $levels) {
            $levels = $wpdb->get_results("SELECT * FROM {$this->db_name} {$where} ORDER BY {$args['orderby']}{$limit};");
            wp_cache_set($cache_key, $levels, 'rcp');
        }
        $levels = apply_filters('rcp_get_levels', $levels);
        if (!empty($levels)) {
            return $levels;
        }
        return false;
    }

Usage Example

function rcp_get_subscription_levels($status = 'all')
{
    global $wpdb, $rcp_db_name;
    $rcp_levels = new RCP_Levels();
    $levels = $rcp_levels->get_levels(array('status' => $status));
    if ($levels) {
        return $levels;
    } else {
        return array();
    }
}
All Usage Examples Of RCP_Levels::get_levels