点击自定义插件管理菜单将重定向到实时站点上的“不需要更新”

时间:2021-03-05 作者:Roshan Chapagain

我构建了一个自定义WordPress插件,可以将Woocommerce的购买信息发送到CRM。该插件在localhost上运行良好。但在live网站上,每当我点击管理菜单时,我总是被重定向到;无需更新“;页

enter image description here

这是我的主要插件文件:

/**
 * Plugin Name: Woo Crm
 * Description: Sends customer data to the CRM on purchase.
 */

if (!defined(\'ABSPATH\')) {
    echo \'I am a plugin I cannot do anything when called directly.\';
    exit;
}

// Config
define(\'PLUGIN_NAME\', \'Woo Crm\');
define(\'PLUGIN_SLUG\', \'woo_crm\');
define(\'PLUGIN_URL\', plugin_dir_url(__FILE__));
define(\'PLUGIN_PATH\', plugin_dir_path(__FILE__));

// Imports
require_once(PLUGIN_PATH . \'utils/utils.php\');
require_once(PLUGIN_PATH . \'views/views.php\');
require_once(PLUGIN_PATH . \'services/crm/crm.php\');
require_once(PLUGIN_PATH . \'views/components/settings/settings.php\');

class WooCrm
{
    function __construct()
    {
        // Register Styles
        add_action(\'admin_enqueue_scripts\', array($this, \'register_styles\'));

        // Create Menu Page
        add_action(\'admin_menu\', array($this, \'plugin_setup_menu\'));

        // Add Settings Fields to Menu Page
        add_action(\'admin_init\', array(\'settings\', \'init\'));

        // Woocommerce dynamic hook from Settings API
        $hook = get_when_to_send_data_hook();
        add_action($hook, array($this, \'woo_order_create_client\'));
    }

    function woo_order_create_client($order_id)
    {
        // Create client logic
    }

    function plugin_setup_menu()
    {
        $icon_url = PLUGIN_URL . "public/images/dash-icon.png";
        add_menu_page(__(PLUGIN_NAME, PLUGIN_SLUG), __(PLUGIN_NAME, PLUGIN_SLUG), \'manage_options\', PLUGIN_SLUG, array(\'views\', \'admin\'), $icon_url);
    }

    function register_styles()
    {
        wp_register_style(\'woo_crm_admin\', PLUGIN_URL . \'public/css/admin.css\');
        wp_enqueue_style(\'woo_crm_admin\');
    }

}

new WooCrm();
任何帮助都将不胜感激。

1 个回复
SO网友:Roshan Chapagain

该错误是由于粗心的代码设计造成的。导致使用过多require.

正在更改

function plugin_setup_menu()
{
        $icon_url = PLUGIN_URL . "public/images/dash-icon.png";
        add_menu_page(__(PLUGIN_NAME, PLUGIN_SLUG), __(PLUGIN_NAME, PLUGIN_SLUG), \'manage_options\', PLUGIN_SLUG, array(\'views\', \'admin\'), $icon_url);
}

function plugin_setup_menu()
{
        $icon_url = PLUGIN_URL . "public/images/dash-icon.png";
        add_menu_page(PLUGIN_NAME, PLUGIN_NAME, \'manage_options\', PLUGIN_SLUG, array($this,\'admin_menu_view\'), $icon_url);
 }
并添加另一种方法

function admin_menu_view()
{
    include_once PLUGIN_PATH . \'views/admin.php\';
}
为我修复了问题。