Guest User

Untitled

a guest
Oct 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. // Initialization and Hooks
  2. global $wpdb;
  3. global $wp_version;
  4. global $wpmyfirstplugin_version;
  5. global $wpmyfirstplugin_db_version;
  6. global $wpmyfirstplugin_table_name;
  7. global $wp_version;
  8. $wpmyfirstplugin_version = '1.0.1';
  9. $wpmyfirstplugin_db_version = '0.0.1';
  10. $wpmyfirstplugin_table_name = $wpdb->prefix.'imart_setting';
  11.  
  12. function wpmyfirstplugin_install()
  13. {
  14. global $wpdb;
  15. global $wpmyfirstplugin_table_name;
  16. global $wpmyfirstplugin_db_version;
  17.  
  18. // create table on first install
  19. if($wpdb->get_var("show tables like '$wpmyfirstplugin_table_name'") != $wpmyfirstplugin_table_name) {
  20. wpmyfirstplugin_createTable($wpdb, $wpmyfirstplugin_table_name);
  21.  
  22. //add_option("wpmyfirstplugin_db_version", $wpmyfirstplugin_db_version);
  23. //add_option("wpmyfirstplugin_configuration", '');
  24. }
  25.  
  26. }
  27.  
  28. function wpmyfirstplugin_createTable($wpdb, $table_name)
  29. {
  30. $sql = "CREATE TABLE ".$table_name." (
  31. main_id bigint(20) NOT NULL auto_increment,
  32. main_key varchar(255) default NULL,
  33. main_value longtext,
  34. PRIMARY KEY (`imart_id`)
  35. ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;";
  36.  
  37. $results = $wpdb->query($sql);
  38. }
  39.  
  40.  
  41. register_activation_hook(__FILE__,'wpmyfirstplugin_createTable');
  42.  
  43. wpmyfirstplugin_createTable($wpdb, $wpmyfirstplugin_table_name);
  44.  
  45. $results = $wpdb->query($sql);
  46.  
  47. function test_db_install()
  48. {
  49. global $wpdb;
  50. require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
  51. $sql="
  52. CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."imart_setting`
  53. (
  54. main_id bigint(20) NOT NULL auto_increment,
  55. main_key varchar(255) default NULL,
  56. main_value longtext,
  57. PRIMARY KEY (`main_id`)
  58. );";
  59. dbDelta($sql);
  60.  
  61. $insert_sql ="
  62. INSERT INTO `wp_posts`(`post_author`, `post_date`, `post_date_gmt`, `post_content`, `post_title`, `post_excerpt`, `post_status`, `comment_status`, `ping_status`, `post_password`, `post_name`, `to_ping`, `pinged`, `post_modified`, `post_modified_gmt`, `post_content_filtered`, `post_parent`, `guid`, `menu_order`, `post_type`, `post_mime_type`, `comment_count`) VALUES ('admin','','','[Alumini Dashboard]','Dashbord','','publish','','','','dashbord','','','','','','','','','page','','')";
  63.  
  64. dbDelta($insert_sql);
Add Comment
Please, Sign In to add comment