• Resolved AbbaTheHorse

    (@mattalexander)


    Hi there

    I appreciate this is a really, really basic question, but I’m only brand new to WordPress and so would appreciate your help.

    I’ve followed your example of how to create custom alerts, but how do I get a custom plugin that I’ve written to raise that alert?

    So, in your example you’ve got

    add_action('sample_hook_name', array($this, 'SampleFunction'), 10, 2);

    But how do I get my custom plugin to raise that as an alert?

    I’ve tried:

    do_action( 'sample_hook_name', 1, 2 );

    But it doesn’t work, with the function ‘SampleFunction’ never being called.

    Hopefully this is something simple that I’ve missded.

    Many thanks 🙂

    • This topic was modified 8 years, 7 months ago by AbbaTheHorse.
    • This topic was modified 8 years, 7 months ago by AbbaTheHorse.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @mattalexander,

    Thanks for using our plugin.

    In regards to your query, all you have to do is replace the sample_hook_name with a WordPress hook that you are trying to hook into to make the corresponding function work.

    While I trust the above helps you achieve what you need, please do not hesitate to ask in case of further queries.

    Thread Starter AbbaTheHorse

    (@mattalexander)

    Hi, thanks for getting back to me.

    What you’ve suggested is how I assumed I should handle this, but I’m still having issues.

    If, for instance I set my CustomHooks.php file as follows:

    add_action('admin_footer', array($this, 'SampleFunction'), 10, 2);

    Then I can see the custom alert in the audit log.

    But in my own plugin that I’ve written, I have the following after a form is saved:

    do_action("sec_mod_update", $modificationItem->ref);

    And have changed my CustomHooks.php file to:

    add_action('sec_mod_update', array($this, 'SampleFunction'), 10, 2);

    But when I save the form, nothing is added to the audit log.

    Any help you might be able to give would be very much appreciated.

    Thanks again,

    Matt

    In your reply you mention this code:

    add_action('sec_mod_update', array($this, 'SampleFunction'), 10, 2);

    You are only giving one argument to the do_action function. So this code should be like this

    add_action( 'sec_mod_update', array( $this, 'SampleFunction' ), 10, 1 );

    By the way you can also refer to the plugin WP Security Audit Log addon for Paid Memberships Pro. This plugin was built by a good friend of mine and is using the Custom Alerts. It might be a very good example to check.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Custom Alerts’ is closed to new replies.