Skip to main content

REPL CLI

The WP-Node CLI provides a REPL (Read-Eval-Print Loop) interface that extends the standard Node.js REPL with WP-Node specific functionality.

When initializing Node.js REPL, WP-Node adds a wp object, which provides access to WP-Node Context. This is particularly useful for debugging and exploring WordPress database records interactively.

Starting the REPL

Start the REPL CLI with:

npx @rnaga/wp-node-cli -- repl

Example Usage

Get a Post

Retrieve and examine a WordPress post (e.g., post ID = 1):

wp-node> const post = await wp.utils.post.get(1);
undefined
wp-node> post.props.post_title
'Hello world!'
wp-node>

Assign User and check Capabilities

Assume a user role (Administrator) and check capabilities:

wp-node> await wp.current.assumeUser(1);
undefined
wp-node> const user = wp.current.user
undefined
wp-node> user.props.user_login
'wptest'
wp-node> const role = await user.role();
undefined
wp-node> await role.can("edit_posts");
true
wp-node>