admin管理员组文章数量:1122846
When I click on "Update now" the plugin gets installed, but I'm getting the following error:
The plugin "test/test.php" has been deactivated due to an error: Plugin file does not exist.
Also, I can see on the file structure the plugin has been installed using a random suffix (test-wmAX6O
) instead of just using test
for the folder name.
I'm returning the following on check_for_plugin_update
:
$plugin_info = array(
'slug' => 'test',
'id' => 'test/test.php',
'plugin' => 'test/test.php',
'new_version' => $remote_version->version,
'url' => $remote_version->info_url,
'package' => $remote_version->download_url,
'requires_php' => '',
'compatibility' => new stdClass(),
);
$checked_data->response['test/test.php'] = (object) $plugin_info;
return $checked_data;
Which gets called in the main file test/test.php
in the constructor:
public function __construct() {
....
$this->force_plugin_update_check();
add_action( 'pre_set_site_transient_update_plugins', array($this, 'check_for_plugin_update') );
}
function force_plugin_update_check(){
delete_site_transient('update_plugins');
wp_update_plugins(); // Force a fresh update check
}
The plugin's main file test/test.php
also contains the following header comments:
<?php
/**
* Plugin Name: Test
* Plugin URI:
* Description: A brief description of the plugin.
* Text Domain: test
* Version: 1.1.1
* Author: XXXX
* Author URI:
* License: GPL2
* @package test
**/
Am I missing something?
It looks like there's a problem with the "slug" but I can't see why.
I can't find any good documentation on pre_set_site_transient_update_plugins
anywhere on WordPress, so I'm a bit lost here.
When I click on "Update now" the plugin gets installed, but I'm getting the following error:
The plugin "test/test.php" has been deactivated due to an error: Plugin file does not exist.
Also, I can see on the file structure the plugin has been installed using a random suffix (test-wmAX6O
) instead of just using test
for the folder name.
I'm returning the following on check_for_plugin_update
:
$plugin_info = array(
'slug' => 'test',
'id' => 'test/test.php',
'plugin' => 'test/test.php',
'new_version' => $remote_version->version,
'url' => $remote_version->info_url,
'package' => $remote_version->download_url,
'requires_php' => '',
'compatibility' => new stdClass(),
);
$checked_data->response['test/test.php'] = (object) $plugin_info;
return $checked_data;
Which gets called in the main file test/test.php
in the constructor:
public function __construct() {
....
$this->force_plugin_update_check();
add_action( 'pre_set_site_transient_update_plugins', array($this, 'check_for_plugin_update') );
}
function force_plugin_update_check(){
delete_site_transient('update_plugins');
wp_update_plugins(); // Force a fresh update check
}
The plugin's main file test/test.php
also contains the following header comments:
<?php
/**
* Plugin Name: Test
* Plugin URI: https://test.io
* Description: A brief description of the plugin.
* Text Domain: test
* Version: 1.1.1
* Author: XXXX
* Author URI: https://test.io
* License: GPL2
* @package test
**/
Am I missing something?
It looks like there's a problem with the "slug" but I can't see why.
I can't find any good documentation on pre_set_site_transient_update_plugins
anywhere on WordPress, so I'm a bit lost here.
1 Answer
Reset to default 0I tried the hook update_plugins_{$hostname}
following the fresher informations I found in the link quoted by Tom J Nowell :
https://make.wordpress.org/core/2021/06/29/introducing-update-uri-plugin-header-in-wordpress-5-8/
here is a example of plugin with self managed update. it's a base for update by the Updates page and the Plugins page and this example can be complete to manage more details, e.g. in the plugin information page. then don't hesitate to edit to complete.
<?php
/*
Plugin Name: MY_PLUGIN
Version: 128
Plugin URI: https://my_domain.com/my_plugin
Update URI: https://my_domain.com/my_plugin
*/
if (!function_exists("add_action")) {
echo "plugin";
exit();
}
// the part "my_domain.com" in the hook is the domain of the url in the header "Update URI"
add_filter("update_plugins_my_domain.com", function ($update, $plugin_data, $plugin_file, $locales) {
// if you manage more plugins on the same domain,
// test here if it's the current plugin
if (TRUE) { // if there is a new version for this plugin
$update = [
"slug" => "MY_PLUGIN",
"version" => 137, // new version
"package" => "https://my_domain.com/plugins-updates/my_plugin-v137.zip",
];
}
return $update;
}, 10, 4);
// filter to manage the information page of the plugin
add_filter("plugins_api", function ($res, $action, $args) {
if ( ("plugin_information" === $action)
&& ("MY_PLUGIN" === $args->slug)
) {
$res = (object) [
"slug" => $args->slug,
"name" => "Name of the plugin",
"sections" => [
"description" => "<strong>plugin information</strong>",
"changelog" => "<ul><li>details of the change log</li></ul>",
],
"banners" => [
"low" => "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/8_Poultry.jpg/1024px-8_Poultry.jpg",
],
"download_link" => ".", // just any single character is enough
// to enable update button on information page
];
}
return $res;
}, 10, 3);
本文标签: Plugin39s quotUpdate Nowquot not workingInstalled in folder with random suffix
版权声明:本文标题:Plugin's "Update Now" not working - Installed in folder with random suffix 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736291921a1928825.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Update URI:
field for the plugin header and theupdate_plugins_{$hostname}
filters. Ignoring that, wouldn't the transient be set when the plugin updates are checked, so your filter would be added after rather than before? Order matters! – Tom J Nowell ♦ Commented Aug 21, 2024 at 12:48update_plugins_
or theUpdate URI
I've read the article multiple times but I still don't understand how that helps with the updates. Any place where I can see a code example? – Alvaro Commented Aug 21, 2024 at 16:12pre_set_site_transient_update_plugins
forsite_transient_update_plugins
but still not working. Same problem. – Alvaro Commented Aug 21, 2024 at 17:17