|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Gravity Perks // Better User Activation // Conditional Activation Pages |
| 4 | + * https://gravitywiz.com/documentation/gravity-forms-better-user-activation/ |
| 5 | + * |
| 6 | + * Experimental Snippet 🧪 |
| 7 | + * |
| 8 | + * This experimental snippet allows you to load a different activation page depending on a value |
| 9 | + * in its associated entry. |
| 10 | + */ |
| 11 | +add_filter( 'gpbua_activation_page_id', function( $activation_page_id ) { |
| 12 | + |
| 13 | + // Update "1234" to the ID of your conditional activation page. Add additional page IDs as needed. |
| 14 | + $activation_page_ids = array( $activation_page_id, 1234 ); |
| 15 | + |
| 16 | + // Allow conditional activation pages to be treated as activation pages in the post editor. |
| 17 | + if ( is_admin() ) { |
| 18 | + if ( in_array( rgget( 'post' ), $activation_page_ids ) ) { |
| 19 | + return (int) rgget( 'post' ); |
| 20 | + } elseif ( in_array( rgpost( 'post_ID' ), $activation_page_ids ) ) { |
| 21 | + return (int) rgpost( 'post_ID' ); |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + parse_str( $_SERVER['QUERY_STRING'], $query_args ); |
| 26 | + $activation_key = rgar( $query_args, 'key', rgar( $query_args, 'gfur_activation' ) ); |
| 27 | + if ( ! $activation_key ) { |
| 28 | + return $activation_page_id; |
| 29 | + } |
| 30 | + |
| 31 | + require_once( gf_user_registration()->get_base_path() . '/includes/signups.php' ); |
| 32 | + global $wpdb; |
| 33 | + $wpdb->signups = $wpdb->base_prefix . 'signups'; |
| 34 | + |
| 35 | + $signup = GFSignup::get( $activation_key ); |
| 36 | + if ( is_wp_error( $signup ) ) { |
| 37 | + if ( $signup->get_error_code() !== 'already_active' ) { |
| 38 | + return $activation_page_id; |
| 39 | + } |
| 40 | + $meta = unserialize( $signup->error_data['already_active']->meta ); |
| 41 | + $entry = GFAPI::get_entry( $meta['lead_id'] ); |
| 42 | + } else { |
| 43 | + $entry = $signup->lead; |
| 44 | + } |
| 45 | + |
| 46 | + // Update "5" to the field ID for whose value the conditional will be based. |
| 47 | + $value = $entry[5]; |
| 48 | + |
| 49 | + switch ( $value ) { |
| 50 | + // Update "my_custom_value" to the entry value that should trigger the conditional activation page. |
| 51 | + case 'my_custom_value': |
| 52 | + $activation_page_id = 3105; |
| 53 | + break; |
| 54 | + } |
| 55 | + |
| 56 | + return $activation_page_id; |
| 57 | +} ); |
0 commit comments