LLMS_Post_Model::toArrayCustom( array $arr )

Called by toArray to add custom fields via get_post_meta()


Description Description

Removes all custom props registered to the $this->properties automatically. Also removes some fields used by the WordPress core that don’t hold necessary data. Extending classes may override this class to exclude, extend, or modify the custom fields for a post type.


Top ↑

Parameters Parameters

$arr

(array) (Required) Existing post array.


Top ↑

Return Return

(array)


Top ↑

Source Source

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

		return array_values( array_unique( $images ) );
	}

	/**
	 * Called by toArray to add custom fields via get_post_meta()
	 *
	 * Removes all custom props registered to the $this->properties automatically.
	 * Also removes some fields used by the WordPress core that don't hold necessary data.
	 * Extending classes may override this class to exclude, extend, or modify the custom fields for a post type.
	 *
	 * @since 3.16.11
	 * @since 3.30.0 Use `maybe_unserialize()` to ensure array data is accessible as an array.
	 * @since 3.30.2 Add filter to allow 3rd parties to prevent a field from being added to the custom field array.
	 *
	 * @param array $arr Existing post array.
	 * @return array
	 */
	protected function toArrayCustom( $arr ) {

		// Build an array of keys that are registered or can be excluded as a custom field.
		$props = array_keys( $this->get_properties() );
		foreach ( $props as &$prop ) {
			$prop = $this->meta_prefix . $prop;
		}
		$props[] = '_edit_lock';
		$props[] = '_edit_last';

		// Get all meta data.
		$custom = array();
		foreach ( get_post_meta( $this->get( 'id' ) ) as $key => $vals ) {

			// Skip registered fields or fields 3rd parties want to skip.
			/**
			 * Filters whether the custom field should be excluded in the array representation of the post model
			 *
			 * The dynamic portion of this hook, `$this->model_post_type`, refers to the model's post type. For example "course",
			 * "lesson", "membership", etc...
			 *
			 * @since 3.30.2
			 *

Top ↑

Changelog Changelog

Changelog
Version Description
3.30.2 Add filter to allow 3rd parties to prevent a field from being added to the custom field array.
3.30.0 Use maybe_unserialize() to ensure array data is accessible as an array.
3.16.11 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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