Skip to content

Conversation

veryspry
Copy link
Contributor

@veryspry veryspry commented Sep 5, 2025

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

Copy link

coderabbitai bot commented Sep 5, 2025

Walkthrough

Adds a new class GPSA_Enable_For_All_Posts_Of_Type that registers filters to include a configured post type in GPSA-supported types and to merge per-type GPSA settings into document-level settings for posts of that type (defaults: post_type = 'post', gpsa_enabled = true).

Changes

Cohort / File(s) Summary
GPSA enable-for-post-type class
gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php
Adds class GPSA_Enable_For_All_Posts_Of_Type with public static properties $post_type and $settings; constructor __construct( $args = array() ) normalizes inputs (default post_type = 'post', merges settings to ensure gpsa_enabled = true) and registers filters gpsa_supported_post_types and gpsa_document_settings. Adds static methods ensure_supported_post_types( $post_types ) (appends configured post type) and override_document_level_settings( $settings, $post_id ) (loads post, checks post_type, merges configured settings into document settings). Includes PHPDoc type definitions and a usage example.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks (2 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly conveys the primary change—enabling GPSA for all posts of a specified post type—and directly relates to the main purpose of the pull request, even though it includes the filename prefix which adds some extra length. It remains focused on the substantive update and would be understandable to reviewers scanning history.
Description Check ✅ Passed The description adheres to the repository’s template by providing a Context section with the HelpScout ticket link and a Summary section that succinctly explains what the pull request introduces, and it properly omits unused Notion and Slack placeholders. It addresses the key template requirements and gives reviewers clear visibility into the purpose of the change.

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.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

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 details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3fb6345 and 7d87c51.

📒 Files selected for processing (1)
  • gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • gp-submit-to-access/gpsa-enable-for-all-posts-of-type.php
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch matt/gpsa-post-type

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

github-actions bot commented Sep 5, 2025

Warnings
⚠️ When ready, don't forget to request reviews on this pull request from your fellow wizards.

Generated by 🚫 dangerJS against 7d87c51

@veryspry veryspry force-pushed the matt/gpsa-post-type branch from 86c1eb0 to 97982f2 Compare September 5, 2025 09:32
…ing GPSA via snippet for all posts of type.
@veryspry veryspry force-pushed the matt/gpsa-post-type branch from 97982f2 to 2d17470 Compare September 5, 2025 09:35
Copy link

@coderabbitai coderabbitai bot left a 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 type

Adds 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 redeclaration

Prevents 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 type

Add 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_access

A 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 comment

Clarify 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 2d17470 and 0ebfbb0.

📒 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.

Copy link

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0ebfbb0 and 97c2db5.

📒 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.

@veryspry veryspry force-pushed the matt/gpsa-post-type branch from 97c2db5 to 3fb6345 Compare September 9, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant