/**
  * This function is responsible for checking whether or not a post is:
  * 		1. transitioning from not published to published &
  * 		2. has the "push setting" set to true
  *
  * This function should only be called automatically through the WordPress action hook `transition_post_status`.
  * If the criteria above (1 & 2) are met, it handles gathering the information we need to send a push notification
  * and then sends it.
  *
  * @param string $new_status
  * @param string $old_status
  * @param null|WP_Post $post
  */
 public static function transition_post_status($new_status = '', $old_status = '', $post = null)
 {
     /** Permissions *******************************************************/
     // Bail if post is empty
     if (empty($post)) {
         return;
     }
     // Bail if not an allowed post type
     if (!self::_is_post_type_allowed(get_post_type($post))) {
         return;
     }
     // Only users that can edit this post can push
     if (!current_user_can('edit_post', $post->ID) && !defined('DOING_CRON')) {
         return;
     }
     // Bail for new auto-draft transitions
     if ('auto-draft' === $new_status && 'new' === $old_status) {
         return;
     }
     // No autosaves or revisions
     if (wp_is_post_autosave($post->ID) || wp_is_post_revision($post->ID)) {
         return;
     }
     /** Already Pushed ****************************************************/
     // Get push time if it's already set
     $push_setting = self::get_push_setting($post->ID);
     // Bail if the push status is publish, since posts cannot be unpushed
     if (!empty($push_setting['time']) && 'pushed' === $push_setting['status']) {
         return;
     }
     /** Validate Push Status **********************************************/
     /**
      * Force pushed status to unpushed if no time exists.
      *
      * This fixes otherwise unexpected data corruption from who-knows-where, and prevents a post thinking it's been
      * pushed, without knowing when it happened, resulting in an inconsistent checkbox UI.
      **/
     if (empty($push_setting['time'])) {
         $push_setting['status'] = 'unpushed';
     }
     /** Validate Push Time ************************************************/
     // Current author is saving or updating a post
     if (self::_is_post_request()) {
         // Checkbox is unchecked so force time to 0
         if (!defined('DOING_CRON') && (empty($_POST['pushup-notification-creation']) || 'off' === $_POST['pushup-notification-creation'])) {
             $push_setting['time'] = 0;
             // Checkbox is checked, so force time to current time
         } elseif ('on' === $_POST['pushup-notification-creation']) {
             $push_setting['time'] = current_time('timestamp');
         }
         // Future dated post switching to publish
     } elseif ('publish' === $new_status && 'future' === $old_status) {
         // Checkbox was not checked when post was saved, so force time to 0
         if (empty($push_setting['time'])) {
             $push_setting['time'] = 0;
             // Checkbox was previously checked, so update the push time
         } else {
             $push_setting['time'] = current_time('timestamp');
         }
     }
     /** Check the API *****************************************************/
     // Don't push if post was previously pushed
     if ('publish' === $new_status && !empty($push_setting['time'])) {
         $post_url = PushUp_Notifications_Core::get_shortlink($post->ID);
         $url_parameter = str_replace(array('http://', 'https://'), '', $post_url);
         // cap for title is: 35 characters (before being trimmed by OSX)
         // cap for body is: 133 characters (before being trimmed by OSX)
         $title = PushUp_Notifications_Core::get_post_title();
         $body = self::_maybe_trim_post_title(apply_filters('the_title', $post->post_title, $post->ID));
         $action = 'See Post';
         $pushed = self::send_message($title, $body, $action, array($url_parameter));
     } else {
         $pushed = null;
     }
     /** Push Status *******************************************************/
     // Setup the push status
     if (is_array($pushed)) {
         $push_setting = $pushed;
     } elseif ('pushed' !== $push_setting['status']) {
         $push_setting['status'] = 'unpushed';
     }
     // Update the push setting
     self::set_push_setting($push_setting, $post->ID);
 }