$field) { if (!is_array($field)) continue; $key = sanitize_text_field($key); if ($key=='') continue; //Every value is forced to a scalar first: the editor never posts nested values here, and //the sanitizers below expect strings. $field = array_map(function($v){ return is_scalar($v)?$v:''; },$field); $type = sanitize_key($field['type'] ?? ''); $limit = absint($field['characterlimit'] ?? 0); $fields[$key] = [ 'type' => in_array($type,['text','textarea','select'],true)?$type:'text', 'title' => sanitize_text_field($field['title'] ?? ''), 'clean' => sanitize_key($field['clean'] ?? ''), 'required' => !empty($field['required']), 'options' => sanitize_textarea_field($field['options'] ?? ''), 'characterlimit' => $limit>0?$limit:'', //blank and 0 both mean "no limit" ]; } return wp_slash(wp_json_encode($fields)); } function ticketdrum_settings() { ticketdrum_require_admin(); global $wpdb,$ticketdrum_api,$ticketdrum_payment_data; $action = sanitize_text_field(wp_unslash($_GET['action'] ?? '')); $tab = sanitize_text_field(wp_unslash($_GET['tab'] ?? '')); $id = absint(wp_unslash($_GET['id'] ?? 0)); $message = ''; if (!get_option('ticketdrum_emailconfirmation_user')) /* translators: %s: the {$name} placeholder, which must be kept as is */ add_option('ticketdrum_emailconfirmation_user',"
".sprintf(__('Dear %s,','ticketdrum'),'{$name}')."
\n".'{$order_details}'."\n".__('Thank you for your order.','ticketdrum')."
\n".get_bloginfo()."
"); if (!get_option('ticketdrum_emailconfirmation_admin')) /* translators: %s: the {$name} placeholder, which must be kept as is */ add_option('ticketdrum_emailconfirmation_admin',"".sprintf(__('New order placed by %s,','ticketdrum'),'{$name}')."
\n".'{$order_details}'."\n".get_bloginfo()."
"); if (!get_option('ticketdrum_emailconfirmation_emails')) add_option('ticketdrum_emailconfirmation_emails',get_bloginfo('admin_email')); if ($action=='') { #die(''.print_r($_POST,true).''); #$_POST = array_map('sanitize_text_field', $_POST); $allowed_tags = [ 'a' =>[], 'br' =>[], 'hr' =>[], 'p' =>[], 'strong'=>[], 'em' =>[], 'b' =>[], 'i' =>[], 'span' =>[], ]; if (!empty($_POST['action'])) check_admin_referer('ticketdrum_settings'); if (sanitize_key(wp_unslash($_POST['action'] ?? ''))=='update_settings') { update_option('ticketdrum_currency',sanitize_text_field(wp_unslash($_POST['ticketdrum_currency'] ?? ''))); update_option('ticketdrum_tax_mode',sanitize_text_field(wp_unslash($_POST['ticketdrum_tax_mode'] ?? ''))); update_option('ticketdrum_tax_rate',absint(wp_unslash($_POST['ticketdrum_tax_rate'] ?? 0))); update_option('ticketdrum_tax_title',sanitize_text_field(wp_unslash($_POST['ticketdrum_tax_title'] ?? ''))); update_option('ticketdrum_emailconfirmation_emails',sanitize_text_field(wp_unslash($_POST['ticketdrum_emailconfirmation_emails'] ?? ''))); foreach (array_keys(ticketdrum_labels()) as $label_key) { $label_option = 'ticketdrum_label_'.$label_key; $label_value = trim(sanitize_text_field(wp_unslash($_POST[$label_option] ?? ''))); if (isset($_POST[$label_option.'_default']) || $label_value=='') delete_option($label_option); //Missing option = the built-in default applies else update_option($label_option,$label_value); } // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- ticketdrum_sanitize_custom_formdata() decodes the posted JSON and rebuilds it key by key through the appropriate sanitizer for each; see its definition at the top of this file. update_option('ticketdrum_custom_formdata',ticketdrum_sanitize_custom_formdata(wp_unslash($_POST['ticketdrum_custom_formdata'] ?? ''))); update_option('ticketdrum_fee_paid_by',sanitize_key(wp_unslash($_POST['ticketdrum_fee_paid_by'] ?? ''))=='organiser'?'organiser':'buyer'); update_option('ticketdrum_invoice_details',sanitize_textarea_field(wp_unslash($_POST['ticketdrum_invoice_details'] ?? ''))); $message = __('Settings updated.','ticketdrum'); } elseif (sanitize_key(wp_unslash($_POST['action'] ?? ''))=='update_labels') { foreach (array_keys(ticketdrum_labels()) as $label_key) { $label_option = 'ticketdrum_label_'.$label_key; $label_value = trim(sanitize_text_field(wp_unslash($_POST[$label_option] ?? ''))); if (isset($_POST[$label_option.'_default']) || $label_value=='') delete_option($label_option); //Missing option = the built-in default applies else update_option($label_option,$label_value); } $message = __('Labels updated.','ticketdrum'); } elseif (sanitize_key(wp_unslash($_POST['action'] ?? ''))=='update_email_templates') { $options = ['ticketdrum_emailconfirmation_user','ticketdrum_emailconfirmation_admin']; foreach ($options as $option) if (get_option($option)===false) add_option($option,wp_kses(wp_unslash($_POST[$option] ?? ''),$allowed_tags)); else update_option($option,wp_kses(wp_unslash($_POST[$option] ?? ''),$allowed_tags)); $message = __('Email templates updated.','ticketdrum'); } elseif (sanitize_key(wp_unslash($_POST['action'] ?? ''))=='update_stripe') { $stripe_mode = sanitize_key(wp_unslash($_POST['ticketdrum_stripe_mode'] ?? ''))=='live'?'live':'test'; if (get_option('ticketdrum_stripe_mode')===false) add_option('ticketdrum_stripe_mode',$stripe_mode); else update_option('ticketdrum_stripe_mode',$stripe_mode); $message = __('Stripe settings updated.','ticketdrum'); } ?>
'.esc_html($message).'
'.esc_html__('Card payments are processed through TicketDrum\'s Stripe Connect platform, so connect this site to the TicketDrum service before linking your Stripe account. Free tickets, check-in and everything else work without this.','ticketdrum').'
'; if (!empty($_GET['refresh_stripe'])) check_admin_referer('ticketdrum_stripe_refresh'); if (ticketdrum_is_connected()) { $api_response = $ticketdrum_api->fetch_stripe_credentials(); if ($api_response && !empty($api_response['result'])) { $payment_data = []; $options = ['live_stripe_access_token','live_stripe_refresh_token','live_stripe_publishable_key','live_stripe_user_id','test_stripe_access_token','test_stripe_refresh_token','test_stripe_publishable_key','test_stripe_user_id','fee_percent','fee_fixed','stripe_percent','stripe_fixed']; foreach ($options as $opt) $payment_data[$opt] = $api_response[$opt]; if (get_option('ticketdrum_payment_data')!==false) update_option('ticketdrum_payment_data',json_encode($payment_data)); else add_option('ticketdrum_payment_data',json_encode($payment_data)); if (get_option('ticketdrum_last_checked')!==false) update_option('ticketdrum_last_checked',time()); else add_option('ticketdrum_last_checked',time()); } $ticketdrum_payment_data = json_decode(get_option('ticketdrum_payment_data'),true); if (!$ticketdrum_payment_data || count($ticketdrum_payment_data)==0) $ticketdrum_payment_data = false; } if (!empty($_GET['disconnect_stripe'])) { check_admin_referer('ticketdrum_stripe_disconnect'); $api_response = $ticketdrum_api->disconnect_stripe(sanitize_key(wp_unslash($_GET['environment'] ?? ''))=='live'?'live':'test'); if (get_option('ticketdrum_payment_data')!==false) update_option('ticketdrum_payment_data',''); else add_option('ticketdrum_payment_data',''); if (get_option('ticketdrum_last_checked')!==false) update_option('ticketdrum_last_checked',time()); else add_option('ticketdrum_last_checked',time()); } ?> TICKETDRUM_URL.'/stripe-connect', 'account' => get_option('ticketdrum_account_id'), 'refresh_url' => wp_nonce_url(admin_url('admin.php?page=ticketdrum_settings&tab=stripe&refresh_stripe=1'),'ticketdrum_stripe_refresh'), ]).'); });'); ?>