2015-09-16 37 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 (

測試它是否有效

相關問題