LLMS_Admin_Builder::heartbeat_received( array $res, array $data )

Handle AJAX Heartbeat received calls


Description Description

All builder data is sent through the heartbeat.


Top ↑

Parameters Parameters

$res

(array) (Required) Response data.

$data

(array) (Required) Data from the heartbeat api. Builder data will be in the "llms_builder" array.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/admin/class.llms.admin.builder.php

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
public static function heartbeat_received( $res, $data ) {
 
    // Exit if there's no builder data in the heartbeat data.
    if ( empty( $data['llms_builder'] ) ) {
        return $res;
    }
 
    // Isolate builder data & ensure slashes aren't removed.
    $data = $data['llms_builder'];
 
    // Escape slashes.
    $data = json_decode( $data, true );
 
    // Setup our return.
    $ret = array(
        'status'  => 'success',
        'message' => esc_html__( 'Success', 'lifterlms' ),
    );
 
    // Need a numeric ID for a course post type!
    if ( empty( $data['id'] ) || ! is_numeric( $data['id'] ) || 'course' !== get_post_type( $data['id'] ) ) {
 
        $ret['status']  = 'error';
        $ret['message'] = esc_html__( 'Error: Invalid or missing course ID.', 'lifterlms' );
 
    } elseif ( ! current_user_can( 'edit_course', $data['id'] ) ) {
 
        $ret['status']  = 'error';
        $ret['message'] = esc_html__( 'Error: You do not have permission to edit this course.', 'lifterlms' );
 
    } else {
 
        if ( ! empty( $data['detach'] ) && is_array( $data['detach'] ) ) {
 
            $ret['detach'] = self::process_detachments( $data );
 
        }
 
        if ( current_user_can( 'delete_course', $data['id'] ) ) {
 
            if ( ! empty( $data['trash'] ) && is_array( $data['trash'] ) ) {
 
                $ret['trash'] = self::process_trash( $data );
 
            }
        }
 
        if ( ! empty( $data['updates'] ) && is_array( $data['updates'] ) ) {
 
            $ret['updates']['sections'] = self::process_updates( $data );
 
        }
    }
 
    // Unescape slashes after saved.
    // This ensures that updates are recognized as successful during Sync comparisons.
    // phpcs:ignore -- commented out code
    // $ret = json_decode( str_replace( '\\\\', '\\', json_encode( $ret ) ), true );
 
    // Return our data.
    $res['llms_builder'] = $ret;
 
    return $res;
 
}


Top ↑

Changelog Changelog

Changelog
Version Description
3.24.2 Unknown.
3.16.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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