PodsAPI::delete_pod PHP Method

delete_pod() public method

$params['id'] int The Pod ID $params['name'] string The Pod name
Since: 1.7.9
public delete_pod ( array $params, boolean $strict = false, boolean $delete_all = false ) : boolean
$params array An associative array of parameters
$strict boolean (optional) Makes sure a pod exists, if it doesn't throws an error
$delete_all boolean (optional) Whether to delete all content from a WP object
return boolean
    public function delete_pod($params, $strict = false, $delete_all = false)
    {
        /**
         * @var $wpdb wpdb
         */
        global $wpdb;
        if (!is_object($params) && !is_array($params)) {
            if (is_numeric($params)) {
                $params = array('id' => $params);
            } else {
                $params = array('name' => $params);
            }
            $params = (object) pods_sanitize($params);
        } else {
            $params = (object) pods_sanitize($params);
        }
        $params->table_info = false;
        $pod = $this->load_pod($params, $strict);
        if (empty($pod)) {
            if (false !== $strict) {
                return pods_error(__('Pod not found', 'pods'), $this);
            }
            return false;
        }
        $params->id = (int) $pod['id'];
        $params->name = $pod['name'];
        foreach ($pod['fields'] as $field) {
            $field['pod'] = $pod;
            $this->delete_field($field, false);
        }
        // Only delete the post once the fields are taken care of, it's not required anymore
        $success = wp_delete_post($params->id);
        if (!$success) {
            return pods_error(__('Pod unable to be deleted', 'pods'), $this);
        }
        // Reset content
        if ($delete_all) {
            $this->reset_pod($params, $pod);
        }
        if (!pods_tableless()) {
            if ('table' == $pod['storage']) {
                try {
                    pods_query("DROP TABLE IF EXISTS `@wp_pods_{$params->name}`", false);
                } catch (Exception $e) {
                    // Allow pod to be deleted if the table doesn't exist
                    if (false === strpos($e->getMessage(), 'Unknown table')) {
                        return pods_error($e->getMessage(), $this);
                    }
                }
            }
            pods_query("DELETE FROM `@wp_podsrel` WHERE `pod_id` = {$params->id} OR `related_pod_id` = {$params->id}", false);
        }
        // @todo Delete relationships from tableless relationships
        // Delete any relationship references
        $sql = "\n            DELETE `pm`\n            FROM `{$wpdb->postmeta}` AS `pm`\n            LEFT JOIN `{$wpdb->posts}` AS `p`\n                ON `p`.`post_type` = '_pods_field'\n                    AND `p`.`ID` = `pm`.`post_id`\n            LEFT JOIN `{$wpdb->postmeta}` AS `pm2`\n                ON `pm2`.`meta_key` = 'pick_object'\n                    AND `pm2`.`meta_value` = 'pod'\n                    AND `pm2`.`post_id` = `pm`.`post_id`\n            WHERE\n                `p`.`ID` IS NOT NULL\n                AND `pm2`.`meta_id` IS NOT NULL\n                AND `pm`.`meta_key` = 'pick_val'\n                AND `pm`.`meta_value` = '{$params->name}'\n        ";
        pods_query($sql);
        $this->cache_flush_pods($pod);
        return true;
    }