2016-07-27 54 views
0

我想製作一個BuddyPress羣擴展插件。我用改編自Group Extension API頁面(一切最初的註釋塊直接複製後)下面的代碼 -WordPress插件崩潰整個網站與500內部服務器錯誤

<?php 
/* 
Plugin Name: Group Emails 
Description: Add group email functionality to BuddyPress 
Version: 0.1.0 
Author: SDGApps 
Author URI: https://sdgapps.com 
*/ 

/** 
* The bp_is_active('groups') check is recommended, to prevent problems 
* during upgrade or when the Groups component is disabled 
*/ 
if (bp_is_active('groups')) : 

class Group_Extension_Example_2 extends BP_Group_Extension { 
    /** 
    * Here you can see more customization of the config options 
    */ 
    function __construct() { 
     $args = array(
      'slug' => 'group-extension-example-2', 
      'name' => 'Group Extension Example 2', 
      'nav_item_position' => 105, 
      'screens' => array(
       'edit' => array(
        'name' => 'GE Example 2', 
        // Changes the text of the Submit button 
        // on the Edit page 
        'submit_text' => 'Submit, suckaz', 
       ), 
       'create' => array(
        'position' => 100, 
       ), 
      ), 
     ); 
     parent::init($args); 
    } 

    function display($group_id = NULL) { 
     $group_id = bp_get_group_id(); 
     echo 'This plugin is 2x cooler!'; 
    } 

    function settings_screen($group_id = NULL) { 
     $setting = groups_get_groupmeta($group_id, 'group_extension_example_2_setting'); 

     ?> 
     Save your plugin setting here: <input type="text" name="group_extension_example_2_setting" value="<?php echo esc_attr($setting) ?>" /> 
     <?php 
    } 

    function settings_screen_save($group_id = NULL) { 
     $setting = isset($_POST['group_extension_example_2_setting']) ? $_POST['group_extension_example_2_setting'] : ''; 
     groups_update_groupmeta($group_id, 'group_extension_example_2_setting', $setting); 
    } 

    /** 
    * create_screen() is an optional method that, when present, will 
    * be used instead of settings_screen() in the context of group 
    * creation. 
    * 
    * Similar overrides exist via the following methods: 
    * * create_screen_save() 
    * * edit_screen() 
    * * edit_screen_save() 
    * * admin_screen() 
    * * admin_screen_save() 
    */ 
    function create_screen($group_id = NULL) { 
     $setting = groups_get_groupmeta($group_id, 'group_extension_example_2_setting'); 

     ?> 
     Welcome to your new group! You are neat. 
     Save your plugin setting here: <input type="text" name="group_extension_example_2_setting" value="<?php echo esc_attr($setting) ?>" /> 
     <?php 
    } 

} 
bp_register_group_extension('Group_Extension_Example_2'); 

endif; 

我是新來的兩個WordPress和PHP(是啊是啊,誰不知道PHP :-)所以你會介意告訴我爲什麼加載這個插件會導致500個內部服務器錯誤導致整個站點失效?

+1

你能檢查錯誤日誌文件嗎? – Milap

+0

仍在努力獲取FTP訪問權限。 – NargothBond

回答

1

由於您在定義之前使用'bp_is_active'函數,因此您的代碼會拋出502錯誤。您需要在腳本之前先加載BuddyPress函數。

有一種方法可以確保BP功能已經加載,請使用bp_include操作。

請參閱此鏈接:https://codex.buddypress.org/plugindev/checking-buddypress-is-active/

不要忘記發展上php.ini中的錯誤報告一個新的插件,或者至少轉彎時啓用WP_DEBUG。

謝謝:)