Or, embed this snippet using GenerateWP WordPress Plugin.

Download

Clone

NCAA

class Custom_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_options_page(
			esc_html__( '', 'text_domain' ),
			esc_html__( '', 'text_domain' ),
			'manage_options',
			'',
			array( $this, 'page_layout' )
		);

	}

	public function init_settings() {

		register_setting(
			'settings_group',
			'settings_name'
		);

		add_settings_section(
			'settings_name_section',
			'',
			false,
			'settings_name'
		);

		add_settings_field(
			'student_registration_form_pdf',
			__( 'Student Registration form PDF', 'text_domain' ),
			array( $this, 'render_student_registration_form_pdf_field' ),
			'settings_name',
			'settings_name_section'
		);
		add_settings_field(
			'this_month_calendar_pdf',
			__( 'This Month Calendar PDF', 'text_domain' ),
			array( $this, 'render_this_month_calendar_pdf_field' ),
			'settings_name',
			'settings_name_section'
		);
		add_settings_field(
			'this_year_school_calendar_pdf',
			__( 'This Year School Calendar PDF', 'text_domain' ),
			array( $this, 'render_this_year_school_calendar_pdf_field' ),
			'settings_name',
			'settings_name_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.', 'text_domain' ) );
		}

		// 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( 'settings_group' );
		do_settings_sections( 'settings_name' );
		submit_button();

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

	}

	function render_student_registration_form_pdf_field() {

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

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

		// Field output.
		echo '<input type="url" name="settings_name[student_registration_form_pdf]" class="regular-text student_registration_form_pdf_field" placeholder="' . esc_attr__( '', 'text_domain' ) . '" value="' . esc_attr( $value ) . '">';

	}

	function render_this_month_calendar_pdf_field() {

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

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

		// Field output.
		echo '<input type="url" name="settings_name[this_month_calendar_pdf]" class="regular-text this_month_calendar_pdf_field" placeholder="' . esc_attr__( '', 'text_domain' ) . '" value="' . esc_attr( $value ) . '">';

	}

	function render_this_year_school_calendar_pdf_field() {

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

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

		// Field output.
		echo '<input type="url" name="settings_name[this_year_school_calendar_pdf]" class="regular-text this_year_school_calendar_pdf_field" placeholder="' . esc_attr__( '', 'text_domain' ) . '" value="' . esc_attr( $value ) . '">';

	}

}

new Custom_Settings_Page;