Ein WordPress-Plugin bearbeiten, um meine eigenen functionen hinzuzufügen

Ich versuche, diesem PHP-Skript weitere Felder hinzuzufügen. Standardmäßig können Besucher Ihrer Site ihren Namen und ihre E-Mail-Adresse eingeben, um sie in einer Liste am Backend zu registrieren, die ich dann als CSV-Datei exportieren kann. Im Moment versuche ich Felder für Telefonnummer, Stadt, Staat, ect hinzuzufügen. Ich konnte die Felder hinzufügen, sie werden jedoch nicht am Back-End registriert. Wenn ich mit dem Hinzufügen eines Feldes fertig bin, bricht es jedes zweite Feld. Hier ist mein PHP-Code. Alles, was auf die Nummer verweist, oder sml_number, versuche ich hinzuzufügen.

Edit: Ich war nicht klar genug. Ich denke, das Problem ist am Ende von sml.php.

Unten sind, was ich denke, die Probleme könnten sein.

// Handle form Post if ($_POST['sml_subscribe']) { $name = $_POST['sml_name']; $email = $_POST['sml_email']; $number = $_POST['sml_number']; if (is_email($email)) { $exists = mysql_query("SELECT * FROM ".$wpdb->prefix."sml where sml_email like '".$wpdb->escape($email)."' limit 1"); if (mysql_num_rows($exists) query("insert into ".$wpdb->prefix."sml (sml_name, sml_email, sml_number) values ('".$wpdb->escape($name)."', '".$wpdb->escape($email)."', '".$wpdb->escape($number)."')"); } } } 

und

  if ($_SERVER['REQUEST_METHOD']=="POST" and $_POST['sml_import']) { $correct = 0; if($_FILES['file']['tmp_name']) { if(!$_FILES['file']['error']) { $file = file_get_contents ($_FILES['file']['tmp_name']); $lines = preg_split('/\r\n|\r|\n/', $file); if (count($lines)) { $sql = array(); foreach ($lines as $data) { $data = explode(',', $data); $num = count($data); $row++; if (is_email(trim($data[0]))) { $c = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."sml where sml_email LIKE '".$wpdb->escape(trim($data[0]))."' limit 1", ARRAY_A); if (!is_array($c)) { $wpdb->query("INSERT INTO ".$wpdb->prefix."sml (sml_email, sml_name, sml_number) VALUES ('".$wpdb->escape(trim($data[0]))."', '".$wpdb->escape(trim($data[1]))."', '".$wpdb->escape(trim($data[0]))."')"); $correct++; } else { $exists++; } } else { $invalid++; } } } else { $message = 'Oh no! Your CSV file does not apear to be valid, please check the format and upload again.'; } if (!$message) { $message = $correct.' records have been imported. '.($invalid?$invalid.' could not be imported due to invalid email addresses. ':'').($exists?$exists.' already exists. ':''); } } else { $message = 'Ooops! There seems to of been a problem uploading your csv'; } } } 

Und unten ist der gesamte Inhalt des Plugins als Referenz.

sml.php:

  // Plugin Activation function sml_install() { global $wpdb; $table = $wpdb->prefix."sml"; $structure = "CREATE TABLE $table ( id INT(9) NOT NULL AUTO_INCREMENT, sml_name VARCHAR(200) NOT NULL, sml_email VARCHAR(200) NOT NULL, sml_number VARCHAR(200) NOT NULL, UNIQUE KEY id (id) );"; $wpdb->query($structure); } register_activation_hook( __FILE__, 'sml_install' ); // Plugin Deactivation function sml_uninstall() { global $wpdb; } register_deactivation_hook( __FILE__, 'sml_uninstall' ); // Left Menu Button function register_sml_menu() { add_menu_page('Subscribers', 'Subscribers', 'add_users', dirname(__FILE__).'/index.php', '', plugins_url('sml-admin-icon.png', __FILE__), 58.122); } add_action('admin_menu', 'register_sml_menu'); // Generate Subscribe Form function smlsubform($atts=array()){ extract(shortcode_atts(array( "prepend" => '', "showname" => true, "nametxt" => 'Name:', "nameholder" => 'Enter your name.', "emailtxt" => 'Email:', "emailholder" => 'Enter your email address.', "numbertxt" => 'Phone Number:', "numberholder" => 'Enter your Phone Number.', "showsubmit" => true, "submittxt" => 'Subscribe', "jsthanks" => false, "thankyou" => 'Thank you for subscribing to our mailing list!' ), $atts)); $return = '
'; if ($prepend) $return .= '

'.$prepend.'

'; if ($_POST['sml_subscribe'] && $thankyou) { if ($jsthanks) { $return .= "window.onload = function() { alert('".$thankyou."'); }"; } else { $return .= '

