我尝试在我的WordPress插件中包含this library。
我已经使用这段代码将composer autoloader包含到类文件中,但是我总是从服务器得到一个500错误,看起来库没有在需要的时候加载
<?php
/*
* Plugin Name: Custom Ticketing
*/
require_once __DIR__ . '/vendor/autoload.php';
class CustomTicketing {
public function check_email( WP_REST_Request $request )
{
if( !wp_verify_nonce( $request->get_header('X-WP-Nonce'), 'wp_rest' ) ){
return false;
} else {
$email = sanitize_email( $request->get_param('email') );
$validator = EmailValidation\EmailValidatorFactory::create($email);
return $validator->getValidationResults->asArray();
}
}
}
从wordpress的错误日志会给予我这个消息,这是非常明确的
[13-Mar-2023 14:54:20 UTC] PHP Warning: Undefined property: EmailValidation\EmailValidator::$getValidationResults in /home/myserver/coolwebsite/wp-content/wp-content/plugins/custom-ticketing/index.php on line 382
[13-Mar-2023 14:54:20 UTC] PHP Fatal error: Uncaught Error: Call to a member function asArray() on null in /home/myserver/coolwebsite/wp-content/plugins/custom-ticketing/index.php:382
当我需要库来解决问题时,我需要在类或方法中使用自动加载器吗?
1条答案
按热度按时间q3qa4bjr1#
看起来您缺少一些
()
。请在“最后”行尝试以下操作:return $validator->getValidationResults()->asArray();