Repository navigation
Fixed file loading helpers for upload ability - #1416
girishpanchal30 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟢 Approved
This approves the fix, and the notes ask a developer to check other admin helpers and possible file.php name collisions.
Validation details
- Files reviewed: 3/3 changed files. Unchecked rows: precedent #962 (undefined function in a context that does not load it), and the shared global names rows Declared names, Guard coverage and Shared copies.
- On pr-base, a REST dry run fails with
rm -f /run/php/php8.3-fpm.pid; cd /workspace && (sandbox-serve.sh > checks/R1/serve2.log 2>&1; echo EXIT $?); tail -2 ch…printedCall to undefined function wp_tempnam()(run R25). - At HEAD, a REST save returns
cd /workspace/checks/R1 && rm -f trace.txt; ./probe.sh head_fpm_dry_false false; head -c 250 head_fpm_dry_false.body; ec…printed"created":true(run R28). - The new e2e spec passes at HEAD with
mkdir -p /workspace/checks/R1/storage-states && cd /repo && set -o pipefail; timeout 280 ./node_modules/.bin/playwright …printed2 passed(run R31). It fails with pr-base classes with/workspace/checks/R1/swap.sh /workspace/pr-base-tree && cd /repo && set -o pipefail; rm -f /workspace/checks/R1/trace.tx…printed2 failed(run R32). - Sandbox: WordPress 7.1.5 and PHP 8.3.36, with the promotions-skip mu-plugin active.
Untested areas
- Precedent #962 (undefined function in a context that does not load it): the Pro add-on paths were not inspected.
- Shared global names rows Declared names, Guard coverage and Shared copies: these were settled from directory searches only.
- The PHPUnit suite was not run. CI owns it.
- The variant pass did not settle these places, where the fixed cause may still reach:
classes/Visualizer/Module/Chart.php:1101-1102,1350-1356— unverified: both URL-probe implementations call unguarded wp_tempnam() for URLs without .csv/.xlsx extensions. Located registrations are AJAX (Chart.php:58, AIBuilder.php:26), not abilities. W…classes/Visualizer/Module/AIBuilder.php:228-229,325-326— unverified: both URL-probe implementations call unguarded wp_tempnam() for URLs without .csv/.xlsx extensions. Located registrations are AJAX (Chart.php:58, AIBuilder.php:26), not abilities. W…classes/Visualizer/Module/Wizard.php:176-194,427-451— unverified: draft-page creation calls unguarded post_exists(). Located entry is the wizard AJAX dispatcher; confirming its defining include is preloaded likewise requires core bootstrap eviden…
🤖 Automated review · run code-review-agent_6b0525a39ed8b8.77950847.
🤖 Review agent — review posted ✅ on f26ff064 · approved · 0 findings · 25 min
Run code-review-agent_6b0525a39ed8b8.77950847 · trail
| // REST and MCP requests do not load the admin file helpers. | ||
| if ( ! function_exists( 'wp_tempnam' ) ) { | ||
| require_once ABSPATH . 'wp-admin/includes/file.php'; | ||
| } |
There was a problem hiding this comment.
note The guard loads file.php only for wp_tempnam(). If code that the Pro add-on hooks into the upsert-chart save path calls another wp-admin/includes helper, a REST or MCP save still ends with an undefined-function error. The Pro add-on was not inspected. Does any Pro callback on this path call an admin-only helper without loading its file? None means safe. Any such call means the same fatal remains.
There was a problem hiding this comment.
Checked against visualizer-pro origin/development. On the upsert path, Pro hooks only visualizer_pro_new_chart_defaults → createNewChart() (inc/addon.php:523-541, post meta writes only) and visualizer_pro_remove_schedule → deleteSchedule() (inc/addon.php:901-909, meta and option writes only). Neither calls a wp-admin/includes helper. Pro's only other admin-only call, get_editable_roles() (addon.php:799), runs from visualizer_pro_get_permissions_data, which only fires from Render/Layout.php:581,612 in the admin settings sidebar.
|
|
||
| // REST and MCP requests do not load the admin file helpers. | ||
| if ( ! function_exists( 'wp_tempnam' ) ) { | ||
| require_once ABSPATH . 'wp-admin/includes/file.php'; |
There was a problem hiding this comment.
note The require_once runs inside a method. The top-level $wp_file_descriptions array in file.php becomes a local variable, not a global. Later code in the same request that calls get_file_description() would read an empty global. Does anything after a manual-data save in a REST request read file descriptions? Nothing means safe. A reader means wrong file labels in that request.
There was a problem hiding this comment.
The only reader is get_file_description(), called only from wp_print_theme_file_tree() (wp-admin/includes/misc.php:445). That only runs on wp-admin/theme-editor.php, a separate admin request where admin.php loads file.php at global scope. Nothing reads it after a REST save. Core itself does the same in-method include (class-wp-rest-attachments-controller.php:664), and so does this plugin already (Module.php:274, Remote/Fetch.php:105).
| } | ||
|
|
||
| // REST and MCP requests do not load the admin file helpers. | ||
| if ( ! function_exists( 'wp_tempnam' ) ) { |
There was a problem hiding this comment.
note The check tests only wp_tempnam(), but file.php declares about 30 global functions. A plugin that declares one of them, such as list_files(), without a guard and is loaded in the same request makes this include end the request with "Cannot redeclare". Is any such plugin loaded on REST ability requests? None means safe. One means the save fatals.
There was a problem hiding this comment.
A plugin declaring list_files() or similar without a guard would already crash every wp-admin request (wp-admin/includes/admin.php:31 loads file.php unconditionally) and core's REST media upload. Visualizer's remote imports also already load it unconditionally (Remote/Fetch.php:105). This PR adds no new way for that to happen, and the bot's directory search found no copy that collides on REST requests.
| if ( ! function_exists( 'wp_tempnam' ) ) { | ||
| require_once ABSPATH . 'wp-admin/includes/file.php'; | ||
| } |
There was a problem hiding this comment.
note Two directory plugins ship their own full copy of file.php: WP Time Capsule and Local Sync. A search found neither loading its copy on a normal REST request. If one of them loads its copy first, this guard skips the core file and runs their wp_tempnam(). Does either plugin load its bridge copy outside its own bridge entry point? No means safe. Yes means the save runs their copy.
There was a problem hiding this comment.
The bot's own search found that neither plugin loads its copy outside its own bridge entry point, so the trigger isn't reachable on a REST ability request. And if one were loaded first, core's admin.php:31 require_once would hit the same redeclare on any admin page, so those copies can't coexist with a normal request anyway.
Summary
Improved chart creation through the REST API by ensuring the required file helpers are loaded before processing requests. Expanded end-to-end test coverage and added a mechanism to disable SDK promotions during tests, preventing promotional content from interfering with test results and keeping the test environment consistent with expected real-world behavior.
Will affect visual aspect of the product
NO
Check before Pull Request is ready:
Closes #1412