LLMS_REST_Database_Resource::create_prepare( array $data )

Prepare data for creation.


Parameters Parameters

$data

(array) (Required) Array of data.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/abstracts/class-llms-rest-database-resource.php

	public function create_prepare( $data ) {

		if ( ! empty( $data['id'] ) ) {
			// Translators: %s = name of the resource type (for example: "API Key").
			return new WP_Error( 'llms_rest_' . $this->id . '_exists', sprintf( __( 'Cannot create a new %s with a pre-defined ID.', 'lifterlms' ), $this->get_i18n_name() ) );
		}

		// Merge in default values.
		$data = wp_parse_args( array_filter( $data ), $this->get_default_column_values() );

		// Required Fields.
		foreach ( $this->required_columns as $key ) {

			if ( empty( $data[ $key ] ) ) {
				return new WP_Error(
					'llms_rest_' . $this->id . '_missing_' . $key,
					// Translators: %1$s = name of the resource type; %2$s = field name.
					sprintf( __( '%1$s "%2$s" is required.', 'lifterlms' ), $this->get_i18n_name(), $key )
				);
			}
		}

		$err = $this->is_data_valid( $data );
		if ( is_wp_error( $err ) ) {
			return $err;
		}

		return $data;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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