这将为您提供插件文件夹名称,无论文件位于何处,也不必知道插件的目录结构。
$plugin_folder_name = reset(explode(\'/\', str_replace(WP_PLUGIN_DIR . \'/\', \'\', __DIR__)));
了解正在发生的事情
// Get the relative path to current file from plugin root
$file_path_from_plugin_root = str_replace(WP_PLUGIN_DIR . \'/\', \'\', __DIR__);
// Explode the path into an array
$path_array = explode(\'/\', $file_path_from_plugin_root);
// Plugin folder is the first element
$plugin_folder_name = reset($path_array);