Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

Courses Settings Page

class Prakmed_Course_Settings_Page {

	public function __construct() {

		add_action( 'admin_menu', array( $this, 'add_admin_menu' ) );
		add_action( 'admin_init', array( $this, 'init_settings'  ) );

	}

	public function add_admin_menu() {

		add_submenu_page(
			'/edit.php?post_type=prakmed_course',
			esc_html__( 'Course settings', 'bam_courses_launcher' ),
			esc_html__( 'Settings', 'bam_courses_launcher' ),
			'manage_options',
			'course-setting',
			array( $this, 'page_layout' )
		);

	}

	public function init_settings() {

		register_setting(
			'prakmed_course_settings_group',
			'prakmed_course_settings'
		);

		add_settings_section(
			'prakmed_course_settings_section',
			'',
			false,
			'prakmed_course_settings'
		);

		add_settings_field(
			'learninglocker_key',
			__( 'Learninglocker key', 'bam_courses_launcher' ),
			array( $this, 'render_learninglocker_key_field' ),
			'prakmed_course_settings',
			'prakmed_course_settings_section'
		);
		add_settings_field(
			'learninglocker_secret',
			__( 'Learninglocker secret', 'bam_courses_launcher' ),
			array( $this, 'render_learninglocker_secret_field' ),
			'prakmed_course_settings',
			'prakmed_course_settings_section'
		);
		add_settings_field(
			'course_launcher',
			__( 'Course launcher URL', 'bam_courses_launcher' ),
			array( $this, 'render_course_launcher_field' ),
			'prakmed_course_settings',
			'prakmed_course_settings_section'
		);
		add_settings_field(
			'course_upload_folder',
			__( 'Course upload folder', 'bam_courses_launcher' ),
			array( $this, 'render_course_upload_folder_field' ),
			'prakmed_course_settings',
			'prakmed_course_settings_section'
		);

	}

	public function page_layout() {

		// Check required user capability
		if ( !current_user_can( 'manage_options' ) )  {
			wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'bam_courses_launcher' ) );
		}

		// Admin Page Layout
		echo '<div class="wrap">' . "n";
		echo '	<h1>' . get_admin_page_title() . '</h1>' . "n";
		echo '	<form action="options.php" method="post">' . "n";

		settings_fields( 'prakmed_course_settings_group' );
		do_settings_sections( 'prakmed_course_settings' );
		submit_button();

		echo '	</form>' . "n";
		echo '</div>' . "n";

	}

	function render_learninglocker_key_field() {

		// Retrieve data from the database.
		$options = get_option( 'prakmed_course_settings' );

		// Set default value.
		$value = isset( $options['learninglocker_key'] ) ? $options['learninglocker_key'] : '';

		// Field output.
		echo '<input type="text" name="prakmed_course_settings[learninglocker_key]" class="regular-text learninglocker_key_field" placeholder="' . esc_attr__( '', 'bam_courses_launcher' ) . '" value="' . esc_attr( $value ) . '">';
		echo '<p class="description">' . __( 'Public key for Learning locker launcher', 'bam_courses_launcher' ) . '</p>';

	}

	function render_learninglocker_secret_field() {

		// Retrieve data from the database.
		$options = get_option( 'prakmed_course_settings' );

		// Set default value.
		$value = isset( $options['learninglocker_secret'] ) ? $options['learninglocker_secret'] : '';

		// Field output.
		echo '<input type="text" name="prakmed_course_settings[learninglocker_secret]" class="regular-text learninglocker_secret_field" placeholder="' . esc_attr__( '', 'bam_courses_launcher' ) . '" value="' . esc_attr( $value ) . '">';
		echo '<p class="description">' . __( 'Secret key for Learning locker launcher', 'bam_courses_launcher' ) . '</p>';

	}

	function render_course_launcher_field() {

		// Retrieve data from the database.
		$options = get_option( 'prakmed_course_settings' );

		// Set default value.
		$value = isset( $options['course_launcher'] ) ? $options['course_launcher'] : '';

		// Field output.
		echo '<input type="url" name="prakmed_course_settings[course_launcher]" class="regular-text course_launcher_field" placeholder="' . esc_attr__( 'https://launcher.learninglocker.net/', 'bam_courses_launcher' ) . '" value="' . esc_attr( $value ) . '">';
		echo '<p class="description">' . __( 'The URL of the service providing the learning record store', 'bam_courses_launcher' ) . '</p>';

	}

	function render_course_upload_folder_field() {

		// Retrieve data from the database.
		$options = get_option( 'prakmed_course_settings' );

		// Set default value.
		$value = isset( $options['course_upload_folder'] ) ? $options['course_upload_folder'] : '';

		// Field output.
		echo '<input type="text" name="prakmed_course_settings[course_upload_folder]" class="regular-text course_upload_folder_field" placeholder="' . esc_attr__( '', 'bam_courses_launcher' ) . '" value="' . esc_attr( $value ) . '">';
		echo '<p class="description">' . __( 'The name of the name of folder, where xApi courses ar uploaded', 'bam_courses_launcher' ) . '</p>';

	}

}

new Prakmed_Course_Settings_Page;