Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions classes/models/FrmUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -603,22 +603,41 @@ private function fields() {
* @return array
*/
private function actions() {
$args = array(
'post_type' => FrmFormActionsController::$action_post_type,
'numberposts' => 100,
);
$actions = array();
$offset = 0;
$limit = 100;
$limit_plus_one = $limit + 1;

do {
$args = array(
'post_type' => FrmFormActionsController::$action_post_type,
'numberposts' => $limit_plus_one,
'offset' => $offset,
);
$saved_actions = get_posts( $args );
$has_more = count( $saved_actions ) === $limit_plus_one;

$actions = array();
$saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' );
if ( $has_more ) {
// Pop off the last item as it is only queried to determine if there are more results.
array_pop( $saved_actions );
}

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 ),
);
}
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 ),
Comment on lines +612 to +630

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ 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 -B4

Repository: 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:


🏁 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.php

Repository: 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.

);
unset( $action );
}

$offset += $limit;

unset( $saved_actions );

gc_collect_cycles();
} while ( $has_more );

return $actions;
}
Expand Down
Loading