当前位置: 首页>>代码示例>>PHP>>正文


PHP _wp_get_post_revision_version函数代码示例

本文整理汇总了PHP中_wp_get_post_revision_version函数的典型用法代码示例。如果您正苦于以下问题:PHP _wp_get_post_revision_version函数的具体用法?PHP _wp_get_post_revision_version怎么用?PHP _wp_get_post_revision_version使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_wp_get_post_revision_version函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _wp_upgrade_revisions_of_post

/**
 * Upgrade the revisions author, add the current post as a revision and set the revisions version to 1
 *
 * @since 3.6.0
 * @access private
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param WP_Post $post      Post object
 * @param array   $revisions Current revisions of the post
 * @return bool true if the revisions were upgraded, false if problems
 */
function _wp_upgrade_revisions_of_post($post, $revisions)
{
    global $wpdb;
    // Add post option exclusively
    $lock = "revision-upgrade-{$post->ID}";
    $now = time();
    $result = $wpdb->query($wpdb->prepare("INSERT IGNORE INTO `{$wpdb->options}` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, 'no') /* LOCK */", $lock, $now));
    if (!$result) {
        // If we couldn't get a lock, see how old the previous lock is
        $locked = get_option($lock);
        if (!$locked) {
            // Can't write to the lock, and can't read the lock.
            // Something broken has happened
            return false;
        }
        if ($locked > $now - 3600) {
            // Lock is not too old: some other process may be upgrading this post.  Bail.
            return false;
        }
        // Lock is too old - update it (below) and continue
    }
    // If we could get a lock, re-"add" the option to fire all the correct filters.
    update_option($lock, $now);
    reset($revisions);
    $add_last = true;
    do {
        $this_revision = current($revisions);
        $prev_revision = next($revisions);
        $this_revision_version = _wp_get_post_revision_version($this_revision);
        // Something terrible happened
        if (false === $this_revision_version) {
            continue;
        }
        // 1 is the latest revision version, so we're already up to date.
        // No need to add a copy of the post as latest revision.
        if (0 < $this_revision_version) {
            $add_last = false;
            continue;
        }
        // Always update the revision version
        $update = array('post_name' => preg_replace('/^(\\d+-(?:autosave|revision))[\\d-]*$/', '$1-v1', $this_revision->post_name));
        // If this revision is the oldest revision of the post, i.e. no $prev_revision,
        // the correct post_author is probably $post->post_author, but that's only a good guess.
        // Update the revision version only and Leave the author as-is.
        if ($prev_revision) {
            $prev_revision_version = _wp_get_post_revision_version($prev_revision);
            // If the previous revision is already up to date, it no longer has the information we need :(
            if ($prev_revision_version < 1) {
                $update['post_author'] = $prev_revision->post_author;
            }
        }
        // Upgrade this revision
        $result = $wpdb->update($wpdb->posts, $update, array('ID' => $this_revision->ID));
        if ($result) {
            wp_cache_delete($this_revision->ID, 'posts');
        }
    } while ($prev_revision);
    delete_option($lock);
    // Add a copy of the post as latest revision.
    if ($add_last) {
        wp_save_post_revision($post->ID);
    }
    return true;
}
开发者ID:AndreyLanko,项目名称:perevorot-prozorro-wp,代码行数:76,代码来源:revision.php

示例2: edit_post

/**
 * Update an existing post with values provided in $_POST.
 *
 * @since 1.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param array $post_data Optional.
 * @return int Post ID.
 */
