Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Where in my admin class should I place the action hooks for adding css, scripts and the add menu page?

In the __construct? Or should they be placed in a method?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Since you are using OOP, you probably want to architecture your plugin more efficiently. This is fine, but you'll be the one to structure your classes and build them.

So what if you put it in the __construct() function? That's fine, as long as you initiate a new instance of the class. Putting it in a method (private or public) will give the same thing as long as you call that method from inside or outside of your class.

I do use OOP for almost all of the WordPress plugins I create. Usually, I use the construct() function to add hooks for enqueue(ing) CSS, Scripts or other actions and filters. However, this is completely up to you, and you are free to design your classes as you wish.

share|improve this answer
    
Thanks a lot Abid! Actually I set up a simple MVC Pattern for all my plugins that I can use over and over again. I have a main controller which will take care of the frontend. The __construct of my maincontroller checks if there's an admin_init and if so, creates a new admin controller that extends my main controller. –  Jesper Purola Jun 23 '12 at 21:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.