LLMS_Admin_Builder::update_custom_schemas( string $type, obj $post, array $post_data )

Handle updating custom schema data


Description Description


Parameters Parameters

$type

(string) (Required) Model type (lesson, quiz, etc...).

$post

(obj) (Required) LLMS_Post_Model object for the model being updated.

$post_data

(array) (Required) Assoc array of raw data to update the model with.


Top ↑

Return Return

(void)


Top ↑

Source Source

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

	public static function update_custom_schemas( $type, $post, $post_data ) {

		$schemas = self::get_custom_schemas();
		if ( empty( $schemas[ $type ] ) ) {
			return;
		}

		$groups = $schemas[ $type ];

		foreach ( $groups as $name => $group ) {

			// Allow 3rd parties to manage their own custom save methods.
			if ( apply_filters( 'llms_builder_update_custom_fields_group_' . $name, false, $post, $post_data, $groups ) ) {
				continue;
			}

			foreach ( $group['fields'] as $fields ) {

				foreach ( $fields as $field ) {

					$keys = array( $field['attribute'] );
					if ( isset( $field['switch_attribute'] ) ) {
						$keys[] = $field['switch_attribute'];
					}

					foreach ( $keys as $attr ) {

						if ( isset( $post_data[ $attr ] ) ) {

							if ( isset( $field['sanitize_callback'] ) ) {
								$val = call_user_func( $field['sanitize_callback'], $post_data[ $attr ] );
							} else {
								if ( is_array( $post_data[ $attr ] ) ) {
									$val = array_map( 'sanitize_text_field', $post_data[ $attr ] );
								} else {
									$val = sanitize_text_field( $post_data[ $attr ] );
								}
							}

							$attr = isset( $field['attribute_prefix'] ) ? $field['attribute_prefix'] . $attr : $attr;
							update_post_meta( $post_data['id'], $attr, $val );

						}
					}
				}
			}
		}

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.30.0 Array fields will run field values through sanitize_text_field() instead of requiring a custom sanitization callback.
3.17.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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