LLMS_AJAX_Handler::instructors_mb_store( array $request )

Store data for the instructors metabox


Parameters Parameters

$request

(array) (Required) $_REQUEST object.


Top ↑

Return Return

(array)


Top ↑

Source Source

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

250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
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.