Beispiel #1
0
/**
 * Autosave with heartbeat
 *
 * @since 3.9.0
 *
 * @param array $response The Heartbeat response.
 * @param array $data     The $_POST data sent.
 * @return array The Heartbeat response.
 */
function heartbeat_autosave($response, $data)
{
    if (!empty($data['wp_autosave'])) {
        $saved = wp_autosave($data['wp_autosave']);
        if (is_wp_error($saved)) {
            $response['wp_autosave'] = array('success' => false, 'message' => $saved->get_error_message());
        } elseif (empty($saved)) {
            $response['wp_autosave'] = array('success' => false, 'message' => __('Error while saving.'));
        } else {
            /* translators: draft saved date format, see http://php.net/date */
            $draft_saved_date_format = __('g:i:s a');
            /* translators: %s: date and time */
            $response['wp_autosave'] = array('success' => true, 'message' => sprintf(__('Draft saved at %s.'), date_i18n($draft_saved_date_format)));
        }
    }
    return $response;
}
 /**
  * Filter @see heartbeat_received
  * @since 1.0.1
  *
  * @param array  $response
  * @param array  $data
  * @param string $screen_id
  *
  * @return array
  */
 public static function filter__heartbeat_received($response, $data, $screen_id)
 {
     if (false !== strpos($_SERVER['HTTP_REFERER'], 'wpglobus=off')) {
         /**
          * Check $_SERVER['HTTP_REFERER'] for wpglobus toggle is off because wpglobus-admin.js doesn't loaded in this mode
          */
         return $response;
     }
     if (!empty($data['wp_autosave'])) {
         if (empty($data['wp_autosave']['post_id']) || (int) $data['wp_autosave']['post_id'] == 0) {
             /**
              * wp_autosave may come from edit.php page
              */
             return $response;
         }
         if (empty($data['wpglobus_heartbeat'])) {
             /**
              * Check for wpglobus key
              */
             return $response;
         }
         $title_wrap = false;
         $content_wrap = false;
         $post_title_ext = '';
         $content_ext = '';
         foreach (WPGlobus::Config()->enabled_languages as $language) {
             if ($language == WPGlobus::Config()->default_language) {
                 $post_title_ext .= WPGlobus::add_locale_marks($data['wp_autosave']['post_title'], $language);
                 $content_ext .= WPGlobus::add_locale_marks($data['wp_autosave']['content'], $language);
             } else {
                 if (!empty($data['wp_autosave']['post_title_' . $language])) {
                     $title_wrap = true;
                     $post_title_ext .= WPGlobus::add_locale_marks($data['wp_autosave']['post_title_' . $language], $language);
                 }
                 if (!empty($data['wp_autosave']['content_' . $language])) {
                     $content_wrap = true;
                     $content_ext .= WPGlobus::add_locale_marks($data['wp_autosave']['content_' . $language], $language);
                 }
             }
         }
         if ($title_wrap) {
             $data['wp_autosave']['post_title'] = $post_title_ext;
         }
         if ($content_wrap) {
             $data['wp_autosave']['content'] = $content_ext;
         }
         /**
          * Filter before autosave
          * @since 1.0.2
          *
          * @param array $data ['wp_autosave'] Array of post data.
          */
         $data['wp_autosave'] = apply_filters('wpglobus_autosave_post_data', $data['wp_autosave']);
         $saved = wp_autosave($data['wp_autosave']);
         if (is_wp_error($saved)) {
             $response['wp_autosave'] = array('success' => false, 'message' => $saved->get_error_message());
         } elseif (empty($saved)) {
             $response['wp_autosave'] = array('success' => false, 'message' => __('Error while saving.'));
         } else {
             /* translators: draft saved date format, see http://php.net/date */
             $draft_saved_date_format = __('g:i:s a');
             /* translators: %s: date and time */
             $response['wp_autosave'] = array('success' => true, 'message' => sprintf(__('Draft saved at %s.'), date_i18n($draft_saved_date_format)));
         }
     }
     return $response;
 }