LLMS_AJAX_Handler::instructors_mb_store( array $request )
Store data for the instructors metabox
Parameters Parameters
- $request
-
(array) (Required) $_REQUEST object.
Return Return
(array)
Source Source
File: includes/class.llms.ajax.handler.php
}
/**
* Store data for the instructors metabox
*
* @since 3.13.0
* @since 3.30.3 Fixed typos.
*
* @param array $request $_REQUEST object.
* @return array
*/
public static function instructors_mb_store( $request ) {
// validate required params.
if ( ! isset( $request['store_action'] ) ||
! isset( $request['post_id'] ) ) {
wp_die();
}
if ( ! llms_current_user_can_edit_product( $request['post_id'] ) ) {
wp_die();
}
$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;
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 3.30.3 | Fixed typos. |
| 3.13.0 | Introduced. |