$code, 'event_id' => absint(wp_unslash($_POST['event_id'] ?? 0)), 'type' => sanitize_key(wp_unslash($_POST['type'] ?? ''))=='fixed'?'fixed':'percent', 'amount' => (float)sanitize_text_field(wp_unslash($_POST['amount'] ?? 0)), 'max_uses' => absint(wp_unslash($_POST['max_uses'] ?? 0)), 'expires' => trim(sanitize_text_field(wp_unslash($_POST['expires'] ?? '')))!=''?gmdate("Y-m-d 23:59:59",strtotime(sanitize_text_field(wp_unslash($_POST['expires'])))):null, 'active' => isset($_POST['active'])?1:0, ]; $edit_id = absint(wp_unslash($_POST['id'] ?? 0)); if ($code=='' || $data['amount']<=0) $message = __('Please provide a code and an amount greater than zero.','ticketdrum'); elseif ($edit_id>0) { $wpdb->update(TICKETDRUM_PROMOCODES_TABLE,$data,['id'=>$edit_id]); $message = __('Promo code updated.','ticketdrum'); } else { $data['added'] = gmdate("Y-m-d H:i:s"); if ($wpdb->insert(TICKETDRUM_PROMOCODES_TABLE,$data)===false) $message = __('Could not save - is that code already in use?','ticketdrum'); else $message = __('Promo code added.','ticketdrum'); } } elseif (sanitize_key(wp_unslash($_GET['action'] ?? ''))=='delete' && absint(wp_unslash($_GET['id'] ?? 0))>0 && check_admin_referer('ticketdrum_promocode_delete')) { $wpdb->delete(TICKETDRUM_PROMOCODES_TABLE,['id'=>(int)$_GET['id']]); $message = __('Promo code deleted.','ticketdrum'); } $editing = false; if (sanitize_key(wp_unslash($_GET['action'] ?? ''))=='edit' && absint(wp_unslash($_GET['id'] ?? 0))>0) $editing = $wpdb->get_row($wpdb->prepare("SELECT * FROM %i WHERE id=%d",TICKETDRUM_PROMOCODES_TABLE,(int)$_GET['id']),ARRAY_A); $codes = $wpdb->get_results($wpdb->prepare("SELECT * FROM %i ORDER BY added DESC",TICKETDRUM_PROMOCODES_TABLE),ARRAY_A); $events = $wpdb->get_results($wpdb->prepare("SELECT id,title FROM %i WHERE status!='archived' ORDER BY added DESC",TICKETDRUM_EVENTS_TABLE),ARRAY_A); ?>
'.esc_html($message).'