コード例 #1
0
<?php

if ($_POST) {
    if (isset($_POST['title']) && !empty($_POST['title']) && isset($_POST['message']) && !empty($_POST['message']) && isset($_POST['wp_chrome_new_notification']) && wp_verify_nonce($_POST['wp_chrome_new_notification'], 'wp_chrome_new_notification')) {
        $data = array('title' => sanitize_text_field($_POST['title']), 'message' => sanitize_text_field($_POST['message']), 'url' => sanitize_text_field($_POST['url']));
        $result = WPChromePush::init()->sendGCM($data, 'message');
        $answer = json_decode($result);
        if ($answer) {
            $suc = $answer->{'success'};
            $fail = $answer->{'failure'};
            //if debug
            if (get_option('web_push_debuger')) {
                $gcm_output = "<div id='message' class='updated'><p><b>Push Notification Sent</b><i>&nbsp;&nbsp;</i></p><p>{$result}</p></div>";
            } else {
                $gcm_output = "<div id='message' class='updated'><p><b>Push Notification Sent</b><i>&nbsp;&nbsp;</i></p><p>" . __('Success:', 'px_gcm') . " {$suc}  &nbsp;&nbsp;" . __('Failed:', 'px_gcm') . " {$fail} </p></div>";
            }
        } else {
            $error_message = "<div id='message' class='error'><p><b>Error: </b>{$result}</p></div>";
        }
    } else {
        $error_message = "<div id='message' class='error'><p><b>Error: </b>Please complete all the fields.</p></div>";
    }
}
?>

<div class="wrap">
<h2>New Push Notification</h2>
<p><?php 
echo isset($gcm_output) ? $gcm_output : '';
?>
</p>
コード例 #2
0
<?php

if (!defined('ABSPATH')) {
    exit;
}
// Exit if accessed directly
/*
Plugin Name: Chrome Push Notifications
Plugin URI: http://www.github.com/aglipanci
Description: Chrome Push Notifications GCM
Version: 1.1.5
Author: Agli Panci
Author URI: http://www.aglipanci.com/
*/
if (!defined('CHROME_PUSH_PLUGIN_DIR')) {
    define('CHROME_PUSH_PLUGIN_DIR', plugin_dir_path(__FILE__));
}
if (!defined('CHROME_PUSH_PLUGIN_URL')) {
    define('CHROME_PUSH_PLUGIN_URL', plugin_dir_url(__FILE__));
}
require_once CHROME_PUSH_PLUGIN_DIR . 'includes/class-chrome-push.php';
register_activation_hook(__FILE__, array('WPChromePush', 'installFunctions'));
//start the plugin
WPChromePush::init();