Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Callback prefix in a class method #33

Open
soderlind opened this issue Feb 13, 2022 · 1 comment
Open

Bug: Callback prefix in a class method #33

soderlind opened this issue Feb 13, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@soderlind
Copy link

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' ] );
	}
@johnbillion
Copy link
Collaborator

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

@johnbillion johnbillion added the bug Something isn't working label Feb 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants