Skip to content

Proposal for new global parameter to execute PHP code #5446

@austinginder

Description

@austinginder

The global argument --require is useful in a wide range of situations however I would like a easy way to run simple PHP code without having to create a file. Considering WP-CLI has native commands wp eval <php-code> and wp eval-file <file>, I propose a new separate global argument for running arbitrary PHP code.

Now I'd rather not break existing workflows so maybe --require=<file> could remain as-is and a new global argument be introduced for running code. How about something like --require-code=<php-code>.

With this we could simply do something like wp plugin update --all --require-code="define( 'WP_ADMIN', true );" and would be a fair solution for this common issue wp-cli/extension-command#106. Would also be useful for a wide range of situations.

Ideas or thoughts?

An alternative cleaner idea would be to make --require smart. It could hunt for a PHP file to require, if not found, it could maybe try and see if it's PHP and run that? I'm not sure.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions