Created
December 2, 2016 19:36
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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