'.$thankyou.'

'; } } if ($showname) $return .= '

'; $return .= '

'; $return .= '

'; if ($showsubmit) $return .= '

'; $return .= '
'; return $return; } add_shortcode( 'smlsubform', 'smlsubform' ); // Handle form Post if ($_POST['sml_subscribe']) { $name = $_POST['sml_name']; $email = $_POST['sml_email']; $number = $_POST['sml_number']; if (is_email($email)) { $exists = mysql_query("SELECT * FROM ".$wpdb->prefix."sml where sml_email like '".$wpdb->escape($email)."' limit 1"); if (mysql_num_rows($exists) query("insert into ".$wpdb->prefix."sml (sml_name, sml_email, sml_number) values ('".$wpdb->escape($name)."', '".$wpdb->escape($email)."', '".$wpdb->escape($number)."')"); } } } function plugin_get_version() { $plugin_data = get_plugin_data( __FILE__ ); $plugin_version = $plugin_data['Version']; return $plugin_version; } ?>

index.php

 

Mail list subscribers

<form method="post" action="?page="> query("delete from ".$wpdb->prefix."sml where id = '".$wpdb->escape($id)."' limit 1"); $count++; } $message = $count." subscribers have been removed successfully."; } } if ($_SERVER['REQUEST_METHOD']=="POST" and $_POST['sml_import']) { $correct = 0; if($_FILES['file']['tmp_name']) { if(!$_FILES['file']['error']) { $file = file_get_contents ($_FILES['file']['tmp_name']); $lines = preg_split('/\r\n|\r|\n/', $file); if (count($lines)) { $sql = array(); foreach ($lines as $data) { $data = explode(',', $data); $num = count($data); $row++; if (is_email(trim($data[0]))) { $c = $wpdb->get_row("SELECT * FROM ".$wpdb->prefix."sml where sml_email LIKE '".$wpdb->escape(trim($data[0]))."' limit 1", ARRAY_A); if (!is_array($c)) { $wpdb->query("INSERT INTO ".$wpdb->prefix."sml (sml_email, sml_name, sml_number) VALUES ('".$wpdb->escape(trim($data[0]))."', '".$wpdb->escape(trim($data[1]))."', '".$wpdb->escape(trim($data[0]))."')"); $correct++; } else { $exists++; } } else { $invalid++; } } } else { $message = 'Oh no! Your CSV file does not apear to be valid, please check the format and upload again.'; } if (!$message) { $message = $correct.' records have been imported. '.($invalid?$invalid.' could not be imported due to invalid email addresses. ':'').($exists?$exists.' already exists. ':''); } } else { $message = 'Ooops! There seems to of been a problem uploading your csv'; } } } //echo $sql; if ($message) { echo '

'.$message.'

'; } ?> get_results( "SELECT * FROM ".$wpdb->prefix."sml"); if (count($results)<1) echo ''; else { foreach($results as $row) { echo ''; } } ?>
Name Email Address Number
Name Email Address Number
No mailing list subscribers have been added.
id)).'"> '.esc_js(esc_html($row->sml_name)).' '.esc_js(esc_html($row->sml_email)).' '.esc_js(esc_html($row->sml_number)).'

<a class="button" href="https://wordpress.stackexchange.com/questions/134115/editing-a-wordpress-plugin-to-add-my-own-functionality/">Export List

export-csv.php

 get_results( "SELECT * FROM ".$wpdb->prefix."sml"); echo "First Name,Last Name,Email Address\r\n"; if (count($results)) { foreach($results as $row) { $n = doSplitName($row->sml_name); echo $n['first'].','.$n['last'].','.$row->sml_email."\r\n"; } } } function doSplitName($name) { $results = array(); $r = explode(' ', $name); $size = count($r); if (mb_strpos($r[0], '.') === false) { $results['salutation'] = ''; $results['first'] = $r[0]; } else { $results['salutation'] = $r[0]; $results['first'] = $r[1]; } if (mb_strpos($r[$size - 1], '.') === false) { $results['suffix'] = ''; } else { $results['suffix'] = $r[$size - 1]; } $start = ($results['salutation']) ? 2 : 1; $end = ($results['suffix']) ? $size - 2 : $size - 1; $last = ''; for ($i = $start; $i  

Jede und jede Hilfe wird sehr geschätzt. Oder auch nur ein Stoß in die richtige Richtung. Ich arbeite seit Wochen daran, und ich bin nicht php php. Vielen Dank.

Solutions Collecting From Web of "Ein WordPress-Plugin bearbeiten, um meine eigenen functionen hinzuzufügen"