LLMS_Post_Model::set( string $key, mixed $val )

Setter


Description Description


Parameters Parameters

$key

(string) (Required) Key of the property.

$val

(mixed) (Required) Value to set the property with.


Top ↑

Return Return

(boolean) true on success, false on error or if the submitted value is the same as what's in the database


Top ↑

Source Source

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

	public function set( $key, $val ) {

		$val = $this->scrub( $key, $val );

		// update WordPress Post Properties using the wp_insert_post() function
		if ( in_array( $key, array_keys( $this->get_post_properties() ) ) ) {

			$post_key = 'post_' . $key;

			switch ( $key ) {

				case 'content':
					$val = apply_filters( 'content_save_pre', $val );
				break;

				case 'excerpt':
					$val = apply_filters( 'excerpt_save_pre', $val );
				break;

				case 'menu_order':
					$post_key = 'menu_order';
				break;

				case 'title':
					$val = apply_filters( 'title_save_pre', $val );
				break;

			}

			$args = array(
				'ID' => $this->get( 'id' ),
			);

			$args[ $post_key ] = apply_filters( 'llms_set_' . $this->model_post_type . '_' . $key, $val, $this );

			if ( wp_update_post( wp_slash( $args ) ) ) {
				$this->post->{$post_key} = $val;
				return true;
			} else {
				return false;
			}
		} // End if().
		elseif ( ! in_array( $key, $this->get_unsettable_properties() ) ) {

			$u = update_post_meta( $this->id, $this->meta_prefix . $key, apply_filters( 'llms_set_' . $this->model_post_type . '_' . $key, $val, $this ) );
			if ( is_numeric( $u ) || true === $u ) {
				return true;
			} else {
				return false;
			}
		} // we have a problem...
		else {

			return false;

		}

	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.30.3 Use wp_slash() when setting properties.
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: