Opened 5 years ago
Last modified 5 years ago
#47730 new defect (bug)
Function plugins_api is not triggered for non wp-marketplace plugins
Reported by: | marthm | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 5.2.2 |
Component: | Plugins | Keywords: | dev-feedback |
Focuses: | administration | Cc: |
Description
I currently try to setup a private-hosted repository for my own plugins / themes and tried to do that with the filter hooks in the plugin-install.php file - the documentation of it indicates that this should be possible, even on the latest version (5.2.2).
I activated my own plugin on my bedrock (https://roots.io/bedrock/) setup and following the tutorial https://rudrastyh.com/wordpress/self-hosted-plugin-update.html#comments i tried to implement the update mechanism.
I think while doing that i stumbled upon a bug that causes wordpress to not trigger the plugins_api method at all - i can hook into the "site_transient_update_plugins" filter to display the update-badge next to the plugins navbar item but the update text / button and show-details button for my plugins wont show up.
Change History (4)
#2
in reply to:
↑ 1
@
5 years ago
Replying to pento:
Thank you for the bug report, @marthm!
Could you please add step-by-step instructions, with sample code, to reproduce this issue?
As noted in my bug report i use this tutorial and i copied all the code with some minor changes. Here's the code that i use:
<?php /** * Plugin Name: Testplugin für Repository Funktionalität * Description: nya * Author: marthm * Author URI: https://example.com * Version: 1.0 * * @package somepackage * @author marthm */ /* * $res contains information for plugins with custom update server * $action 'plugin_information' * $args stdClass Object ( [slug] => woocommerce [is_ssl] => [fields] => Array ( [banners] => 1 [reviews] => 1 [downloaded] => [active_installs] => 1 ) [per_page] => 24 [locale] => en_US ) */ function smh_test_pluginSlug( $res, $action, $args ){ echo "Test"; // do nothing if this is not about getting plugin information if( $action !== 'plugin_information' ) return false; // do nothing if it is not our plugin if( 'planet_test' !== $args->slug ) return $res; // trying to get from cache first, to disable cache comment 18,28,29,30,32 //if( false == $remote = get_transient( 'smh_upgrade_pluginSlug' ) ) { // info.json is the file with the actual plugin information on your server $remote = wp_remote_get( 'https://someWebsite/marthm/WordPressRepo/test/info.json', array( 'timeout' => 10, 'sslverify' => false, 'headers' => array( 'Accept' => 'application/json' ) ) ); //var_dump($remote); //if ( !is_wp_error( $remote ) && isset( $remote['response']['code'] ) && $remote['response']['code'] == 200 && !empty( $remote['body'] ) ) { //echo "ERROR!"; //set_transient( 'smh_upgrade_pluginSlug', $remote, 3600 ); // 12 hours cache (12*60*60) = 43200 //} //} if( $remote ) { $remote = json_decode( $remote['body'] ); $res = new stdClass(); $res->name = $remote->name; $res->slug = 'pluginSlug'; $res->version = $remote->version; $res->tested = $remote->tested; $res->requires = $remote->requires; $res->author = '<a href="https://example.com">some company uwu</a>'; // I decided to write it directly in the plugin //$res->author_profile = 'https://profiles.wordpress.org/rudrastyh'; // WordPress.org profile $res->download_link = $remote->download_url; $res->trunk = $remote->download_url; $res->last_updated = $remote->last_updated; $res->sections = array( 'description' => $remote->sections->description, // description tab 'installation' => $remote->sections->installation, // installation tab 'changelog' => $remote->sections->changelog, // changelog tab // you can add your custom sections (tabs) here ); // in case you want the screenshots tab, use the following HTML format for its content: // <ol><li><a href="IMG_URL" target="_blank" rel="noopener noreferrer"><img src="IMG_URL" alt="CAPTION" /></a><p>CAPTION</p></li></ol> if( !empty( $remote->sections->screenshots ) ) { $res->sections['screenshots'] = $remote->sections->screenshots; } $res->banners = array( 'low' => 'https://someWebsite/marthm/WordPressRepo/test/banner-772x250.jpg', 'high' => 'https://someWebsite/marthm/WordPressRepo/test/banner-1544x500.jpg' ); $res->contributors = array( 'contributor1' => 'mailto:marthm@example.com', 'contributor2' => 'mailto:meow@example.com' ); return $res; } return false; } add_filter('plugins_api_result', 'smh_test_pluginSlug', 20, 3); add_filter('plugins_api', 'smh_test_pluginSlug', 20, 3);
With the json file being:
{ "name" : "Test-Plugin", "slug" : "pluginSlug", "download_url" : "https://someWebsite/marthm/WordPressRepo/test/update.zip", "version" : "1.1", "requires" : "3.0", "tested" : "4.8.1", "last_updated" : "2019-07-17 11:00:00", "upgrade_notice" : "Ein Plugin-Update ist verfügbar.", "author" : "marthm", "author_homepage" : "https://www.example.com", "sections" : { "description" : "This is the plugin to test your updater script", "installation" : "Upload the plugin to your blog, Activate it, that's it!", "changelog" : "<h4>1.1 – August 17, 2017</h4><ul><li>Some bugs are fixed.</li><li>Release date.</li></ul>" } }
I tried to echo out something to test if the function gets called at all, but i can't find that "test" in the html of the plugin-list page at all ;-;
The server i try to call in the function doesn't have a valid ssl-certificate as for why i deactivate the sslverify.
The zip-file that's mentioned in the .json file (update.zip) doesn't exist as of now, but that shouldn't be a problem, right? o:
I tried to fix something with adding that other "plugins_api_result" filter, but that doesn't seem to work either ;-;
What should happen after the plugin gets activated:
There should be a "view details" button next to the author link that displays the information from the json in a modal.
What happens instead:
Nothing :c
I hope this helps :)
Thank you for the bug report, @marthm!
Could you please add step-by-step instructions, with sample code, to reproduce this issue?