Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Prefill Gravity Forms
- */
- function bis_init_prefill_gf_fields() {
- global $post;
- if ( ! empty( $post->ID ) ) {
- $post_meta = get_post_meta( $post->ID );
- $post_meta_keys = array_keys( $post_meta );
- if ( is_array( $post_meta_keys ) ) {
- foreach ( $post_meta_keys as $meta_key ) {
- if ( preg_match( '/^prefill_gf_(.*)/', $meta_key, $matches ) ) {
- $gf_field_parameter = $matches[1];
- add_filter( 'gform_field_value_' . $gf_field_parameter, 'bis_prefill_gf_fields', 10, 2 );
- }
- }
- }
- }
- }
- add_action( 'wp', 'bis_init_prefill_gf_fields' );
- function bis_prefill_gf_fields( $value, $field ) {
- global $post;
- if ( ! empty( $field->inputName ) && ! empty( $post->ID ) ) {
- $value = get_post_meta( $post->ID, 'prefill_gf_' . $field->inputName, true );
- }
- return $value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement