Easily hook into WordPress' actions.
Instead of creating a function then calling that function inside of WordPress' add_action
function, simply access it through the service container and use a callback.
Let's say we've created a service provider specifically for theme functions. We'll send an email on save_post
.
<?php namespace App\Providers;
use Illuminate\Mail\Message;
use Illuminate\Support\ServiceProvider;
class ThemeFunctionsServiceProvider extends ServiceProvider
{
public function register()
{
$this->app['actions']->listen('save_post', function($id, $post) {
app('mailer')->send('emails.saved_post', $post, function(Message $message) {
$message->from('[email protected]');
$message->to('[email protected]');
$message->subject('Post was saved');
});
});
}
}
Of course you can also hook into WordPress actions using the app helper function.
app('actions')->listen('save_post', function() {
//Code goes here
});