Can we set delete = 1 when we uninstall the plugin or the package before uninstalling or after uninstalling not manually dynamically?

Hello Everyone,

Can we set delete = 1 when we uninstall the plugin or the package before uninstalling or after uninstalling not manually it should be dynamically.
Please suggest any solution.

Parents
  • Yes, you can set delete = 1 when you uninstall a plugin or package dynamically. Here is a solution:

    function uninstall_plugin($plugin_name) {
      // Get the plugin data.
      $plugin_data = get_plugin_data($plugin_name);
    
      // Set the delete flag to 1.
      $plugin_data['delete'] = 1;
    
      // Update the plugin data.
      update_plugin_data($plugin_name, $plugin_data);
    }
    
    // Uninstall the plugin.
    uninstall_plugin('my-plugin');
    

Reply
  • Yes, you can set delete = 1 when you uninstall a plugin or package dynamically. Here is a solution:

    function uninstall_plugin($plugin_name) {
      // Get the plugin data.
      $plugin_data = get_plugin_data($plugin_name);
    
      // Set the delete flag to 1.
      $plugin_data['delete'] = 1;
    
      // Update the plugin data.
      update_plugin_data($plugin_name, $plugin_data);
    }
    
    // Uninstall the plugin.
    uninstall_plugin('my-plugin');
    

Children