Skip to content

Commit 1ad0207

Browse files
authored
gpbua-conditional-activation-pages.php: Migrated from experimental folder.
1 parent e21b59b commit 1ad0207

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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

Comments
 (0)