Make WordPress Core

Ticket #19373: patch.diff

File patch.diff, 1.8 KB (added by alexkingorg, 13 years ago)

Add a $user param to wp_insert_post to provide user context

  • wp-includes/post.php

     
    24122412 * @param bool $wp_error Optional. Allow return of WP_Error on failure.
    24132413 * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success.
    24142414 */
    2415 function wp_insert_post($postarr, $wp_error = false) {
     2415function wp_insert_post($postarr, $wp_error = false, $user = null) {
    24162416        global $wpdb, $wp_rewrite, $user_ID;
    24172417
     2418        if ( is_null( $user ) ) {
     2419                $user = $user_ID;
     2420        }
     2421
    24182422        $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID,
    24192423                'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
    24202424                'menu_order' => 0, 'to_ping' =>  '', 'pinged' => '', 'post_password' => '',
     
    24252429
    24262430        unset( $postarr[ 'filter' ] );
    24272431
    2428         $postarr = sanitize_post($postarr, 'db');
     2432        if ( $user ) {
     2433                $postarr = sanitize_post($postarr, 'db');
     2434        }
    24292435
    24302436        // export array as variables
    24312437        extract($postarr, EXTR_SKIP);
     
    24792485        }
    24802486
    24812487        // Don't allow contributors to set the post slug for pending review posts
    2482         if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) )
     2488        if ( 'pending' == $post_status && $user && !user_can( $user, 'publish_posts' ) )
    24832489                $post_name = '';
    24842490
    24852491        // Create a valid post name.  Drafts and pending posts are allowed to have an empty
     
    26152621                        $taxonomy_obj = get_taxonomy($taxonomy);
    26162622                        if ( is_array($tags) ) // array = hierarchical, string = non-hierarchical.
    26172623                                $tags = array_filter($tags);
    2618                         if ( current_user_can($taxonomy_obj->cap->assign_terms) )
     2624                        if ( !$user || user_can( $user, $taxonomy_obj->cap->assign_terms) )
    26192625                                wp_set_post_terms( $post_ID, $tags, $taxonomy );
    26202626                }
    26212627        }