/** * Delete meta data by meta ID. * * NOTE: This is the Connections equivalent of @see delete_metadata_by_mid() in WordPress core ../wp-includes/meta.php * * @access public * @since 8.1.7 * @static * * @global wpdb $wpdb WordPress database abstraction object. * * @uses absint() * @uses sanitize_key() * @uses cnMeta::tableName() * @uses cnMeta::getByID() * @uses wpdb::delete() * @uses do_action() * * @param string $type Type of object metadata is for (e.g., entry, term) * @param int $id ID for a specific meta row * * @return bool True on successful delete, false on failure. */ public static function deleteByID($type, $id) { /** @var wpdb $wpdb */ global $wpdb; // Make sure everything is valid. if (!$type || !is_numeric($id)) { return FALSE; } $id = absint($id); if (!$id) { return FALSE; } $table = cnMeta::tableName($type); // object and id columns $column = sanitize_key($type . '_id'); // Fetch the meta and go on if it's found. if ($meta = cnMeta::getByID($type, $id)) { $object_id = $meta->{$column}; /** This action is documented in wp-includes/meta.php */ do_action("cn_delete_{$type}_meta", (array) $id, $object_id, $meta->meta_key, $meta->meta_value); // Run the query, will return true if deleted, false otherwise $result = (bool) $wpdb->delete($table, array('meta_id' => $id)); // Clear the caches. wp_cache_delete($object_id, 'cn_' . $type . '_meta'); /** This action is documented in wp-includes/meta.php */ do_action("cn_deleted_{$type}_meta", (array) $id, $object_id, $meta->meta_key, $meta->meta_value); return $result; } return FALSE; }