0

I've implemented this update class in my plugin, but for some reason the update banner isn't diplayed.

Within the class Wp_License_Manager_Client I have this code:

add_filter('pre_set_site_transient_update_plugins', array($this, 'check_for_update'));

that fire the function check_for_update, in particular the following line is called:

$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
);

This is the 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" 
    }

I replaced the values for privacy, but as you can see the object is correctly created.

The situation in the panel is the following:

enter image description here

As you can see from the image Wordpress show me that there is one update, but when I click on "updates", it says that all the plugins are updated. Also, I get the update badge notification only when I clear the cache.

What is going on?

PS: I'm testing this in my localhost with XAMPP and wordpress version is 6.0.1.

6
  • Which cache plugin you are using can you specify that.
    – Prits
    Sep 16, 2022 at 11:28
  • @Prits I doesn't have any cache plugin
    – sfarzoso
    Sep 16, 2022 at 11:36
  • So what this line means " Also, I get the update badge notification only when I clear the cache. " can you explain a bit.
    – Prits
    Sep 16, 2022 at 12:01
  • @Prits I usally clear the cache using the console -> network -> disable cache
    – sfarzoso
    Sep 16, 2022 at 12:48
  • That cache didn't create issue with this.
    – Prits
    Sep 16, 2022 at 12:58

3 Answers 3

2

I ran across this a few weeks ago with a client site - maybe this will help.

 /**
 * 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 .= "<p><strong>Plugin</strong> <u>$plugin</u> is reporting an available update.</p>";
        }
    }

    // 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 .= "<p><strong>Theme</strong> <u>$theme</u> is reporting an available update.</p>";
        }
    }

    if ( empty( $output ) ) $output = "No pending updates found in the database.";

    wp_die( $output );
}
add_action( 'init', 'debug_pending_updates' );

Append your admin url as follows:

For example: https://yoursite.com/wp-admin/?debug_updates
1
+50

Tutorial you are using is 7 years old, I wouldn't bother wit it as it is probably not fully compatible with latest WP-Core and auto-updates.

I'm using free (MIT license) and regularly maintained Plugin Update Checker & WP Update Server WP libraries for my Warp iMagick plugin.

Check this tutorial to add licencing.

0

You can use this code to check if plugin updates is available :

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

it provides an array you can easily show that in the list in your setting page.

7
  • The code you provided returns an empty response, but as you can see from my question the transient is correctly valorized
    – sfarzoso
    Sep 16, 2022 at 12:52
  • Can you check your wp_options table with the key '_site_transient_update_plugins' and double check if you see in correct database and also add the SS for plugin update available .
    – Prits
    Sep 16, 2022 at 12:58
  • The value of _site_transient_update_plugins is the following: pastebin.com/WLZQeTQP also I don't know what does SS means
    – sfarzoso
    Sep 16, 2022 at 13:19
  • The link is not available and add SS means Screenshot of that meta key wp_options table.
    – Prits
    Sep 16, 2022 at 13:32
  • here we go: controlc.com/782d5ddf and here the ss: i.imgur.com/SHlYhGZ.jpg
    – sfarzoso
    Sep 16, 2022 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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