@@ 268-336 (lines=69) @@ | ||
265 | * |
|
266 | * @since 2.0 |
|
267 | */ |
|
268 | public function save_post_meta ( $id, $post_meta = null, $strict = false, $fields = array() ) { |
|
269 | $simple_tableless_objects = PodsForm::simple_tableless_objects(); |
|
270 | ||
271 | $conflicted = pods_no_conflict_check( 'post' ); |
|
272 | ||
273 | if ( !$conflicted ) |
|
274 | pods_no_conflict_on( 'post' ); |
|
275 | ||
276 | if ( !is_array( $post_meta ) ) |
|
277 | $post_meta = array(); |
|
278 | ||
279 | $id = (int) $id; |
|
280 | ||
281 | $meta = get_post_meta( $id ); |
|
282 | ||
283 | foreach ( $meta as $k => $value ) { |
|
284 | if ( is_array( $value ) && 1 == count( $value ) ) |
|
285 | $meta[ $k ] = current( $value ); |
|
286 | } |
|
287 | ||
288 | foreach ( $post_meta as $meta_key => $meta_value ) { |
|
289 | if ( null === $meta_value || ( $strict && '' === $post_meta[ $meta_key ] ) ) { |
|
290 | $old_meta_value = ''; |
|
291 | ||
292 | if ( isset( $meta[ $meta_key ] ) ) |
|
293 | $old_meta_value = $meta[ $meta_key ]; |
|
294 | ||
295 | delete_post_meta( $id, $meta_key, $old_meta_value ); |
|
296 | } |
|
297 | else { |
|
298 | $simple = false; |
|
299 | ||
300 | if ( isset( $fields[ $meta_key ] ) ) { |
|
301 | $field_data = $fields[ $meta_key ]; |
|
302 | ||
303 | $simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) ); |
|
304 | } |
|
305 | ||
306 | if ( $simple ) { |
|
307 | delete_post_meta( $id, $meta_key ); |
|
308 | ||
309 | update_post_meta( $id, '_pods_' . $meta_key, $meta_value ); |
|
310 | ||
311 | if ( ! is_array( $meta_value ) ) { |
|
312 | $meta_value = array( $meta_value ); |
|
313 | } |
|
314 | ||
315 | foreach ( $meta_value as $value ) { |
|
316 | add_post_meta( $id, $meta_key, $value ); |
|
317 | } |
|
318 | } |
|
319 | else { |
|
320 | update_post_meta( $id, $meta_key, $meta_value ); |
|
321 | } |
|
322 | } |
|
323 | } |
|
324 | ||
325 | if ( $strict ) { |
|
326 | foreach ( $meta as $meta_key => $meta_value ) { |
|
327 | if ( !isset( $post_meta[ $meta_key ] ) ) |
|
328 | delete_post_meta( $id, $meta_key, $meta_value ); |
|
329 | } |
|
330 | } |
|
331 | ||
332 | if ( !$conflicted ) |
|
333 | pods_no_conflict_off( 'post' ); |
|
334 | ||
335 | return $id; |
|
336 | } |
|
337 | ||
338 | /** |
|
339 | * Save a user and it's meta |
|
@@ 688-760 (lines=73) @@ | ||
685 | * |
|
686 | * @since 2.0 |
|
687 | */ |
|
688 | public function save_term_meta ( $id, $term_meta = null, $strict = false, $fields = array() ) { |
|
689 | if ( ! function_exists( 'get_term_meta' ) ) { |
|
690 | return $id; |
|
691 | } |
|
692 | ||
693 | $simple_tableless_objects = PodsForm::simple_tableless_objects(); |
|
694 | ||
695 | $conflicted = pods_no_conflict_check( 'taxonomy' ); |
|
696 | ||
697 | if ( !$conflicted ) |
|
698 | pods_no_conflict_on( 'taxonomy' ); |
|
699 | ||
700 | if ( !is_array( $term_meta ) ) |
|
701 | $term_meta = array(); |
|
702 | ||
703 | $id = (int) $id; |
|
704 | ||
705 | $meta = get_term_meta( $id ); |
|
706 | ||
707 | foreach ( $meta as $k => $value ) { |
|
708 | if ( is_array( $value ) && 1 == count( $value ) ) |
|
709 | $meta[ $k ] = current( $value ); |
|
710 | } |
|
711 | ||
712 | foreach ( $term_meta as $meta_key => $meta_value ) { |
|
713 | if ( null === $meta_value || ( $strict && '' === $term_meta[ $meta_key ] ) ) { |
|
714 | $old_meta_value = ''; |
|
715 | ||
716 | if ( isset( $meta[ $meta_key ] ) ) |
|
717 | $old_meta_value = $meta[ $meta_key ]; |
|
718 | ||
719 | delete_term_meta( $id, $meta_key, $old_meta_value ); |
|
720 | } |
|
721 | else { |
|
722 | $simple = false; |
|
723 | ||
724 | if ( isset( $fields[ $meta_key ] ) ) { |
|
725 | $field_data = $fields[ $meta_key ]; |
|
726 | ||
727 | $simple = ( 'pick' == $field_data[ 'type' ] && in_array( pods_var( 'pick_object', $field_data ), $simple_tableless_objects ) ); |
|
728 | } |
|
729 | ||
730 | if ( $simple ) { |
|
731 | delete_term_meta( $id, $meta_key ); |
|
732 | ||
733 | update_term_meta( $id, '_pods_' . $meta_key, $meta_value ); |
|
734 | ||
735 | if ( ! is_array( $meta_value ) ) { |
|
736 | $meta_value = array( $meta_value ); |
|
737 | } |
|
738 | ||
739 | foreach ( $meta_value as $value ) { |
|
740 | add_term_meta( $id, $meta_key, $value ); |
|
741 | } |
|
742 | } |
|
743 | else { |
|
744 | update_term_meta( $id, $meta_key, $meta_value ); |
|
745 | } |
|
746 | } |
|
747 | } |
|
748 | ||
749 | if ( $strict ) { |
|
750 | foreach ( $meta as $meta_key => $meta_value ) { |
|
751 | if ( !isset( $term_meta[ $meta_key ] ) ) |
|
752 | delete_term_meta( $id, $meta_key, $meta_value ); |
|
753 | } |
|
754 | } |
|
755 | ||
756 | if ( !$conflicted ) |
|
757 | pods_no_conflict_off( 'taxonomy' ); |
|
758 | ||
759 | return $id; |
|
760 | } |
|
761 | ||
762 | /** |
|
763 | * Save a set of options |