سلام و عرض ادب این کدها رو به این شکل زدم اما بعد از غیر فعال کردن پلاگین جدول و کانفیگ ها در دیتابیس پاک نمیشن ممنون میشم بفرمایید مشکل کجاست؟
<?php
/*
Plugin Name: wordpress config table
Plugin URI: https://narmafzar5.com/
Description: wordpress plugin to manage config and table
Version: 1.0.0
Author: erfan
Author URI: https://erfantayebi.ir
License: GPLv2 or later
Text Domain: wordpress-config-table
Domain Path: /languages/
*/
function pi_install_defult_configs()
{
$current_configs = get_option('pi_configs');
if (!$current_configs){
$defult_configs = [
'amount' => 500000,
'role' => 'administrator'
];
update_option('pi_configs' , $defult_configs);
}
}
function pi_install_db()
{
global $wpdb ;
$customer_table_name = $wpdb -> prefix . 'customers' ;
$collate = $wpdb -> get_charset_collate();
$customer_table_sql = "
CREATE TABLE IF NOT EXISTS `{$customer_table_name}` (
`ID` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`wallet` int(11) NOT NULL,
`total_orders` int(11) NOT NULL
) {$collate};
";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($customer_table_sql);
}
function pi_uninstall()
{
global $wpdb ;
$customer_table_name = $wpdb -> prefix . 'customers' ;
$wpdb->query("DROP TABLE IF EXISTS {$customer_table_name}");
delete_option('pi_configs');
}
function pi_activate()
{
pi_install_defult_configs();
pi_install_db();
register_uninstall_hook(__FILE__ , 'pi_uninstall');
}
register_activation_hook(__FILE__ , 'pi_activate');
سلام خدمت شما. پیشنهاد می کنم برای حذف کردن جدول ها از تابع dbDelta استفاده کنید. نمونه کد رو در زیر می تونید ببینید.
private function index_test_001() {
global $wpdb;
$table_name = $wpdb->prefix . 'dbdelta_test_001';
$wpdb_collate = $wpdb->collate;
$sql =
"CREATE TABLE {$table_name} (
id mediumint(8) unsigned NOT NULL auto_increment ,
first varchar(255) NULL,
PRIMARY KEY (id),
KEY first (first)
)
COLLATE {$wpdb_collate}";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta( $sql );
}
سلام مجدد از این تابع هم استفاده کردم و کدهای زیر رو زدم اما متاستفانه مشکل حل نشد ممنون میشم راهنمای بفرمایید
کدها :
<?php
/*
Plugin Name: wordpress config table
Plugin URI: https://narmafzar5.com/
Description: wordpress plugin to manage config and table
Version: 1.0.0
Author: erfan
Author URI: https://erfantayebi.ir
License: GPLv2 or later
Text Domain: wordpress-config-table
Domain Path: /languages/
*/
function pi_install_defult_configs()
{
$current_configs = get_option('pi_configs');
if (!$current_configs){
$defult_configs = [
'amount' => 500000,
'role' => 'administrator'
];
update_option('pi_configs' , $defult_configs);
}
}
function pi_install_db()
{
global $wpdb ;
$customer_table_name = $wpdb -> prefix . 'customers' ;
$collate = $wpdb -> get_charset_collate();
$customer_table_sql = "
CREATE TABLE IF NOT EXISTS `{$customer_table_name}` (
`ID` int(11) NOT NULL,
`user_id` int(11) NOT NULL,
`wallet` int(11) NOT NULL,
`total_orders` int(11) NOT NULL
) {$collate};
";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($customer_table_sql);
}
function pi_uninstall()
{
global $wpdb ;
$customer_table_name = $wpdb -> prefix . 'customers' ;
//$wpdb->query("DROP TABLE IF EXISTS {$customer_table_name}");
$customer_delete_table_sql = "DROP TABLE IF EXISTS `{$customer_table_name}`" ;
delete_option('pi_configs');
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($customer_delete_table_sql);
}
function pi_activate()
{
pi_install_defult_configs();
pi_install_db();
register_uninstall_hook(__FILE__ , 'pi_uninstall');
}
register_activation_hook(__FILE__ , 'pi_activate');
در زمان فعال سازی خطایی نشون داده نمیشه؟ کدهای ایجاد جدول رو در phpmyadmin بررسی یا تست کردین که خطایی نداشته باشه؟