如何使用GET_PLUGIN_UPDATES()函数?

时间:2020-02-06 作者:Beppe

我想使用此功能获取一些信息,但如何获取所需的数据?例如,对于wp\\u get\\u data(),我这样做

$example = wp_get_update_data();
echo $example [\'title\'];

echo $example[\'count\'][\'plugins\']; 
它可以打印我想要的数据。对于get\\u plugin\\u updates(),请调用我需要的内容。我想要echo name插件|实际版本|更新版本

1 个回复
最合适的回答,由SO网友:Hector 整理而成

欢迎

函数返回所有可能更新的数组。意味着您需要指定获取其信息所需的插件。

的样本输出get_plugin_updates 拜访admin_init:

array(1) {
  ["fast-velocity-minify/fvm.php"]=>
  object(stdClass)#7844 (14) {
    ["Name"]=>
    string(20) "Fast Velocity Minify"
    ["PluginURI"]=>
    string(23) "http://fastvelocity.com"
    ["Version"]=>
    string(5) "2.7.7"
    ["Description"]=>
    string(192) "Improve your speed score on GTmetrix, Pingdom Tools and Google PageSpeed Insights by merging and minifying CSS and JavaScript files into groups, compressing HTML and other speed optimizations."
    ["Author"]=>
    string(12) "Raul Peixoto"
    ["AuthorURI"]=>
    string(23) "http://fastvelocity.com"
    ["TextDomain"]=>
    string(20) "fast-velocity-minify"
    ["DomainPath"]=>
    string(0) ""
    ["Network"]=>
    bool(false)
    ["RequiresWP"]=>
    string(0) ""
    ["RequiresPHP"]=>
    string(0) ""
    ["Title"]=>
    string(20) "Fast Velocity Minify"
    ["AuthorName"]=>
    string(12) "Raul Peixoto"
    ["update"]=>
    object(stdClass)#7799 (12) {
      ["id"]=>
      string(34) "w.org/plugins/fast-velocity-minify"
      ["slug"]=>
      string(20) "fast-velocity-minify"
      ["plugin"]=>
      string(28) "fast-velocity-minify/fvm.php"
      ["new_version"]=>
      string(5) "2.7.8"
      ["url"]=>
      string(51) "https://wordpress.org/plugins/fast-velocity-minify/"
      ["package"]=>
      string(69) "https://downloads.wordpress.org/plugin/fast-velocity-minify.2.7.8.zip"
      ["icons"]=>
      array(1) {
        ["1x"]=>
        string(73) "https://ps.w.org/fast-velocity-minify/assets/icon-128x128.jpg?rev=1440946"
      }
      ["banners"]=>
      array(1) {
        ["1x"]=>
        string(75) "https://ps.w.org/fast-velocity-minify/assets/banner-772x250.jpg?rev=1440936"
      }
      ["banners_rtl"]=>
      array(0) {
      }
      ["tested"]=>
      string(5) "5.3.2"
      ["requires_php"]=>
      string(3) "5.6"
      ["compatibility"]=>
      object(stdClass)#7800 (0) {
      }
    }
  }
}
因此,您需要在获取插件名称之前指定插件。您需要将代码更改为以下代码:

$plugin_updates = get_plugin_updates();

// Print plugin name.
echo [\'my-plugin/my-plugin.php\']->Name;

// Print plugin update version.
echo [\'my-plugin/my-plugin.php\']->update->new_version;