• Resolved 2shaynez

    (@2shaynez)


    I just went through hell after updating to 4.1
    I’ve worked out all my kinks except for 1

    for the past year I have been using this piece of code in my theme’s functions.php (minus the backtics ` obviously) to automatically delete my sample page every time I make a new site:

    5 // Find and delete the WP default 'Sample Page'
    6 $defaultPage = get_page_by_title( 'Sample Page' );
    7 wp_delete_post( $defaultPage->ID );

    However, all of a sudden, I am getting this error:
    Notice: Trying to get property of non-object in ../wp-content/themes/Nuvellen/functions.php on line 7

    I just did a test by making a new site, and it does delete the sample page, but I can’t figure out why it would give me this error all of a sudden

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • You should do a check to see that defaultPage is not empty before you attempt to delete it. That is most likely your problem. The sample pages was deleted; and the next time the code is run it attempts to delete a non-object.

    Thread Starter 2shaynez

    (@2shaynez)

    Is defaultPage defined anywhere else, perhaps within the default wordpress files. I keep this at the top of my functions.php on numerous 1000+ site networks and never had a problem. I get what you mean by it running and trying to find something that isn’t there but it wouldn’t make sense that I’ve never had this problem before. Also that would defeat the purpose of this widely used script…

    Thread Starter 2shaynez

    (@2shaynez)

    Solution: I had wp-debug set to true when trying to battle multiple bugs after updating to 4.1. Forgot to switch back to false, fixed her right up!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Automatic Sample Page Delete’ is closed to new replies.