Skip to content

Bug: Callback prefix in a class method #33

@soderlind

Description

@soderlind

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' ] );
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions