Пример #1
0
/**
 * MRP_save_postdata - Prepare to save the selected relations
 *
 * @param int   $post_id - The id of the post being saved
 */
function MRP_save_postdata($post_id)
{
    if (!isset($_POST['MRP_noncename'])) {
        return $post_id;
    }
    if (!wp_verify_nonce($_POST['MRP_noncename'], plugin_basename(__FILE__))) {
        return $post_id;
    }
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return $post_id;
        }
    } else {
        if (!current_user_can('edit_post', $post_id)) {
            return $post_id;
        }
    }
    # Do not create a relationship with the revisions and autosaves in WP 2.6
    if (function_exists("wp_is_post_revision")) {
        if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
            return $post_id;
        }
    }
    MRP_save_relationships($post_id, $_POST['MRP_related_posts']);
}
/**
 * MRP_save_postdata - Prepare to save the selected relations
 *
 * @param int   $post_id - The id of the post being saved
 */
function MRP_save_postdata($post_id)
{
    if (!isset($_POST['MRP_noncename'])) {
        return $post_id;
    }
    if (!wp_verify_nonce($_POST['MRP_noncename'], plugin_basename(__FILE__))) {
        return $post_id;
    }
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return $post_id;
        }
    } else {
        if (!current_user_can('edit_post', $post_id)) {
            return $post_id;
        }
    }
    # Do not create a relationship with the revisions and autosaves in WP 2.6
    if (function_exists("wp_is_post_revision")) {
        if (wp_is_post_revision($post_id) || wp_is_post_autosave($post_id)) {
            return $post_id;
        }
    }
    $related_posts = array();
    for ($i = 0; $i < count($_POST['MRP_related_post_ids']); $i++) {
        $related_posts[] = array('id' => $_POST['MRP_related_post_ids'][$i], 'rel_type' => $_POST['MRP_related_post_types'][$i], 'rel_strength' => $_POST['MRP_related_post_strengths'][$i]);
    }
    MRP_save_relationships($post_id, $related_posts);
}