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::parse_properties_to_set( array $model_array )

Parse the LifterLMS post properties to set.


Description Description

Logic moved from set_bulk() method.


Top ↑

Parameters Parameters

$model_array

(array) (Required) Associative array of key/val pairs.


Top ↑

Return Return

(array|bool) Returns false if nothing to set or an array that contains all the post properties and all the metas to set.


Top ↑

Source Source

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

	private function parse_properties_to_set( $model_array ) {

		$llms_post = array(
			'post' => array(),
			'meta' => array(),
		);

		$post_properties       = array_keys( $this->get_post_properties() );
		$unsettable_properties = $this->get_unsettable_properties();

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

			// Sanitize the post properties keys by removing the 'post_' prefix.
			if ( 'post_' === substr( $key, 0, 5 ) ) {
				$_key = substr( $key, 5 );
				if ( in_array( $_key, $post_properties, true ) ) {
					$key = $_key;
				}
			}

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

			/**
			 * WordPress Post properties to be updated using the wp_insert_post() function.
			 *
			 * The 'edit_date' must be passed to the wp_update_post() function in order
			 * to allow 'drafty' posts' creation date to be modified.
			 */
			if ( in_array( $key, $post_properties, true ) || 'edit_date' === $key ) {

				$type          = 'post';
				$llms_post_key = "post_{$key}";

				switch ( $key ) {

					case 'content':
						/** This is a WordPress core filter. {@see kses_init_filters()}*/
						$val = stripslashes( apply_filters( 'content_save_pre', addslashes( $val ) ) );
						break;

					case 'excerpt':
						/** This is a WordPress core filter. {@see kses_init_filters()}*/
						$val = stripslashes( apply_filters( 'excerpt_save_pre', addslashes( $val ) ) );
						break;

					case 'edit_date':
					case 'ping_status':
					case 'comment_status':
					case 'menu_order':
						$llms_post_key = $key;
						break;

					case 'title':
						/** This is a WordPress core filter. {@see kses_init_filters()}*/
						$val = stripslashes( apply_filters( 'title_save_pre', addslashes( $val ) ) );
						break;
				}
			} elseif ( ! in_array( $key, $unsettable_properties, true ) ) {
				$type          = 'meta';
				$llms_post_key = $key;
			} else {
				continue;
			}

			/**
			 * Filters the property value prior to be set.
			 *
			 * The first dynamic portion of this hook, `$this->model_post_type`, refers to the model's post type. For example "course",
			 * "lesson", "membership", etc...
			 * The second dynamic part of this hook, `$key`, refers to the property name.
			 *
			 * @since Unknown
			 *
			 * @param mixed           $val       The property value.
			 * @param LLMS_Post_Model $llms_post The LLMS_Post_Model instance.
			 */
			$llms_post[ $type ][ $llms_post_key ] = apply_filters( "llms_set_{$this->model_post_type}_{$key}", $val, $this );

		}

		return empty( $llms_post['post'] ) && empty( $llms_post['meta'] ) ? false : $llms_post;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
6.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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