plugin_basename() - WordPress 函数参考中文文档

返回介绍

plugin_basename()

发布于 2017-09-11 字数3385 浏览 925 评论 0

plugin_basename( string $file )

Gets the basename of a plugin.


描述

This method extracts the name of a plugin from its filename.


参数

$file

(string)
(Required)
The filename of plugin.


返回值

(string) The name of a plugin.


源代码

File: wp-includes/plugin.php

function plugin_basename( $file ) {
	global $wp_plugin_paths;

	// $wp_plugin_paths contains normalized paths.
	$file = wp_normalize_path( $file );

	arsort( $wp_plugin_paths );
	foreach ( $wp_plugin_paths as $dir => $realdir ) {
		if ( strpos( $file, $realdir ) === 0 ) {
			$file = $dir . substr( $file, strlen( $realdir ) );
		}
	}

	$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
	$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );

	$file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
	$file = trim($file, '/');
	return $file;
}

更新日志

Version 描述
1.5.0 Introduced.

相关函数

Uses

  • wp-includes/functions.php:
    wp_normalize_path()

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/plugin.php:
    is_uninstallable_plugin()
  • wp-admin/includes/plugin.php:
    uninstall_plugin()
  • wp-admin/includes/plugin.php:
    add_menu_page()
  • wp-admin/includes/plugin.php:
    add_submenu_page()
  • wp-admin/includes/plugin.php:
    activate_plugin()
  • wp-admin/includes/plugin.php:
    deactivate_plugins()
  • wp-admin/includes/plugin.php:
    get_plugin_data()
  • wp-admin/includes/plugin.php:
    _get_plugin_data_markup_translate()
  • wp-admin/includes/plugin.php:
    get_plugin_files()
  • wp-admin/includes/plugin.php:
    get_plugins()
  • wp-includes/link-template.php:
    plugins_url()
  • wp-includes/plugin.php:
    register_activation_hook()
  • wp-includes/plugin.php:
    register_deactivation_hook()
  • wp-includes/plugin.php:
    register_uninstall_hook()
  • Show 11 more used by
    Hide more used by


User Contributed Notes

  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 Codex

    If your plugin file is located at /home/www/wp-content/plugins/wpdocs-plugin/wpdocs-plugin.php, and you call:

    
    $x = plugin_basename( __FILE__ );
    

    The $x variable will equal to “wpdocs-plugin/wpdocs-plugin.php”.

上一篇:plugins_url()

下一篇:plugin_dir_path()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!