When passing this array of options:

$this->service_options = array(
        array( 'key' => 'ADDENDIO_SERVICE_LIFETIME', 'value' => '15' ),
        array( 'key' => 'DB_NAME', 'value' => 'db_name' ),
        array( 'key' => 'DB_USER', 'value' => 'db_user' ),
        array( 'key' => 'DB_PASS', 'value' => 'db_pass' ),
        array( 'key' => 'SSH_USER', 'value' => 'ssh_root' ),
        array( 'key' => 'SSH_PASS', 'value' => 'ssh_pass' ),
        array( 'key' => 'VIRTUAL_HOST', 'value' => 'mytestcontainer.n1.addendio.com' ),
        array( 'key' => 'DB_HOST', 'value' => '127.0.0.1' ),
        array(
            'key'   => 'WP_CLI',
            'value' => array(
                'wp core download --version=4.7.4 --locale=en_US',
                'wp core config --dbname={DB_NAME} --dbuser={DB_USER} --dbpass={DB_PASS} --dbhost={DB_HOST}',
                'wp core install --url=http://mytestcontainer.n1.addendio.com --title=WordPress --admin_user=admin --admin_password=parol --admin_email=testadmin@mail.com --skip-plugins --skip-themes',
                'wp plugin install akismet',
                'wp plugin activate akismet',
                'wp option add dwpb_enable=yes=--autoload=yes',
                'wp option add dwpbcd_use=yes=--autoload=yes',
                'wp option add dwpbcd_time_left="2017-05-03 03:06"=--autoload=yes',
                'wp option add dwpbcd_text="Before shutdown."=--autoload=yes',
                'wp option add dwpbcd_link_text="Get a FREE 60 minutes sandbox by registering to Addendio.com" --autoload=yes',
                'wp option add dwpbcd_link_url="https://addendio.com/wp-login.php?action=register" --autoload=yes',
                'wp option add dwpbcd_link_target="_blank" --autoload=yes',
                'wp plugin install rating-widget',
                'wp plugin activate rating-widget',
            ),
        ),
    );

And processing them like this:

public function create_service() {
    $user     = Addendio_Sandbox_Management::USERNAME;
    $password = Addendio_Sandbox_Management::API_KEY;

    $service  = wp_safe_remote_post(
        self::HOST . self::URL,
        array(
            'httpversion' => '1.1',
            'headers' => array(
                'Content-type'  => 'application/json',
                'Accept'        => 'application/json',
                'charset'       => 'utf-8',
                'Authorization' => 'Basic ' . base64_encode( "{$user}:{$password}" ),
            ),
            'body'    => json_encode( array(
                'image'                 => self::IMAGE,
                'container_envvars'     => $this->service_options,
                'target_num_containers' => 1,
            ) ),
        )
    );
}

WP_CLI variable comes to API in such strange way:

[u'wp core download --version=4.7.4 --locale=en_US', u'wp core config --dbname={DB_NAME} --dbuser={DB_USER} --dbpass={DB_PASS} --dbhost={DB_HOST}', u'wp core install --url=http://mytestcontainer.n1.addendio.com --title=WordPress --admin_user=admin --admin_password=parol --admin_email=testadmin@mail.com --skip-plugins --skip-themes', u'wp plugin install akismet', u'wp plugin activate akismet', u'wp option add dwpb_enable=yes=--autoload=yes', u'wp option add dwpbcd_use=yes=--autoload=yes', u'wp option add dwpbcd_time_left="2017-05-03 03:06"=--autoload=yes', u'wp option add dwpbcd_text="Before shutdown."=--autoload=yes', u'wp option add dwpbcd_link_text="Get a FREE 60 minutes sandbox by registering to Addendio.com" --autoload=yes', u'wp option add dwpbcd_link_url="https://addendio.com/wp-login.php?action=register" --autoload=yes', u'wp option add dwpbcd_link_target="_blank" --autoload=yes', u'wp plugin install rating-widget', u'wp plugin activate rating-widget']

Seems like first quote of every item in WP_CLI array is replaced with:
u’

I tried to use json_encode with different constant parameters but still no luck.
Maybe anyone faced similar issue ?

Read more here: PHP strange json_encode symbols


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: