2015-09-16 33 views
0

我试图开发一个插件。插件已经开发,但开发的人留给我们没有支持已经给予。当我尝试激活时出现以下错误没有被激活。

致命错误:使用$这个时候不是在C对象方面:\ XAMPP \ htdocs中.. \可湿性粉剂内容\上线插件\ SJR产品进口\的functions.php 238

线编号和相关函数如下所示。 我不知道可能是什么问题。

/** 
* Installation. Runs on activation. 
* @since 1.0.0 
* @return void 
*/ 
function install(){ 

global $wpdb; 

$charset_collate = $wpdb->get_charset_collate(); 

$sql = "CREATE TABLE {$this->db_table} (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 
      `row_id` varchar(22) DEFAULT NULL, 
      `title` varchar(255) DEFAULT '', 
      `description` text, 
      `google_product_category` text, 
      `product_type` text, 
      `link` text, 
      `image_link` text, 
      `additional_image_link` text, 
      `condition` text, 
      `availability` text, 
      `price` text, 
      `sale_price` text, 
      `sale_price_effective_date` text, 
      `brand` text, 
      `gtin` text, 
      `mpn` varchar(22) DEFAULT NULL, 
      `item_group_id` int(22) DEFAULT NULL, 
      `color` text, 
      `material` text, 
      `pattern` text, 
      `size` text, 
      `gender` text, 
      `age_group` text, 
      `adwords_labels` text, 
      `custom_label_0` text, 
      `custom_label_1` text, 
      `custom_label_2` text, 
      `custom_label_3` text, 
      `custom_label_4` text, 
      `feed_file` varchar(255) DEFAULT NULL, 
      `modified` datetime DEFAULT NULL, 
      PRIMARY KEY (`id`), 
      UNIQUE KEY `row_id` (`row_id`), 
      KEY `title` (`title`), 
      KEY `item_group_id` (`item_group_id`) 
     ) $charset_collate;"; 

require_once ABSPATH . 'wp-admin/includes/upgrade.php'; 

dbDelta($sql); 
} // End install() 

请help.thanks。

回答

0

您在线路上有一个错误:

$sql = "CREATE TABLE {$this->db_table} (

这里,$this是不确定的。

把它作为一个全局变量。

对于这一点,改变global $wpdb;global $wpdb, $this;

OR,从那里你应该得到的db_table值检查,替代$this->db_table更换合适的变量/对象。

0
if (!is_object($wpdb)) { 
    require_once ABSPATH . 'wp-admin/includes/FILE NAME CLASS OF YOUR FUNCTION get_charset_collate.php'; 
    $wpdb = new 'CLASS_NAME OF YOUR FUNCTION get_charset_collate'; 
} 

,并试图取代{$这个 - > db_table} {用$ wpdb-> db_table} 注:这是检查对象变量只是想法。

+0

对不起,我没有得到这个 – Melvin

0

你应该有下面的代码像在functions.php中使用$this

class SomeClass { 
    var $db_table = 'my_table'; 
    ... 
    function install() { 
     global $wpdb; 

     $charset_collate = $wpdb->get_charset_collate(); 

     $sql = "CREATE TABLE {$this->db_table} (

但你可能没有类似的代码从var $db_table

得到$this->db_table因此,与

替换线238
$sql = "CREATE TABLE my_table (

测试它是否有效

相关问题