MasterStudy LMS Pro Plus
Plugin PageVideo TutorialsChangelogResourcesGet MasterStudy
  • Introduction | MasterStudy LMS Documentation
  • Getting Started
    • Free Version and Pro Plus Version
    • System Requirements
    • Plugin Installation
    • Upgrading the License
    • Update The Plugin
    • AppSumo Deal
    • Update Billing Details and Access Invoices
    • LMS Wizard
    • LMS Widgets
      • Gutenberg Blocks
    • License Utilization
    • Fueature Request
  • LMS Settings
    • General
    • Courses
    • Course
    • Course Player
    • Reports & Analytics
    • Quiz
    • LMS Pages
    • Payment Methods
    • reCAPTCHA
    • Profiles
      • Authorization
      • Social Login
      • Profile Menu Reordering
    • Grades
    • Certificates
    • Payout
    • Privacy Policy
    • Shortcodes
    • Import/Export
  • LMS PRO Addons
    • Certificate Builder
    • Email Manager and Branding
      • Email Templates
    • LMS Forms Editor
      • How to edit the registration form?
    • Zoom Conferencing
    • Google Meet
    • Assignments
    • Drip Content
    • Group Courses
    • Live Streaming
    • Course Bundles
    • Point System
    • Media File Manager
    • SCORM
    • Trial Courses
    • Statistics & Payouts
    • Online Testing
    • Multi-instructors
    • Google Classroom
    • Udemy Course Importer
    • Prerequisites
    • The Gradebook
    • Upcoming Course Status
    • Question Media
    • Social Login
    • Audio Lesson
    • Grades
  • LMS Course Features
    • Course Builder
      • How to Add Math Equations in MasterStudy?
    • Lessons
    • Video Lessons
    • Quizzes
    • Questions
    • Reviews
    • Orders
      • Sales Page for Instructor
    • Courses Category
    • Course & Lesson Materials
    • Course Drafts for Instructors
    • Manage Students
    • Change Course Author
    • Instructors Requests
    • Video Preview for Single Course
    • Course Announcements
    • Public Profiles
  • PayPal Payouts Setup
    • General Settings
    • Business Account Settings
    • Developer Account Settings
    • Instructor Settings
    • Payouts Process
    • Automatic Payouts (Expert)
  • LMS Analytics
    • Analytics for Admin
      • Revenue
      • Engagement
      • Users
      • Reviews
    • Analytics for Instructors
      • Revenue
      • Engagement
      • Students
      • Reviews
    • Student Reports
  • Integrations
    • Membership System
    • H5P Plugin
    • Presto Player Integration
    • SureTriggers Integration
    • PeepSo Integration
    • Studiocart Integration
    • VdoCipher Integration
    • Polylang Integration
      • LMS Contents Translation
    • Plugin Translation
      • Loco Translate
  • WPML
    • Getting Started
    • Translating LMS pages
    • Translating Lessons
    • Translating Quizzes
    • Translating Assignments
    • Translating Courses
    • Making Static String Translations
  • Divi Builder Integration
    • Getting Started
    • MasterStudy LMS Divi Modules
  • Woocommerce
    • Installation and Settings
    • Orders Management
  • Troubleshooting
    • Introduction
    • Plugin Conflicts
    • Theme Compatibility
    • 404 Errors
    • Update Issues
    • New Comment Email
    • Cache Settings
    • Email not sending
    • Debug Logs
    • Submit a Support Ticket
  • Developer's guide
    • Components
      • Back-link
      • Button
      • Countdown
      • Curriculum-accordion
      • Discussions
      • File-attachment
      • Progress
      • Tabs
      • Nav-button
      • Hint
      • Editor
      • Alert
      • File-upload
      • Loader
      • Tabs-pagination
      • Dark-mode-button
      • Buy-button
      • Pagination
    • Course Builder Customization
    • Course Builder Custom Fields
    • Course Player Templates
  • Changelog
  • Release Notes
  • Changelog (Free Version)
  • Changelog (Pro Version)
  • Changelog (Divi Modules)
  • Stylemixthemes
    • MasterStudy Starter Theme
    • MasterStudy LMS Plugin
    • Themes
    • Plugins
Powered by GitBook
On this page
  • Registering Custom Fields
  • How to filter custom fields before sending to Course Builder
  • Processing Input Data
  • Outputting Custom Fields
  • Custom Field Types
  • Text
  • Textarea
  • Number
  • Date
  • Checkbox
  • Radio
  • Select
  • Repeater
  • Full Example

Was this helpful?

Export as PDF
  1. Developer's guide

Course Builder Custom Fields

Course Builder Custom Fields help to customize Course Builder by adding fields like:

  • input (text, number, radio, checkbox, date, ..)

  • textarea

  • select

  • repeater

