WordPress插件开发过程中获取插件信息-博客程序技术分享中心-开发交流社区-GOdou社区

WordPress插件开发过程中获取插件信息

WordPress在插件开发中,可以获取到插件的一些信息,比如插件名称,插件版本等。最常用的就是获取插件版本,然后提示更新之类的。

获取插件信息本来是get_plugin_data,但是我使用这个在插件中获取不到,我看了get_plugin_data源码,发现可以这样写:

$default_headers = array(
  'Name'        => 'Plugin Name',
  'PluginURI'   => 'Plugin URI',
  'Version'     => 'Version',
  'Description' => 'Description',
  'Author'      => 'Author',
  'AuthorURI'   => 'Author URI',
  'TextDomain'  => 'Text Domain',
  'DomainPath'  => 'Domain Path',
  'Network'     => 'Network',
  'RequiresWP'  => 'Requires at least',
  'RequiresPHP' => 'Requires PHP',
  'UpdateURI'   => 'Update URI',
  // Site Wide Only is deprecated in favor of Network.
  '_sitewide'   => 'Site Wide Only',
);

$plugin_data = get_file_data( __FILE__, $default_headers, 'plugin' );
var_dump(__FILE__);///www/wwwroot/kekc.cn/wp-content/plugins/zibll_Add_ons/zibll_Add_ons.php

这样就获取到了插件的信息,数组为$plugin_data。

请登录后发表评论

    没有回复内容