SHARE
TWEET

Untitled

a guest Nov 5th, 2013 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3.  * Plugin Name: Jquery Contact Us
  4.  * Description: This is contact us form with jquery Validation & Bootstrap 3.0
  5.  * Author: Kalpit Pandit
  6.  * Author URI: www.google.com
  7.  * Version: 1.0
  8.  */
  9. ?>
  10. <?php
  11. global $page_id;
  12. register_activation_hook(__FILE__,'createTable');
  13. register_deactivation_hook(__FILE__, 'dropTable');
  14. add_filter('template_include', 'add_template');
  15. add_action('admin_menu','createMenu');
  16.  
  17. function createTable()
  18. {
  19.     global $wpdb;
  20.     if($wpdb->query("Show tables like 'kp_contact'") > 0) {
  21. //        createPage();
  22.         do_action('create_Page');
  23.     }
  24.     else
  25.     {
  26.        $qa="create table kp_contact (cid int AUTO_INCREMENT PRIMARY KEY, name varchar(50), email varchar(50), contact varchar(15), type varchar(10), message longtext)";
  27.        $q="create table kp_contact_config (cid int AUTO_INCREMENT PRIMARY KEY, Message Longtext,email varchar(30),pagetitle varchar(30))";
  28.        
  29.        $wpdb->query($qa);
  30.        $wpdb->query($q);
  31.        $wpdb->insert("kp_contact_config",array('message'=>'Thanks for contacting with us. Will reach you soon','email'=>  get_option('admin_email'),'pagetitle'=>'Contact Us'),array('%s','%s','%s'));
  32. //        createPage();
  33.         do_action('create_Page');
  34.     }
  35. }
  36. add_action('create_Page','createPage',10);
  37. function createMenu()
  38. {
  39.     add_menu_page('Configuration Contact Page', 'Conatct US Setting', 'manage_options', __FILE__, 'welcome');
  40. }
  41.  
  42. function welcome()
  43. {    global $wpdb;
  44.     ?>
  45.    
  46.     <form method="POST" action="<?php echo plugins_url().'/kp_contactus/kp_contact_config.php'?>" id="ok">
  47.         <table>
  48.             <tr><td colspan="2"> <h3> Welcome to Setting </h3></td></tr>
  49.             <tr><td><label>Thanks Message</label></td>
  50.                 <?php $message=$wpdb->get_var("select message from kp_contact_config order by cid desc limit 1");
  51.                 $email=$wpdb->get_var("select email from kp_contact_config order by cid desc limit 1");
  52.                 $ptitle=$wpdb->get_var("select pagetitle from kp_contact_config order by cid desc limit 1"); ?>
  53.                 <td><input type="text" name="message" class="form-control" required="" value="<?php echo $message; ?>"/></td></tr>
  54.              <tr><td><label>Receiver Email</label></td>
  55.                 <td><input type="email" name="email" class="form-control" required="" value="<?php echo $email; ?>"/></td></tr>
  56.              <tr><td><label>Page Title</label></td>
  57.                 <td><input type="text" name="ptitle" class="form-control" required="" value="<?php echo $ptitle; ?>"/></td></tr>
  58.              <input type="hidden"
  59.             <tr> <td><?php submit_button(); ?></td></tr>
  60.         </table>
  61.     </form>
  62. <?php }
  63.  
  64. function dropTable()
  65. {
  66.     global $wpdb;
  67.     if( get_option('the_page_id_i_created') )
  68.     {
  69.       wp_delete_post(get_option('the_page_id_i_created'),$force_delete=TRUE);
  70.     }
  71.     $pageid=  get_option('the_page_id_i_created');
  72.     $wpdb->query("drop table kp_contact");
  73.     $wpdb->query("drop table kp_contact_config");
  74.     $wpdb->delete("wp_posts",array('post_name'=>$pageid+1,'post_type'=>'nav_menu_item'),array('%d','%s'));
  75. }
  76.  
  77. function createPage()
  78. {
  79.     global $user_ID;
  80.     global $page_id;
  81.     $page['post_type']    = 'page';
  82.     $page['post_content'] = 'Template did not attached. Please try to install/Uninstall it.';    
  83.     $page['post_status']  = 'publish';
  84.     $page['post_title']   = 'Contact Us';
  85.  
  86.     $page_id = wp_insert_post ($page);
  87.     update_option('the_page_id_i_created', $page_id );
  88. }
  89.  
  90. function add_template( $template )
  91. {
  92.     if( is_page( 'contact-us' ) )
  93.         $template = dirname( __FILE__ ) . '/kp_contact_form.php';
  94.     return $template;
  95. }
  96. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top