[wp-trac] [WordPress Trac] #47730: Function plugins_api is not triggered for non wp-marketplace plugins

WordPress Trac noreply at wordpress.org
Fri Jul 19 06:28:04 UTC 2019


#47730: Function plugins_api is not triggered for non wp-marketplace plugins
-------------------------------+------------------------------
 Reporter:  marthm             |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Plugins            |     Version:  5.2.2
 Severity:  normal             |  Resolution:
 Keywords:  reporter-feedback  |     Focuses:  administration
-------------------------------+------------------------------

Comment (by marthm):

 Replying to [comment:1 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
 <?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 at example.com',
                         'contributor2' => 'mailto:meow at 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:


 {{{#!json
 {
     "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 :)

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47730#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list