这个自定义WordPress插件PHP代码的问题是什么?[关闭]

8wigbo56  于 9个月前  发布在  WordPress
关注(0)|答案(1)|浏览(101)

**已关闭。**此问题需要debugging details。目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将帮助其他人回答问题。
13天前关闭
社区在12天前审查了是否重新打开这个问题,并将其关闭:
原始关闭原因未解决
Improve this question
因此,我试图为woocommerce定制一个支付网关插件。这段代码似乎没问题,但当我上传到我的网站时,我的网站显示“本网站出现严重错误。请检查您的网站管理员电子邮件收件箱以获取说明。”

<?php
/**
 * Plugin Name: Custom Bkash Payment for WC
 * Plugin URI: 
 * Description: This plugin helps you to add Bkash store payment link to checkout page.
 * Version: 1.0.0
 * Author: Classified
 * Author URI: https://example.com
 * License: GPL-2.0 or later
 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: custom-bkash-payment
 */

// Your plugin code goes here.
if ( ! in_array( 'woocommerce/woocommerce.php', apply_filters('active_plugins', get_option( 'active_plugins' )))) return;

add_action( 'plugins_loaded', 'custom_bkash-payment_init', 11);

function custom_bkash_payment_init() {
    if ( class_exists('WC_Payment_Gateway')) {
        class WC_Custom_Bkash_Pay_Gateway extends WC_Payment_Gateway {
            public function __construct() {
                $this->id = 'custom_payment';
                $this->icon = apply_filters( 'woocommerce_custom_bkash_payment_icon', plugins_url( '/assets/icon.png' , __FILE__ ));
                $this->has_fields = false;
                $this->method_title = __( 'bKash Payment', 'custom-bkash-payment');
                $this->method_description = __( 'bKash Payment System.', 'custom-bkash-payment');

                $this->init_form_fields();
                $this->init_settings();
            }

            public function init_form_fields() {
                $this->form_fields = apply_filters( 'woo_custom_bkash_pay_fields', array(
                    'enabled' => array( 
                        'title' => __( 'Enable/Disable', 'custom-bkash-payment'),
                    ),
                ));
            }
        }
    }
}

字符串
我试着问过ChatGPT,但ChatGPT回答说代码没有问题。

b1zrtrql

b1zrtrql1#

你似乎错误地使用了你的函数:

add_action( 'plugins_loaded', 'custom_bkash-payment_init', 11);

字符串
你可能想传递custom_bkash_payment_init而不是custom_bkash-payment_init作为第二个参数(在bkashpayment之间应该有一个下划线_,而不是一个破折号-):

add_action( 'plugins_loaded', 'custom_bkash_payment_init', 11 );

相关问题