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

	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.