Skip to content

Instantly share code, notes, and snippets.

@collegeman
Created December 2, 2016 19:36
Show Gist options
  • Save collegeman/0251fc8d3b168f4f0c47cde55fcc367d to your computer and use it in GitHub Desktop.
Save collegeman/0251fc8d3b168f4f0c47cde55fcc367d to your computer and use it in GitHub Desktop.
A more powerful example of what you can do with an Illuminated WordPress Plugin
<?php
namespace YourPlugin;
use YourPlugin\Notifications\PostSaved;
/**
* Your plugin inherits everything that a Laravel container can do.
* Like, sending messages on Slack using Laravel's Notification framework.
*/
class YourPlugin extends \FatPanda\Illuminate\WordPress\Plugin
{
/**
* This function is automatically discovered and hooked
* into WordPress' "save_post" event.
*/
function onSavePost($post_id)
{
if (wp_is_post_revision($post_id)) {
return false;
} else {
$this->notifyPostSaved(get_post($post_id));
}
}
/**
* Send a notification to Slack that this post was saved.
*/
protected function notifyPostSaved($post)
{
$this->notification->send($this->currentuser, new PostSaved($post));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment