admin管理员组文章数量:1415136
On plugin activation hook I want to create a table but the following code is giving Uncaught Error
. I just wonder why it is not giving this error since I am properly including update.php
.
global $wpdb;
$sql = 'CREATE TABLE IF NOT EXISTS '.$wpdb->prefix.'gs_orders(';
$sql .= 'id BIGINT(20) AUTO_INCREMENT NOT NULL,';
$sql .= 'order_number VARCHAR(200) NOT NULL,';
$sql .= 'group_id INT NOT NULL,';
$sql .= 'group_admin BIGINT(20) NOT NULL,';
$sql .= 'group_user BIGINT(20) NOT NULL,';
$sql .= 'product_groups VARCHAR(255),';
$sql .= 'products VARCHAR(255),';
$sql .= 'created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,';
$sql .= 'updated_at DATETIME NULL DEFAULT NULL,';
$sql .= 'PRIMARY KEY (id),';
$sql .= 'INDEX (order_number, group_id, group_admin, group_user),';
$sql .= ')' . $wpdb->get_charset_collate() . ';';
require_once ABSPATH . '/wp-admin/includes/update.php';
dbDelta($sql);
Above code is on the plugin activation callback function.
On plugin activation hook I want to create a table but the following code is giving Uncaught Error
. I just wonder why it is not giving this error since I am properly including update.php
.
global $wpdb;
$sql = 'CREATE TABLE IF NOT EXISTS '.$wpdb->prefix.'gs_orders(';
$sql .= 'id BIGINT(20) AUTO_INCREMENT NOT NULL,';
$sql .= 'order_number VARCHAR(200) NOT NULL,';
$sql .= 'group_id INT NOT NULL,';
$sql .= 'group_admin BIGINT(20) NOT NULL,';
$sql .= 'group_user BIGINT(20) NOT NULL,';
$sql .= 'product_groups VARCHAR(255),';
$sql .= 'products VARCHAR(255),';
$sql .= 'created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,';
$sql .= 'updated_at DATETIME NULL DEFAULT NULL,';
$sql .= 'PRIMARY KEY (id),';
$sql .= 'INDEX (order_number, group_id, group_admin, group_user),';
$sql .= ')' . $wpdb->get_charset_collate() . ';';
require_once ABSPATH . '/wp-admin/includes/update.php';
dbDelta($sql);
Above code is on the plugin activation callback function.
Share Improve this question asked Aug 24, 2019 at 8:05 pixelngrainpixelngrain 1,3901 gold badge23 silver badges50 bronze badges1 Answer
Reset to default 0I was including the wrong file. Instead of update.php
I should include upgrade.php
. I know it's a silly mistake but maybe help someone who does the same in future.
本文标签: plugin developmentWordPress Fatal error Uncaught Error Call to undefined function dbDelta()
版权声明:本文标题:plugin development - WordPress Fatal error: Uncaught Error: Call to undefined function dbDelta() 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745219688a2648333.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论