admin管理员组文章数量:1122832
I am trying to get update_plugins_hostname filter to work to show plugin updates.
I used this sample plugin, however plugin doesnt show updates available (it just show version 1.0 installed). This is the only plugin I have activated. No errors. Updates are shown with other premium pluigns if I activate them.
When is this update_plugins_hostname filter suppose to fire? and how could I test this?
/*
Plugin Name: Sample Plugin Name
Plugin URI:
Description: Your Plugin Description
Author: Name
Version: 1.0
Update URI:
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
//Run your plugin as usual
if( ! class_exists( 'SampleExtension' ) ) {
class SampleExtension {
public function __construct() {
//Check for updates
require_once( plugin_dir_path( __FILE__ ) . 'class-update.php' );
$update = new Simple_Update_Check('simple-wp-plugin-update');
}
}
new SampleExtension();
}
class-update.php:
defined( 'ABSPATH' ) || exit;
if( ! class_exists( 'Simple_Update_Check' ) ) {
class Simple_Update_Check{
public $plugin_slug;
public $api_url;
public function __construct($plugin_slug) {
$this->plugin_slug = $plugin_slug;
$this->api_url = '.json';
add_filter('update_plugins_mydomain', array($this, 'update'), 10, 4);
add_filter('plugins_api', array( $this, 'info' ), 20, 3 );
}
public function update($update, $plugin_data, $plugin_file, $locales) {
$remote = wp_remote_get($this->api_url);
if(!is_wp_error( $remote )) {
$remote = json_decode( wp_remote_retrieve_body( $remote ) );
}
return $remote;
}
public function info($res, $action, $args){
if('plugin_information' === $action && $args->slug == $this->plugin_slug) {
$remote = wp_remote_get($this->api_url);
if(!is_wp_error( $remote )) {
$res = json_decode( wp_remote_retrieve_body( $remote ) );
$res->sections = json_decode(json_encode($res->sections), true);
}
}
return $res;
}
}
}
sample.json
{
"slug" : "simple-wp-plugin-update",
"version" : "2.0",
"url": ";,
"tested" : "5.8",
"requires_php" : "5.3",
"name" : "Sample Plugin Name",
"author" : "<a href=''>Name</a>",
"requires" : "3.0",
"last_updated" : "2023-05-20 16:00:00",
"sections" : {
"description" : "Description for the Description tab in the modal",
"installation" : "Description for the Install tab in the modal",
"changelog" : "<h4>2.0</h4><ul><li>Bug fix</li></ul>"
}
}
本文标签: plugin developmentupdatepluginshostname filter show available updates
版权声明:本文标题:plugin development - update_plugins_hostname filter show available updates 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736291485a1928733.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论