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 — updates title/slug if the page exists with old values. */ public static function generate_if_needed(): void { $page_id = (int) get_option( 'academiccrew_members_archive_page_id', 0 ); if ( $page_id && ( $page = get_post( $page_id ) ) && 'trash' !== $page->post_status ) { $updates = []; if ( in_array( $page->post_title, [ 'Team', 'Teams' ], true ) ) { $updates['post_title'] = __( 'People', 'academiccrew' ); $updates['post_name'] = 'people'; } 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' => __( 'People', 'academiccrew' ), 'post_content' => '[academiccrew_members_archive]', 'post_status' => 'publish', 'post_type' => 'page', 'post_name' => 'people', 'meta_input' => [ '_academiccrew_is_members_archive' => 1, 'pyre_page_title' => 'no', 'pyre_sidebar_position' => 'none', ], ], true ); if ( ! is_wp_error( $page_id ) && $page_id ) { update_option( 'academiccrew_members_archive_page_id', $page_id ); } } }