michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
337 stars 71 forks source link

How to use Namespace Classes in hooks with {instantiated class name} #249

Closed webstractions closed 8 years ago

webstractions commented 8 years ago

I am trying to wrap my head around using Namespaced classes in callback hook functions that use {instantiated class name} as part of the function name.

Namespaced classes use '/' and not underscores. I am having a problem figuring out how to add actions and filters.

michaeluno commented 8 years ago

Hi,

I've uploaded an example here. You can simply download and install it as a plugin.

Hope it helps.

webstractions commented 8 years ago

Thanks Michael. Helped immensely. I was trying to use the class name as part of the method name within the class to avoid having to add the action or filter. Guess that is not possible, but no worries. Thought I was missing something in my train of thought. Thanks again.

michaeluno commented 8 years ago

I see. For the dynamically generated functions for hooks, you need to replace \ with _. If your class name is like Foo\Bar\MyClass then the function name used in the class should be Foo_Bar_MyClass.