返回介绍

_get_plugin_data_markup_translate()

发布于 2017-09-11 13:24:38 字数 4350 浏览 922 评论 0 收藏 0

Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use get_plugin_data() instead.

_get_plugin_data_markup_translate( $plugin_file,  $plugin_data,  $markup = true,  $translate = true )

Sanitizes plugin data, optionally adds markup, optionally translates.


description


源代码

File: wp-admin/includes/plugin.php

function _get_plugin_data_markup_translate( $plugin_file, $plugin_data, $markup = true, $translate = true ) {

	// Sanitize the plugin filename to a WP_PLUGIN_DIR relative path
	$plugin_file = plugin_basename( $plugin_file );

	// Translate fields
	if ( $translate ) {
		if ( $textdomain = $plugin_data['TextDomain'] ) {
			if ( ! is_textdomain_loaded( $textdomain ) ) {
				if ( $plugin_data['DomainPath'] ) {
					load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) . $plugin_data['DomainPath'] );
				} else {
					load_plugin_textdomain( $textdomain, false, dirname( $plugin_file ) );
				}
			}
		} elseif ( 'hello.php' == basename( $plugin_file ) ) {
			$textdomain = 'default';
		}
		if ( $textdomain ) {
			foreach ( array( 'Name', 'PluginURI', 'description', 'Author', 'AuthorURI', 'Version' ) as $field )
				$plugin_data[ $field ] = translate( $plugin_data[ $field ], $textdomain );
		}
	}

	// Sanitize fields
	$allowed_tags = $allowed_tags_in_links = array(
		'abbr'    => array( 'title' => true ),
		'acronym' => array( 'title' => true ),
		'code'    => true,
		'em'      => true,
		'strong'  => true,
	);
	$allowed_tags['a'] = array( 'href' => true, 'title' => true );

	// Name is marked up inside <a> tags. Don't allow these.
	// Author is too, but some plugins have used <a> here (omitting Author URI).
	$plugin_data['Name']        = wp_kses( $plugin_data['Name'],        $allowed_tags_in_links );
	$plugin_data['Author']      = wp_kses( $plugin_data['Author'],      $allowed_tags );

	$plugin_data['description'] = wp_kses( $plugin_data['description'], $allowed_tags );
	$plugin_data['Version']     = wp_kses( $plugin_data['Version'],     $allowed_tags );

	$plugin_data['PluginURI']   = esc_url( $plugin_data['PluginURI'] );
	$plugin_data['AuthorURI']   = esc_url( $plugin_data['AuthorURI'] );

	$plugin_data['Title']      = $plugin_data['Name'];
	$plugin_data['AuthorName'] = $plugin_data['Author'];

	// Apply markup
	if ( $markup ) {
		if ( $plugin_data['PluginURI'] && $plugin_data['Name'] )
			$plugin_data['Title'] = '<a href="' . $plugin_data['PluginURI'] . '">' . $plugin_data['Name'] . '</a>';

		if ( $plugin_data['AuthorURI'] && $plugin_data['Author'] )
			$plugin_data['Author'] = '<a href="' . $plugin_data['AuthorURI'] . '">' . $plugin_data['Author'] . '</a>';

		$plugin_data['description'] = wptexturize( $plugin_data['description'] );

		if ( $plugin_data['Author'] )
			$plugin_data['description'] .= ' <code>' . sprintf( __('By %s.'), $plugin_data['Author'] ) . '</code>';
	}

	return $plugin_data;
}

更新日志

Versiondescription
2.7.0Introduced.

相关函数

Uses

  • wp-includes/l10n.php: is_textdomain_loaded()
  • wp-includes/l10n.php: load_plugin_textdomain()
  • wp-includes/l10n.php: translate()
  • wp-includes/l10n.php: __()
  • wp-includes/formatting.php: esc_url()
  • wp-includes/formatting.php: wptexturize()
  • wp-includes/kses.php: wp_kses()
  • wp-includes/plugin.php: plugin_basename()
  • Show 3 more uses Hide more uses

Used By

  • wp-admin/includes/class-wp-plugins-list-table.php: WP_Plugins_List_Table::prepare_items()
  • wp-admin/includes/plugin.php: get_plugin_data()
  • wp-admin/update-core.php: list_plugin_updates()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文