kevinlangleyjr / wp-contextual-help
WordPress 插件,允许开发者在 WordPress 中轻松扩展上下文帮助下拉内容区域。
This package is auto-updated.
Last update: 2024-03-29 03:19:41 UTC
README
贡献者:kevinlangleyjr, Mte90
标签:contextual, help
最低要求:3.3
测试到:4.9
稳定标签:1.0.4
许可证:GPLv2 或更高版本
许可证 URI:https://gnu.ac.cn/licenses/gpl-2.0.html
允许开发者轻松扩展 WordPress 中上下文帮助下拉内容区域。
描述
添加辅助功能,便于在整个 WordPress 网站管理中添加 WP 上下文帮助。
安装
作为标准插件
请参阅 安装插件。
作为主题或插件依赖项
将插件拖放到包含的主题或插件中后,添加以下内容
if( ! class_exists( 'WP_Contextual_Help' ) ) { require_once( $path_to_help . '/wp-contextual-help.php' ); }
作为 composer 依赖项
将以下内容添加到 composer.json 的 required 依赖项中
{ // ... "require": { "kevinlangleyjr/wp-contextual-help": "~0.0.1" // Most recent tagged version }, // ... }
用法
当您注册一个标签时,您有几个选项来决定显示哪些内容。
如果在标签参数中提供了一个回调参数,那么它将具有优先权,并且插件不会在帮助文档目录中查找任何 HTML 文件。
如果在标签参数中提供了一个文件参数,插件将寻找该特定文件,如果不存在,将在内容位置输出警告消息,以通知开发者指定的帮助文档不存在。
如果没有将文件或回调参数传递给标签参数,则默认情况下,插件将寻找与标签 ID 相同名称的文件。例如,对于 post-management
,它将在帮助文档目录中寻找 post-management.html
。
HTML 帮助文档
所有帮助文档应位于 get_template_directory() . '/includes/help-docs/';
目录中,所有图像位于 get_template_directory() . '/includes/help-docs/img/';
您可以使用 wp_contextual_help_docs_dir
过滤器更改 HTML 文件的目录,使用 wp_contextual_help_docs_url
过滤器更改图像的基本 URL。在我们的帮助文档中,我们使用变量 {WP_HELP_IMG_URL}
作为图像 URL 的占位符,然后在渲染之前替换为过滤器的值或默认帮助文档图像目录。
注册标签
使用 WP_Contextual_Help::register_tab()
方法注册帮助标签。
参数
$id
(字符串) - 用于帮助标签 ID 的字符串$title
(字符串) - 在标签中显示给用户的标题$args
(数组) - 帮助标签的选项数组page
(字符串,数组) - 启用帮助标签的页面post_type
(字符串,数组) - 限制标签仅在这些特定的帖子类型上显示file
(字符串) - 在标签中读取和输出的 HTML 文件wpautop
(布尔值) - 默认:False - 将 wpautop 应用于加载的 HTML 文件callback
- 如果用户更倾向于自定义回调而不是自动加载HTML文件,那么这就是应用它的地方
示例
<?php add_action( 'init', function(){ if( !class_exists( 'WP_Contextual_Help' ) ) return; // Only display on the pages - post.php and post-new.php, but only on the `post` post_type // This would automatically look for a file called post-management.html within get_template_directory() . '/includes/help-docs/'; WP_Contextual_Help::register_tab( 'post-management', 'Post Management', array( 'page' => array( 'post.php', 'post-new.php' ), 'post_type' => 'post', 'wpautop' => true ) ); // Add to a custom admin page WP_Contextual_Help::register_tab( 'custom-settings', 'Custom Settings', array( 'page' => 'settings_page_custom-settings-page', 'wpautop' => true ) ); // Add help tab with custom callback WP_Contextual_Help::register_tab( 'custom-callback', 'Custom Callback Example', array( 'page' => array( 'post.php', 'post-new.php' ), 'post_type' => 'post', 'callback' => function( $screen, $tab ) { echo '<p>It is super easy to add new help tabs!</p>'; } ) ); } ); ?>
变更日志
请参阅完整的变更日志:https://github.com/kevinlangleyjr/wp-contextual-help/releases。