admin管理员组文章数量:1314504
Class cannot be found, but the declaration is correct. Here is my code:
Info-Wheel.php
if ( file_exists( dirname( __FILE__ ) . "/vendor/autoload.php" ) ) {
require_once dirname( __FILE__ ) . "/vendor/autoload.php";
}
use Blocks\Base\Activation;
use Blocks\Base\Deactivation;
/**
* The code that runs during plugin activation
*/
function iw_activate_plugin() {
>> Activation::activate();
}
/**
* The code that runs during plugin deactivation
*/
function iw_deactivate_plugin() {
Deactivation::deactivate();
}
/**
* Register Hooks for deactivation and activation
*/
register_activation_hook( __FILE__, "iw_activate_plugin" );
register_deactivation_hook( __FILE__, "iw_deactivate_plugin" );
/**
* If class exists run it
*/
if ( class_exists( "Inc\\Init" ) ) {
Blocks\Init::register_services();
}
Activation.php
/**
* Remove rewrite rules and then recreate rewrite rules.
*/
class Activation {
public static function activate() {
flush_rewrite_rules( );
}
}
I use composer, so I can use namespaces. Here is an image of my folder structure:
In my opinion, the class Activation should be found and executed, but somehow WordPress can't find it? I have checked the names and copy-pasted them, just to be sure they're the same. I marked line 56 with a double arrow.
Here is the full error message:
Fatal error: Uncaught Error: Class 'Blocks\Base\Activation' not found in D:\Programme\MAMP\htdocs\wordpress\wp-content\plugins\Info-Wheel\Info-Wheel.php:56
Stack trace:
#0 D:\Programme\MAMP\htdocs\wordpress\wp-includes\class-wp-hook.php(287): iw_activate_plugin('')
#1 D:\Programme\MAMP\htdocs\wordpress\wp-includes\class-wp-hook.php(311): WP_Hook->apply_filters('', Array)
#2 D:\Programme\MAMP\htdocs\wordpress\wp-includes\plugin.php(478): WP_Hook->do_action(Array)
#3 D:\Programme\MAMP\htdocs\wordpress\wp-admin\plugins.php(193): do_action('activate_Info-W...')
#4 {main} thrown in D:\Programme\MAMP\htdocs\wordpress\wp-content\plugins\Info-Wheel\Info-Wheel.php on line 56
Edit: Here is a line from the autoloader:
"autoload": {
"psr-4": {"Blocks\\": "./Blocks"}
}
Class cannot be found, but the declaration is correct. Here is my code:
Info-Wheel.php
if ( file_exists( dirname( __FILE__ ) . "/vendor/autoload.php" ) ) {
require_once dirname( __FILE__ ) . "/vendor/autoload.php";
}
use Blocks\Base\Activation;
use Blocks\Base\Deactivation;
/**
* The code that runs during plugin activation
*/
function iw_activate_plugin() {
>> Activation::activate();
}
/**
* The code that runs during plugin deactivation
*/
function iw_deactivate_plugin() {
Deactivation::deactivate();
}
/**
* Register Hooks for deactivation and activation
*/
register_activation_hook( __FILE__, "iw_activate_plugin" );
register_deactivation_hook( __FILE__, "iw_deactivate_plugin" );
/**
* If class exists run it
*/
if ( class_exists( "Inc\\Init" ) ) {
Blocks\Init::register_services();
}
Activation.php
/**
* Remove rewrite rules and then recreate rewrite rules.
*/
class Activation {
public static function activate() {
flush_rewrite_rules( );
}
}
I use composer, so I can use namespaces. Here is an image of my folder structure:
In my opinion, the class Activation should be found and executed, but somehow WordPress can't find it? I have checked the names and copy-pasted them, just to be sure they're the same. I marked line 56 with a double arrow.
Here is the full error message:
Fatal error: Uncaught Error: Class 'Blocks\Base\Activation' not found in D:\Programme\MAMP\htdocs\wordpress\wp-content\plugins\Info-Wheel\Info-Wheel.php:56
Stack trace:
#0 D:\Programme\MAMP\htdocs\wordpress\wp-includes\class-wp-hook.php(287): iw_activate_plugin('')
#1 D:\Programme\MAMP\htdocs\wordpress\wp-includes\class-wp-hook.php(311): WP_Hook->apply_filters('', Array)
#2 D:\Programme\MAMP\htdocs\wordpress\wp-includes\plugin.php(478): WP_Hook->do_action(Array)
#3 D:\Programme\MAMP\htdocs\wordpress\wp-admin\plugins.php(193): do_action('activate_Info-W...')
#4 {main} thrown in D:\Programme\MAMP\htdocs\wordpress\wp-content\plugins\Info-Wheel\Info-Wheel.php on line 56
Edit: Here is a line from the autoloader:
"autoload": {
"psr-4": {"Blocks\\": "./Blocks"}
}
Share
Improve this question
edited Nov 24, 2020 at 12:09
Mähnenwolf
asked Nov 24, 2020 at 11:47
MähnenwolfMähnenwolf
1479 bronze badges
1 Answer
Reset to default 2It was a caching problem with composer.
I retroactively changed my composer.json
, so I had to open my terminal and run composer dumpautoload
to correct the cache.
本文标签:
版权声明:本文标题:plugin development - Class cannot be found, but it's available in the file, I get: Fatal Error: Uncaught Error: Class &a 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741968050a2407665.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论