-
Notifications
You must be signed in to change notification settings - Fork 92
gpsa-enable-for-all-posts-of-type.php
: Added snippet to allow enabling GPSA via snippet for all posts of type.
#1158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
WalkthroughAdds a new class Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant WP as WordPress Runtime
participant Class as GPSA_Enable_For_All_Posts_Of_Type
participant GPSA as GPSA Filter Consumers
Note over Class: class instantiated with args (post_type?, settings?)
WP->>Class: include file & new GPSA_Enable_For_All_Posts_Of_Type(args)
Class->>WP: add_filter('gpsa_supported_post_types', Class::ensure_supported_post_types)
Class->>WP: add_filter('gpsa_document_settings', Class::override_document_level_settings)
WP->>GPSA: apply_filters('gpsa_supported_post_types', types)
GPSA-->>Class: ensure_supported_post_types(types)
Class-->>GPSA: return types (with configured post_type appended if absent)
WP->>GPSA: apply_filters('gpsa_document_settings', base_settings, post_id)
GPSA-->>Class: override_document_level_settings(base_settings, post_id)
Class->>WP: get_post(post_id)
alt post_type matches configured
Class-->>GPSA: return merged_settings = array_merge(base_settings, configured_settings)
else not match
Class-->>GPSA: return base_settings
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
86c1eb0
to
97982f2
Compare
…ing GPSA via snippet for all posts of type.
97982f2
to
2d17470
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (5)
gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php (5)
12-18
: Use strict in_array() check for post typeAdds type-safety; avoids edge cases if an unexpected non-string sneaks in.
- add_filter( 'gpsa_supported_post_types', function( $post_types ) use ( $post_type ) { - if ( ! in_array( $post_type, $post_types ) ) { + add_filter( 'gpsa_supported_post_types', function( $post_types ) use ( $post_type ) { + if ( ! in_array( $post_type, $post_types, true ) ) { $post_types[] = $post_type; } return $post_types; });
11-11
: Guard function definition to avoid redeclarationPrevents fatal errors if the snippet is loaded multiple times.
+if ( ! function_exists( 'gpsa_enable_for_all_posts_of_type' ) ) : function gpsa_enable_for_all_posts_of_type( $post_type, $settings = array() ) { // … } +endif;Also applies to: 31-31
3-10
: Complete the docblock for settings and return typeAdd missing param docs and return spec.
/** * Gravity Perks // Submit to Access // Enable for all Posts of Type * https://gravitywiz.com/documentation/gravity-forms-submit-to-access/ * * Enables GPSA for all posts of a specific type. * * @param string $post_type The post type to enable GPSA for. + * @param array $settings Optional GPSA settings to merge when the post type matches. + * @return void */
106-106
: Provide a valid example value for gpsa_accessA concrete example reduces copy/paste errors.
-// // 'gpsa_access' => '', +// // 'gpsa_access' => array( 'type' => 'custom', 'duration' => array( 'value' => 30, 'unit' => 'days' ) ),
52-52
: Minor wording tweak in commentClarify that multiple IDs are supported.
- 'gpsa_required_form_ids' => array( 1 ), // UPDATE `1` with the form id you want to require. + 'gpsa_required_form_ids' => array( 1 ), // UPDATE `1` with the form ID(s) you want to require.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled
- Linear integration is disabled
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php
(1 hunks)
🔇 Additional comments (1)
gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php (1)
33-55
: Invocation only runs when snippet file is explicitly included
The file has no WordPress plugin header and isn’t required or included anywhere in the codebase, so it won’t auto-load—its invocation will only execute when a user manually includes the snippet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php (1)
61-71
: Guard against null post; fix spacing; ensure early return.Dereferencing $post without a null-check can fatal if get_post() returns null. Also remove the space before "(" in the function declaration to satisfy PHPCS.
Apply:
- public static function override_document_level_settings ( $settings, $post_id ) { - $post = get_post( $post_id ); - if ( $post->post_type === self::$post_type ) { - $settings = array_merge( - $settings, - self::$settings - ); - } - - return $settings; - } + public static function override_document_level_settings( $settings, $post_id ) { + $post = get_post( $post_id ); + if ( ! $post || $post->post_type !== self::$post_type ) { + return $settings; + } + $merged_settings = array_merge( $settings, self::$settings ); + return $merged_settings; + }
🧹 Nitpick comments (6)
gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php (6)
50-50
: PHPCS: add spaces inside function parentheses.WordPress standard requires spaces after "(". This also fixes CI failure noted at Line 50.
- add_filter('gpsa_document_settings', array( self::class, 'override_document_level_settings' ), 10, 2 ); + add_filter( 'gpsa_document_settings', array( self::class, 'override_document_level_settings' ), 10, 2 );
46-47
: Align assignment operators per WPCS.- self::$post_type = $post_type; - self::$settings = $settings; + self::$post_type = $post_type; + self::$settings = $settings;
31-35
: Incorrect @var type for $post_type.This is a string, not boolean.
- * @var boolean + * @var string
53-59
: Use strict in_array for post type check.Prevents unexpected matches.
- if ( ! in_array( self::$post_type, $post_types ) ) { + if ( ! in_array( self::$post_type, $post_types, true ) ) {
41-45
: Indent docblock closing with tabs (not spaces).Matches WPCS: tabs for indentation, spaces only for mid-line alignment.
- */ + */
30-51
: Avoid global static state; prefer instance properties and callbacks.Static props mean the last instantiation wins; multiple post-type configs will clobber each other. Instance state avoids this.
-class GPSA_Enable_For_All_Posts_Of_Type { +class GPSA_Enable_For_All_Posts_Of_Type { /** - * @var string + * @var string */ - public static $post_type; + private $post_type; /** * @var GPSADocumentSettings */ - public static $settings; + private $settings; /** * @param string $post_type The post type to enable GPSA for. * @param GPSADocumentSettings $settings The settings for GPSA. */ public function __construct( $post_type, $settings ) { - self::$post_type = $post_type; - self::$settings = $settings; + $this->post_type = $post_type; + $this->settings = $settings; - add_filter( 'gpsa_supported_post_types', array( self::class, 'ensure_supported_post_types' ), 10, 1 ); - add_filter( 'gpsa_document_settings', array( self::class, 'override_document_level_settings' ), 10, 2 ); + add_filter( 'gpsa_supported_post_types', array( $this, 'ensure_supported_post_types' ), 10, 1 ); + add_filter( 'gpsa_document_settings', array( $this, 'override_document_level_settings' ), 10, 2 ); } - public static function ensure_supported_post_types( $post_types ) { - if ( ! in_array( self::$post_type, $post_types, true ) ) { - $post_types[] = self::$post_type; + public function ensure_supported_post_types( $post_types ) { + if ( ! in_array( $this->post_type, $post_types, true ) ) { + $post_types[] = $this->post_type; } return $post_types; } - public static function override_document_level_settings( $settings, $post_id ) { - $post = get_post( $post_id ); - if ( ! $post || $post->post_type !== self::$post_type ) { - return $settings; - } - $merged_settings = array_merge( $settings, self::$settings ); - return $merged_settings; + public function override_document_level_settings( $settings, $post_id ) { + $post = get_post( $post_id ); + if ( ! $post || $post->post_type !== $this->post_type ) { + return $settings; + } + return array_merge( $settings, $this->settings ); } }Also applies to: 53-71
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php
(1 hunks)
🧰 Additional context used
🪛 GitHub Check: PHPCS (Files Changed)
gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php
[failure] 61-61:
Space between function name and opening parenthesis is prohibited.
[failure] 50-50:
Expected 1 spaces after opening parenthesis; 0 found
[warning] 47-47:
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
[failure] 44-44:
Tabs must be used to indent lines; spaces are not allowed
[failure] 14-14:
Spaces must be used for mid-line alignment; tabs are not allowed
[failure] 13-13:
Spaces must be used for mid-line alignment; tabs are not allowed
[failure] 12-12:
Spaces must be used for mid-line alignment; tabs are not allowed
[failure] 11-11:
Spaces must be used for mid-line alignment; tabs are not allowed
[failure] 10-10:
Spaces must be used for mid-line alignment; tabs are not allowed
🪛 GitHub Actions: PHP Lint (PR)
gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php
[error] 10-10: PHPCS error: Spaces must be used for mid-line alignment; tabs are not allowed (WordPress.WhiteSpace.DisallowInlineTabs.NonIndentTabsUsed)
🔇 Additional comments (1)
gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php (1)
74-91
: Confirm sample configuration behavior.Do you intend this example instantiation to run by default in the snippet library? If not, consider commenting it out to avoid accidental activation when included verbatim.
97c2db5
to
3fb6345
Compare
3fb6345
to
7d87c51
Compare
Context
⛑️ Ticket(s): https://secure.helpscout.net/conversation/3050511236/88377?viewId=6987275
Summary
Allows GPSA to be enabled via filter for all Posts of a given type.
Relies on: https://github.com/gravitywiz/gp-submit-to-access/pull/10