Home > other >  Bash script add some lines to created config file in WP-CLI
Bash script add some lines to created config file in WP-CLI

Time:02-10

Below bash script create for me in WP-CLI config file and add database details:

#set database details in the config file
  su -s /bin/bash -c "/usr/local/bin/wp config create --dbname=$wpconfigdbuser --dbuser=$wpconfigdbuser --dbpass=$dbpass --dbhost=localhost" $username

I need to add to .wp-config this 2 lines code:

define('DISALLOW_FILE_EDIT', true);
define('DISALLOW_FILE_MODS', true);

Can anyone help me?

CodePudding user response:

You can just append those values to the wp-config.php file after the wp-cli creates it. Does the following work for your purposes?

For example,

su -s /bin/bash -c "/usr/local/bin/wp config create --dbname=$wpconfigdbuser --dbuser=$wpconfigdbuser --dbpass=$dbpass --dbhost=localhost" $username
cat << EOF >> wp-config.php
define('DISALLOW_FILE_EDIT', true);
define('DISALLOW_FILE_MODS', true);
EOF

Or all on one line,

su -s /bin/bash -c "/usr/local/bin/wp config create --dbname=$wpconfigdbuser --dbuser=$wpconfigdbuser --dbpass=$dbpass --dbhost=localhost" $username && printf "define('DISALLOW_FILE_EDIT', true);\ndefine('DISALLOW_FILE_MODS', true);\n" >> wp-config.php

In practice,

$ su -s /bin/bash -c "/usr/local/bin/wp config create --dbname=$wpconfigdbuser --dbuser=$wpconfigdbuser --dbpass=$dbpass --dbhost=localhost" $username && printf "define('DISALLOW_FILE_EDIT', true);\ndefine('DISALLOW_FILE_MODS', true);\n" >> wp-config.php
Success: Generated 'wp-config.php' file.
$ cat wp-config.php
...
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
    define( 'ABSPATH', dirname( __FILE__ ) . '/' );
}

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
define('DISALLOW_FILE_EDIT', true);
define('DISALLOW_FILE_MODS', true);
  •  Tags:  
  • bash
  • Related