Wp eval (WP-CLI)
Versie door Jeroen Strompf (overleg | bijdragen) op 29 jul 2022 om 11:26
wp eval executes arbitrary PHP code within or not 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
Voorbeeld
#!/bin/bash # # Interact with ACF fields through PHP-API # ############################################################### # Go to example.com ############################################################### # cd /var/www/example.com ############################################################### # Use the_field (ACF command) ############################################################### # php_string='the_field("hero_text",7);' wp eval "$php_string"