LLMS_Admin_Builder::handle_ajax( array $request )

A terrible Rest API for the course builder


Parameters Parameters

$request

(array) (Required) $_REQUEST


Top ↑

Return Return

(array)


Top ↑

Source Source

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

	public static function handle_ajax( $request ) {

		// @todo Do some real error handling here.
		if ( ! $request['course_id'] || ! current_user_can( 'edit_course', $request['course_id'] ) ) {
			return array();
		}

		switch ( $request['action_type'] ) {

			case 'ajax_save':
				if ( isset( $request['llms_builder'] ) ) {

					$request['llms_builder'] = stripslashes( $request['llms_builder'] );
					wp_send_json( self::heartbeat_received( array(), $request ) );

				}

				break;

			case 'get_permalink':
				$id = isset( $request['id'] ) ? absint( $request['id'] ) : false;
				if ( ! $id ) {
					return array();
				}
				$title = isset( $request['title'] ) ? sanitize_title( $request['title'] ) : null;
				$slug  = isset( $request['slug'] ) ? sanitize_title( $request['slug'] ) : null;
				$link  = get_sample_permalink( $id, $title, $slug );
				wp_send_json(
					array(
						'slug'      => $link[1],
						'permalink' => str_replace( '%pagename%', $link[1], $link[0] ),
					)
				);

				break;

			case 'lazy_load':
				$ret = array();
				if ( isset( $request['load_id'] ) ) {
					$post = llms_get_post( absint( $request['load_id'] ) );
					$ret  = $post->toArray();
				}
				wp_send_json( $ret );

				break;

			case 'search':
				$page      = isset( $request['page'] ) ? $request['page'] : 1;
				$term      = isset( $request['term'] ) ? sanitize_text_field( $request['term'] ) : '';
				$post_type = '';
				if ( isset( $request['post_type'] ) ) {
					if ( is_array( $request['post_type'] ) ) {
						$post_type = array_map( 'sanitize_text_field', $request['post_type'] );
					} else {
						$post_type = sanitize_text_field( $request['post_type'] );
					}
				}
				wp_send_json( self::get_existing_posts( $post_type, $term, $page ) );
				break;

		}

		return array();

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.17.0 Remove remove_all_* hooks added in version 4.16.0.
4.16.0 Remove all filters/actions applied to the title/content when handling the ajax_save by deafault. This is specially to prevent plugin conflicts, see <a href="https://github.com/gocodebox/lifterlms/issues/1530">https://github.com/gocodebox/lifterlms/issues/1530</a>.
3.19.2 Unknown.
3.13.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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