Skip to content

Commit

Permalink
correctly untrash functional pages (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarczewski committed Dec 13, 2020
1 parent a1e86cc commit eb76edc
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions bip-pages-activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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' ) ) ) {
Expand Down

0 comments on commit eb76edc

Please sign in to comment.