Permalinks::add_rewrite_rules( $wp_rewrite )


Source

File: classes/Permalinks.php

	public function add_rewrite_rules( $wp_rewrite ) {
		$course_base_slug     = dozent_course_base_slug();
		$lecture_base_slug    = dozent_lecture_base_slug();
		$quiz_base_slug       = dozent_quiz_base_slug();
		$assignment_base_slug = dozent_assignment_base_slug();

		$new_rules = [
			//Lesson Permalink
			$course_base_slug . "/(.+?)/{$lecture_base_slug}/(.+?)/?$"    => "index.php?post_type=dozent_lecture&name=" . $wp_rewrite->preg_index( 2 ),
			//Quiz Permalink
			$course_base_slug . "/(.+?)/{$quiz_base_slug}/(.+?)/?$"       => "index.php?post_type=dozent_quiz&name=" . $wp_rewrite->preg_index( 2 ),
			//Assignments URL
			$course_base_slug
			. "/(.+?)/{$assignment_base_slug}/(.+?)/?$" => "index.php?post_type=dozent_assignment&name=" . $wp_rewrite->preg_index( 2 ),

			//Private Video URL
			"video-url/(.+?)/?$" => "index.php?post_type=dozent_lecture&lecture_video=true&name=" . $wp_rewrite->preg_index( 1 ),
			//Student Public Profile URL
			"profile/(.+?)/(.+?)/?$" => "index.php?dozent_profile_username=" . $wp_rewrite->preg_index( 1 ) . "&profile_sub_page=" . $wp_rewrite->preg_index( 2 ),
			"profile/(.+?)/?$" => "index.php?dozent_profile_username=" . $wp_rewrite->preg_index( 1 ),
		];

		//Dashboard URL
		$dashboard_permalink_groups = dozent_dashboard_permalinks();

		foreach ( $dashboard_permalink_groups as $dashboard_pages ) {
			foreach ( $dashboard_pages as $dashboard_page ) {
				$page_id = dozent_array_get( 'id', $dashboard_page );

				$new_rules["(.+?)/{$page_id}/?$"] = 'index.php?pagename=' . $wp_rewrite->preg_index( 1 ) . '&dozent_dashboard_page=' . $page_id;

				//Sub Page of dashboard sub page
				//regext = ([^/]*)
				$new_rules["(.+?)/{$page_id}/(.+?)/?$"] = 'index.php?pagename=' . $wp_rewrite->preg_index( 1 ) . '&dozent_dashboard_page=' . $page_id . '&dozent_dashboard_sub_page=' . $wp_rewrite->preg_index( 2 );
			}
		}

		$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
	}