Registering Custom Fields

Course, Lesson, and Quiz Custom Fields could be added using filters:

  • masterstudy_lms_course_custom_fields

  • masterstudy_lms_lesson_custom_fields

  • masterstudy_lms_quiz_custom_fields

Example:

function masterstudy_lms_custom_fields( $custom_fields ) {
	$quiz_custom_fields = array(
		array(
			'type'    => 'text',
			'name'    => 'my-text-field',
			'label'   => __( 'Text field', 'masterstudy-lms-learning-management-system' ),
		),
		...
	);

	return array_merge( $custom_fields, $quiz_custom_fields );
}

add_filter( 'masterstudy_lms_course_custom_fields', 'masterstudy_lms_custom_fields' );

How to filter custom fields before sending to Course Builder

Course Builder Custom Fields could be filtered before sending to Course Builder using masterstudy_lms_course_builder_custom_fields filter.

Example:

function masterstudy_lms_filter_custom_fields( $custom_fields, $post_id ) {
  ... // Here Custom Fields could be manipulated 
  
  return $custom_fields;
}

add_filter( 'masterstudy_lms_course_builder_custom_fields', 'masterstudy_lms_filter_custom_fields', 10, 2 );

Processing Input Data

All input data will be automatically saved to post_meta. Additionally, data can be used with action:

do_action( 'masterstudy_lms_custom_fields_updated', int $post_id, array $data )

Parameters:

  • $post_id int Course, Lesson, or Quiz Post ID.

  • $data array key => value array of Custom Fields

Example:

function masterstudy_lms_after_custom_fields_updated( $post_id, $data ) {
  ... // Here is your code 
}

add_filter( 'masterstudy_lms_custom_fields_updated', 'masterstudy_lms_after_custom_fields_updated', 10, 2 );

Outputting Custom Fields

All values from Custom Fields will be saved as Post Meta fields with corresponding keys. So they can be easily retrieved and displayed as post meta fields.

Example:

$my_text_field = get_post_meta( get_the_ID(), 'my-text-field', true );

echo esc_html( $my_text_field );

Custom Field Types

There are text, textarea, number, checkbox, radio and select types of custom fields. Let's look at examples of each.

Text

array(
	'type'        => 'text',
	'name'        => 'my-text-field',
	'label'       => __( 'Text field', 'masterstudy-lms-learning-management-system' ),
	'default'     => '', // Optional
	'required'    => true, // Optional
	'custom_html' => '<a href="#">Custom Link</a>', // Optional
)

Textarea

array(
	'type'     => 'textarea',
	'name'     => 'my-textarea-field',
	'label'    => __( 'Textarea field', 'masterstudy-lms-learning-management-system' ),
	'default'  => '', // Optional
	'required' => true, // Optional
)

Number

array(
	'type'        => 'number',
	'name'        => 'my-number-field',
	'label'       => __( 'Number field', 'masterstudy-lms-learning-management-system' ),
	'default'     => 10, // Optional
	'required'    => true, // Optional
	'custom_html' => '<a href="#">Custom Button</a>', // Optional
)

Date

array(
	'type'        => 'date',
	'name'        => 'my-date-field',
	'label'       => __( 'Date field', 'masterstudy-lms-learning-management-system' ),
	'default'     => 1707868800000, // Timestamp. Optional
	'required'    => true, // Optional
	'custom_html' => '<a href="#">Custom Button</a>', // Optional
)

DatePicker field accepts and returns a value in Timestamp format. So the output of the date value is also different from other fields.

Example:

$my_date_field = get_post_meta( get_the_ID(), 'my-date-field', true );

echo gmdate( get_option('date_format'), $my_date_field );

Checkbox

array(
	'type'        => 'checkbox',
	'name'        => 'my-checkbox-field',
	'label'       => __( 'Checkbox field', 'masterstudy-lms-learning-management-system' ),
	'default'     => true, // Optional
	'required'    => true, // Optional
	'custom_html' => '<div>HTML Code</div>', // Optional
)

Radio

array(
	'type'        => 'radio',
	'name'        => 'my-radio-field',
	'label'       => __( 'Radio field', 'masterstudy-lms-learning-management-system' ),
	'default'     => 'option-1', // Optional
	'required'    => true, // Optional
	'custom_html' => '<div>HTML Code</div>', // Optional
	'options'     => array(
		array(
			'value' => 'option-1',
			'label' => __( 'Option 1', 'masterstudy-lms-learning-management-system' ),
		),
		array(
			'value' => 'option-2',
			'label' => __( 'Option 2', 'masterstudy-lms-learning-management-system' ),
		),
	),
)

Select

