"register_activation_hook"功能在WordPress中不起作用(应用程序服务器)



Appserv(本地主机(安装在我自己的计算机上。我正在尝试创建一个 mysql 表。但不幸的是,register_activation_hook功能不起作用。

我正在尝试使用下面的create_table函数创建一个表。

<?php
function create_table()
{
global $wpdb;
$charset = $wpdb->get_charset_collate();
$tablo_adi = $wpdb->prefix."bilgiler";
$sql = "CREATE TABLE $tablo_adi(
id mediumint(9) NOT NULL AUTO_INCREMENT,
name VARCHAR(300) NOT NULL,
mail VARCHAR(300) NOT NULL,
phone VARCHAR(300) NOT NULL,
UNIQUE KEY id (id)) $charset;";
require_once(ABSPATH. "wp-admin/includes/upgrade.php"); 
dbDelta($sql);

} register_activation_hook(__FILE__,'create_table'); ?>

包含代码的页面:

<?php 
/*
Plugin name: 2.Ders
plugin URI: https://www.google.com
Description: 2.Derste 
Version: 0.2 (Beta)
Author: Baran Kanat
Author URI: https://www.gogole.com/developer/
*/
add_action("admin_menu","ders_iki");
function ders_iki()
{
add_menu_page("Ders iki - Title","ders-iki-menu","manage_options","ders-iki","eklenti_icerigi","dashicons-wordpress-alt");
}
function eklenti_icerigi() 
{?>
<form method="POST">
<br>
<label>İsim:</label>
<input type="text" name="isim"><br><br>
<label>E-posta</label>
<input type="email" name="eposta"><br><br>
<label>Telefon</label>
<input type="number" name="telefon">
<input type="submit" name="gonder">
</form>


<?php
function create_table()
{
global $wpdb;
$charset = $wpdb->get_charset_collate();
$tablo_adi = $wpdb->prefix."bilgiler";
$sql = "CREATE TABLE $tablo_adi(
id mediumint(9) NOT NULL AUTO_INCREMENT,
isim VARCHAR(300) NOT NULL,
eposta VARCHAR(300) NOT NULL,
telefon VARCHAR(300) NOT NULL,
UNIQUE KEY id (id)) $charset;";
require_once(ABSPATH. "wp-admin/includes/upgrade.php"); 
dbDelta($sql);


} register_activation_hook(__FILE__,'create_table');

if (isset($_POST['gonder'])) 
{
global $wpdb;
$wpdb->insert($wpdb->prefix."bilgiler",
array(
"isim" => $_POST['isim'],
"eposta" => $_POST['eposta'],
"telefon" => $_POST['telefon']
));}

} 


?>

你能帮忙解决这个问题吗?

服务器信息:php 版本 7.2,Appserv(本地主机(

这一切都对我有用。我能够在提交时激活插件并将数据添加到表中。

尝试将其完全粘贴,看看是否有效。

/*
Plugin name: 2.Ders
plugin URI: https://www.google.com
Description: 2.Derste 
Version: 0.2 (Beta)
Author: Baran Kanat
Author URI: https://www.gogole.com/developer/
*/
add_action("admin_menu","ders_iki");
function ders_iki()
{
add_menu_page("Ders iki - Title","ders-iki-menu","manage_options","ders-iki","eklenti_icerigi","dashicons-wordpress-alt");
}
function eklenti_icerigi() 
{?>
<form method="POST">
<br>
<label>İsim:</label>
<input type="text" name="isim"><br><br>
<label>E-posta</label>
<input type="email" name="eposta"><br><br>
<label>Telefon</label>
<input type="number" name="telefon">
<input type="submit" name="gonder">
</form>
<?php
function create_table() {
global $wpdb;
$tablo_adi = 'testing_hook';
$sql = "CREATE TABLE $tablo_adi(
id mediumint(9) NOT NULL AUTO_INCREMENT,
name VARCHAR(300) NOT NULL,
mail VARCHAR(300) NOT NULL,
phone VARCHAR(300) NOT NULL,
UNIQUE KEY id (id)) $charset;";
require_once(ABSPATH. "wp-admin/includes/upgrade.php"); 
dbDelta($sql);
} 

register_activation_hook(__FILE__, 'create_table'); 

if (isset($_POST['gonder'])) 
{
global $wpdb;
$wpdb->insert("testing_hook",
array(
"name" => $_POST['isim'],
"mail" => $_POST['eposta'],
"phone" => $_POST['telefon']
));
}
} 

希望对您有所帮助。

相关内容

最新更新