Skip to content

visualizer/upsert-chart fails with undefined wp_tempnam() in REST/MCP requests #1412

Description

@pirate-bot

Summary

Creating a chart with manual column and row data through visualizer/upsert-chart can fail with Call to undefined function wp_tempnam(). The submission reports the error while creating a combo chart, including with dry_run enabled. Valid requests are expected to create the chart or return a validation preview; affected requests terminate instead, preventing both creation and dry-run validation.

Customer context

  • Product / area: Visualizer, visualizer/upsert-chart ability exposed through Easy MCP AI
  • Version: Easy MCP AI 2.2.2 reported; installed Visualizer version not provided. The relevant defect is present in inspected Visualizer tags v4.0.9–v4.0.11.
  • Environment: REST/MCP ability invocation; WordPress and PHP versions not provided
  • Reported symptom: Undefined wp_tempnam() while creating a combo chart, with and without dry_run
  • Impact: Chart creation and validation preview fail

Reproduction notes

Reported: invoke wp_ability_visualizer_upsert_chart to create a combo chart; both normal and dry-run calls fail with undefined wp_tempnam(). Source-derived verification case: enable the Visualizer ability on WordPress with the Abilities API, use an authorized account and a permitted chart type, supply valid typed columns and nonempty rows, and invoke it through a fresh REST/MCP request without the admin file helper preloaded. Repeat with dry_run true and false. Not executed locally; exact reporter payload and installed Visualizer version are unavailable.

Diagnosis

Conclusion

Visualizer's manual-data ability path calls an admin-file helper without establishing that its defining file is loaded. The reported undefined-function error matches this source defect. Valid typed columns and rows reach the call before the dry-run return. This is a dependency-loading defect, not evidence of mixed Visualizer class versions.

Where this likely occurs

  • classes/Visualizer/Module/Abilities.php — Visualizer_Module_Abilities::executeUpsertChart() lines 631–669 invokes manual-source construction; its dry-run return is later at lines 691–700.
  • classes/Visualizer/Module/Abilities.php — Visualizer_Module_Abilities::buildManualSource() lines 1153–1205 validates the supplied data and then calls wp_tempnam() without loading its defining include.
  • index.php — visualizer_launch() lines 135–152 registers the abilities module outside the conditional admin-module branch; visualizer_autoloader() lines 43–51 resolves Visualizer classes, not WordPress functions.
  • classes/Visualizer/Module.php — Visualizer_Module::_getCSV() lines 266–276 demonstrates that another Visualizer path explicitly accounts for this helper's optional availability.
  • Commit 54b9615d introduced the abilities module. The unguarded call is present in release tags v4.0.9, v4.0.10, and v4.0.11. No previously working ability version was established, so this is not classified as a regression.

Engineering notes

The callback is implemented by the free Visualizer plugin; inspection of visualizer-pro found no replacement for this ability path. Easy MCP 2.2.2 bridges enabled abilities to their callbacks rather than implementing chart creation. The failure depends on whether another request component has already loaded the WordPress helper. WordPress's official wp_tempnam() reference was checked and identifies wp-admin/includes/file.php as its defining file; WordPress core was not present in the inspected plugin checkout. The constructed reachable input is a permitted chart type with valid manual columns and rows, regardless of dry_run. The reporter's precise input and installed Visualizer version remain unknown.

Test coverage status

tests/test-chart-data-sanitization.php — test_get_chart_ability_returns_stored_cells() lines 111–117 covers the read ability, not chart upsert or its non-admin dependency loading. No relevant upsert/dry-run coverage was found during inspection. Runtime reproduction and PHPUnit execution were unavailable because PHP is not installed in this workspace environment.

What to verify or explore next

  • Reproduce through a fresh REST/MCP request in which wp_tempnam() is initially unavailable, using valid manual columns and rows.
  • Compare dry_run true and false, checking validation output and chart persistence respectively.
  • Confirm the reported combo-chart case with a plan that permits that chart type, and compare a supported free chart type.
  • Check the installed Visualizer version and whether other active plugins incidentally load the admin file helper.

