Skip to content

Instantly share code, notes, and snippets.

@stompweb
Created September 17, 2016 14:26
Show Gist options
  • Save stompweb/f75e9d2f9036a6a618c6e4d2a9a5c68d to your computer and use it in GitHub Desktop.
Save stompweb/f75e9d2f9036a6a618c6e4d2a9a5c68d to your computer and use it in GitHub Desktop.
Backdrop Test
<?php
function exp_add_notifications( $post_id, $post ) {
if ( 'auto-save' == $post->post_status || 'auto-draft' == $post->post_status ) {
return;
}
$message = get_the_title( $post_id ) . ' was added.';
$task = new \HM\Backdrop\Task( 'exp_send_notifications', $message );
$task->schedule();
}
add_action( 'publish_topic', 'exp_add_notifications', 10, 2 );
function exp_send_notifications( $message ) {
$users = new WP_User_Query( array( 'role' => 'Subscriber' ) );
if ( ! empty( $users ) ) {
foreach ( $users as $user ) {
exp_add_notification( $user->ID, $message );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment