Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Post_Model::update_meta_properties( array $post_meta_properties, boolean $allow_same_meta_value )

Update post meta properties.


Description Description

Logic moved from set_bulk() method.


Top ↑

Parameters Parameters

$post_meta_properties

(array) (Required) Array of post meta properties to set.

$allow_same_meta_value

(boolean) (Required) Whether or not updating a meta with the same value as stored in the db is allowed. By default update_post_meta doesn't allow that.


Top ↑

Return Return

(void|WP_Error)


Top ↑

Source Source

File: includes/abstracts/abstract.llms.post.model.php

	private function update_meta_properties( $post_meta_properties, $allow_same_meta_value ) {

		if ( empty( $post_meta_properties ) ) {
			return;
		}

		$error = new WP_Error();

		foreach ( $post_meta_properties as $key => $val ) {

			if ( $allow_same_meta_value ) {
				/**
				 * Do pretty much(*) the same check for a duplicate value as in `update_metadata()`
				 * to avoid `update_post_meta()` returning false.
				 * {@see WP_REST_Meta_Fields::update_meta_value()}.
				 *
				 * If the new value to be set equals the old one don't update it.
				 *
				 * (*) This is not exactly the same check you can find in `update_metadata()` as that
				 * account for multiple meta values for the same key, while we don't.
				 */
				$old_value = get_post_meta( $this->id, $this->meta_prefix . $key, true );
				if ( $this->is_meta_value_same_as_stored_value( $key, $old_value, $val ) ) {
					continue;
				}
			}

			$u = update_post_meta( $this->id, $this->meta_prefix . $key, $val );

			if ( ! ( is_numeric( $u ) || true === $u ) ) {
				$error->add( 'invalid_meta', sprintf( __( 'Cannot insert/update the %s meta', 'lifterlms' ), $key ) );
			}
		}

		if ( $error->has_errors() ) {
			return $error;
		}

	}

Top ↑

User Contributed Notes User Contributed Notes

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