首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用get_plugin_updates()函数?

如何使用get_plugin_updates()函数?
EN

WordPress Development用户
提问于 2020-02-06 19:23:08
回答 1查看 256关注 0票数 0

我想要使用这个函数来获取一些信息,但是如何获取我所需要的数据呢?例如,对于wp_get_data(),我会这样做

代码语言:javascript
复制
$example = wp_get_update_data();
echo $example ['title'];

代码语言:javascript
复制
echo $example['count']['plugins']; 

打印我想要的数据。对于get_plugin_updates(),不要调用我需要的东西。我想要回显名称-plugin\实际版本/更新版本

EN

回答 1

WordPress Development用户

回答已采纳

发布于 2020-02-07 07:48:04

欢迎。

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

get_plugin_updates调用在admin_init上的示例输出:

代码语言:javascript
复制
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) {
      }
    }
  }
}

因此,您需要指定插件,然后才能得到它的名称。您需要将代码更改为如下代码:

代码语言:javascript
复制
$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;
票数 0
EN
页面原文内容由WordPress Development提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://wordpress.stackexchange.com/questions/358047

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档