使用 WP-CLI 设置 Wordfence/ LitespeedCache / WoodySnippets 等插件

问题描述 投票:0回答:1

我正在尝试编写一个 shell 脚本来为我的 WordPress 网站进行默认设置。但是我找不到通过 shell 命令或 php 脚本自动将设置加载到这些插件中的解决方案。

有谁有解决方案,这样我就不必使用设置文件手动设置/更新大约 20 个 WordPress 页面?我对每一个解决方案都很满意,只要它能缩短流程。
(安装和激活插件不是问题。)

wordpress shell wp-cli
1个回答
0
投票
    <?php
// Check if the Wordfence class and method exist
if (class_exists('wordfence') && method_exists('wordfence', 'importSettings')) {
// Provide the token for importing settings
$token = file_get_contents('/Websites/wordpress-setup/wordfence-token.txt');
if ($token) {
    $result = wordfence::importSettings($token);
    if ($result) {
        echo "Wordfence settings imported successfully.\n";
    } else {
        echo "Failed to import Wordfence settings.\n";
    }
} else {
    echo "Wordfence settings token not found or could not be read.\n";
}
} else {
   echo "Wordfence importSettings method not available.\n";
   exit(1);
}

这解决了在 wp-site 文件夹中运行时 wordfence 设置的问题。

© www.soinside.com 2019 - 2024. All rights reserved.