Created
December 14, 2013 23:37
-
-
Save iwek/7966522 to your computer and use it in GitHub Desktop.
Quick Contact WordPress Plugin Part 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @package Quick Contact | |
* @version 0.1 | |
*/ | |
/* | |
Plugin Name: Quick Contact | |
Plugin URI: http://techslides.com/ | |
Description: Quick Contact WordPress Plugin to make an Ajax form submission, store it in the database, and show it in a Admin backend page. | |
Version: 0.1 | |
Author URI: http://techslides.com/ | |
*/ | |
register_activation_hook(__FILE__,'qc_install'); | |
register_deactivation_hook(__FILE__, 'qc_uninstall' ); | |
global $jal_db_version; | |
$jal_db_version = "1.0"; | |
function qc_install() { | |
global $wpdb; | |
global $jal_db_version; | |
$table_name = $wpdb->prefix . "quickcontact"; | |
//http://codex.wordpress.org/Creating_Tables_with_Plugins | |
$sql = "CREATE TABLE $table_name ( | |
id mediumint(9) NOT NULL AUTO_INCREMENT, | |
time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, | |
name VARCHAR(120) NOT NULL, | |
email VARCHAR(120) DEFAULT '' NOT NULL, | |
message text NOT NULL, | |
UNIQUE KEY id (id) | |
);"; | |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); | |
dbDelta($sql); | |
add_option("jal_db_version", $jal_db_version); | |
} | |
function qc_uninstall() { | |
global $wpdb; | |
global $jal_db_version; | |
$table_name = $wpdb->prefix . "quickcontact"; | |
$wpdb->query("DROP TABLE IF EXISTS $table_name"); | |
require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); | |
dbDelta($sql); | |
} | |
//http://codex.wordpress.org/Shortcode_API | |
function function_qc_form(){ | |
$html = '<div id="qc_form"> | |
<form id="ContactForm" action=""> | |
<p> | |
<label>Name</label> | |
<input id="name" name="name" maxlength="120" type="text" autocomplete="off"/> | |
</p> | |
<p> | |
<label>Email</label> | |
<input id="email" name="email" maxlength="120" type="text" autocomplete="off"/> | |
</p> | |
<p> | |
<label>Message</label> | |
<textarea id="message" name="message" cols="6" rows="5" autocomplete="off"></textarea> | |
</p> | |
<p class="submit"> | |
<input id="send" type="button" value="Submit"/> | |
</p> | |
</form> | |
</div>'; | |
return $html; | |
} | |
add_shortcode( 'qc_form', 'function_qc_form' ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment