WordPress.org

Make WordPress Core

Ticket #17913: meta-boxes.diff

File meta-boxes.diff, 1.7 KB (added by niallkennedy, 8 years ago)

Disable comments input checkbox in post meta box if change will have no effect

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

     
    444444?>
    445445<input name="advanced_view" type="hidden" value="1" />
    446446<p class="meta-options">
    447         <label for="comment_status" class="selectit"><input name="comment_status" type="checkbox" id="comment_status" value="open" <?php checked($post->comment_status, 'open'); ?> /> <?php _e( 'Allow comments.' ) ?></label><br />
     447        <label for="comment_status" class="selectit"><input name="comment_status" type="checkbox" id="comment_status" value="open" <?php
     448
     449        $checked = false;
     450        if ( $post->comment_status === 'open' )
     451                $checked = true;
     452
     453        if ( get_option( 'close_comments_for_old_posts', false ) ) {
     454                $last_allowed_time = current_time( 'timestamp', 1 ) - ( absint( get_option( 'close_comments_days_old', 0 ) ) * 24 * 60 * 60 ); // now - days in seconds
     455                $post_timestamp = mysql2date( 'U', $post->post_date_gmt, false );
     456                if ( $post_timestamp < $last_allowed_time ) {
     457                        $checked = false;
     458                        echo 'disabled="disabled" ';
     459                }
     460        }
     461        if ( $checked )
     462                echo 'checked="checked"';
     463        ?> /> <?php _e( 'Allow comments.' ) ?></label><br />
    448464        <label for="ping_status" class="selectit"><input name="ping_status" type="checkbox" id="ping_status" value="open" <?php checked($post->ping_status, 'open'); ?> /> <?php printf( __( 'Allow <a href="%s" target="_blank">trackbacks and pingbacks</a> on this page.' ), __( 'http://codex.wordpress.org/Introduction_to_Blogging#Managing_Comments' ) ); ?></label>
    449465        <?php do_action('post_comment_status_meta_box-options', $post); ?>
    450466</p>