Make WordPress Core

Ticket #8592: 8592.5.fork.diff

File 8592.5.fork.diff, 4.8 KB (added by plocha, 11 years ago)
  • wp-admin/includes/meta-boxes.php

     
    644644                        'show_option_none' => __('(no parent)'),
    645645                        'sort_column'      => 'menu_order, post_title',
    646646                        'echo'             => 0,
     647                        'post_status'      => 'publish,private',
    647648                );
    648649
    649650                $dropdown_args = apply_filters( 'page_attributes_dropdown_pages_args', $dropdown_args, $post );
  • wp-admin/includes/class-wp-posts-list-table.php

     
    902902                        'show_option_none'  => __( 'Main Page (no parent)' ),
    903903                        'option_none_value' => 0,
    904904                        'sort_column'       => 'menu_order, post_title',
     905                        'post_status'       => 'publish,private',
    905906                );
    906907
    907908                if ( $bulk )
  • wp-includes/post.php

     
    27552755        if ( empty($post_type) )
    27562756                $post_type = 'post';
    27572757
     2758        if ( isset($post_parent) )
     2759                $post_parent = (int) $post_parent;
     2760        else
     2761                $post_parent = 0;
     2762        // Check the post_parent to see if it will cause a hierarchy loop
     2763        $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr );
     2764        //inherit parent post status when private
     2765        if ( $post_parent ) {
     2766                $parent_status = get_post( $post_parent )->post_status;
     2767                if ( 'private' === $parent_status ) {
     2768                        $post_status = $parent_status;
     2769                } elseif ( 'publish' !== $parent_status ) {
     2770                        if ( $wp_error ) {
     2771                                return new WP_Error( 'invalid_parent_status',
     2772                                                __( 'The selected parent has an invalid status' ),
     2773                                                $parent_status );
     2774                        } else {
     2775                                return 0;
     2776                        }
     2777                }
     2778        }
     2779
    27582780        if ( empty($post_status) )
    27592781                $post_status = 'draft';
    27602782
     
    28512873        if ( ! isset($pinged) )
    28522874                $pinged = '';
    28532875
    2854         if ( isset($post_parent) )
    2855                 $post_parent = (int) $post_parent;
    2856         else
    2857                 $post_parent = 0;
    2858 
    2859         // Check the post_parent to see if it will cause a hierarchy loop
    2860         $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr );
    2861 
    28622876        if ( isset($menu_order) )
    28632877                $menu_order = (int) $menu_order;
    28642878        else
     
    28762890        $where = array( 'ID' => $post_ID );
    28772891
    28782892        if ( $update ) {
     2893                $result = affect_descendants( $post_ID, $data, $previous_status );
     2894                if ( is_wp_error( $result ) ) {
     2895                        if ( $wp_error ) {
     2896                                return $result;
     2897                        }
     2898                        return 0;
     2899                }
    28792900                do_action( 'pre_post_update', $post_ID, $data );
    28802901                if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) {
    28812902                        if ( $wp_error )
     
    29652986}
    29662987
    29672988/**
     2989 * Affects descendant pages on some post status changes.
     2990 * @param array $data Array with new post fields
     2991 * @param string $previous_status
     2992 * @return int|WP_Error WP_Error on failure. Otherwise 0
     2993 */
     2994function affect_descendants( $ID, $data, $previous_status ) {
     2995        $getter_args = array();
     2996        $force_inheritance = false;
     2997        //remove parentship for all childrens if post status does not support it
     2998        if ( in_array( $previous_status , array( 'publish', 'private' ) ) &&
     2999                        ! in_array( $data['post_status'], array( 'publish', 'private' ) ) ) {
     3000                $getter_args = array(
     3001                                'parent' => $ID,
     3002                                'hierarchical' => 0,
     3003                                'post_status' => 'publish,future,draft,pending,private',
     3004                        );
     3005        }
     3006        //publish->private? set post status of all descendants to private
     3007        if ( 'publish' === $previous_status && 'private' === $data['post_status'] ) {
     3008                $getter_args = array(
     3009                                'child_of' => $ID,
     3010                                'post_status' => 'publish,future,draft,pending',
     3011                        );
     3012                $force_inheritance = true;
     3013        }
     3014        if ( ! count( $getter_args ) ) { //no need for changes
     3015                return 0;
     3016        }
     3017
     3018        $descendants = get_pages( $getter_args );
     3019        if ( false === $descendants ) {
     3020                return new WP_Error( 'get_descendant_fail',
     3021                                __( 'Could not get descendant' ), $getter_args );
     3022        }
     3023        if ( ! count( $descendants ) ) {
     3024                return 0;
     3025        }
     3026        global $wpdb;
     3027        $sql = "UPDATE {$wpdb->posts} SET ";
     3028        if ( $force_inheritance ) {
     3029                $sql .= 'post_status="private"';
     3030        } else {
     3031                $sql .= 'post_parent=0';
     3032        }
     3033        $sql .= ' WHERE ';
     3034        for ( $i = 0; $i != count( $descendants ); $i++ ) {
     3035                $sql .= "ID={$descendants[$i]->ID} ";
     3036                if ( count( $descendants ) - 1 != $i ) {
     3037                        $sql .= 'OR ';
     3038                }
     3039        }
     3040
     3041        if ( FALSE === $wpdb->query( $sql ) ) {
     3042                return new WP_Error( 'affect_descendant_fail',
     3043                                __( 'Could not affect descendants' ), $sql );
     3044        }
     3045        return 0;
     3046}
     3047
     3048/**
     3049 *
     3050
     3051/**
    29683052 * Update a post with new post data.
    29693053 *
    29703054 * The date does not have to be set for drafts. You can set the date and it will