add_action( 'init', $this, 'register_cpt' ); $loader->add_filter( 'post_type_link', $this, 'linked_page_permalink', 10, 2 ); $loader->add_filter( 'use_block_editor_for_post_type', $this, 'disable_block_editor', 10, 2 ); } public function disable_block_editor( bool $use, string $post_type ): bool { return 'acc_collaboration' === $post_type ? false : $use; } /** * Redirect the CPT permalink to the linked WP page so the admin "View" * button and get_permalink() both point to the canonical front-end URL. */ public function linked_page_permalink( string $url, \WP_Post $post ): string { if ( $post->post_type !== 'acc_collaboration' ) { return $url; } $page_id = (int) get_post_meta( $post->ID, '_academiccrew_linked_page_id', true ); if ( ! $page_id ) { return $url; } // Use get_post() + build the page URL without triggering this filter again. $page = get_post( $page_id ); if ( ! $page || $page->post_type !== 'page' ) { return $url; } $page_url = get_permalink( $page ); return $page_url ?: $url; } public function register_cpt(): void { $labels = [ 'name' => __( 'Research Projects', 'academiccrew' ), 'singular_name' => __( 'Research Project', 'academiccrew' ), 'add_new' => __( 'Add New', 'academiccrew' ), 'add_new_item' => __( 'Add New Research Project', 'academiccrew' ), 'edit_item' => __( 'Edit Research Project', 'academiccrew' ), 'new_item' => __( 'New Research Project', 'academiccrew' ), 'view_item' => __( 'View Research Project', 'academiccrew' ), 'search_items' => __( 'Search Research Projects', 'academiccrew' ), 'not_found' => __( 'No research projects found.', 'academiccrew' ), 'not_found_in_trash' => __( 'No research projects found in Trash.', 'academiccrew' ), 'all_items' => __( 'All Research Projects', 'academiccrew' ), 'menu_name' => __( 'Research Projects', 'academiccrew' ), ]; register_post_type( 'acc_collaboration', [ 'labels' => $labels, 'public' => true, 'publicly_queryable' => false, 'show_ui' => true, 'show_in_menu' => true, 'show_in_rest' => true, 'menu_icon' => 'dashicons-analytics', 'capability_type' => 'post', 'has_archive' => false, 'rewrite' => false, 'supports' => [ 'title', 'editor', 'thumbnail', 'custom-fields' ], 'query_var' => true, ] ); } }