WordPress.org

Make WordPress Core

Ticket #8592: 8592-parent-status-check.diff

File 8592-parent-status-check.diff, 6.3 KB (added by sillybean, 5 years ago)

Force children of unpublished parent pages to inherit status. Includes new argument filters for wp_list_pages() and wp_dropdown_pages().

  • wp-admin/includes/meta-boxes.php

     
    1414
    1515        $post_type = $post->post_type;
    1616        $post_type_object = get_post_type_object($post_type);
    17         $can_publish = current_user_can($post_type_object->cap->publish_posts);
     17    $can_publish = current_user_can($post_type_object->cap->publish_posts);
     18    $unpublished_parent = false;
     19    if ( isset( $post->post_parent ) && $post->post_parent ) {
     20        $parent_status = get_post_status( $post->post_parent );
     21        if ( 'publish' !== $parent_status ) {
     22            $unpublished_parent = true;
     23            $post->post_status = $parent_status;
     24        }
     25    }
    1826?>
    1927<div class="submitbox" id="submitpost">
    2028
     
    2331<?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?>
    2432<div style="display:none;">
    2533<?php submit_button( __( 'Save' ), 'button', 'save' ); ?>
     34<input type="hidden" name="unpublished_parent" id="unpublished_parent" value="<?php if ( $unpublished_parent ) echo
     351; else echo 0; ?>" />
    2636</div>
    2737
    2838<div id="minor-publishing-actions">
     
    124134}
    125135
    126136echo esc_html( $visibility_trans ); ?></span>
    127 <?php if ( $can_publish ) { ?>
     137<?php if ( $unpublished_parent ) { ?>
     138<p><?php printf('To publish this page, you must first <a href="%s">publish its parent page</a>.', get_edit_post_link( $post->post_parent ) ); ?></p>
     139<?php } elseif ( $can_publish ) { ?>
    128140<a href="#visibility" class="edit-visibility hide-if-no-js"><?php _e('Edit'); ?></a>
    129141
    130142<div id="post-visibility-select" class="hide-if-js">
     
    220232<div id="publishing-action">
    221233<span class="spinner"></span>
    222234<?php
    223 if ( !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0 == $post->ID ) {
     235if ( !$unpublished_parent && !in_array( $post->post_status, array('publish', 'future',
     236        'private') ) || 0 == $post->ID ) {
    224237        if ( $can_publish ) :
    225238                if ( !empty($post->post_date_gmt) && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) : ?>
    226239                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" />
  • wp-includes/post-template.php

     
    784784        );
    785785
    786786        $r = wp_parse_args( $args, $defaults );
     787        $r = apply_filters( 'wp_dropdown_pages_args', $r );
     788    // revert to default (public) post_status on the Reading Settings page
     789    $screen = get_current_screen();
     790    if ( 'options-reading' == $screen->base )
     791        unset( $r['post_status'] );
    787792        extract( $r, EXTR_SKIP );
    788793
    789794        $pages = get_pages($r);
     
    829834        );
    830835
    831836        $r = wp_parse_args( $args, $defaults );
     837        $r = apply_filters( 'wp_list_pages_args', $r );
    832838        extract( $r, EXTR_SKIP );
    833839
    834840        $output = '';
  • wp-includes/post.php

     
    26752675        if ( empty($post_type) )
    26762676                $post_type = 'post';
    26772677
    2678         if ( empty($post_status) )
    2679                 $post_status = 'draft';
     2678    if ( isset($post_parent) )
     2679        $post_parent = (int) $post_parent;
     2680    else
     2681        $post_parent = 0;
     2682
     2683    // Check the post_parent to see if it will cause a hierarchy loop
     2684    $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr );
     2685
     2686    // Check to see if the post parent is unpublished. If so, set this post status to match.
     2687        if ( isset( $post_parent ) && $post_parent ) {
     2688        $post_parent_object = get_post( $post_parent );
     2689        if ( 'publish' !== $post_parent_object->post_status ) {
     2690            $post_status = $post_parent_object->post_status;
     2691        }
     2692    }
     2693    if ( empty($post_status) )
     2694        $post_status = 'draft';
    26802695
    26812696        if ( !empty($post_category) )
    26822697                $post_category = array_filter($post_category); // Filter out empty terms
     
    27702785
    27712786        if ( ! isset($pinged) )
    27722787                $pinged = '';
    2773 
    2774         if ( isset($post_parent) )
    2775                 $post_parent = (int) $post_parent;
    2776         else
    2777                 $post_parent = 0;
    2778 
    2779         // Check the post_parent to see if it will cause a hierarchy loop
    2780         $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr );
    27812788
    27822789        if ( isset($menu_order) )
    27832790                $menu_order = (int) $menu_order;
  • wp-admin/js/post.js

     
    515515                        if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
    516516                                publishOn = postL10n.publishOnFuture;
    517517                                $('#publish').val( postL10n.schedule );
    518                         } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
     518                        } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' && $('#unpublished_parent').val() != 1 ) {
    519519                                publishOn = postL10n.publishOn;
    520520                                $('#publish').val( postL10n.publish );
    521521                        } else {
  • wp-includes/js/autosave.js

     
    176176
    177177                        if ( res.responses[0].data ) // update autosave message
    178178                                jQuery('.autosave-message').text( res.responses[0].data );
     179
     180            if ( res.responses[0].supplemental.parent_status ) // update hidden unpublished_parent field
     181                jQuery('#unpublished_parent').val( res.responses[0].supplemental.parent_status );
    179182                }
    180183        }
    181184
  • wp-admin/includes/ajax-actions.php

     
    10811081                                $id = $post->ID;
    10821082                }
    10831083
     1084        $parent_status = get_post_status( $post->post_parent );
     1085        if ( $parent_status !== 'publish' )
     1086            $supplemental['replace-unpublished_parent'] = 1;
     1087
    10841088                if ( ! is_wp_error($id) ) {
    10851089                        /* translators: draft saved date format, see http://php.net/date */
    10861090                        $draft_saved_date_format = __('g:i:s a');