From eb76edcc320707fdcd53d0812967b2e74204ab4e Mon Sep 17 00:00:00 2001 From: Lucas Garczewski Date: Sun, 13 Dec 2020 23:18:45 +0100 Subject: [PATCH] correctly untrash functional pages (#21) --- bip-pages-activation.php | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/bip-pages-activation.php b/bip-pages-activation.php index 8b23e8b..fe0398f 100644 --- a/bip-pages-activation.php +++ b/bip-pages-activation.php @@ -28,10 +28,15 @@ function create_page( $title, $content = '' ) { } function create_functional_page( $title, $content = '' ) { - if ( !is_page( $title ) ) { - $page_id = create_page( $title, $content ); + $page = get_page_by_title( $title, OBJECT, 'bip' ); + + if ( $page && get_post_status( $page ) != 'trash' ) { + $page_id = $page->ID; + } elseif ( get_post_status( $page ) == 'trash' ) { + $new_page = wp_untrash_post( $page->ID ); + $page_id = $new_page->ID; } else { - $page_id = untrash_page( $title ); + $page_id = create_page( $title, $content ); } return $page_id; @@ -62,18 +67,6 @@ function create_instructions_page() { } } -function untrash_page( $title ) { - $page = WP_Post( $title ); - - if ( get_post_status( $page->ID ) == 'trash' ) { - untrash_post( $page ); - } else { - // error handling here - } - - return $page->ID; -} - function add_logo_widget() { // initialize widget properties if not set yet if ( empty( get_option( 'widget_bip-logo' ) ) ) {