Changing options on wp-discourse plugin via wp-cli

(Keith John Hutchison) #1


How do you change the wp-discourse plugin options via the word press command line?

For example.

How would you change the wp-discourse options url and the api key via the wp command line?

(Simon Cossar) #2

Enter the wp shell with wp shell. You can see all the plugin’s options by running:

wp> WPDiscourse\Utilities\Utilities::get_options();

The options are stored in arrays, based on which of the option pages they are saved on. You can find the names of the arrays with:

wp> get_option('discourse_option_groups');

The API key and Discourse URL are stored in the 'discourse_connect' array. You can update them with something like this:

wp> $connection_options = get_option('discourse_connect');

Make the changes you want to make to the returned array, then run:

wp> update_option('discourse_connect', $connection_options);

(Keith John Hutchison) #3

Many thanks for your guidance Simon.

This is what I ended up doing.

Created a file called activate-wordpress-plugins.php which I called from the command line with

    /usr/bin/wp --allow-root --path=/var/www/html eval-file /var/www/html/activate-wordpress-plugins.php

The contents of activate-wordpress-plugins.php follows.


echo('Getting discourse settings' . "\n" ) ;
$connection_options = get_option('discourse_connect') ;
echo('Setting discourse url to ' . getenv('DISCOURSE_URL') . "\n" ) ;
$connection_options['url'] = getenv('DISCOURSE_URL') ;
echo('Setting discourse api key to ' . getenv('DISCOURSE_API_KEY') . "\n" ) ;
$connection_options['api-key'] = getenv('DISCOURSE_API_KEY') ;
echo('Updating discourse settings' . "\n" ) ;
echo( update_option('discourse_connect', $connection_options) ) ;


where DISCOURSE_URL and DISCOURSE_API_KEY are valid environment variables.

(system) closed #4

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.