Get content from POST submission if it exists

This commit is contained in:
Kelly Dwan 2019-10-08 13:38:33 -04:00
parent a7a8a37019
commit f646e1f107
No known key found for this signature in database
GPG key ID: 8BA5575F3D11575D

View file

@ -307,17 +307,23 @@ function get_input_filters() {
* @return array Pledge data * @return array Pledge data
*/ */
function get_pledge_meta( $pledge_id = 0, $context = '' ) { function get_pledge_meta( $pledge_id = 0, $context = '' ) {
// Get existing pledge, if it exists.
$pledge = get_post( $pledge_id ); $pledge = get_post( $pledge_id );
$keys = get_pledge_meta_config( $context ); $keys = get_pledge_meta_config( $context );
$meta = array(); $meta = array();
// Get POST'd submission, if it exists.
$submission = filter_input_array( INPUT_POST, get_input_filters() );
foreach ( $keys as $key => $config ) { foreach ( $keys as $key => $config ) {
if ( ! $pledge instanceof WP_Post ) { if ( isset( $submission[ $key ] ) ) {
$meta[ $key ] = $config['default'] ?: ''; $meta[ $key ] = $submission[ $key ];
} else { } else if ( $pledge instanceof WP_Post ) {
$meta_key = META_PREFIX . $key; $meta_key = META_PREFIX . $key;
$meta[ $key ] = get_post_meta( $pledge->ID, $meta_key, true ); $meta[ $key ] = get_post_meta( $pledge->ID, $meta_key, true );
} else {
$meta[ $key ] = $config['default'] ?: '';
} }
} }