找不到插件类

时间:2019-07-14 23:36:09

标签: wordpress composer-php

一切正常,我可以在本地Wamp服务器中激活我的插件,但是当我尝试在网站上上传并激活我的插件时,出现致命错误,提示找不到类。

我试图在我的网站上使用ssh运行composer init和composer install

这是我的主要插件PHP文件:

    if( file_exists( dirname(__FILE__) . '/vendor/autoload.php'))
        require_once plugin_dir_path(__FILE__) . '/vendor/autoload.php';


function activate_aa_test()
{
    Inc\Base\Activate::activate();
}
function deactivate_aa_test()
{
    Inc\Base\Deactivate::deactivate();
}

register_activation_hook(__FILE__, 'activate_aa_test');
register_deactivation_hook(__FILE__, 'deactivate_aa_test');

这是composer.json

    "name": "vahid/aa-test",
    "description": "test",
    "type": "project",
    "license": "GPL",
    "authors": [
        {
            "name": "Vahid",
            "email": "test@test.com"
        }
    ],
    "minimum-stability": "dev",
    "require": {},
    "autoload": {
        "psr-4": {"Inc\\": "./inc"}
    }
}

这些是WordPress错误:

Fatal error: Uncaught Error:
Class 'Inc\Base\Activate' not found in /home/vahidsapp/public_html/wp-content/plugins/aa-test/aa-test.php:34 
Stack trace: #0 /home/vahidsapp/public_html/wp-includes/class-wp-hook.php(286): activate_aa_test('') 
#1 /home/vahidsapp/public_html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array) 
#2 /home/vahidsapp/public_html/wp-includes/plugin.php(465): WP_Hook->do_action(Array) 
#3 /home/vahidsapp/public_html/wp-admin/plugins.php(177): do_action('activate_aa-tes...') 
#4 {main} thrown in /home/vahidsapp/public_html/wp-content/plugins/aa-test/aa-test.php on line 34

1 个答案:

答案 0 :(得分:0)

我发现了问题, 我必须将类映射添加到composer.json:

"require": {},
    "config": {
        "optimize-autoloader": true
    },
    "autoload": {
        "psr-4": {"Inc\\": "./inc"},
        "classmap": ["inc/"]
    }