如何使用条件语句使wp-cli在wp-config文件中工作?

时间:2017-12-13 01:22:58

标签: php wordpress wp-cli

我正在测试使用wp-cli更新我的域proddevstagingtestupdate网站。

在我的wp-config文件中有条件语句,然后我收到以下错误:

PHP Notice:  Undefined index: HTTP_HOST in phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(1070) : eval()'d code on line 22
PHP Notice:  Undefined index: HTTP_HOST in phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(1070) : eval()'d code on line 24
PHP Notice:  Undefined index: HTTP_HOST in phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(1070) : eval()'d code on line 26
PHP Notice:  Undefined index: HTTP_HOST in phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(1070) : eval()'d code on line 28
PHP Notice:  Undefined variable: db_name in phar:///usr/local/bin/wp/php/WP_CLI/Runner.php(1070) : eval()'d code on line 34
Error: Can’t select database. We were able to connect to the database server (which means your username and password is okay) but not able to select the `` database.

这就是我对wp-config.php文件进行编码的方法!!!

if ($_SERVER["HTTP_HOST"] === 'example.com') {
  $db_name = 'example';
}else if ($_SERVER["HTTP_HOST"] === 'dev.example.com') {
  $db_name = 'example_dev';
}else if ($_SERVER["HTTP_HOST"] === 'staging.example.com'){
  $db_name = 'example_staging';
}else if ($_SERVER["HTTP_HOST"] === 'update.example.com') {
  $db_name = 'example_update';
}

define('DB_NAME', $db_name);

有什么方法可以让wp-cli使用这个文件吗?

1 个答案:

答案 0 :(得分:1)

true

从命令行使用PHP时不存在。您最好的选择是在命令行中使用该文件时指定一个案例,例如:

<Grid x:Name"main_grid">
    ...
    <controls:SelectionConverter x:Key="SelectionConverter" />
    <Style x:Key="SelectionStyle" TargetType="Border">
        <Setter Property="Background" Value="{Binding Converter={StaticResource SelectionConverter}}"/>
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsEnabled, ElementName=main_grid}" Value="True">
                <Setter Property="Background" Value="Red" />
            </DataTrigger>
        </Style.Triggers>
    </Style>
    ...
</Grid>

由于我不太确定你想要$ db_name是什么,当你在wp-cli时我没有在第一组括号中设置它。