LLMS_AJAX_Handler::instructors_mb_store( array $request )

Store data for the instructors metabox


Description Description


Parameters Parameters

$request

(array) (Required) $_REQUEST object.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/class.llms.ajax.handler.php

	public static function instructors_mb_store( $request ) {

		// validate required params
		if ( ! isset( $request['store_action'] ) || ! isset( $request['post_id'] ) ) {

			return array(
				'data' => array(),
				'message' => __( 'Missing required parameters', 'lifterlms' ),
				'success' => false,
			);

		}

		$post = llms_get_post( $request['post_id'] );

		switch ( $request['store_action'] ) {

			case 'load':
				$instructors = $post->get_instructors();
			break;

			case 'save':

				$instructors = array();

				foreach ( $request['rows'] as $instructor ) {

					foreach ( $instructor as $key => $val ) {

						$new_key = str_replace( array( 'llms', '_' ), '', $key );
						$new_key = preg_replace( '/[0-9]+/', '', $new_key );
						$instructor[ $new_key ] = $val;
						unset( $instructor[ $key ] );

					}

					$instructors[] = $instructor;

				}

				$post->set_instructors( $instructors );

			break;

		}

		$data = array();

		foreach ( $instructors as $instructor ) {

			$new_instructor = array();
			foreach ( $instructor as $key => $val ) {
				if ( 'id' === $key ) {
					$val = llms_make_select2_student_array( array( $instructor['id'] ) );
				}
				$new_instructor[ '_llms_' . $key ] = $val;
			}
			$data[] = $new_instructor;
		}

		wp_send_json( array(
			'data' => $data,
			'message' => 'success',
			'success' => true,
		) );

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.30.3 Fixed typos.
3.13.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.





Permalink: