#php #wordpress #plugins #controller #dirname
#php #wordpress #Плагины #контроллер #dirname
Вопрос:
Я создал пользовательский плагин WordPress в local. Я хотел загрузить его на веб-сайт, но теперь, когда я пытаюсь активировать, я получаю сообщение об ошибке.
Это ошибка:
Warning: dirname() expects exactly 1 parameter, 2 given in /home/x/x/x/x/x/wp-content/plugins/X-plugin/inc/Base/BaseController.php on line 18
Warning: dirname() expects exactly 1 parameter, 2 given in /home/x/x/x/x/x/wp-content/plugins/X-plugin/inc/Base/BaseController.php on line 19
Warning: dirname() expects exactly 1 parameter, 2 given in /home/x/x/x/x/x/wp-content/plugins/X-plugin/inc/Base/BaseController.php on line 20
Warning: dirname() expects exactly 1 parameter, 2 given in /home/x/x/x/x/x/wp-content/plugins/X-plugin/inc/Base/BaseController.php on line 18
Warning: dirname() expects exactly 1 parameter, 2 given in /home/x/x/x/x/x/wp-content/plugins/X-plugin/inc/Base/BaseController.php on line 19
Warning: dirname() expects exactly 1 parameter, 2 given in /home/x/x/x/x/x/wp-content/plugins/X-plugin/inc/Base/BaseController.php on line 20
Мой код:
<?php
/**
* @package XPlugin
*/
namespace IncBase;
class BaseController
{
public $plugin_path;
public $plugin_url;
public $plugin;
public function __construct() {
$this->plugin_path = plugin_dir_path( dirname( __FILE__, 2 ) );
$this->plugin_url = plugin_dir_url( dirname( __FILE__, 2 ) );
$this->plugin = plugin_basename( dirname( __FILE__, 3 ) ) . '/X-plugin.php';
}
}
Как я могу активировать свой плагин, что именно мне нужно изменить?
Ответ №1:
dirname принимает только один параметр, вы передаете два. т.е. должно быть dirname(__FILE__)