array(
	'type'        => 'select',
	'name'        => 'my-select-field',
	'label'       => __( 'Select field', 'masterstudy-lms-learning-management-system' ),
	'default'     => 'option-1', // Optional
	'required'    => true, // Optional
	'custom_html' => '<div>HTML Code</div>', // Optional
	'options'     => array(
		array(
			'value' => 'option-1',
			'label' => __( 'Option 1', 'masterstudy-lms-learning-management-system' ),
		),
		array(
			'value' => 'option-2',
			'label' => __( 'Option 2', 'masterstudy-lms-learning-management-system' ),
		),
	),
)

Repeater

You can use all Field Types inside a Repeater. For example:

array(
	'type'   => 'repeater',
	'name'   => 'my-repeater-field',
	'label'  => __( 'Repeater field', 'masterstudy-lms-learning-management-system' ),
	'fields' => array(
		array(
			'type'  => 'text',
			'name'  => 'my-repeater-text-field',
			'label' => __( 'Text field', 'masterstudy-lms-learning-management-system' ),
		),
		array(
			'type'  => 'date',
			'name'  => 'my-repeater-date-field',
			'label' => __( 'Date field', 'masterstudy-lms-learning-management-system' ),
		),
		// More fields
	),
),

Repeater field doesn't support Validation.

Full Example

Here is an example of all custom field types with filters used:

<?php
function masterstudy_lms_custom_fields( $custom_fields ) {
	$my_custom_fields = array(
		array(
			'type'        => 'text',
			'name'        => 'my-text-field',
			'label'       => __( 'Text field', 'masterstudy-lms-learning-management-system' ),
			'default'     => '', // Optional
			'required'    => false, // Optional
			'custom_html' => '<a href="#">Custom Link</a>', // Optional
		),
		array(
			'type'        => 'number',
			'name'        => 'my-number-field',
			'label'       => __( 'Number field', 'masterstudy-lms-learning-management-system' ),
			'default'     => 10, // Optional
			'required'    => true, // Optional
			'custom_html' => '<div>HTML Code</div>', // Optional
		),
		array(
			'type'        => 'date',
			'name'        => 'my-date-field',
			'label'       => __( 'Date field', 'masterstudy-lms-learning-management-system' ),
			'default'     => 1707868800000, // Timestamp. Optional
			'required'    => true, // Optional
			'custom_html' => '<a href="#">Custom Button</a>', // Optional
		),
		array(
			'type'        => 'textarea',
			'name'        => 'my-textarea-field',
			'label'       => __( 'Textarea field', 'masterstudy-lms-learning-management-system' ),
			'default'     => '', // Optional
			'required'    => true, // Optional
			'custom_html' => '<div>HTML Code</div>', // Optional
		),
		array(
			'type'        => 'checkbox',
			'name'        => 'my-checkbox-field',
			'label'       => __( 'Checkbox field', 'masterstudy-lms-learning-management-system' ),
			'default'     => true, // Optional
			'required'    => false, // Optional
			'custom_html' => '<div>HTML Code</div>', // Optional
		),
		array(
			'type'        => 'radio',
			'name'        => 'my-radio-field',
			'label'       => __( 'Radio field', 'masterstudy-lms-learning-management-system' ),
			'default'     => 'option-1', // Optional
			'required'    => true, // Optional
			'custom_html' => '<div>HTML Code</div>', // Optional
			'options'     => array(
				array(
					'value' => 'option-1',
					'label' => __( 'Option 1', 'masterstudy-lms-learning-management-system' ),
				),
				array(
					'value' => 'option-2',
					'label' => __( 'Option 2', 'masterstudy-lms-learning-management-system' ),
				),
			),
		),
		array(
			'type'        => 'select',
			'name'        => 'my-select-field',
			'label'       => __( 'Select field', 'masterstudy-lms-learning-management-system' ),
			'default'     => 'option-1', // Optional
			'required'    => true, // Optional
			'custom_html' => '<div>HTML Code</div>', // Optional
			'options'     => array(
				array(
					'value' => 'option-1',
					'label' => __( 'Option 1', 'masterstudy-lms-learning-management-system' ),
				),
				array(
					'value' => 'option-2',
					'label' => __( 'Option 2', 'masterstudy-lms-learning-management-system' ),
				),
			),
		),
	);

	return array_merge( $custom_fields, $my_custom_fields );
}

add_filter( 'masterstudy_lms_course_custom_fields', 'masterstudy_lms_custom_fields' );
add_filter( 'masterstudy_lms_lesson_custom_fields', 'masterstudy_lms_custom_fields' );
add_filter( 'masterstudy_lms_quiz_custom_fields', 'masterstudy_lms_custom_fields' );

PreviousCourse Builder CustomizationNextCourse Player Templates

Last updated 11 months ago

Was this helpful?