WordPress / WordPress/wordpress-playground

Blueprint accepting OS-level environment variable

Open
#2,011 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

[Package][@wp-playground] CLI [Type] Enhancement
Dominant language
JavaScript
Stars
2k
Forks
462
Avg merge
18h 44m
Merged PRs (30d)
33

Description

This blueprint:

{
  "login": true,
  "steps": [
    {
      "step": "runPHP",
      "code": "<?php require_once 'wordpress/wp-load.php'; wp_insert_post( [ 'post_title' => 'env', 'post_content' => print_r( $_ENV, true ) ] );"
    }
  ]
}

Generates a post with this content:

Array
(
  [USER] => web_user
  [LOGNAME] => web_user
  [PATH] => /
  [PWD] => /
  [HOME] => /home/web_user
  [LANG] => C.UTF-8
  [_] => cli.ts
  [USE_ZEND_ALLOC] => 0
)

It can be a useful addition for blueprints started using the CLI in this way:

TEST="test" bun cli.ts server --blueprint=./test.json

To inherit the TEST environment var. This is a quite advanced option so it should be available only to PHPRunOptions. The env record should be open to be overwritten by the caller. Such as:

```json
{
  "login": true,
  "steps": [
    {
      "step": "runPHPWithOptions",
      "options": {
        "env": {
          "TEST": "false"
        },
        "code": "<?php require_once 'wordpress/wp-load.php'; wp_insert_post( [ 'post_title' => 'env', 'post_content' => print_r( $_ENV, true ) ] );"
      }
    }
  ]
}

So that it will be possible to write this for rapid prototyping:

TEST="true" bun cli.ts server --blueprint=./test.json

The CLI should have a list of env vars to exclude, such as other security measures.

Addendum: Apparently, $_ENV does not have the values passed if used in the code entry. This may be a bug.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with cli.ts and the runPHPWithOptions/PHPRunOptions entry points, then inspect how the blueprint's PHP code receives environment variables. Verify that inherited variables such as TEST are available, caller-provided env values override them, and excluded variables remain unavailable; also investigate the addendum about $_ENV not receiving values in code entries.

Written by the indexing model from the issue text.

Assessment

Tech stack
bun, javascript, php
Domain
cli, security
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.