0

I'm developing a wordpress plugin for a project. I'm expected to manage other plugins in this plugin. For example, I will be able to install Akismet over my plugin. I have done things like install, activating, deactivating. But I could not delete the plugin.

I can also delete direct attachment files, but I don't want to. I should use as many wordpress functions as possible.

delete_plugins('litespeed-cache/litespeed-cache.php')

This function does not work. I tried to integrate this function, but it was very complicated. Can you help me?

--EDİT--

I'm sorry, I didn't pay attention. There is another problem right now. I wrote a new plugin and it worked fine when I added the following code.

register_activation_hook( __FILE__, 'index' );

function index() {
    delete_plugins( [
        'litespeed-cache/litespeed-cache.php',
    ] );
}

But it didn't work on my own plugin.

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' ]); } }

0

Use TGM plugin activation, for requiring other plugins inside a plugin for your plugin to work.

Here you go http://tgmpluginactivation.com/

  • Thanks for help. But I can't use it because there are project requirements. I need to do this with wordpress plugins and functions. – Ali Erdem Akın Sep 26 '18 at 8:40
  • Oh okay, I wish I could help but am not skilled enough as of yet to help right away. I am sure someone will help and your problem will be resolved. – Adnan Sep 26 '18 at 8:42
0

As you can see from the docs. The parameter must be an array, not a single string. I'm not sure if this will resolve the issue as I haven't used this function before.

So your function call should be:

delete_plugins([
  'litespeed-cache/litespeed-cache.php',
]);

-- Edit after question update: --

In order to make add_action('exampleUninstallPlugin','exampleUninstallPlugin'); work, you need to invoke that exampleUninstallPlugin action from some code via do_action('exampleUninstallPlugin', $args) like you did in your show_fields callback with do_action('turhostUninstallPlugin').

Is your show_fields function invoked? If so, you need to correct the action name in the function or vice versa:

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'
    ]);
  }
  // …
}
  • My message is long, I have edited the subject. – Ali Erdem Akın Sep 26 '18 at 8:25
  • Please have a look again. You mismatched your action name. – Fabian Marz Sep 26 '18 at 8:58
  • First of all, thanks for helping us, Fabian. I arranged it as you said. I'm always making a mistake because I have to hurry. I apologize again. The following error is returned when I call the Rest service. There was an error parsing JSON data Unexpected token < in JSON at position 0* – Ali Erdem Akın Sep 26 '18 at 9:06
  • Did my answer helped with your issue or not? It's not clear to me, sorry. – Fabian Marz Sep 26 '18 at 9:20
  • Corrected function as you said. But he gave me the error I said above. ** error: There was an error parsing JSON data Unexpected token < in JSON at position 0 ** – Ali Erdem Akın Sep 26 '18 at 10:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.