1

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?

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

BlueSquare23 thanks Dear for help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.