add_action( 'admin_init', $this, 'maybe_generate_archive' ); } public function maybe_generate_archive(): void { static::generate_if_needed(); // One-time flush to remove the CPT /projects/ rewrite rule now that the // CPT uses rewrite:false and WP pages own that URL pattern exclusively. if ( ! get_option( 'academiccrew_collab_rewrite_flushed_v2' ) ) { flush_rewrite_rules( false ); update_option( 'academiccrew_collab_rewrite_flushed_v2', 1 ); } } /** * Creates the archive page and stores its ID in options. * Safe to call multiple times — updates title/content if the page exists * with the old "Collaborations" values from a prior install. */ public static function generate_if_needed(): void { $page_id = (int) get_option( 'academiccrew_collaborations_archive_page_id', 0 ); if ( $page_id && ( $page = get_post( $page_id ) ) && 'trash' !== $page->post_status ) { $updates = []; if ( in_array( $page->post_title, [ 'Collaborations', 'Research Projects' ], true ) ) { $updates['post_title'] = __( 'Projects', 'academiccrew' ); $updates['post_name'] = 'projects'; } if ( '[academiccrew_collaborations]' === trim( $page->post_content ) ) { $updates['post_content'] = '[academiccrew_projects]'; } if ( $updates ) { $updates['ID'] = $page_id; wp_update_post( $updates ); } // 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' => __( 'Projects', 'academiccrew' ), 'post_content' => '[academiccrew_projects]', 'post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'projects', 'meta_input' => [ '_academiccrew_is_collaborations_archive' => 1, 'pyre_page_title' => 'no', 'pyre_sidebar_position' => 'none', ], ], true ); if ( ! is_wp_error( $page_id ) && $page_id ) { update_option( 'academiccrew_collaborations_archive_page_id', $page_id ); } } }