function edit_post($post_data = null)
{
    global $wpdb;
    if (empty($post_data)) {
        $post_data =& $_POST;
    }
    // Clear out any data in internal vars.
    unset($post_data['filter']);
    $post_ID = (int) $post_data['post_ID'];
    $post = get_post($post_ID);
    $post_data['post_type'] = $post->post_type;
    $post_data['post_mime_type'] = $post->post_mime_type;
    if (!empty($post_data['post_status'])) {
        $post_data['post_status'] = sanitize_key($post_data['post_status']);
        if ('inherit' == $post_data['post_status']) {
            unset($post_data['post_status']);
        }
    }
    $ptype = get_post_type_object($post_data['post_type']);
    if (!current_user_can('edit_post', $post_ID)) {
        if ('page' == $post_data['post_type']) {
            wp_die(__('Sorry, you are not allowed to edit this page.'));
        } else {
            wp_die(__('Sorry, you are not allowed to edit this post.'));
        }
    }
    if (post_type_supports($ptype->name, 'revisions')) {
        $revisions = wp_get_post_revisions($post_ID, array('order' => 'ASC', 'posts_per_page' => 1));
        $revision = current($revisions);
        // Check if the revisions have been upgraded
        if ($revisions && _wp_get_post_revision_version($revision) < 1) {
            _wp_upgrade_revisions_of_post($post, wp_get_post_revisions($post_ID));
        }
    }
    if (isset($post_data['visibility'])) {
        switch ($post_data['visibility']) {
            case 'public':
                $post_data['post_password'] = '';
                break;
            case 'password':
                unset($post_data['sticky']);
                break;
            case 'private':
                $post_data['post_status'] = 'private';
                $post_data['post_password'] = '';
                unset($post_data['sticky']);
                break;
        }
    }
    $post_data = _wp_translate_postdata(true, $post_data);
    if (is_wp_error($post_data)) {
        wp_die($post_data->get_error_message());
    }
    // Post Formats
    if (isset($post_data['post_format'])) {
        set_post_format($post_ID, $post_data['post_format']);
    }
    $format_meta_urls = array('url', 'link_url', 'quote_source_url');
    foreach ($format_meta_urls as $format_meta_url) {
        $keyed = '_format_' . $format_meta_url;
        if (isset($post_data[$keyed])) {
            update_post_meta($post_ID, $keyed, wp_slash(esc_url_raw(wp_unslash($post_data[$keyed]))));
        }
    }
    $format_keys = array('quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed');
    foreach ($format_keys as $key) {
        $keyed = '_format_' . $key;
        if (isset($post_data[$keyed])) {
            if (current_user_can('unfiltered_html')) {
                update_post_meta($post_ID, $keyed, $post_data[$keyed]);
            } else {
                update_post_meta($post_ID, $keyed, wp_filter_post_kses($post_data[$keyed]));
            }
        }
    }
    if ('attachment' === $post_data['post_type'] && preg_match('#^(audio|video)/#', $post_data['post_mime_type'])) {
        $id3data = wp_get_attachment_metadata($post_ID);
        if (!is_array($id3data)) {
            $id3data = array();
        }
        foreach (wp_get_attachment_id3_keys($post, 'edit') as $key => $label) {
            if (isset($post_data['id3_' . $key])) {
                $id3data[$key] = sanitize_text_field(wp_unslash($post_data['id3_' . $key]));
            }
        }
        wp_update_attachment_metadata($post_ID, $id3data);
    }
    // Meta Stuff
    if (isset($post_data['meta']) && $post_data['meta']) {
        foreach ($post_data['meta'] as $key => $value) {
//.........这里部分代码省略.........
开发者ID:nicholasgriffintn,项目名称:WordPress,代码行数:101,代码来源:post.php

示例3: wp_delete_post_revision

        }
    }
    // If this autosave isn't different from the current post, begone.
    if (!$notice) {
        wp_delete_post_revision($autosave->ID);
    }
    unset($autosave_field, $_autosave_field);
}
$post_type_object = get_post_type_object($post_type);
// All meta boxes should be defined and added before the first do_meta_boxes() call (or potentially during the do_meta_boxes action).
require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';
$publish_callback_args = null;
if (post_type_supports($post_type, 'revisions') && 'auto-draft' != $post->post_status) {
    $revisions = wp_get_post_revisions($post_ID);
    // Check if the revisions have been upgraded
    if (!empty($revisions) && _wp_get_post_revision_version(end($revisions)) < 1) {
        _wp_upgrade_revisions_of_post($post, $revisions);
    }
    // We should aim to show the revisions metabox only when there are revisions.
    if (count($revisions) > 1) {
        reset($revisions);
        // Reset pointer for key()
        $publish_callback_args = array('revisions_count' => count($revisions), 'revision_id' => key($revisions));
        add_meta_box('revisionsdiv', __('Revisions'), 'post_revisions_meta_box', null, 'normal', 'core');
    }
}
if ('attachment' == $post_type) {
    wp_enqueue_script('image-edit');
    wp_enqueue_style('imgareaselect');
    add_meta_box('submitdiv', __('Save'), 'attachment_submit_meta_box', null, 'side', 'core');
    add_action('edit_form_after_title', 'edit_form_image_editor');
开发者ID:openify,项目名称:wordpress-composer,代码行数:31,代码来源:edit-form-advanced.php

示例4: edit_post

/**
 * Update an existing post with values provided in $_POST.
 *
 * @since 1.5.0
 *
 * @param array $post_data Optional.
 * @return int Post ID.
 */
function edit_post($post_data = null)
{
    global $wpdb;
    if (empty($post_data)) {
        $post_data =& $_POST;
    }
    // Clear out any data in internal vars.
    unset($post_data['filter']);
    $post_ID = (int) $post_data['post_ID'];
    $post = get_post($post_ID);
    $post_data['post_type'] = $post->post_type;
    $post_data['post_mime_type'] = $post->post_mime_type;
    if (!empty($post_data['post_status'])) {
        $post_data['post_status'] = sanitize_key($post_data['post_status']);
        if ('inherit' == $post_data['post_status']) {
            unset($post_data['post_status']);
        }
    }
    $ptype = get_post_type_object($post_data['post_type']);
    if (!current_user_can('edit_post', $post_ID)) {
        if ('page' == $post_data['post_type']) {
            wp_die(__('You are not allowed to edit this page.'));
        } else {
            wp_die(__('You are not allowed to edit this post.'));
        }
    }
    if (post_type_supports($ptype->name, 'revisions')) {
        $revisions = wp_get_post_revisions($post_ID, array('order' => 'ASC', 'posts_per_page' => 1));
        $revision = current($revisions);
        // Check if the revisions have been upgraded
        if ($revisions && _wp_get_post_revision_version($revision) < 1) {
            _wp_upgrade_revisions_of_post($post, wp_get_post_revisions($post_ID));
        }
    }
    if (isset($post_data['visibility'])) {
        switch ($post_data['visibility']) {
            case 'public':
                $post_data['post_password'] = '';
                break;
            case 'password':
                unset($post_data['sticky']);
                break;
            case 'private':
                $post_data['post_status'] = 'private';
                $post_data['post_password'] = '';
                unset($post_data['sticky']);
                break;
        }
    }
    $post_data = _wp_translate_postdata(true, $post_data);
    if (is_wp_error($post_data)) {
        wp_die($post_data->get_error_message());
    }
    // Post Formats
    if (isset($post_data['post_format'])) {
        set_post_format($post_ID, $post_data['post_format']);
    }
    $format_meta_urls = array('url', 'link_url', 'quote_source_url');
    foreach ($format_meta_urls as $format_meta_url) {
        $keyed = '_format_' . $format_meta_url;
        if (isset($post_data[$keyed])) {
            update_post_meta($post_ID, $keyed, wp_slash(esc_url_raw(wp_unslash($post_data[$keyed]))));
        }
    }
    $format_keys = array('quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed');
    foreach ($format_keys as $key) {
        $keyed = '_format_' . $key;
        if (isset($post_data[$keyed])) {
            if (current_user_can('unfiltered_html')) {
                update_post_meta($post_ID, $keyed, $post_data[$keyed]);
            } else {
                update_post_meta($post_ID, $keyed, wp_filter_post_kses($post_data[$keyed]));
            }
        }
    }
    if ('attachment' === $post_data['post_type'] && preg_match('#^(audio|video)/#', $post_data['post_mime_type'])) {
        $id3data = wp_get_attachment_metadata($post_ID);
        if (!is_array($id3data)) {
            $id3data = array();
        }
        foreach (wp_get_attachment_id3_keys($post, 'edit') as $key => $label) {
            if (isset($post_data['id3_' . $key])) {
                $id3data[$key] = sanitize_text_field(wp_unslash($post_data['id3_' . $key]));
            }
        }
        wp_update_attachment_metadata($post_ID, $id3data);
    }
    // Meta Stuff
    if (isset($post_data['meta']) && $post_data['meta']) {
        foreach ($post_data['meta'] as $key => $value) {
            if (!($meta = get_post_meta_by_id($key))) {
                continue;
//.........这里部分代码省略.........
开发者ID:GaryJones,项目名称:dockerfiles,代码行数:101,代码来源:post.php

示例5: edit_post

/**
 * Update an existing post with values provided in $_POST.
 *
 * @since 1.5.0
 *
 * @param array $post_data Optional.
 * @return int Post ID.
 */
function edit_post( $post_data = null ) {

	if ( empty($post_data) )
		$post_data = &$_POST;

	// Clear out any data in internal vars.
	unset( $post_data['filter'] );

	$post_ID = (int) $post_data['post_ID'];
	$post = get_post( $post_ID );
	$post_data['post_type'] = $post->post_type;
	$post_data['post_mime_type'] = $post->post_mime_type;

	if ( ! empty( $post_data['post_status'] ) ) {
		$post_data['post_status'] = sanitize_key( $post_data['post_status'] );

		if ( 'inherit' == $post_data['post_status'] ) {
			unset( $post_data['post_status'] );
		}
	}

	$ptype = get_post_type_object($post_data['post_type']);
	if ( !current_user_can( 'edit_post', $post_ID ) ) {
		if ( 'page' == $post_data['post_type'] )
			wp_die( __('You are not allowed to edit this page.' ));
		else
			wp_die( __('You are not allowed to edit this post.' ));
	}

	if ( post_type_supports( $ptype->name, 'revisions' ) ) {
		$revisions = wp_get_post_revisions( $post_ID, array( 'order' => 'ASC', 'posts_per_page' => 1 ) );
		$revision = current( $revisions );

		// Check if the revisions have been upgraded
		if ( $revisions && _wp_get_post_revision_version( $revision ) < 1 )
			_wp_upgrade_revisions_of_post( $post, wp_get_post_revisions( $post_ID ) );
	}

	if ( ( empty( $post_data['action'] ) || 'autosave' != $post_data['action'] ) && 'auto-draft' == $post_data['post_status'] ) {
		$post_data['post_status'] = 'draft';
	}

	if ( isset($post_data['visibility']) ) {
		switch ( $post_data['visibility'] ) {
			case 'public' :
				$post_data['post_password'] = '';
				break;
			case 'password' :
				unset( $post_data['sticky'] );
				break;
			case 'private' :
				$post_data['post_status'] = 'private';
				$post_data['post_password'] = '';
				unset( $post_data['sticky'] );
				break;
		}
	}

	$post_data = _wp_translate_postdata( true, $post_data );
	if ( is_wp_error($post_data) )
		wp_die( $post_data->get_error_message() );

	// Post Formats
	if ( isset( $post_data['post_format'] ) )
		set_post_format( $post_ID, $post_data['post_format'] );

	$format_meta_urls = array( 'url', 'link_url', 'quote_source_url' );
	foreach ( $format_meta_urls as $format_meta_url ) {
		$keyed = '_format_' . $format_meta_url;
		if ( isset( $post_data[ $keyed ] ) )
			update_post_meta( $post_ID, $keyed, wp_slash( esc_url_raw( wp_unslash( $post_data[ $keyed ] ) ) ) );
	}

	$format_keys = array( 'quote', 'quote_source_name', 'image', 'gallery', 'audio_embed', 'video_embed' );

	foreach ( $format_keys as $key ) {
		$keyed = '_format_' . $key;
		if ( isset( $post_data[ $keyed ] ) ) {
			if ( current_user_can( 'unfiltered_html' ) )
				update_post_meta( $post_ID, $keyed, $post_data[ $keyed ] );
			else
				update_post_meta( $post_ID, $keyed, wp_filter_post_kses( $post_data[ $keyed ] ) );
		}
	}

	// Meta Stuff
	if ( isset($post_data['meta']) && $post_data['meta'] ) {
		foreach ( $post_data['meta'] as $key => $value ) {
			if ( !$meta = get_post_meta_by_id( $key ) )
				continue;
			if ( $meta->post_id != $post_ID )
				continue;
//.........这里部分代码省略.........
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:101,代码来源:post.php


注:本文中的_wp_get_post_revision_version函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。