Nachdem ich viele Fragen und Antworten gelesen hatte und viele die gleiche Frage gestellt hatten, befolgte ich die gleichen Anweisungen wie die Angewiesenen, aber mein Schlechtes, es funktioniert nicht, was ich benutzt habe
Es funktioniert nicht
beispielcode
<?php
/*
Plugin Name: ContactUs
Plugin URI:
Description: Simple Plugin Developed for Testing purpose
Version: 1.0.0
Author: rajeshw
Author URI: codelisense.com
*/
//Creating table
function contact_installation(){
global $wpdb;
$table_name = $wpdb->prefix. "contactus";
if($wpdb->get_var ('SHOW TABLES LIKE' .$table_name ) != $table_name){
$sql= "CREATE TABLE" .$table_name. "(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
require_once (ABSPATH. 'wp-admin/includes/upgrade.php' );
$wpdb->query($sql);
//had replaced the above line with this line
dbDelta($sql);
}
}
register_activation_hook(__FILE__, 'contact_installation');
Tabelle wurde nicht erstellt ... Bitte helfen Sie
Ihre Punkt- und Zitatenotation ist flippig. Versuche dies:
if($wpdb->get_var("SHOW TABLES LIKE '$table_name'" ) != $table_name){
$sql= "CREATE TABLE $table_name (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
);";
require_once (ABSPATH. 'wp-admin/includes/upgrade.php' );
dbDelta($sql);
}
Versuchen Sie diesen Code.
Erstelle eine Datei wie "my_db.php" und füge diesen Code ein:
global $table_version;
$table_version = "1.0";
function func_table_contactus(){
creat_table_contactus();
}
function creat_table_contactus(){
global $wpdb;
global $table_version;
$table_contactus = $wpdb->prefix."contactus";
$slider_ver = get_option("table_version");
$check_table_contactus = $wpdb->get_var("SHOW TABLES LIKE '$table_contactus'");
if($check_table_contactus != $table_contactus || $slider_ver != $table_version ) {
$sql= "CREATE TABLE" .$table_name. "(
id INT(6) UNSIGNED NOT NULL AUTO_INCREMENT,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
PRIMARY KEY (id)
)";
require_once(ABSPATH.'wp-admin/includes/upgrade.php');
dbDelta($sql);
update_option("table_version", $table_version);
}
else{
add_option("table_version", $table_version);
}
}
und in deiner Plugin-Hauptdatei
<?php
/*
Plugin Name: ContactUs
Plugin URI:
Description: Simple Plugin Developed for Testing purpose
Version: 1.0.0
Author: rajeshw
Author URI: codelisense.com
*/
require "my_db.php";
add_action('plugins_loaded', 'func_table_contactus');
Hoffe du findest deine Lösung