Make WordPress Core

Changeset 25686


Ignore:
Timestamp:
10/03/2013 03:50:26 AM (11 years ago)
Author:
nacin
Message:

Reset "Page on Front" when such a page is trashed.

props danielbachhuber.
fixes #24171.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r25669 r25686  
    23182318    }
    23192319
    2320     if ( 'page' == $post->post_type) {
    2321         // if the page is defined in option page_on_front or post_for_posts,
    2322         // adjust the corresponding options
    2323         if ( get_option('page_on_front') == $postid ) {
    2324             update_option('show_on_front', 'posts');
    2325             delete_option('page_on_front');
    2326         }
    2327         if ( get_option('page_for_posts') == $postid ) {
    2328             delete_option('page_for_posts');
    2329         }
    2330     } else {
    2331         unstick_post($postid);
    2332     }
    2333 
    23342320    // Do raw query. wp_get_post_revisions() is filtered
    23352321    $revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) );
     
    23662352    return $post;
    23672353}
     2354
     2355/**
     2356 * Resets the page_on_front, show_on_front, and page_for_post settings when a
     2357 * linked page is deleted or trashed.
     2358 *
     2359 * Also ensures the post is no longer sticky.
     2360 *
     2361 * @access private
     2362 * @since 3.7.0
     2363 * @param $post_id
     2364 */
     2365function _reset_front_page_settings_for_post( $post_id ) {
     2366    $post = get_post( $post_id );
     2367    if ( 'page' == $post->post_type ) {
     2368        // If the page is defined in option page_on_front or post_for_posts,
     2369        // adjust the corresponding options
     2370        if ( get_option( 'page_on_front' ) == $post->ID ) {
     2371            update_option( 'show_on_front', 'posts' );
     2372            update_option( 'page_on_front', 0 );
     2373        }
     2374        if ( get_option( 'page_for_posts' ) == $post->ID ) {
     2375            delete_option( 'page_for_posts', 0 );
     2376        }
     2377    }
     2378    unstick_post( $post->ID );
     2379}
     2380add_action( 'before_delete_post', '_reset_front_page_settings_for_post' );
     2381add_action( 'wp_trash_post',      '_reset_front_page_settings_for_post' );
    23682382
    23692383/**
Note: See TracChangeset for help on using the changeset viewer.