^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_plugin_data()用法示例

get_plugin_data( string $plugin_file,  bool $markup = true,  bool $translate = true )

Parses the plugin contents to retrieve plugin’s metadata.


描述

The metadata of the plugin’s data searches for the following in the plugin’s header. All plugin data must be on its own line. For plugin 描述, it must not have any newlines or only parts of the 描述 will be displayed and the same goes for the plugin data. The below is formatted for printing.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包

/*
Plugin Name: Name of Plugin
Plugin URI: Link to plugin information
描述: Plugin 描述
Author: Plugin author's name
Author URI: Link to the author's web site
Version: Must be set in the plugin for WordPress 2.3+
Text Domain: Optional. Unique identifier, should be same as the one used in
    load_plugin_textdomain()
Domain Path: Optional. Only useful if the translations are located in a
    folder above the plugin's base path. For example, if .mo files are
    located in the locale folder then Domain Path will be "/locale/" and
    must have the first slash. Defaults to the base folder the plugin is
    located in.
Network: Optional. Specify "Network: true" to require that a plugin is activated
    across all sites in an installation. This will prevent a plugin from being
    activated on a single site when Multisite is enabled.
 * /

Some users have issues with opening large files and manipulating the contents for want is usually the first 1kiB or 2kiB. This function stops pulling in the plugin contents when it has all of the required plugin data.

The first 8kiB of the file will be pulled in and if the plugin data is not within that first 8kiB, then the plugin author should correct their plugin and move the plugin data headers to the top.

The plugin file is assumed to have permissions to allow for scripts to read the file. This is not checked however and the file is only opened for reading.


参数

$plugin_file

(string)
(Required)
Path to the main plugin file.

$markup

(bool)
(Optional)
If the returned data should have HTML markup applied.

Default value: true

$translate

(bool)
(Optional)
If the returned data should be translated.

Default value: true


返回值

(array) { Plugin data. Values will be empty if not supplied by the plugin. @type string $Name Name of the plugin. Should be unique. @type string $Title Title of the plugin and link to the plugin’s site (if set). @type string $描述 Plugin 描述. @type string $Author Author’s name. @type string $AuthorURI Author’s website address (if set). @type string $Version Plugin version. @type string $TextDomain Plugin textdomain. @type string $DomainPath Plugins relative directory path to .mo files. @type bool $Network Whether the plugin can only be activated network-wide. }


源代码

File: wp-admin/includes/plugin.php

function get_plugin_data( $plugin_file, $markup = true, $translate = true ) {

	$default_headers = array(
		'Name' => 'Plugin Name',
		'PluginURI' => 'Plugin URI',
		'Version' => 'Version',
		'描述' => '描述',
		'Author' => 'Author',
		'AuthorURI' => 'Author URI',
		'TextDomain' => 'Text Domain',
		'DomainPath' => 'Domain Path',
		'Network' => 'Network',
		// Site Wide Only is deprecated in favor of Network.
		'_sitewide' => 'Site Wide Only',
	);

	$plugin_data = get_file_data( $plugin_file, $default_headers, 'plugin' );

	// Site Wide Only is the old header for Network
	if ( ! $plugin_data['Network'] && $plugin_data['_sitewide'] ) {
		/* translators: 1: Site Wide Only: true, 2: Network: true */
		_deprecated_argument( __FUNCTION__, '3.0.0', sprintf( __( 'The %1$s plugin header is deprecated. Use %2$s instead.' ), '<code>Site Wide Only: true</code>', '<code>Network: true</code>' ) );
		$plugin_data['Network'] = $plugin_data['_sitewide'];
	}
	$plugin_data['Network'] = ( 'true' == strtolower( $plugin_data['Network'] ) );
	unset( $plugin_data['_sitewide'] );

	// If no text domain is defined fall back to the plugin slug.
	if ( ! $plugin_data['TextDomain'] ) {
		$plugin_slug = dirname( plugin_basename( $plugin_file ) );
		if ( '.' !== $plugin_slug && false === strpos( $plugin_slug, '/' ) ) {
			$plugin_data['TextDomain'] = $plugin_slug;
		}
	}

	if ( $markup || $translate ) {
		$plugin_data = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup, $translate );
	} else {
		$plugin_data['Title']      = $plugin_data['Name'];
		$plugin_data['AuthorName'] = $plugin_data['Author'];
	}

	return $plugin_data;
}

更新日志

Version 描述
1.5.0 Introduced.

相关函数

Uses

  • wp-admin/includes/plugin.php:
    _get_plugin_data_markup_translate()
  • wp-includes/l10n.php:
    __()
  • wp-includes/functions.php:
    get_file_data()
  • wp-includes/functions.php:
    _deprecated_argument()
  • wp-includes/plugin.php:
    plugin_basename()

Used By

  • wp-admin/includes/ajax-actions.php:
    wp_ajax_delete_plugin()
  • wp-admin/includes/ajax-actions.php:
    wp_ajax_update_plugin()
  • wp-admin/includes/class-wp-automatic-updater.php:
    WP_Automatic_Updater::update()
  • wp-admin/includes/class-plugin-upgrader.php:
    Plugin_Upgrader::bulk_upgrade()
  • wp-admin/includes/class-plugin-upgrader.php:
    Plugin_Upgrader::check_package()
  • wp-admin/includes/plugin.php:
    get_dropins()
  • wp-admin/includes/plugin.php:
    is_network_only_plugin()
  • wp-admin/includes/plugin.php:
    get_plugins()
  • wp-admin/includes/plugin.php:
    get_mu_plugins()
  • Show 4 more used by
    Hide more used by


  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

    Contributed by pepe

    If $markup or $translate are set to true (as they are by default), the function indirectly calls wptexturize, potentially breaking other plugins if this happens before the init hook.

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