Skip to content

Commit 86c1eb0

Browse files
committed
gpsa-enable-for-all-posts-of-type.php: Added snippet to allow enabling GPSA via snippet for all posts of type.
1 parent 2999ced commit 86c1eb0

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
/**
4+
* Gravity Perks // Submit to Access // Enable for all Posts of Type
5+
* https://gravitywiz.com/documentation/gravity-forms-submit-to-access/
6+
*
7+
* Enables GPSA for all posts of a specific type.
8+
*
9+
* @param string $post_type The post type to enable GPSA for.
10+
*/
11+
function gpsa_enable_for_all_posts_of_type( $post_type ) {
12+
add_filter( 'gpsa_supported_post_types', function( $post_types ) use ( $post_type ) {
13+
if ( ! in_array( $post_type, $post_types ) ) {
14+
$post_types[] = $post_type;
15+
}
16+
17+
return $post_types;
18+
});
19+
20+
add_filter('gpsa_document_settings', function( $settings, $post_id ) use ( $post_type ) {
21+
$post = get_post( $post_id );
22+
if ( $post->post_type === $post_type ) {
23+
/**
24+
* @var boolean
25+
*/
26+
$settings['gpsa_enabled'] = true;
27+
28+
/**
29+
* @var array<int>
30+
*/
31+
$settings['gpsa_required_form_ids'][] = 1;
32+
33+
/**
34+
* optionally override the default message to display while the content is loading
35+
* @var string
36+
*/
37+
// $settings['gpsa_content_loading_message'] = '';
38+
39+
/**
40+
* optionally redirect to a specific URL where the access form is located
41+
* @var string
42+
*/
43+
// $settings['gpsa_form_redirect_path'] = '';
44+
45+
/**
46+
* optionally require a unique form submission for every post
47+
* @var boolean
48+
*/
49+
// $settings['gpsa_require_unique_form_submission'] = false;
50+
51+
/**
52+
* optionally override the default access duration.
53+
* @var array{
54+
* type: 'session' | 'never' | 'custom',
55+
* duration: array{
56+
* value: number,
57+
* unit: 'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds',
58+
* }
59+
* }
60+
*/
61+
// $settings['gpsa_access'] = '';
62+
63+
/**
64+
* optionally override the default requires access message
65+
* @var string
66+
*/
67+
// $settings['gpsa_requires_access_message'] = '';
68+
69+
/**
70+
* optionally override the default access behavior
71+
* @var string 'show_message' | 'redirect'
72+
*/
73+
// $settings['gpsa_access_behavior'] = '';
74+
}
75+
76+
return $settings;
77+
}, 10, 2);
78+
}
79+
80+
/**
81+
* Usage: Enable for all posts of type `drum-machine`
82+
*/
83+
gpsa_enable_for_all_posts_of_type( 'drum-machine' );

0 commit comments

Comments
 (0)