admin管理员组文章数量:1316838
When running sudo wp install plugin pluginname --allowroot
It causes an error:
PHP Fatal error: Uncaught Error: Using $this when not in object context in /var/www/html/wp-content/plugins/pluginname/blocks.php:89
We have a custom plugin that has this line:
class Block{
public static function Run() {
add_action('enqueue_block_editor_assets',array($this,'RegisterBlock')); //complains on this line
When installing via WP admin - it works fine. But when using WP-CLI it fails.
Any help will be appreciated
When running sudo wp install plugin pluginname --allowroot
It causes an error:
PHP Fatal error: Uncaught Error: Using $this when not in object context in /var/www/html/wp-content/plugins/pluginname/blocks.php:89
We have a custom plugin that has this line:
class Block{
public static function Run() {
add_action('enqueue_block_editor_assets',array($this,'RegisterBlock')); //complains on this line
When installing via WP admin - it works fine. But when using WP-CLI it fails.
Any help will be appreciated
Share Improve this question asked Nov 6, 2020 at 18:29 Michael SorianoMichael Soriano 1031 bronze badge1 Answer
Reset to default 2public static function Run() {
The "static" here means this function doesn't have an object context i.e. it's intended to be called as Block::Run()
without actually making a Block. That said, $block = new Block(); $block->Run();
will still work, but it still doesn't have $this set inside the method.
Instead you can use the class name instead of $this to make a callable for a static method:
class Block{
public static function Run() {
add_action('enqueue_block_editor_assets', array('Block', 'RegisterBlock') );
But I've no idea how the original code is working in wp-admin. Is it code definitely being called?
本文标签: wp cliWPCLI plugin install causes PHP fatal errorUsing this when not in object context
版权声明:本文标题:wp cli - WP-CLI plugin install causes PHP fatal error - Using $this when not in object context 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742010818a2412851.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论