Button to update plugin I’ve made doesn’t show

Question

I’ve created a (simple) plugin just to add a few basic functions and I’m using this in multiple many of my clients websites.

What I’m trying to do is to be able to update the plugin within the admin dashboard, just as a others plugins work. When there is a new release, a button appears to click and download the new update.

I’ve managed to make the wordpress detect a new version (I think I did) but there is no button to update the plugin, there is just the orange badge showing that there is 1 plugin to be updated.

I’m using this code on the main php plugin file to track changes:

/**
* WPBeginner - WordPress Tutorials-plugin
* Plugin Name:       plugin-name
* Plugin URI:        https://-my-website-/assets/plugin/plugin-name/
* Description:       Description.
* Version:           1.1.0
* Author:            plugin-name
* Author URI:        https://-my-website-/
* License:           GPL-2.0+
* License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain:       plugin-name
* Domain Path:       /languages
*/

add_filter('site_transient_update_plugins', 'update_plugin' );

function update_plugin( $transient ) {
  if ( empty($transient->checked ) ) {
    return $transient;
  }

  if( false == $remote = get_transient( 'plugin-name' ) ) {

    $remote = wp_remote_get( 'https://-my-website-/assets/plugin/plugin-name/info.json', array(
      'timeout' => 10,
      'headers' => array(
        'Accept' => 'application/json'
      )
    ));

    if ( !is_wp_error( $remote ) && isset( $remote['response']['code'] ) && $remote['response']['code'] == 200 && !empty( $remote['body'] ) ) {
      set_transient( 'plugin-name', $remote, 10 );
    }
  }

  if( $remote ) {
    $remote = json_decode( $remote['body'] );

    if( $remote && version_compare( '1.1.0', $remote->version, '<' ) && version_compare($remote->requires, get_bloginfo('version'), '<' ) ) {
      $res = new stdClass();
      $res->slug = 'plugin-name';
      $res->plugin = 'plugin-name.php';
      $res->new_version = $remote->version;
      $res->tested = $remote->tested;
      $res->package = $remote->download_url;
      $transient->response[$res->plugin] = $res;
      $transient->checked[$res->plugin] = $remote->version;
    }
  }

  return $transient;
}

And also this info.json file

{
  "version": "1.1.0",
  "download_url": "https://-my-website-/assets/plugin/plugin-name.rar",
  "requires": "3.0",
  "tested": "4.0",
  "requires_php": "5",
  "last_updated": "2020-06-10 10:00:00",
  "sections": {
    "description": "Description",
    "installation": "Install"
  },
  "banners": {
    "low": "https://-my-website-/assets/plugin/banner-772x250.jpg",
    "high": "https://-my-website-/assets/plugin/banner-1544x500.jpg"
  }
}

So, when I change something on the code I also change the version number in all files, create a new zip file and upload to my own hosting server. Then I go to my client website and check for new updates. At this point, like I said, I can see the badge indicating there is a new update, but the plugin list doesn’t show the button to update.

What am I doing wrong this is not showing?

Note I’m completely new to create wp plugins, this is my first try ever.

0
, celsomtrindade 8 months 0 Answers 96 views 0

Leave an answer