add_action( 'admin_init', $this, 'maybe_generate_archive' ); } public function maybe_generate_archive(): void { static::generate_if_needed(); } /** * Creates the archive page and stores its ID in options. * Safe to call multiple times — skips if a published page already exists. */ public static function generate_if_needed(): void { $page_id = (int) get_option( 'academiccrew_publications_archive_page_id', 0 ); if ( $page_id && ( $page = get_post( $page_id ) ) && 'trash' !== $page->post_status ) { // Ensure Avada metas are present (idempotent). Clear fusion_builder_status // so Fusion Builder does not try to load its editor on this page. update_post_meta( $page_id, 'pyre_page_title', 'no' ); update_post_meta( $page_id, 'pyre_sidebar_position', 'none' ); update_post_meta( $page_id, 'fusion_builder_status', '' ); return; } $page_id = wp_insert_post( [ 'post_title' => __( 'Publications', 'academiccrew' ), 'post_content' => '[academiccrew_publications_archive]', 'post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'publications', 'meta_input' => [ '_academiccrew_is_publications_archive' => 1, 'pyre_page_title' => 'no', 'pyre_sidebar_position' => 'none', ], ], true ); if ( ! is_wp_error( $page_id ) && $page_id ) { update_option( 'academiccrew_publications_archive_page_id', $page_id ); } } }