vscode-wordpress-hooks icon indicating copy to clipboard operation
vscode-wordpress-hooks copied to clipboard

Bug: Callback prefix in a class method

Open soderlind opened this issue 3 years ago • 1 comments

When I add a hook to a class method;

  1. If I have a namspace, __NAMESPACE__ is prefixed the callback name:
<?php
declare( strict_types = 1 );
namespace Soderlind\Test;

class Test {
	public function __construct() {
		add_filter('the_content',__NAMESPACE__ . '\\filter_the_content' );
		add_action('init',__NAMESPACE__ . '\\action_init' );
	}
.
.
.
}
  1. If I don't have a namespace:
	public function __construct() {
		add_filter('the_content','filter_the_content' );
		add_action('init','action_init' );
	}

In both cases, the correct is

	public function __construct() {
		add_filter('the_content', [ $this, 'filter_the_content' ] ); 
		add_action('init', [ $this,'action_init' ] );
	}

soderlind avatar Feb 13 '22 10:02 soderlind

Thanks, the callback generation in general is quite buggy. I need to revisit it.

johnbillion avatar Feb 13 '22 16:02 johnbillion