按下按钮时,我的插件中有什么导致"White Screen of Death"?



我最近做了我自己的混合搭配大量代码插件来处理我的WooCommerce网站上的表单(使其更适合购买sutff的公司(。它在本地完美运行,但是当我把它放在我的网站上时,当我使用将您定向到其他页面(在网站上(的链接/按钮时,我会出现白屏死机 - 我不知道为什么!有什么想法吗?

我还没有真正尝试过任何东西,因为我对woocommerce,wordpress和PHP的了解是......初学者,最多。

该插件:

/*
 * Plugin Name: Posifon Form Management Plugin
 */
defined('ABSPATH') or die('No script kiddies please!');
/* === GENERAL === */
/* Add new fields */
add_filter( 'woocommerce_checkout_fields' , 'plugin_add_custom_billing_fields' );
function plugin_add_custom_billing_fields($fields) {
    $fields['billing']['billing_org_number'] = array(
        'label'     => __('Organisationsnummer', 'woocommerce'),
        'placeholder'   => __('T.ex. 1234-5678', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-wide'),
        'clear'     => true,
    );
    $fields['billing']['billing_org_reference'] = array(
        'label'     => __('Kostnadsställe/referens', 'woocommerce'),
        'placeholder'   => __('T.ex. Per Olofsson', 'woocommerce'),
        'required'  => true,
        'class'     => array('form-row-wide'),
        'clear'     => true,
    );
    return $fields;
}
/* Save fields to database */
function reigel_woocommerce_checkout_update_user_meta( $customer_id, $posted) {
    if (isset($posted['billing_org_number'])) {
        $dob = sanitize_text_field( $posted['billing_org_number'] );
        update_user_meta( $customer_id, 'billing_org_number', $dob);
    }
    if (isset($posted['billing_org_reference'])) {
        $dob = sanitize_text_field( $posted['billing_org_reference'] );
        update_user_meta( $customer_id, 'billing_org_reference', $dob);
    }
}
add_action( 'woocommerce_update_user_meta', 'reigel_woocommerce_checkout_update_user_meta', 10, 2 );
/* === MY ACCOUNT / EDIT ADRESSES / BILLING === */
/* Override default fields */
add_filter( 'woocommerce_billing_fields', 'plugin_override_account_billing', 20, 1 );
function plugin_override_account_billing( $fields ) {
    // Only on my account 'edit-address'
    if( is_wc_endpoint_url( 'edit-address' ) ){
        // Company
        $fields['billing_company']['required'] = true;
        $fields['billing_company']['label'] = 'Organisation';
        // Organisation Number
        $fields['billing_org_number']['label'] = 'Organisationsnummer';
        $fields['billing_org_number']['required'] = true;
        // Organisation Reference
        $fields['billing_org_reference']['label'] = 'Kostnadsställe/referens';
        $fields['billing_org_reference']['required'] = true;
        // Put City and Postcode on same row
        $fields['billing_postcode']['class'][0] = 'form-row-first';
        $fields['billing_city']['class'][0] = 'form-row-last';
    }
    return $fields;
}
/* Change order of BILLING */
add_filter( 'woocommerce_billing_fields', 'plugin_change_order_account_billing', 20, 1 );
function plugin_change_order_account_billing( $fields ) {
    // Only on my account 'edit-address'
    if( is_wc_endpoint_url( 'edit-address' ) ){
        $fields['billing_company']['priority'] = 10;
        $fields['billing_org_number']['priority'] = 20;
        $fields['billing_org_reference']['priority'] = 30;
        $fields['billing_address_1']['priority'] = 40;
        $fields['billing_address_2']['priority'] = 50;
        $fields['billing_postcode']['priority'] = 60;
        $fields['billing_city']['priority'] = 70;
        $fields['billing_country']['priority'] = 80;
        $fields['billing_first_name']['priority'] = 90;
        $fields['billing_last_name']['priority'] = 100;
        $fields['billing_phone']['priority'] = 110;
        $fields['billing_email']['priority'] = 120;
    }
    return $fields;
}
/* === MY ACCOUNT / EDIT ADRESSES / SHIPPING === */
/* Override default fields */
add_filter( 'woocommerce_shipping_fields', 'plugin_override_account_shipping', 20, 1 );
function plugin_override_account_shipping( $fields ) {
    // Only on my account 'edit-address'
    if( is_wc_endpoint_url( 'edit-address' ) ){
        // Company
        $fields['shipping_company']['required'] = true;
        $fields['shipping_company']['label'] = 'Organisation';
        // Put City and Postcode on same row
        $fields['shipping_postcode']['class'][0] = 'form-row-first';
        $fields['shipping_city']['class'][0] = 'form-row-last';
        unset($fields['shipping_first_name']);
        unset($fields['shipping_last_name']);
    }
    return $fields;
}
/* Change order of BILLING */
add_filter( 'woocommerce_shipping_fields', 'plugin_change_order_account_shipping', 20, 1 );
function plugin_change_order_account_shipping( $fields ) {
    // Only on my account 'edit-address'
    if( is_wc_endpoint_url( 'edit-address' ) ){
        $fields['shipping_company']['priority'] = 10;
        $fields['shipping_address_1']['priority'] = 20;
        $fields['shipping_address_2']['priority'] = 30;
        $fields['shipping_postcode']['priority'] = 40;
        $fields['shipping_city']['priority'] = 50;
        $fields['shipping_country']['priority'] = 70;
    }
    return $fields;
}
/* === CHECKOUT / BILLING === */
/* Override default fields */
add_filter('woocommerce_checkout_fields', 'plugin_override_default_billing_fields');
function plugin_override_default_billing_fields($fields) {
    $fields['billing']['billing_company']['required'] = true;
    $fields['billing']['billing_postcode']['class'][0] = 'form-row-first';
    $fields['billing']['billing_city']['class'][0] = 'form-row-last';
    return $fields;
}
/* Change order of billing CHECKOUT */
add_filter("woocommerce_checkout_fields", "plugin_override_order_checkout_fields");
function plugin_override_order_checkout_fields($fields) {
    $order = array(
        'billing_first_name',
        'billing_last_name',
        'billing_company',
        'billing_email',
        'billing_phone',
        'billing_country',
        'billing_address_1',
        'billing_address_2',
        'billing_city',
        'billing_postcode',
        'billing_org_number',
        'billing_org_reference'
    );
    foreach($order as $field) {
        $ordered_fields[$field] = $fields['billing'][$field];
    };
    $fields['billing'] = $ordered_fields;
    $fields['billing']['billing_company']['priority'] = 10;
    $fields['billing']['billing_org_number']['priority'] = 20;
    $fields['billing']['billing_org_reference']['priority'] = 30;
    $fields['billing']['billing_address_1']['priority'] = 40;
    $fields['billing']['billing_address_2']['priority'] = 50;
    $fields['billing']['billing_postcode']['priority'] = 60;
    $fields['billing']['billing_city']['priority'] = 70;
    $fields['billing']['billing_country']['priority'] = 80;
    $fields['billing']['billing_first_name']['priority'] = 100;
    $fields['billing']['billing_last_name']['priority'] = 110;
    $fields['billing']['billing_email']['priority'] = 130;
    $fields['billing']['billing_phone']['priority'] = 140;

    return $fields;
}
/* === CHECKOUT / SHIPPING === */
/* Override default fields */
add_filter('woocommerce_checkout_fields', 'plugin_override_default_shipping_fields');
function plugin_override_default_shipping_fields($fields) {
    // Company
    $fields['shipping']['shipping_company']['required'] = true;
    $fields['shipping']['shipping_company']['label'] = 'Organisation';
    // Put City and Postcode on same row
    $fields['shipping']['shipping_postcode']['class'][0] = 'form-row-first';
    $fields['shipping']['shipping_city']['class'][0] = 'form-row-last';
    // Remove first- and last name
    unset($fields['shipping']['shipping_first_name']);
    unset($fields['shipping']['shipping_last_name']);
    return $fields;
}
/* Change order of billing CHECKOUT */
add_filter("woocommerce_checkout_fields", "plugin_override_order_checkout_shipping_fields");
function plugin_override_order_checkout_shipping_fields($fields) {
    $order = array(
        'shipping_company',
        'shipping_country',
        'shipping_address_1',
        'shipping_address_2',
        'shipping_city',
        'shipping_postcode',
    );
    foreach($order as $field) {
        $ordered_fields[$field] = $fields['shipping'][$field];
    };
    $fields['shipping'] = $ordered_fields;
    $fields['shipping']['shipping_company']['priority'] = 10;
    $fields['shipping']['shipping_address_1']['priority'] = 40;
    $fields['shipping']['shipping_address_2']['priority'] = 50;
    $fields['shipping']['shipping_postcode']['priority'] = 60;
    $fields['shipping']['shipping_city']['priority'] = 70;
    $fields['shipping']['shipping_country']['priority'] = 80;

    return $fields;
}
/* === MY ACCOUNT === */
/* Override default fields */
add_filter('woocommerce_billing_fields', 'plugin_override_default_account_fields');
function plugin_override_default_account_fields($fields) {
    if( is_user_logged_in() && is_account_page() ) {
        unset($fields['account_first_name']);
        unset($fields['account_last_name']);
    }
    return $fields;
}
/* === DISPLAYING === */
/* Display field value on the order edit page ADMIN */
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'plugin_checkout_field_display_admin_order_meta', 10, 1 );
function plugin_checkout_field_display_admin_order_meta($order) {
    echo '<p><strong>'.__('Organisationsnummer').':</strong> ' . get_post_meta( $order->get_id(), '_billing_org_number', true ) . '</p>';
    echo '<p><strong>'.__('Kostnadsställe/referens').':</strong> ' . get_post_meta( $order->get_id(), '_billing_org_reference', true ) . '</p>';
}

需要更多代码,我将对其进行编辑并将其交给您,我也已更改为我的地址.php(woocommerce文件(。

我想要的结果:没有白屏死机。

编辑:我试图为PHP添加更多内存,但没有工作。

在你的wp_config.php(在你的网站的根目录中(,你可能有这样一行:

define('WP_DEBUG', false);

将其更改为:

define('WP_DEBUG', true);

并再次检查您的白屏死机 - 它应该显示哪个文件以及该文件中的哪一行,错误正在发生:-(

感谢 rblarsens 的回答,我发现了错误:

警告:无法修改标头信息 - 标头已由...

这仅仅是由第一个之前的空格(" "(引起的

相关内容

  • 没有找到相关文章

最新更新