Wp eval (WP-CLI)

Uit De Vliegende Brigade
Naar navigatie springen Naar zoeken springen

wp eval executes arbitrary PHP code within or within a website.

$ wp help eval

NAME

  wp eval

DESCRIPTION

  Executes arbitrary PHP code.

SYNOPSIS

  wp eval <php-code> [--skip-wordpress]

  Note: because code is executed within a method, global variables need
  to be explicitly globalized.

OPTIONS

  <php-code>
    The code to execute, as a string.

  [--skip-wordpress]
    Execute code without loading WordPress.

EXAMPLES

    # Display WordPress content directory.
    $ wp eval 'echo WP_CONTENT_DIR;'
    /var/www/wordpress/wp-content

    # Generate a random number.
    $ wp eval 'echo rand();' --skip-wordpress
    479620423