The callback [ 'Book', 'vt_register_book_post_type' ]
is adding a hook to the static method vt_register_book_post_type
in the Book
class of the global namespace.
If you want to add a callback to a static class of the Book namespace, you need to use [ '\Book\Book\', 'vt_register_book_post_type' ]
as a callback, but that will also cause a warning or error because your method is not static. You can declare your method static
, but what I think you want to do is something like this:
namespace Book;
class book {
public function vt_create_book_post_type() {
$labels = [
'name' => _x( 'Books', 'vt-plugin' ),
'singular_name' => _x( 'Book', 'vt-plugin' ),
'menu_name' => _x( 'Books', 'vt-plugin' ),
];
register_post_type( 'book', $args );
}
}
$book = new book();
\add_action( 'init', [ $book, 'vt_create_book_post_type' ] );
There’s nothing wrong with your autoloader. Or at least that’s not what’s causing the error.