Programmatic Notifications through WordPress

You can send notifications through code in a custom plugin or child theme on your WordPress site.

Available is the apppush_send_notification() function. This will send a push to all devices.

To use, add to a custom plugin, and modify to use a WordPress hook of your choosing.

function send_custom_push_notification() {       	
apppush_send_notification( 'My message here' );   
add_action( 'init', 'send_custom_push_notification');

Here's an example of sending a notification when a comment is posted:

function send_custom_push_notification( $id, $comment ) {       	
$data = $comment->comment_content;       	
 if( function_exists('apppush_send_notification') ) {          		
  apppush_send_notification( $data );      	
add_action( 'wp_insert_comment', 'send_custom_push_notification', 10, 2 );

Send pushes to specific devices

Note: this only applies to users who have logged into your WordPress site through your app.

It's also possible to send notifications only to devices you choose. This is useful for users sending private messages to each other, for example in BuddyPress, or in a messaging app.

When an app user logs into your site through the app, their device ID will be saved as user meta.


// Change this hook 
add_action( 'save_post', 'push_to_devices' );  
function push_to_devices() {      
	// @TODO be sure to add a nonce and other type of checks here for the save_post hook or you'll get too many messages sent to the same device      
	if( !class_exists( 'AppPresser_Notifications' ) )        
	// this should be an array of user IDs that you want to send the pushes to. AppPresser saves device IDs if the app user is a logged in member of your WordPress site, for example in BuddyPress. This will not work unless the user has logged in through your app.     
	$recipients = array( 1, 24 );      
	$message = 'Hi there!';      
	$push = new AppPresser_Notifications_Update();     
	$devices = $push->get_devices_by_user_id( $recipients );      
	if( $devices ) {        
		$push->notification_send( 'now', $message, 1, $devices );     

You will want to change the hook, and add your own user IDs to the $recipients array.