我收到以下错误:
致命错误:Uncaught ArgumentCounter错误:函数\\u themename\\Lib\\Classes\\Enqueue::css()的参数太少,在C:\\xampp\\htdocs\\wordpress\\wp includes\\class wp hook中传递了1。php位于第292行,C:\\xampp\\htdocs\\wordpress\\wp content\\themes\\newtheme\\lib\\classes\\Enqueue中至少应有2个。php:11堆栈跟踪:#0 C:\\xampp\\htdocs\\wordpress\\wp includes\\class wp hook。php(292):\\u主题名称\\Lib\\Classes\\Enqueue->;css(“”)#1 C:\\xampp\\htdocs\\wordpress\\wp包含\\class wp挂钩。php(316):WP\\U挂钩->;apply\\u filters(NULL,Array)#2 C:\\xampp\\htdocs\\wordpress\\wp includes\\plugin。php(484):WP\\U挂钩->;do\\u action(Array)#3 C:\\xampp\\htdocs\\wordpress\\wp includes\\script loader。php(2027):do\\u action(\'wp\\u enqueue\\u scri…\')\\35; 4 C:\\xampp\\htdocs\\wordpress\\wp includes\\class wp hook。php(292):wp\\u enqueue\\u scripts(“”)\\35; 5 C:\\xampp\\htdocs\\wordpress\\wp includes\\class wp hook。php(316):WP\\U挂钩->;apply\\u filters(NULL,Array)#6 C:\\xampp\\htdocs\\wordpress\\wp includes\\plugin。php(484):WP\\U挂钩->;do\\u action(Array)#7 C:\\xampp\\htdocs\\wordpress\\wp includes\\general模板。php(3009):do\\u action(\'wp\\u head\')\\8c:\\xampp\\htdocs\\wordpress\\wp content\\themes\\newtheme\\header。php(8):wp\\u head()#9 C:\\xampp\\htdocs\\wordpress\\wp includes\\template。php(730):require\\u once(\'C:\\xampp\\htdocs…\')\\10 C:\\xampp\\htdocs\\wordpress\\wp includes\\template。php(676):load\\u template(\'C:\\xampp\\htdocs…\',true,Array)#11 C:\\xampp\\htdocs\\wordpress\\wp includes\\general template。php(48):locate\\u template(Array,true,true,Array)#12 C:\\xampp\\htdocs\\wordpress\\wp content\\themes\\newtheme\\index。php(19):get\\u header()#13 C:\\xampp\\htdocs\\wordpress\\wp includes\\template loader。php(106):包括(\'C:\\xampp\\htdocs…\')\\14 C:\\xampp\\htdocs\\wordpress\\wp blog header。php(19):require\\u once(\'C:\\xampp\\htdocs…\')\\15 C:\\xampp\\htdocs\\wordpress\\index。php(17):在C:\\xampp\\htdocs\\wordpress\\wp content\\themes\\newtheme\\lib\\classes\\Enqueue中抛出require(\'C:\\xampp\\htdocs…\')\\16{main}。php第11行此网站出现严重错误。
在mytheme/lib/classes/Enqueue中有一个类文件。php:
namespace _themename\\Lib\\Classes;
class Enqueue {
public function __construct() {
add_action(\'wp_enqueue_scripts\', [$this, \'css\']);
add_action(\'wp_enqueue_scripts\', [$this, \'js\']);
add_action(\'admin_enqueue_scripts\', [$this, \'admin_css\']);
add_action(\'admin_enqueue_scripts\', [$this, \'admin_js\']);
}
public function css($handle, $path, $deps=[], $ver=false, $media=\'all\') {
wp_enqueue_style($handle, get_template_directory_uri() . $path, $deps, $ver, $media);
}
public function js($handle, $path, $deps=[], $ver=false, $media=\'all\') {
wp_enqueue_script($handle, get_template_directory_uri() . $path, $deps, $ver, $media);
}
public function admin_css($handle, $path, $deps=[], $var=false, $media=\'all\') {
wp_enqueue_style($handle, get_template_directory_uri() . $path, $deps, $ver, $media);
}
public function admin_js($handle, $path, $deps=[], $var=false, $media=\'all\') {
wp_enqueue_script($handle, get_template_directory_uri() . $path, $deps, $ver, $media);
}
}
和另一个文件mytheme/Lib/enqueue\\u assets。php:
<?php
namespace _themename\\Lib;
require_once get_template_directory() . \'/lib/classes/Enqueue.php\';
use _themename\\Lib\\Classes\\Enqueue;;
$enqueue = new Enqueue;
$enqueue->css(\'_themename-stylesheet\', \'/dist/assets/css/bundle.css\', [], 1.0, \'all\');
这两个文件都包含在函数中。php by require\\u一次。我试图通过为自己创建一个入门主题来学习面向对象的php。提前谢谢。