WordPress Multisite CPT URL

Ich habe mit der Entwicklung eines Plugins für WordPress auf einer Multisite-Installation begonnen und benötige spezielle URLs für die CPTs, die ich mit dem Plugin registriere.

Ich habe CPTs wie: Benutzer, Produkte, Mitgliedschaften .. etc. und ich brauche URLs wie:

http: // {client} .beispiel.com / user / {slug} | {id} / profile

Die Installation erfolgt also auf Subdomain-Basis. Um beispielsweise ein Benutzerprofil anzuzeigen, muss auf diese URL zugegriffen werden.

Ich habe diesen Code bisher:

flush_rules(); } } function gym_create_admin_menu() { add_menu_page( __('GymApp'), __('GymApp'), 'manage_options', $this->plugin_slug, array( $this, 'gym_dashboard'), 'dashicons-id', 20 ); } function gym_dashboard() { } function gym_register_cpts() { register_post_type( 'gyms', array( 'label' => 'Gyms', 'public' => false, 'exclude_from_search' => false, 'show_ui' => true, 'show_in_menu' => $this->plugin_slug, 'menu_position' => 10, 'rewrite' => array( 'slug' => 'gym' ) ) ); register_post_type( 'users', array( 'label' => 'Users', 'public' => false, 'exclude_from_search' => false, 'show_ui' => true, 'show_in_menu' => $this->plugin_slug, 'menu_position' => 20, 'rewrite' => array( 'slug' => 'user' ) ) ); register_post_type( 'products', array( 'label' => 'Products', 'public' => false, 'exclude_from_search' => false, 'show_ui' => true, 'show_in_menu' => $this->plugin_slug, 'menu_position' => 30, 'rewrite' => array( 'slug' => 'product' ) ) ); register_post_type( 'memberships', array( 'label' => 'Memberships', 'public' => false, 'exclude_from_search' => false, 'show_ui' => true, 'show_in_menu' => $this->plugin_slug, 'menu_position' => 40, 'rewrite' => array( 'slug' => 'membership' ) ) ); register_post_type( 'staff', array( 'label' => 'Staff', 'public' => false, 'exclude_from_search' => false, 'show_ui' => true, 'show_in_menu' => $this->plugin_slug, 'menu_position' => 50, 'rewrite' => array( 'slug' => 'staff' ) ) ); } function gym_rewrite_url( ) { add_rewrite_endpoint( 'users', EP_PERMALINK | EP_PAGES ); add_rewrite_rule('^user/([0-9]+)/profile', 'index.php?post_type=users&user_id=$matches[1]', 'top' ); add_rewrite_rule('^user/([0-9]+)/profile', 'index.php?post_type=users&user_id=$matches[1]&profile=yes', 'top' ); add_rewrite_rule('^user/([0-9]+)/details', 'index.php?post_type=users&user_id=$matches[1]&details=yes', 'top' ); } function gym_query_vars( $query_vars ) { $query_vars[] = 'post_type'; $query_vars[] = 'user_id'; $query_vars[] = 'details'; $query_vars[] = 'profile'; return $query_vars; } function gym_page_template( ) { global $wp_query; $this->debug( $wp_query ); if ( get_query_var( 'profile' ) && is_singular( 'users' ) ) { add_filter( 'template_include', function() { return dirname( __FILE__ ) . '/../templates/page-user.php'; }); } if ( get_query_var( 'details' ) && is_singular( 'users' ) ) { add_filter( 'template_include', function() { return dirname( __FILE__ ) . '/../templates/page-user.php'; }); } } function debug( $what ) { echo '
'; var_dump( $what ); echo '

'; }

}

Jede Hilfe wird sehr geschätzt!

Vielen Dank

Solutions Collecting From Web of "WordPress Multisite CPT URL"