Get all form actions for usage tracking#3197
Conversation
📝 WalkthroughWalkthrough
ChangesUsage action collection
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| PHP | Jul 22, 2026 12:53p.m. | Review ↗ | |
| JavaScript | Jul 22, 2026 12:53p.m. | Review ↗ |
Important
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
classes/models/FrmUsage.php (2)
611-616: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winDisable unused meta and term cache hydration.
This code only reads post columns, not metadata or taxonomies. With multiple queries, leaving these options at their defaults can add unnecessary SQL work per page. Set
update_post_meta_cacheandupdate_post_term_cachetofalse. (developer.wordpress.org)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@classes/models/FrmUsage.php` around lines 611 - 616, Update the `$args` array used by `get_posts()` in the saved-actions query to set both `update_post_meta_cache` and `update_post_term_cache` to false, while preserving the existing post type, limit, and offset settings.
610-630: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd pagination boundary tests.
Cover zero, 100, 101, and more than 200 actions, including non-published statuses and JSON settings, to verify no records are omitted or duplicated.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@classes/models/FrmUsage.php` around lines 610 - 630, The pagination loop around FrmUsage’s action retrieval must be covered with boundary tests for zero, 100, 101, and more than 200 actions. Include non-published statuses and JSON settings, then assert every action is returned exactly once with its form_id, type, status, and decoded settings preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@classes/models/FrmUsage.php`:
- Around line 611-630: Update the $args query configuration in the paginated
action-loading loop to include a deterministic order, such as ordering by ID,
before calling get_posts(). Keep the existing limit, offset, and action
collection behavior unchanged.
- Around line 611-623: Update the $args array used by get_posts() in the saved
actions snapshot to include an explicit post_status filter covering all action
statuses intended for the inventory, including draft and private actions. Keep
the existing pagination and action mapping in the foreach loop unchanged.
---
Nitpick comments:
In `@classes/models/FrmUsage.php`:
- Around line 611-616: Update the `$args` array used by `get_posts()` in the
saved-actions query to set both `update_post_meta_cache` and
`update_post_term_cache` to false, while preserving the existing post type,
limit, and offset settings.
- Around line 610-630: The pagination loop around FrmUsage’s action retrieval
must be covered with boundary tests for zero, 100, 101, and more than 200
actions. Include non-published statuses and JSON settings, then assert every
action is returned exactly once with its form_id, type, status, and decoded
settings preserved.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 561559d8-b73b-4bc9-b1d4-5743f83ec6c7
📒 Files selected for processing (1)
classes/models/FrmUsage.php
| $args = array( | ||
| 'post_type' => FrmFormActionsController::$action_post_type, | ||
| 'numberposts' => $limit, | ||
| 'offset' => $offset, | ||
| ); | ||
| } | ||
| $saved_actions = get_posts( $args ); | ||
|
|
||
| foreach ( $saved_actions as $action ) { | ||
| $actions[] = array( | ||
| 'form_id' => $action->menu_order, | ||
| 'type' => $action->post_excerpt, | ||
| 'status' => $action->post_status, | ||
| 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ), |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the relevant method and nearby context.
file="classes/models/FrmUsage.php"
wc -l "$file"
sed -n '560,680p' "$file"
# Find the action post type definition and any related status handling.
rg -n "action_post_type|post_status|get_posts\(" classes -g '*.php'Repository: Strategy11/formidable-forms
Length of output: 10749
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Map the FrmUsage class and inspect the actions() method.
ast-grep outline classes/models/FrmUsage.php --view expanded
# Show the action post type registration and any status-related queries.
rg -n "register_post_type|action_post_type|FrmFormActionsController" classes -g '*.php' -A4 -B4Repository: Strategy11/formidable-forms
Length of output: 29146
🌐 Web query:
WordPress get_posts default post_status when omitted public non-public post types
💡 Result:
When using the WordPress get_posts() function, if the post_status argument is omitted from the input array, the function automatically assigns a default value based on the specified post_type [1][2][3]. The logic applied within get_posts() is as follows: - If post_type is set to attachment, the default post_status is inherit [1][2][4]. - For all other post types (including the default post_type of post or any other registered custom post type), the default post_status is publish [1][5][4]. This behavior is explicitly defined in the function's source code: php if ( empty( $parsed_args['post_status'] ) ) { $parsed_args['post_status'] = ( 'attachment' === $parsed_args['post_type'] ) ? 'inherit' : 'publish'; } It is important to note that get_posts() ultimately passes these arguments to WP_Query [1][6]. While get_posts() itself defaults to publish (or inherit), WP_Query may internally handle additional statuses—such as private—if the current user has the appropriate capabilities to view them [7][4]. However, the get_posts() function intentionally sets these initial defaults to ensure standard public-facing behavior by default [1][4].
Citations:
- 1: https://developer.wordpress.org/reference/functions/get_posts/?referrer=wordpress.com
- 2: https://developer.wordpress.org/reference/functions/get_posts/
- 3: https://docs.w3cub.com/wordpress/functions/get_posts
- 4: https://wp-kama.com/function/get_posts
- 5: https://gabrieleromanato.name/wordpress-the-get_posts-function-in-depth
- 6: https://wpseek.com/function/get_posts/
- 7: https://developer.wordpress.org/reference/classes/WP_Query/get_posts/
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the snapshot payload and how actions() is used.
sed -n '1,220p' classes/models/FrmUsage.php
# Inspect action status defaults/creation paths that show non-published actions exist.
sed -n '460,580p' classes/models/FrmFormAction.php
sed -n '730,820p' classes/models/FrmFormAction.phpRepository: Strategy11/formidable-forms
Length of output: 11172
Include non-published actions in the snapshot. get_posts() defaults to published posts here, so draft/private actions are skipped and the usage payload misses part of the action set. Pass an explicit post_status filter that matches the inventory you want.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@classes/models/FrmUsage.php` around lines 611 - 623, Update the $args array
used by get_posts() in the saved actions snapshot to include an explicit
post_status filter covering all action statuses intended for the inventory,
including draft and private actions. Keep the existing pagination and action
mapping in the foreach loop unchanged.
| $args = array( | ||
| 'post_type' => FrmFormActionsController::$action_post_type, | ||
| 'numberposts' => $limit, | ||
| 'offset' => $offset, | ||
| ); | ||
| } | ||
| $saved_actions = get_posts( $args ); | ||
|
|
||
| foreach ( $saved_actions as $action ) { | ||
| $actions[] = array( | ||
| 'form_id' => $action->menu_order, | ||
| 'type' => $action->post_excerpt, | ||
| 'status' => $action->post_status, | ||
| 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ), | ||
| ); | ||
| unset( $action ); | ||
| } | ||
|
|
||
| $offset += $limit; | ||
| unset( $saved_actions ); | ||
| } while ( count( $actions ) >= $offset ); |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate the relevant file and inspect the surrounding function.
git ls-files 'classes/models/FrmUsage.php'
wc -l classes/models/FrmUsage.php
sed -n '560,660p' classes/models/FrmUsage.phpRepository: Strategy11/formidable-forms
Length of output: 2244
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Search for other get_posts usages in this file to compare ordering/pagination patterns.
rg -n "get_posts\(|orderby|order\s*=>" classes/models/FrmUsage.phpRepository: Strategy11/formidable-forms
Length of output: 209
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the function that contains the paginated query and its surrounding logic.
ast-grep outline classes/models/FrmUsage.php --view expandedRepository: Strategy11/formidable-forms
Length of output: 1053
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect how FrmUsage::actions() is used to judge impact.
sed -n '1,140p' classes/models/FrmUsage.phpRepository: Strategy11/formidable-forms
Length of output: 3704
Add a deterministic order to this paginated query. get_posts() defaults to date ordering, so offset-based paging can skip or duplicate actions when rows share timestamps or change between batches. Add an explicit order, such as orderby => 'ID', or switch to keyset pagination.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@classes/models/FrmUsage.php` around lines 611 - 630, Update the $args query
configuration in the paginated action-loading loop to include a deterministic
order, such as ordering by ID, before calling get_posts(). Keep the existing
limit, offset, and action collection behavior unchanged.
It looks like our usage tracking would only send data for 100 form actions. This update uses batches to pull all form actions, 100 at a time.
This is memory sensitive, so I added some
unsetcode and a call togc_collect_cycles. I also removed our caching layer here, as I think it would just add to memory in most cases since this query isn't really happening in any other code. Without the extra logic, the query is significantly faster as well.Summary by CodeRabbit