Skip to content

Commit 0ebfbb0

Browse files
committed
gpsa-enable-for-all-posts-of-type.php: Updated configuration.
1 parent 2d17470 commit 0ebfbb0

File tree

1 file changed

+92
-56
lines changed

1 file changed

+92
-56
lines changed

gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php

Lines changed: 92 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* @param string $post_type The post type to enable GPSA for.
1010
*/
11-
function gpsa_enable_for_all_posts_of_type( $post_type ) {
11+
function gpsa_enable_for_all_posts_of_type( $post_type, $settings = array() ) {
1212
add_filter( 'gpsa_supported_post_types', function( $post_types ) use ( $post_type ) {
1313
if ( ! in_array( $post_type, $post_types ) ) {
1414
$post_types[] = $post_type;
@@ -17,68 +17,104 @@ function gpsa_enable_for_all_posts_of_type( $post_type ) {
1717
return $post_types;
1818
});
1919

20-
add_filter('gpsa_document_settings', function( $settings, $post_id ) use ( $post_type ) {
20+
add_filter('gpsa_document_settings', function( $base_settings, $post_id ) use ( $post_type, $settings ) {
2121
$post = get_post( $post_id );
2222
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'] = '';
23+
$settings = array_merge(
24+
$base_settings,
25+
$settings
26+
);
7427
}
7528

7629
return $settings;
7730
}, 10, 2);
7831
}
7932

33+
// Configuration:
34+
8035
/**
81-
* Usage: Enable for all posts of type `drum-machine`.
82-
* Update this argument to match the `$post_type` of the posts you'd like to target.
36+
* Minimal configuration to enable for all posts of type `drum-machine`.
37+
*
38+
* Usage:
39+
* 1. Update this argument to match the `$post_type` of the posts you'd like to target.
40+
* 2. Update gpsa_required_form_ids with the form ID you want to require.
41+
*/
42+
gpsa_enable_for_all_posts_of_type(
43+
'drum-machine',
44+
array(
45+
/**
46+
* @var boolean
47+
*/
48+
'gpsa_enabled' => true,
49+
/**
50+
* @var array<int>
51+
*/
52+
'gpsa_required_form_ids' => array( 1 ), // UPDATE `1` with the form id you want to require.
53+
)
54+
);
55+
56+
57+
/**
58+
* Advanced configuration to enable for all posts of type `drum-machine`.
59+
60+
* Usage:
61+
* 1. Update this argument to match the `$post_type` of the posts you'd like to target.
62+
* 2. Update gpsa_required_form_ids with the form ID you want to require.
63+
* 3. Optionally uncomment and provide values for the additional settings.
8364
*/
84-
gpsa_enable_for_all_posts_of_type( 'drum-machine' );
65+
// gpsa_enable_for_all_posts_of_type(
66+
// 'drum-machine',
67+
// array(
68+
// /**
69+
// * @var boolean
70+
// */
71+
// 'gpsa_enabled' => true,
72+
//
73+
// /**
74+
// * @var array<int>
75+
// */
76+
// 'gpsa_required_form_ids' => array( 1 ), // UPDATE `1` with the form id you want to require.
77+
//
78+
// /**
79+
// * optionally override the default message to display while the content is loading
80+
// * @var string
81+
// */
82+
// // 'gpsa_content_loading_message' => '',
83+
//
84+
// /**
85+
// * optionally redirect to a specific URL where the access form is located
86+
// * @var string
87+
// */
88+
// // 'gpsa_form_redirect_path' => '',
89+
//
90+
// /**
91+
// * optionally require a unique form submission for every post
92+
// * @var boolean
93+
// */
94+
// // 'gpsa_require_unique_form_submission' => false,
95+
//
96+
// /**
97+
// * optionally override the default access duration.
98+
// * @var array{
99+
// * type: 'session' | 'never' | 'custom',
100+
// * duration: array{
101+
// * value: number,
102+
// * unit: 'years' | 'months' | 'weeks' | 'days' | 'hours' | 'minutes' | 'seconds',
103+
// * }
104+
// * }
105+
// */
106+
// // 'gpsa_access' => '',
107+
//
108+
// /**
109+
// * optionally override the default requires access message
110+
// * @var string
111+
// */
112+
// // 'gpsa_requires_access_message' = '',
113+
//
114+
// /**
115+
// * optionally override the default access behavior
116+
// * @var string 'show_message' | 'redirect'
117+
// */
118+
// // 'gpsa_access_behavior' = '',
119+
// ),
120+
// );

0 commit comments

Comments
 (0)