LLMS_REST_Webhooks::is_data_valid( array $data )

Validate data supplied for creating/updating a key.


Parameters Parameters

$data

(array) (Required) Associative array of data to set to a key's properties.


Top ↑

Return Return

(WP_Error|true) When data is invalid will return a WP_Error with information about the invalid properties, otherwise true denoting data is valid.


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/class-llms-rest-webhooks.php

	 * @since 1.0.0-beta.1
	 *
	 * @param array $data Associative array of data to set to a key's properties.
	 * @return WP_Error|true When data is invalid will return a WP_Error with information about the invalid properties,
	 *                            otherwise `true` denoting data is valid.
	 */
	protected function is_data_valid( $data ) {

		// Validate Status.
		if ( isset( $data['status'] ) && ! in_array( $data['status'], array_keys( $this->get_statuses() ), true ) ) {
			// Translators: %s = Invalid permission string.
			return new WP_Error( 'llms_rest_webhook_invalid_status', sprintf( __( '"%s" is not a valid status.', 'lifterlms' ), $data['status'] ) );
		}

		// Validate Topics.
		if ( isset( $data['topic'] ) && ! $this->is_topic_valid( $data['topic'] ) ) {
			// Translators: %s = Invalid permission string.
			return new WP_Error( 'llms_rest_webhook_invalid_topic', sprintf( __( '"%s" is not a valid topic.', 'lifterlms' ), $data['topic'] ) );
		}

		// Prevent empty / blank values being passed.
		foreach ( array( 'name', 'delivery_url' ) as $key ) {
			if ( isset( $data[ $key ] ) && empty( $data[ $key ] ) ) {
				// Translators: %s = field name.
				return new WP_Error( 'llms_rest_webhook_invalid_' . $key, sprintf( __( '"%s" is required.', 'lifterlms' ), $key ) );


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.