我已经在插件中实现了这更新类,但是由于某种原因,更新横幅没有被播放。
在类Wp_License_Manager_Client中,我有以下代码:
add_filter('pre_set_site_transient_update_plugins', array($this, 'check_for_update'));它将激发函数check_for_update,特别是下面的一行被调用:
$plugin_slug = plugin_basename($this->plugin_file);
$transient->response[$plugin_slug] = (object) array(
'new_version' => $info->version,
'package' => $info->package_url,
'slug' => $plugin_slug,
'url' => $info->package_url
);这是var_dump($transient->response[$plugin_slug]):
object(stdClass)#8891 (4) {
["new_version"]=> string(5) "1.0.1"
["package"]=> string(107) "https://example.com/api/license-manager/v1/get?p=my-plugin&e=foo@mysite.com&l=123456789%24"
["slug"]=> string(47) "my-plugin/public/class-wp-api-client.php"
["url"]=> string(107) "https://example.com/api/license-manager/v1/get?p=my-plugin&e=foo@mysite.com&l=123456789%24"
}为了保护隐私,我替换了这些值,但是正如您所看到的,这个对象是正确创建的。
小组的情况如下:

正如你可以从图片中看到Wordpress告诉我有一个更新,但当我点击“更新”,它说所有的插件都更新了。另外,只有在清除缓存时才会收到更新徽章通知。
怎么一回事?
PS:我正在用XAMPP和wordpress版本6.0.1在我的本地主机上测试这一点。
发布于 2022-09-21 14:24:04
几周前,我在一个客户网站上遇到了这个问题--也许这会有所帮助。
/**
* Debug Pending Updates
*
* Crude debugging method that will spit out all pending plugin
* and theme updates for admin level users when ?debug_updates is
* added to a /wp-admin/ URL.
*/
function debug_pending_updates() {
// Rough safety nets
if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) return;
if ( ! isset( $_GET['debug_updates'] ) ) return;
$output = "";
// Check plugins
$plugin_updates = get_site_transient( 'update_plugins' );
if ( $plugin_updates && ! empty( $plugin_updates->response ) ) {
foreach ( $plugin_updates->response as $plugin => $details ) {
$output .= "Plugin $plugin is reporting an available update.";
}
}
// Check themes
wp_update_themes();
$theme_updates = get_site_transient( 'update_themes' );
if ( $theme_updates && ! empty( $theme_updates->response ) ) {
foreach ( $theme_updates->response as $theme => $details ) {
$output .= "Theme $theme is reporting an available update.";
}
}
if ( empty( $output ) ) $output = "No pending updates found in the database.";
wp_die( $output );
}
add_action( 'init', 'debug_pending_updates' );按以下方式追加您的管理url:
For example: https://yoursite.com/wp-admin/?debug_updates发布于 2022-09-22 13:09:22
你使用的教程已经7岁了,我不介意它,因为它可能不完全兼容最新的WP核心和自动更新。
我使用免费(麻省理工学院许可),并定期维护插件更新检查器 & WP更新服务器 WP库为我的经编iMagick插件。
看看这个添加许可的教程。
发布于 2022-09-16 12:10:56
您可以使用此代码检查插件更新是否可用:
add_action('admin_menu', array($this,'register_test_menu_page'));
public function register_test_menu_page(){
add_menu_page('Test', 'Test Menu', 'manage_options',
'test_user_menu', array($this,'test_user_menu_fun'), null, 4);
}
public function test_user_menu_fun(){
$update_plugins = get_site_transient( 'update_plugins' );
foreach ($update_plugins->response as $key => $value) {
var_dump($value->slug);
}
}它提供了一个数组,您可以很容易地在设置页面的列表中显示这一点。
https://wordpress.stackexchange.com/questions/409354
复制相似问题