Example #1
0
 public static function send($device_token, $message, $additional_data = array(), $badge = null, $sound = 'default')
 {
     if (!self::$apn) {
         $settings = WPAPN_AdminController::getSettings();
         try {
             self::$apn = new WPAPN_APN($settings);
         } catch (Exception $e) {
             WPAPN_AdminController::showMessage($e->getMessage(), true);
             self::$apn = false;
             return false;
         }
     }
     $post_id = wp_insert_post(array('post_type' => WPAPN_NotificationController::$type, 'post_status' => 'publish', 'post_title' => $message));
     if (is_wp_error($post_id)) {
         return false;
     }
     self::$apn->payloadMethod = 'enhance';
     // you can turn on this method for debuggin purpose
     $connected = true;
     try {
         $connected = self::$apn->connectToPush();
     } catch (Exception $e) {
         $connected = false;
     }
     if (!$connected) {
         WPAPN_Plugin::log('APN error', 'Could not connect to the push service');
         return false;
     }
     // adding custom variables to the notification
     if (!empty($additional_data)) {
         self::$apn->setData($additional_data);
     }
     // send
     $send_result = self::$apn->sendMessage($device_token, $message, $badge, $sound);
     wp_update_post(array('ID' => $post_id, 'post_content' => self::$apn->recent_payload));
     update_post_meta($post_id, WP_APN_PLUGIN . '-device-token', $device_token);
     update_post_meta($post_id, WP_APN_PLUGIN . '-badge', $badge);
     update_post_meta($post_id, WP_APN_PLUGIN . '-sound', $sound);
     if ($send_result) {
         update_post_meta($post_id, WP_APN_PLUGIN . '-sent-status', 'sent');
         update_post_meta($post_id, WP_APN_PLUGIN . '-sent-error', '');
         WPAPN_Plugin::log('APN debug', 'Sending successful');
     } else {
         update_post_meta($post_id, WP_APN_PLUGIN . '-sent-status', 'error');
         update_post_meta($post_id, WP_APN_PLUGIN . '-sent-error', self::$apn->error);
         WPAPN_Plugin::log('APN error', self::$apn->error);
     }
     self::$apn->disconnectPush();
     return $post_id;
 }
Example #2
0
?>
									<a href="#!" class="js-tip tip" title="<?php 
_e('ABSPATH will be used as prefix for the specified path', WP_APN_PLUGIN);
?>
"><span class="fa fa-question-circle"></span></a>
								</label>
								
								<input
									type="text"
									class="js-wp-apn-production-certificate-path"
									name="<?php 
echo WP_APN_PLUGIN;
?>
[PermissionFile]"
									value="<?php 
echo WPAPN_AdminController::getSetting('PermissionFile');
?>
"
									/>
									
								<button class="button js-wp-apn-production-certificate-upload">
									<?php 
_e('Upload Certificate', WP_APN_PLUGIN);
?>
								</button>
							</p>
						</div>
						
						<!--<p>
							<blockquote>
								<?php 
 public static function register()
 {
     global $pagenow;
     $register_post_data = array('labels' => array('name' => __('APNs', WP_APN_PLUGIN), 'singular_name' => __('APN', WP_APN_PLUGIN), 'add_new_item' => __('Add APN', WP_APN_PLUGIN), 'add_new' => __('Add APN', WP_APN_PLUGIN), 'edit' => __('Edit', WP_APN_PLUGIN), 'edit_item' => __('Edit APN', WP_APN_PLUGIN), 'new_item' => __('New APN', WP_APN_PLUGIN), 'view' => __('View', WP_APN_PLUGIN), 'view_item' => __('View APN', WP_APN_PLUGIN), 'search_items' => __('Search APNs', WP_APN_PLUGIN), 'not_found' => __('No APNs found', WP_APN_PLUGIN)), 'description' => __('For APNs', WP_APN_PLUGIN), 'public' => false, 'show_ui' => (bool) WPAPN_AdminController::getSetting('show_post_type'), '_builtin' => false, 'capability_type' => 'post', 'capabilities' => array('create_posts' => false), 'menu_icon' => plugins_url('assets/img/notification.png', WP_APN_FILE), 'hierarchical' => false, 'map_meta_cap' => true, 'supports' => array('title'));
     register_post_type(self::$type, $register_post_data);
 }
Example #4
0
 public static function getSetting($name)
 {
     if (self::$cached_settings == null) {
         self::$cached_settings = self::getSettings();
     }
     if (isset(self::$cached_settings[$name])) {
         return self::$cached_settings[$name];
     } else {
         return null;
     }
 }