我正在为一个项目开发wordpress插件。我需要管理这个插件中的其他插件。例如,我将能够在我的插件上安装Akismet。我已经完成了安装、激活、停用等操作。但我无法删除插件。
我也可以删除直接附件文件,但我不想删除。我应该使用尽可能多的wordpress函数。
delete_plugins(\'litespeed-cache/litespeed-cache.php\')
 此功能不起作用。我试图集成这个函数,但它非常复杂。你能帮帮我吗?
--EDİT--
对不起,我没注意。现在还有另一个问题。我写了一个新插件,当我添加以下代码时,它工作得很好。
register_activation_hook( __FILE__, \'index\' );
function index() {
    delete_plugins( [
        \'litespeed-cache/litespeed-cache.php\',
    ] );
}
 但我自己的插件不起作用。
add_action(\'exampleUninstallPlugin\',\'exampleUninstallPlugin\');
function exampleUninstallPlugin($plugins){
    delete_plugins($plugins);
}
add_action( \'rest_api_init\', \'customTestFunction\' );
function customTestFunction() {
    register_rest_route( \'turhost/rest\', \'/api\', array(
        \'methods\'  => \'POST\',
        \'callback\' => \'show_fields\'
    ) );
}
function show_fields( $request ) {
        $parameters = json_decode( base64_decode( $request->get_param( \'data\' ) ), true );
        if ( $parameters[\'action\'] == "uninstallInstalledPlugin" ) {
            do_action(\'turhostUninstallPlugin\',[
               \'litespeed-cache/litespeed-cache.php\'
            ]);
        }
}
 
                SO网友:Fabian Marz
                正如您从docs. 参数必须是数组,而不是单个字符串。我不确定这是否能解决这个问题,因为我以前没有使用过这个函数。
因此,您的函数调用应该是:
delete_plugins([
  \'litespeed-cache/litespeed-cache.php\',
]);
-- Edit after question update: --
为了使
add_action(\'exampleUninstallPlugin\',\'exampleUninstallPlugin\'); 工作,你需要调用
exampleUninstallPlugin 来自某些代码的操作通过
do_action(\'exampleUninstallPlugin\', $args) 就像你在
show_fields 使用回调
do_action(\'turhostUninstallPlugin\').
是你的show_fields 是否调用函数?如果是,则需要更正函数中的操作名称,反之亦然:
add_action(\'turhostUninstallPlugin\', \'turhostUninstallPlugin\');
function turhostUninstallPlugin($plugins) {
  delete_plugins($plugins);
}
function show_fields( $request ) {
  // …
  if ( $parameters[\'action\'] == "uninstallInstalledPlugin" ) {
    do_action(\'turhostUninstallPlugin\',[
      \'litespeed-cache/litespeed-cache.php\'
    ]);
  }
  // …
}