【问题标题】:WordPress plugin crashes entire site with 500 Internal Server ErrorWordPress 插件因 500 Internal Server Error 导致整个站点崩溃
【发布时间】:2016-07-27 06:08:09
【问题描述】:

我正在尝试制作 BuddyPress 组扩展插件。我使用了以下改编自Group Extension API页面的代码(直接复制初始评论块之后的所有内容)-

<?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 内部服务器错误导致整个网站瘫痪吗?

【问题讨论】:

  • 你能检查错误日志文件吗?
  • 仍在努力获取 FTP 访问权限。

标签: php wordpress buddypress internal-server-error


【解决方案1】:

您的代码抛出 502 错误,因为您在定义之前使用了“bp_is_active”函数。您需要先加载 BuddyPress 函数,然后再加载脚本。

有一种方法可以确保已经加载了 BP 函数,请使用 bp_include 操作。

查看此链接:https://codex.buddypress.org/plugindev/checking-buddypress-is-active/

开发新插件时不要忘记启用WP_DEBUG,或者至少在php.ini中打开错误报告。

谢谢:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 2015-05-22
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多