1

Actions usually support the following (if you are creating your plugin using a class based approach):

add_action('admin_notices', array(&$this, 'emailNoticeGUI'));

The wp_schedule_event does not support this kind of triggering. Is there any way I could do this, but still use a class based approach? What are the alternatives? I would like to schedule a hook upon plugin activation, but the activation logic is also based in the class itself.

3
  • Please check wp_schedule_event this may help you. Commented Jan 30, 2016 at 10:42
  • 1
    I am sorry but if something isn't working for you it does not mean it does not support. Share your code what you done so far then only someone can help you.
    – Sumit
    Commented Jan 30, 2016 at 10:52
  • I solved it by using an action and then used that action in the wp_schedule_event_function.
    – ZeroCool
    Commented Jan 31, 2016 at 12:25

2 Answers 2

0

This reason, and others (removing a hook for example) is why you should use for hooks only plain functions or static functions.

OOP in plugins and themes rarely has anything to do with proper OO. If you use it as a way to have a separate namespace, then just use a namespace.

2
  • I think that today we are way beyond the days where you have a million functions following each other. I use OO because it improves readablity. Sure, functions are good for smaller plugins, but when you have a big one that reaches 5000+ LOC, then I think OO is the way to go.
    – ZeroCool
    Commented Jan 31, 2016 at 12:25
  • @ZeroCool, really? so why is this question that you had to ask which show luck of understanding of OOP principals? OOP is not just declaring classes, and done wrong it at best just makes your code longer. you are welcom to read this chat thread - chat.stackexchange.com/transcript/message/27197907#27197907 Commented Jan 31, 2016 at 14:04
0

The solution that I used was the following:

add_action('my_action', array(&$this, 'classFunctionName'));

When scheduling I used the following:

 wp_schedule_event(time(), 'daily', 'my_action');

So the classFunctionName is triggered on a daily basis and it is called from within the plugin class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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