PodsAPI::load_object PHP Method

load_object() public method

$params['id'] int The Object ID $params['name'] string The Object name $params['type'] string The Object type
Since: 2.0
public load_object ( array | object $params, boolean $strict = false ) : array | boolean
$params array | object An associative array of parameters
$strict boolean
return array | boolean
    public function load_object($params, $strict = false)
    {
        if (is_object($params) && isset($params->post_title)) {
            $_object = get_object_vars($params);
        } else {
            $params = (object) pods_sanitize($params);
            if (!isset($params->type) || empty($params->type)) {
                return pods_error(__('Object type is required', 'pods'), $this);
            }
            if ((!isset($params->id) || empty($params->id)) && (!isset($params->name) || empty($params->name))) {
                return pods_error(__('Either Object ID or Name are required', 'pods'), $this);
            }
            /**
             * @var $wpdb wpdb
             */
            global $wpdb;
            if (isset($params->name)) {
                $_object = pods_by_title($params->name, ARRAY_A, '_pods_' . $params->type, 'publish');
            } else {
                $object = $params->id;
                $_object = get_post($object, ARRAY_A);
            }
            if (empty($_object)) {
                if ($strict) {
                    return pods_error(__('Object not found', 'pods'), $this);
                }
                return false;
            }
        }
        $object = array('id' => $_object['ID'], 'name' => $_object['post_title'], 'code' => $_object['post_content'], 'type' => str_replace('_pods_', '', $_object['post_type']), 'slug' => $_object['post_name']);
        $object['options'] = get_post_meta($object['id']);
        foreach ($object['options'] as $option => &$value) {
            if (is_array($value) && 1 == count($value)) {
                $value = current($value);
            }
        }
        return $object;
    }