Unknowns / follow-up

The original chart payload, WordPress/PHP versions, and installed Visualizer/Pro versions were not supplied. The failure was source-confirmed rather than reproduced locally. No matching open issue was found in the Visualizer issue searches.

Confidence

Confidence: 96/100

The exact missing helper is called unconditionally on a reachable manual-data path before the dry-run branch, and its defining include is not established by that path in the inspected releases.


Source: automated in-product feedback — easy-mcp-ai, 2026-11-16
Generated by bug-report-triage (ID: bug-report-triage_6afbe41e54a3b6.69081491)

Activity

  1. added theissue type on Nov 17, 2026
  2. pirate-bot commented on Nov 17, 2026

    @pirate-bot
    ContributorAuthor

    Another customer reported this via support.

    Users creating Visualizer charts through Claude encounter an exception stating Ability "visualizer/upsert-chart" callback threw an exception: Call to undefined function wp_tempnam(). Investigation reveals that Visualizer_Module_Abilities::buildManualSource() calls wp_tempnam() without ensuring that its defining WordPress include (wp-admin/includes/file.php) is loaded, affecting both normal chart creation and dry-run validation previews. To reproduce, invoke the visualizer/upsert-chart ability with valid columns and rows in a request where the admin file helper is not preloaded.


    Source: HelpScout #3516904884
    Generated by bug-report-triage (ID: bug-report-triage_6afc7a2cdee777.35929454)

  3. girishpanchal30 commented on Nov 24, 2026

    @girishpanchal30
    Contributor

    I have fixed it with PR #1416

  4. milicavs commented on Nov 24, 2026

    @milicavs

    🧪 QA steps and test links

    Creating a chart through the visualizer/upsert-chart ability (what Easy MCP AI and other AI clients call) fails with Call to undefined function wp_tempnam(), both for a real create and for a dry_run validation, so no chart is made. It only happens on sites where Themeisle's in-dashboard promotions don't load: on a fresh site they load the missing helper and hide the bug.

    Requires: WordPress 6.9 or newer (Abilities API), the Code Snippets plugin, and the browser console to send the REST request (any REST client works).

    Link Build Bot check
    Reproduce the bug Visualizer 4.0.11 (released) ✅ Reproduced: dry run and create both returned HTTP 500 Call to undefined function wp_tempnam(), no chart saved
    Verify the fix PR #1416 build f26ff06 ✅ Fixed: dry run returned valid: true with the Jan/Feb preview, create returned created: true and the chart was saved (Plugins shows 4.0.11-dev.f001266)

    In the links:

    • Steps 1 and 2 are already done, and the links open on a new post in the block editor.
    • Step 1 is a small must-use plugin with the same filter instead of a Code Snippet.
    • In Playground, set the console's context dropdown (top by default) to the frame on /wp-admin/post-new.php before step 3.
    • They can't show the call from an outside MCP client (Easy MCP AI), which Playground can't receive. The REST call runs the same ability.
    • Tools → QA Logs shows debug.log.

    Reproduce on Visualizer 4.0.11:

    1. Snippets → Add New: title "Hide Themeisle promotions", code add_filter( 'themeisle_sdk_ran_promos', '__return_true' );, Run everywhere, Save and Activate.
    2. Posts → Add New Post.
    3. Open the browser console (F12 → Console) and run:
      await wp.apiFetch( { path: '/wp-abilities/v1/abilities/visualizer/upsert-chart/run', method: 'POST', data: { input: { type: 'line', columns: [ { name: 'Month', type: 'string' }, { name: 'Sales', type: 'number' } ], rows: [ [ 'Jan', 10 ], [ 'Feb', 20 ] ], dry_run: true } } } )
    4. Run it again with dry_run: false.
    5. Open Visualizer → Chart Library.
    • Bug: both calls fail with Ability "visualizer/upsert-chart" callback threw an exception: Call to undefined function wp_tempnam(), and the Chart Library stays empty.
    • Fixed: the dry run returns valid: true with a parsed_preview of the two rows, the second call returns created: true with an id and shortcode, and the line chart shows in the Chart Library.
    Edge cases
    • Same calls with the snippet deactivated (promotions on): both builds create the chart, so the normal path is unchanged.
    • Update an existing chart (chart_id plus new columns and rows): the data is replaced, no error.
    • A text value in the number column with dry_run: true: valid: false with the row error, not a 500.
    • The customer's path, Easy MCP AI with an MCP client creating a combo chart: the chart is created, or rejected with a plan message on the free plan, with no wp_tempnam() error.
    • Creating a chart from manual data in Visualizer → Add New Chart: unchanged.

    Fix: #1416 (open)

  5. pirate-bot commented on Nov 24, 2026

    @pirate-bot
    ContributorAuthor

    QA agent — 🟢 Passing checks · Creating charts through the upsert-chart ability now works; the wp_tempnam() crash is gone for both dry runs and real creates.

    I set up WordPress 7.1.5 with the PR build of Visualizer and turned off the Themeisle promotions so the admin file helper is not preloaded, which is how the bug shows up. On the released code, every valid dry run and create, line or combo, failed with 'Call to undefined function wp_tempnam()'. With the fix, dry runs return the data preview and creates save the chart, which then shows in the Chart Library. That includes the reported combo chart on a Pro plan. Updating a chart, free-plan rejection of combo, invalid-data previews and the normal path with promotions on all behave correctly, and the PR's new end-to-end test passes on the fix and fails on the old code.

    Worth a human look

    1. Try the customer's path end to end: an external MCP client through Easy MCP AI creating a combo chart.
    2. Try creating a manual-data chart from Visualizer > Add New Chart to confirm the editor flow is unchanged (the PR does not touch it).
    3. Check whether the free-plan rejection and non-dry-run validation errors should return a 4xx instead of HTTP 500; the Abilities REST layer currently sends 500 for these WP_Error results.
    4. Review the other unguarded wp_tempnam() calls the code review listed in Chart.php and AIBuilder.php URL-probe paths (AJAX, not abilities).
    Checks (8 passed)
    • ✅ With SDK promotions disabled (admin file helper not preloaded), a REST call to visualizer/upsert-chart with a permitted type (line), valid typed columns and two rows and dry_run:true returns HTTP 200 with valid:true and a parsed_preview containing the Jan/Feb rows, not the 'Call to undefined function wp_tempnam()' exception; the same call fails with that exception on qa-base.
    • ✅ The same request with dry_run:false returns created:true with a chart id and shortcode, the chart is stored (visualizer post with type line and the Jan/Feb data) and it appears in Visualizer > Chart Library; on qa-base no chart is created.
    • ✅ The reported case: creating a combo chart through upsert-chart on a plan that permits combo (Visualizer Pro with seeded valid license) succeeds both as dry_run (valid:true, preview) and as a real create (created:true, stored chart type combo), with no wp_tempnam() error.
    • ✅ On the free plan (Pro inactive) a combo request through upsert-chart is rejected with the plan message ('not available on the current Visualizer plan') instead of a wp_tempnam() error, while a free chart type (line) is still created.
    • ✅ Updating an existing chart through upsert-chart (chart_id plus new columns and rows, dry_run false) returns success and the chart's stored data is replaced with the new rows, with no wp_tempnam() error.
    • ✅ A dry run with a text value in a number column returns HTTP 200 with valid:false and the row error message rather than a 500.
    • ✅ With SDK promotions enabled (normal admin path, mu-plugin removed), upsert-chart dry run and create still succeed.
    • ✅ The PR-added e2e spec tests/e2e/specs/abilities.spec.js (dry run preview and create) passes against the sandbox site with the PR head build.

    Full report, evidence and session trail

  6. pirate-bot commented on Nov 25, 2026

    @pirate-bot
    ContributorAuthor

    🎉 This issue has been resolved in version 4.0.12 🎉

    The release is available on GitHub release

    Your semantic-release bot 📦🚀

  7. added
    released
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug-reportbug-report-triagereleased

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions