Updating a Plugin by Slug on Child Sites Using MainWP

Dear Forum Members,

I’m currently trying to update a plugin by slug on child sites using MainWP and have stumbled upon an issue I was hoping to get some advice on.

This is the PHP code block that I’m currently using:

`$upgradePlugin_information = apply_filters(
    'mainwp_fetchurlauthed',
    $CustomExtension->getChildFile(),
    $this->childEnabled['key'],
    $website_id,
    'admin-ajax.php',
    array('action' => 'upgradeplugintheme', 'args' => $args)
);`

When I attempt to perform the update, I keep getting the following error in German: “Die erforderliche Version wurde nicht erkannt. Bitte stelle sicher, dass du die neueste Version des MainWP Child-Plugins auf deiner Website verwendest.”

It translates to “The required version was not recognized. Please ensure you use the latest version of the MainWP Child plugin on your website.”

I’m sure I’m using the latest version of the MainWP Child plugin.

Can anyone provide some insight on how to perform this plugin update process using the slug on child sites? I’d really appreciate it if someone could share an example or some pointers to resolve this issue.

Thanks in advance for your help!

Sincerely,

Piep

Hey @3ele-projects

Welcome to the MainWP community.

It looks like the issue stems from an incorrect usage of the mainwp_fetchurlauthed hook in your code. Specifically, the last two parameters in your code won’t work as intended:

'admin-ajax.php',
array('action' => 'upgradeplugintheme', 'args' => $args)

To properly trigger the plugin update process, you should instead be using the action mainwp_action_upgradeplugintheme. Here’s an example of how you can modify your code:

do_action('mainwp_action_upgradeplugintheme');

This will call the function upgrade_plugin_theme() responsible for handling the update. However, you’ll need to pass the necessary parameters required by the function for it to work correctly.

If you find this difficult to implement, feel free to share more details about what you’re trying to achieve, and we can look into providing additional guidance or alternative solutions.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.