post_type && 'trash' !== $page->post_status ) { return $page; } } // Migration fallback: look up by the original slug. $page = get_page_by_path( self::PAGE_SLUG ); if ( $page ) { update_option( self::OPTION_PAGE_ID, $page->ID ); } return $page; } /** * Create the temporary page on plugin activation. */ public static function create_temporary_page() { // Re-use an already tracked page if possible. $existing_id = self::get_temporary_page_id(); if ( $existing_id ) { $page = get_post( $existing_id ); if ( $page && 'page' === $page->post_type && 'trash' !== $page->post_status ) { if ( 'draft' === $page->post_status ) { wp_update_post( array( 'ID' => $existing_id, 'post_status' => 'publish', ) ); } return $existing_id; } } // Migration: check by slug for installs that pre-date ID storage. $existing_page = get_page_by_path( self::PAGE_SLUG ); if ( $existing_page ) { if ( in_array( $existing_page->post_status, array( 'draft', 'trash' ), true ) ) { wp_update_post( array( 'ID' => $existing_page->ID, 'post_status' => 'publish', ) ); } update_option( self::OPTION_PAGE_ID, $existing_page->ID ); return $existing_page->ID; } // Create a fresh page. $page_id = wp_insert_post( array( 'post_title' => __( 'Almost Ready', 'almost-ready-temporary-page' ), 'post_name' => self::PAGE_SLUG, 'post_content' => self::get_default_content(), 'post_status' => 'publish', 'post_type' => 'page', 'post_author' => get_current_user_id(), 'meta_input' => array( '_artp_temporary_page' => '1', '_wp_page_template' => 'blank', ), ) ); if ( $page_id && ! is_wp_error( $page_id ) ) { update_option( self::OPTION_PAGE_ID, $page_id ); } return $page_id; } /** * Publish the temporary page (activate maintenance mode). */ public static function activate_temporary_page() { $page = self::get_temporary_page(); if ( $page && 'publish' !== $page->post_status ) { wp_update_post( array( 'ID' => $page->ID, 'post_status' => 'publish', ) ); } } /** * Set the temporary page to draft (deactivate maintenance mode). */ public static function deactivate_temporary_page() { $page = self::get_temporary_page(); if ( $page && 'publish' === $page->post_status ) { wp_update_post( array( 'ID' => $page->ID, 'post_status' => 'draft', ) ); } } /** * Get the default block content for the temporary page. * * @return string Block content. */ private static function get_default_content() { $content = '

✨ Almost Ready!

We\'re putting the finishing touches on something great. Check back soon!

In the meantime, feel free to reach out if you have any questions.

'; return $content; } }