i wrote a little bit plugin, who shows a customized kind in frontend and retailer entered information in native DB with connection to MailChimp. With a shortcode.
Now i´m getting an error “headers already despatched..”, everytime when the put up or website be saved with this shortcode. In frontend the plugin works effectively.
See code and screens beneath:
register_activation_hook(FILE, 'on_activate');
operate on_activate() { international $wpdb;
/// $table_name = $wpdb->prefix . "subscribe_record"; /// $sql = "DROP TABLE IF EXISTS $table_name"; // $wpdb->question($sql); $create_table_query = "CREATE TABLE IF NOT EXISTS
{$wpdb->prefix}subscribe_record
( id INTEGER NOT NULL AUTO_INCREMENT, surename VARCHAR(100), title VARCHAR(100), e mail VARCHAR(100), gender VARCHAR(3), avenue VARCHAR(500), zip VARCHAR(20), metropolis VARCHAR(200), package deal VARCHAR(6), subscribe INTEGER(11), PRIMARY KEY (id))"; require_once( ABSPATH . 'wp-admin/contains/improve.php' ); dbDelta($create_table_query);}
add_action('wp_ajax_insert_subcriber_record', 'insert_subcriber_record'); add_action('wp_ajax_nopriv_insert_subcriber_record', 'insert_subcriber_record');
operate insert_subcriber_record() { international $wpdb;
$tablename = $wpdb->prefix . 'subscribe_record'; $surename = isset($_REQUEST['subcriber_surename']) ? $_REQUEST['subcriber_surename'] : ''; $title = isset($_REQUEST['subcriber_name']) ? $_REQUEST['subcriber_name'] : ''; $e mail = isset($_REQUEST['subcriber_email']) ? $_REQUEST['subcriber_email'] : ''; $gender = isset($_REQUEST['subcriber_gender']) ? $_REQUEST['subcriber_gender'] : 'm'; $avenue = isset($_REQUEST['subcriber_street']) ? $_REQUEST['subcriber_street'] : ''; $zip = isset($_REQUEST['subcriber_zip']) ? $_REQUEST['subcriber_zip'] : ''; $metropolis = isset($_REQUEST['subcriber_city']) ? $_REQUEST['subcriber_city'] : ''; $subscribe = isset($_REQUEST['subcribe']) ? $_REQUEST['subcribe'] : 0; $package deal = isset($_REQUEST['package']) ? $_REQUEST['package'] : 'No'; if($package deal == 'sure'){ $package deal = 'Sure'; } if ($subscribe) { $subscribe = 1; } $information = array( 'surename' => $surename, 'title' => $title, 'e mail' => $e mail, 'gender' => $gender, 'avenue' => $avenue, 'zip' => $zip, 'metropolis' => $metropolis, 'package deal' => $package deal, 'subscribe' => $subscribe ); if(checkSubsriberCount() > 0) { $wpdb->insert($tablename, $information); } $response = array(); if ($subscribe) { $response['data'] = 'sure'; } else { $response['data'] = 'no'; } echo json_encode($response); exit;
}
/** Step 2 (from textual content above). */
add_action('admin_menu', 'subscriber_list_menu');/** Step 1. */
operate subscriber_list_menu() {
add_options_page('WaterWipes Export', 'WaterWipes Export', 'manage_options', 'subscriber_list', 'subscriber_list_func');
}/** Step 3. */
operate checkSubsriberCount(){
international $wpdb; $table_name = $wpdb->prefix . "subscribe_record"; $subscriber = $wpdb->get_results("SELECT * FROM $table_name"); $mailChimpCounter = get_option('mailChimpCounter'); return (int)($mailChimpCounter - depend($subscriber));
}
operate subscriber_list_func() {
if (!current_user_can('manage_options')) {
wp_die(__('You don't have adequate permissions to entry this web page.'));
}international $wpdb; $table_name = $wpdb->prefix . "subscribe_record"; $subscriber = $wpdb->get_results("SELECT * FROM $table_name"); $mailChimpCounter = get_option('mailChimpCounter'); ?> <div class="container"> <h2>Kundenliste</h2> <br/><br/> <div class="row"> <div class="col-md-6"> <div class="form-group"> <label class="sr-only" for="pwd">Mail Chimp Counter Quantity:</label> <enter kind="quantity" worth="<?php echo $mailChimpCounter; ?>" class="form-control" id="txtMailChimp"> </div> </div> <div class="col-md-2"> <button kind="button" class="btn btn-default" id="updateCounter">Submit</button> </div> </div> <div class="row"> <div class="col-md-11"> <desk id="instance" class="desk table-striped table-bordered" fashion="width:100%"> <thead> <tr> <th>Surename</th> <th>Identify</th> <th>Electronic mail</th> <th>Gender</th> <th>Road</th> <th>Zip Code</th> <th>Metropolis</th> <th>Pakcage</th> </tr> </thead> <tbody> <?php foreach ($subscriber as $checklist) { echo '<tr>'; echo '<td>' . $list->surename . '</td>'; echo '<td>' . $list->title . '</td>'; echo '<td>' . $list->e mail . '</td>'; if ($list->gender == 'm') { echo '<td>Male</td>'; } else { echo '<td>Feminine</td>'; } echo '<td>' . $list->avenue . '</td>'; echo '<td>' . $list->zip . '</td>'; echo '<td>' . $list->metropolis . '</td>'; echo '<td>' . $list->package deal . '</td>'; echo '</tr>'; } ?> </tbody> <tfoot> <tr> <th>Surename</th> <th>Identify</th> <th>Electronic mail</th> <th>Gender</th> <th>Road</th> <th>Zip Code</th> <th>Metropolis</th> <th>Pakcage</th> </tr> </tfoot> </desk> </div> </div> </div> <hyperlink rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' kind='textual content/css' media='all' /> <hyperlink rel='stylesheet' href='https://cdn.datatables.internet/1.10.16/css/dataTables.bootstrap.min.css' kind='textual content/css' media='all' /> <hyperlink rel='stylesheet' href='https://cdn.datatables.internet/buttons/1.5.1/css/buttons.bootstrap.min.css' kind='textual content/css' media='all' /> <script kind='textual content/javascript' src='https://code.jquery.com/jquery-3.3.1.js'></script> <script kind='textual content/javascript' src='https://cdn.datatables.internet/1.10.16/js/jquery.dataTables.min.js'></script> <script kind='textual content/javascript' src='https://cdn.datatables.internet/1.10.16/js/dataTables.bootstrap.min.js'></script> <script kind='textual content/javascript' src='https://cdn.datatables.internet/buttons/1.5.1/js/dataTables.buttons.min.js'></script> <script kind='textual content/javascript' src='https://cdn.datatables.internet/buttons/1.5.1/js/buttons.bootstrap.min.js'></script> <script kind='textual content/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js'></script> <script kind='textual content/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/pdfmake.min.js'></script> <script kind='textual content/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.32/vfs_fonts.js'></script> <script kind='textual content/javascript' src='https://cdn.datatables.internet/buttons/1.5.1/js/buttons.html5.min.js'></script> <script kind='textual content/javascript' src='https://cdn.datatables.internet/buttons/1.5.1/js/buttons.print.min.js'></script> <script kind='textual content/javascript' src='https://cdn.datatables.internet/buttons/1.5.1/js/buttons.colVis.min.js'></script> <script> $('physique').on('click on', '#updateCounter', operate () { var get_number = $('#txtMailChimp').val(); var r = affirm("Möchten Sie den Zählerstand speichern?"); if (r == true) { var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>'; jQuery.ajax({ url: ajaxurl, information: {quantity: get_number, motion: 'saveMailChimpnumber'}, technique: 'put up', success: operate (response) { alert('Neuer Zählerstand gespeichert!') }, cache: false, /// contentType: false, /// processData: false }); } }); $(doc).prepared(operate () { var desk = $('#instance').DataTable({ lengthChange: false, buttons: ['excel', 'pdf', 'colvis'] }); desk.buttons().container() .appendTo('#example_wrapper .col-sm-6:eq(0)'); }); </script> <?php
}
add_action('wp_ajax_saveMailChimpnumber', 'saveMailChimpnumber');
add_action('wp_ajax_nopriv_saveMailChimpnumber', 'saveMailChimpnumber');
operate saveMailChimpnumber() {
$worth = isset($_REQUEST['number']) ? $_REQUEST['number'] : 1000;
update_option('mailChimpCounter', $worth);
exit;
}
operate subcriberList_shortCode($atts) {
$a = shortcode_atts(array(
'formid' => ''), $atts);
$adminUrl = admin_url('admin-ajax.php');
?>WaterWipes Take a look at
jQuery(operate ($) {
$('physique').on('click on', '#subcriberSubmitBtn', operate () {
$('.subcriber-response').html('');
var subcriber_surename = $('#subcriber_surename').val();
var subcriber_name = $('#subcriber_name').val();
var subcriber_street = $('#subcriber_street').val();
var subcriber_zip = $('#subcriber_zip').val();
var subcriber_city = $('#subcriber_city').val();
var subcriber_email = $('#subcriber_email').val();
var error = false;
if (subcriber_surename) {
$('#subcriber_surename').css('border-color', '#ccc')
} else {
error = true;
$('#subcriber_surename').css('border-color', '#c91d2e')
}
if (subcriber_name) {
$('#subcriber_name').css('border-color', '#ccc')
} else {
error = true;
$('#subcriber_name').css('border-color', '#c91d2e')
}
if (subcriber_street) {
$('#subcriber_street').css('border-color', '#ccc')
} else {
error = true;
$('#subcriber_street').css('border-color', '#c91d2e')
}
if (subcriber_zip) {
$('#subcriber_zip').css('border-color', '#ccc')
} else {
error = true;
$('#subcriber_zip').css('border-color', '#c91d2e')
}
if (subcriber_city) {
$('#subcriber_city').css('border-color', '#ccc')
} else {
error = true;
$('#subcriber_city').css('border-color', '#c91d2e')
}
if(jQuery("#subcribe").is(":checked")){
if (subcriber_email) {
if (!validateEmail(subcriber_email)) {
$('#subcriber_email').css('border-color', '#c91d2e')
error = true;
}else{
$('#subcriber_email').css('border-color', '#ccc')
}
} else {
error = true;
$('#subcriber_email').css('border-color', '#c91d2e')
}
}else{
$('#subcriber_email').css('border-color', '#ccc')
}
if (error == true) {
$('.subcriber-response').html('Bitte alle erforderlichen Felder ausfüllen.');
return false;
} else {
var elementT = doc.getElementById("subcriberForm");
var ajaxurl = '';
var formdata = new FormData(elementT);
jQuery.ajax({
url: ajaxurl,
information: formdata,
technique: 'POST',
success: operate (response) {
if (response) {
$('.subcriber-response').html('Vielen Dank für deine Nachricht, du erhältst die WaterWipes Probepackung per Put up!');
var obj = jQuery.parseJSON(response);
console.log(obj.information);
$('#subcriber_surename').val('');
$('#subcriber_name').val('');
$('#subcriber_street').val('');
$('#subcriber_zip').val('');
$('#subcriber_city').val('');
$('#subcriber_email').val('');
if (obj.information == 'sure') {
$("#customSubcriber").discover("enter[name='FNAME']").val(subcriber_surename);
$("#customSubcriber").discover("enter[name='LNAME']").val(subcriber_name);
$("#customSubcriber").discover("enter[name='ADDRESS[addr1]']").val(subcriber_street);
$("#customSubcriber").discover("enter[name='ADDRESS[city]']").val(subcriber_city);
$("#customSubcriber").discover("enter[name='ADDRESS[zip]']").val(subcriber_zip);
$("#customSubcriber").discover("enter[name='EMAIL']").val(subcriber_email);
$("#customSubcriber kind").submit();
}
//// location.reload();
} else {
alert('One thing Went Improper, Report Not Up to date');
}
},
cache: false,
contentType: false,
processData: false
});
}
});
});
operate validateEmail($e mail) {
var emailReg = /^([w-.]+@([w-]+.)+[w-]{2,4})?$/;
return emailReg.check($e mail);
}Hier kannst du noch einen Textual content aussuchen 🙂 </p> -->
Ich möchte WaterWipes testen und freue mich über eine Probepackung
Herr
Frau<p><enter kind="e mail" id="subcriber_email" title="subcriber_email" placeholder="E-Mail Adresse" required=""></p> <?php if(checkSubsriberCount() > 0){ ?> <p><enter kind="checkbox" title="subcribe" id="subcribe" worth="sure"><label for="subcribe">Ich möchte den Spinoggelfritz-E-newsletter abonnieren</label></p> <?php }else{ ?> <enter kind="hidden" title="subcribe" worth="sure" > <?php } ?> <p><enter fashion="cursor: pointer;" kind="button" id="subcriberSubmitBtn" worth="Absenden >"></p> </ul> <div class="subcriber-response" fashion="padding-bottom: 4px;padding-top: 10px;"></div> </div> </div> </kind> <!-- / MailChimp for WordPress Plugin --> </div> <div fashion="show: none;" id="customSubcriber"> <?php $formID = $a['formid']; echo do_shortcode("[mc4wp_form id='".$formID."']"); ?> </div> <?php
}
add_shortcode('subcribercustomform', 'subcriberList_shortCode');Thanks for any recommendations.
rgrds
Johannes