/** * Get the form config with the given ID * * @param int $id * @return array|null */ function iphorm_get_form_config($id) { global $wpdb; $id = absint($id); $sql = "SELECT config FROM " . iphorm_get_form_table_name() . " WHERE id = %d"; $config = $wpdb->get_var($wpdb->prepare($sql, $id)); return maybe_unserialize($config); }
/** * Get all the forms from the database with unread entries * * @return object The result object */ function iphorm_get_all_forms_with_unread_entries($active = null) { global $wpdb; $sql = "SELECT f.*, (SELECT COUNT(*) FROM " . iphorm_get_form_entries_table_name() . " WHERE form_id = f.id AND unread = 1) AS entries FROM " . iphorm_get_form_table_name() . " f"; if ($active !== null) { $active = absint($active); $sql .= " WHERE f.active = {$active}"; } $sql .= " HAVING entries > 0"; return $wpdb->get_results($sql); }