getherbert / herbert

The WordPress Plugin Framework:
http://getherbert.com/
634 stars 95 forks source link

How to add actions and filters on front end #189

Open tedsecretsource opened 6 years ago

tedsecretsource commented 6 years ago

What is the recommended way to add actions and filters on the front end? Is there a "default" route that executes on every request or a way to say "every route except wp-admin"? I'd hate to think that we have to add lines to plugin.php. That seems like a hack, but I can't figure out where else to do that. Thanks in advance.

tedmasterweb commented 6 years ago

I found my own answer.

In herbert.config.php, under the requires section, include a file inside your app called actionsAndFilters.php. Then add your actions and filters there and voila, you are now loading actions and filters when your plugin runs. Very nice.

    /**
     * Auto-load all required files.
     */
    'requires' => [
        __DIR__ . '/app/customPostTypes.php',
        __DIR__ . '/app/actionsAndFilters.php'
    ],