WordPress.org

Make WordPress Core

Ticket #8592: 8592.5.diff

File 8592.5.diff, 9.1 KB (added by sillybean, 6 years ago)

Add filters to args for wp_list_pages() and wp_dropdown_pages() except on Reading Settings; force child pages of unpublished parents to inherit status and password

  • src/wp-includes/post.php

     
    27152715        if ( empty($post_type) )
    27162716                $post_type = 'post';
    27172717
     2718    if ( isset($post_parent) )
     2719        $post_parent = (int) $post_parent;
     2720    else
     2721        $post_parent = 0;
     2722
     2723    // Check the post_parent to see if it will cause a hierarchy loop
     2724    $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr );
     2725
     2726    // Check to see if the post parent is unpublished. If so, set this post status to match.
     2727        if ( isset($post_parent) && $post_parent ) {
     2728                $post_parent_object = get_post( $post_parent );
     2729                if ( 'publish' !== $post_parent_object->post_status ) {
     2730                        $post_status = $post_parent_object->post_status;
     2731                }
     2732                // Set this post's password if its parent had one.
     2733                if ( !empty($post_parent_object->post_password) )
     2734                        $post_password = $post_parent_object->post_password;
     2735    }
    27182736        if ( empty($post_status) )
    27192737                $post_status = 'draft';
    27202738
     
    28102828
    28112829        if ( ! isset($pinged) )
    28122830                $pinged = '';
    2813 
    2814         if ( isset($post_parent) )
    2815                 $post_parent = (int) $post_parent;
    2816         else
    2817                 $post_parent = 0;
    2818 
    2819         // Check the post_parent to see if it will cause a hierarchy loop
    2820         $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr );
    28212831
    28222832        if ( isset($menu_order) )
    28232833                $menu_order = (int) $menu_order;
  • src/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 {
  • src/wp-includes/post-template.php

     
    784784        );
    785785
    786786        $r = wp_parse_args( $args, $defaults );
     787        $r = apply_filters( 'wp_dropdown_pages_args', $r );
     788        if ( is_admin() ) {
     789                // revert to default (public) post_status on the Reading Settings page
     790                if ( 'options-reading' == get_current_screen()->base )
     791                        unset( $r['post_status'] );
     792        }
    787793        extract( $r, EXTR_SKIP );
    788794
    789795        $pages = get_pages($r);
     
    829835        );
    830836
    831837        $r = wp_parse_args( $args, $defaults );
     838        $r = apply_filters( 'wp_list_pages_args', $r );
    832839        extract( $r, EXTR_SKIP );
    833840
    834841        $output = '';
  • src/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
  • src/wp-admin/includes/ajax-actions.php

     
    10821082                                $id = $post->ID;
    10831083                }
    10841084
     1085                $parent_status = get_post_status( $post->post_parent );
     1086                $parent_password = get_post_field( 'post_password', $post->post_parent );
     1087                if ( $parent_status !== 'publish' )
     1088                $supplemental['replace-unpublished_parent'] = 1;
     1089                elseif ( !empty($parent_password) )
     1090                        $supplemental['replace-unpublished_parent'] = 2;
     1091
    10851092                if ( ! is_wp_error($id) ) {
    10861093                        /* translators: draft saved date format, see http://php.net/date */
    10871094                        $draft_saved_date_format = __('g:i:s a');
  • src/wp-admin/includes/meta-boxes.php

     
    1515        $post_type = $post->post_type;
    1616        $post_type_object = get_post_type_object($post_type);
    1717        $can_publish = current_user_can($post_type_object->cap->publish_posts);
     18        $unpublished_parent = 0;
     19        if ( isset( $post->post_parent ) && $post->post_parent ) {
     20                $parent_status = get_post_status( $post->post_parent );
     21                $parent_password = get_post_field( 'post_password', $post->post_parent );
     22                if ( 'publish' !== $parent_status ) {
     23                        $unpublished_parent = 1;
     24                        $post->post_status = $parent_status;
     25                }
     26                elseif ( !empty( $parent_password ) ) {
     27                        $unpublished_parent = 2;
     28                }
     29    }
    1830?>
    1931<div class="submitbox" id="submitpost">
    2032
     
    2335<?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?>
    2436<div style="display:none;">
    2537<?php submit_button( __( 'Save' ), 'button', 'save' ); ?>
     38<input type="hidden" name="unpublished_parent" id="unpublished_parent" value="<?php echo
     39esc_attr($unpublished_parent); ?>" />
    2640</div>
    2741
    2842<div id="minor-publishing-actions">
     
    124138}
    125139
    126140echo esc_html( $visibility_trans ); ?></span>
    127 <?php if ( $can_publish ) { ?>
     141<?php if ( 1 == $unpublished_parent ) { ?>
     142<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>
     143<?php } elseif ( $can_publish ) { ?>
    128144<a href="#visibility" class="edit-visibility hide-if-no-js"><?php _e('Edit'); ?></a>
    129145
    130146<div id="post-visibility-select" class="hide-if-js">
     147        <?php if ( 2 == $unpublished_parent ) { ?>
     148                <p><?php printf('This is a child of <a href="%s">a password-protected page</a>. To remove this page\'s password, you must first remove its parent\'s.', get_edit_post_link( $post->post_parent ) ); ?></p>
     149        <?php } ?>
    131150<input type="hidden" name="hidden_post_password" id="hidden-post-password" value="<?php echo esc_attr($post->post_password); ?>" />
    132151<?php if ($post_type == 'post'): ?>
    133152<input type="checkbox" style="display:none" name="hidden_post_sticky" id="hidden-post-sticky" value="sticky" <?php checked(is_sticky($post->ID)); ?> />
    134153<?php endif; ?>
    135154<input type="hidden" name="hidden_post_visibility" id="hidden-post-visibility" value="<?php echo esc_attr( $visibility ); ?>" />
    136 <input type="radio" name="visibility" id="visibility-radio-public" value="public" <?php checked( $visibility, 'public' ); ?> /> <label for="visibility-radio-public" class="selectit"><?php _e('Public'); ?></label><br />
     155<input type="radio" name="visibility" id="visibility-radio-public" value="public" <?php checked( $visibility, 'public' ); ?> <?php if ( 2 == $unpublished_parent ) echo 'disabled'; ?> /> <label for="visibility-radio-public" class="selectit"><?php _e('Public'); ?></label><br />
    137156<?php if ( $post_type == 'post' && current_user_can( 'edit_others_posts' ) ) : ?>
    138157<span id="sticky-span"><input id="sticky" name="sticky" type="checkbox" value="sticky" <?php checked( is_sticky( $post->ID ) ); ?> /> <label for="sticky" class="selectit"><?php _e( 'Stick this post to the front page' ); ?></label><br /></span>
    139158<?php endif; ?>
    140159<input type="radio" name="visibility" id="visibility-radio-password" value="password" <?php checked( $visibility, 'password' ); ?> /> <label for="visibility-radio-password" class="selectit"><?php _e('Password protected'); ?></label><br />
    141160<span id="password-span"><label for="post_password"><?php _e('Password:'); ?></label> <input type="text" name="post_password" id="post_password" value="<?php echo esc_attr($post->post_password); ?>"  maxlength="20" /><br /></span>
    142 <input type="radio" name="visibility" id="visibility-radio-private" value="private" <?php checked( $visibility, 'private' ); ?> /> <label for="visibility-radio-private" class="selectit"><?php _e('Private'); ?></label><br />
     161<input type="radio" name="visibility" id="visibility-radio-private" value="private" <?php checked( $visibility, 'private' ); ?> <?php if ( 2 == $unpublished_parent ) echo 'disabled'; ?> /> <label for="visibility-radio-private" class="selectit"><?php _e('Private'); ?></label><br />
    143162
    144163<p>
    145164 <a href="#visibility" class="save-post-visibility hide-if-no-js button"><?php _e('OK'); ?></a>
     
    220239<div id="publishing-action">
    221240<span class="spinner"></span>
    222241<?php
    223 if ( !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0 == $post->ID ) {
     242if ( !$unpublished_parent && !in_array( $post->post_status, array('publish', 'future', 'private') ) || 0 == $post->ID ) {
    224243        if ( $can_publish ) :
    225244                if ( !empty($post->post_date_gmt) && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) : ?>
    226245                <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr_e('Schedule') ?>" />