· 8 years ago · Mar 12, 2018, 06:34 PM
1<?php
2 /*
3 Plugin Name: demo
4 Plugin URI: http://www.orangecreative.net
5 Description: Plugin for displaying products from an OSCommerce shopping cart database
6 Author: C. Lupu
7 Version: 1.0
8 Author URI: http://www.orangecreative.net
9 */
10 // register_activation_hook( __FILE__,'Contact_form','creat_tabl','display');
11 register_activation_hook( __FILE__, 'myplugin_activate' );
12
13function myplugin_activate()
14{ global $wpdb;
15$table_name = $wpdb->prefix . 'contact';
16$charset_collate = $wpdb->get_charset_collate();
17$sql = "CREATE TABLE $table_name (
18 id mediumint(9) NOT NULL AUTO_INCREMENT,
19 datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
20 name tinytext NOT NULL,
21 text text NOT NULL,
22 url varchar(55) DEFAULT '' NOT NULL,
23 PRIMARY KEY (id)
24 ) $charset_collate;";
25
26 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
27 dbDelta( $sql );
28 }
29 register_deactivation_hook(__FILE__,'deactivate_table');
30 function deactivate_table()
31 {
32 global $wpdb;
33 $table_name = $wpdb->prefix . 'contact';
34 $sql = "DROP TABLE IF EXISTS $table_name;";
35 $wpdb->query($sql);
36 delete_option("my_plugin_db_version");
37 }
38 function showform()
39 {
40 ?>
41 <form id="frmcontact" method="post">
42 <table>
43 <tr>
44 <th>name</th><td><input type="text" name="txtname"></td>
45 </tr>
46 <tr>
47 <td><input type="submit" name="submit" value="submit"></td>
48 </tr>
49 </table>
50 </form>
51 <?php
52 }
53 add_shortcode('showform','showform');
54?>