Example #1
0
/**
 * Update post meta field based on post ID.
 *
 * Use the $prev_value parameter to differentiate between meta fields with the
 * same key and post ID.
 *
 * If the meta field for the post does not exist, it will be added.
 *
 * @since 1.5.0
 * @uses $nxtdb
 * @link http://codex.nxtclass.org/Function_Reference/update_post_meta
 *
 * @param int $post_id Post ID.
 * @param string $meta_key Metadata key.
 * @param mixed $meta_value Metadata value.
 * @param mixed $prev_value Optional. Previous value to check before removing.
 * @return bool False on failure, true if success.
 */
function update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '')
{
    // make sure meta is added to the post, not a revision
    if ($the_post = nxt_is_post_revision($post_id)) {
        $post_id = $the_post;
    }
    return update_metadata('post', $post_id, $meta_key, $meta_value, $prev_value);
}
Example #2
0
 function anon_meta_save_as_revision($revision_id)
 {
     $old_meta = get_post_meta(nxt_is_post_revision($revision_id), '_nxtw_anon_meta', true);
     if (!empty($old_meta)) {
         add_metadata('post', $revision_id, '_nxtw_anon_meta', $old_meta);
         delete_post_meta(nxt_is_post_revision($revision_id), '_nxtw_anon_meta', $old_meta);
     }
 }
 /**
  * Updates the YouTube playlist with the videos found in the just-saved post.
  *
  * @param int $post_id the ID of the just-saved post
  *
  * @access private
  * @since 0.1
  */
 public function _update_videos_on_post_save($post_id)
 {
     global $nxtdb, $blog_id;
     // Ignore post revisions, but remove videos associated with any posts
     // that are not publicly visible
     $post = get_post($post_id);
     if (nxt_is_post_revision($post_id)) {
         return;
     }
     if ($post->post_status != "publish") {
         $this->_update_videos_on_post_delete($post_id);
         return;
     }
     // Determine which videos were previously used in the post content but
     // are no longer present
     $current_videos = $this->_find_video_ids_in_post_content($post->post_content);
     $previous_videos = $nxtdb->get_col($nxtdb->prepare("\n\t\t\tSELECT v.youtube_id FROM {$this->tables->video_usage} AS vu, {$this->tables->videos} AS v\n\t\t\tWHERE vu.blog_id = %d AND vu.post_id = %d AND vu.video_id = v.id", $blog_id, $post_id));
     $unused_videos = array_values(array_diff($previous_videos, $current_videos));
     // Update our local video usage records
     foreach ($current_videos as $video) {
         $this->_add_video_usage($video, $post_id, $blog_id);
         $this->_retrieve_queued_video_info();
     }
     foreach ($unused_videos as $video) {
         $this->_remove_video_usage($video, $post_id, $blog_id);
     }
 }
Example #4
0
/**
 * Retrieve formatted date timestamp of a revision (linked to that revisions's page).
 *
 * @package NXTClass
 * @subpackage Post_Revisions
 * @since 2.6.0
 *
 * @uses date_i18n()
 *
 * @param int|object $revision Revision ID or revision object.
 * @param bool $link Optional, default is true. Link to revisions's page?
 * @return string i18n formatted datetimestamp or localized 'Current Revision'.
 */
function nxt_post_revision_title($revision, $link = true)
{
    if (!($revision = get_post($revision))) {
        return $revision;
    }
    if (!in_array($revision->post_type, array('post', 'page', 'revision'))) {
        return false;
    }
    /* translators: revision date format, see http://php.net/date */
    $datef = _x('j F, Y @ G:i', 'revision date format');
    /* translators: 1: date */
    $autosavef = __('%1$s [Autosave]');
    /* translators: 1: date */
    $currentf = __('%1$s [Current Revision]');
    $date = date_i18n($datef, strtotime($revision->post_modified));
    if ($link && current_user_can('edit_post', $revision->ID) && ($link = get_edit_post_link($revision->ID))) {
        $date = "<a href='{$link}'>{$date}</a>";
    }
    if (!nxt_is_post_revision($revision)) {
        $date = sprintf($currentf, $date);
    } elseif (nxt_is_post_autosave($revision)) {
        $date = sprintf($autosavef, $date);
    }
    return $date;
}
Example #5
0
 /**
  * Monitors updates to all post tables and updates the sitewide posts table
  * based on the status of the post.
  *
  * This does not actually perform any modifications to the sitewide posts
  * table, as such actions are delegated to various other functions that
  * handle addition, deletion or modification.
  *
  * @param int $post_id the ID of the post being modified
  *
  * @access private
  * @since 0.2
  */
 public function _track_single_post($post_id)
 {
     global $blog_id;
     // Abort early if the post is a revision or an initial default post
     $post = get_post($post_id);
     if (nxt_is_post_revision($post_id) || $this->_content_is_initial_for_user($post->post_date_gmt, $post->post_author)) {
         return;
     }
     // Abort if the post is anything besides a post, such as an attachment
     // or a page
     if ($post->post_type !== 'post') {
         return;
     }
     // If the post is being published, update its sitewide record, and remove
     // it from the sitewide table if it is no longer visible to the public,
     // either due to a change of status or outright deletion
     $this->clear_site_cache();
     switch (get_post_status($post_id)) {
         case 'publish':
             $this->_update_sw_post($blog_id, $post_id);
             break;
         default:
             $this->_delete_sw_post($blog_id, $post_id);
     }
 }