LLMS_Post_Model::toArrayCustom( array $arr )
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
Description Description
Parameters Parameters
- $arr
-
(array) (Required) existing post array
Return Return
(array)
Source Source
File: includes/abstracts/abstract.llms.post.model.php
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. if ( in_array( $key, $props, true ) || apply_filters( 'llms_' . $this->model_post_type . '_skip_custom_field', false, $key, $this ) ) { continue; } // add it. $custom[ $key ] = array_map( 'maybe_unserialize', $vals ); } // add the compiled custom array. $arr['custom'] = $custom; return $arr; }
Expand full source code Collapse full source code View on GitHub
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. |
User Contributed Notes User Contributed Notes
Permalink: