Created
October 7, 2015 20:47
-
-
Save wlcdesigns/dd318101d17295b977e2 to your computer and use it in GitHub Desktop.
WordPress Parse Push Notification
This file contains 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 | |
/* | |
* IMPORTANT: YOU MUST DOWNLOAD THE ParsePlatform PHP SDK IN ORDER FOR THIS TO WORK: | |
* https://github.com/ParsePlatform/parse-php-sdk | |
*/ | |
require('parse-php-sdk-master/autoload.php'); | |
use Parse\ParseObject; | |
use Parse\ParseQuery; | |
use Parse\ParseACL; | |
use Parse\ParsePush; | |
use Parse\ParseUser; | |
use Parse\ParseInstallation; | |
use Parse\ParseException; | |
use Parse\ParseAnalytics; | |
use Parse\ParseFile; | |
use Parse\ParseCloud; | |
use Parse\ParseClient; | |
class WP_Parse_Push | |
{ | |
public function __construct(){ | |
add_action( 'save_post', array( $this, '_push_parse'), 15 ); | |
} | |
function _push_parse( $post_id ) | |
{ | |
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { | |
return; | |
} | |
if ( ! current_user_can( 'edit_post', $post_id ) ) { | |
return; | |
} | |
$pushed = get_post_meta($post_id,'_parse_push', true); | |
$parse = array( | |
'application_id' => '', //Parse Aplication ID | |
'rest_api_key' => '', //Parse REST API Key | |
'master_key' => '', // Parse Master Key | |
); | |
ParseClient::initialize( | |
esc_attr($parse['application_id']), | |
esc_attr($parse['rest_api_key']), | |
esc_attr($parse['master_key']) | |
); | |
//Only Push One Time | |
if( $_POST['post_status'] == 'publish' && empty($pushed) ) | |
{ | |
$data = array( | |
"alert" => sanitize_text_field($_POST['post_title']), | |
//"badge" => "Increment", | |
); | |
ParsePush::send(array( | |
"channels" => [News], | |
"data" => $data | |
)); | |
update_post_meta($post_id,'_parse_push', 1); | |
} | |
} | |
} | |
if( is_admin() ){ | |
$push = new WP_Parse_Push; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment