|
Post by account_disabled on Jan 29, 2024 0:18:00 GMT -5
位于 WordPress 管理仪表板右上角的那个小“帮助”选项卡,单击该选项卡会显示有关各种管理页面及其工作方式的有用信息,称为上下文帮助选项卡。 Pause Next Unmute Current Time 0:08 / Duration 2:00 Fullscreen 它是上下文相关的,因为它显示的信息与当前正在查看的管理页面有关。 例如,当在帖子编辑屏幕中单击上下文帮助选项卡时,会显示有关如何执行多项任务的信息,包括以下示例: 如何自定义屏幕显示 如何输入帖子标题和内容 如何将媒体文件插入帖子内容 如何打开或关闭评论和 ping 上下文帮助选项卡 - 发布屏幕 如果您是插件或主题开发人员,这将有助于向用户提供快速文档,从而减少客户的支持问题。如果您想了解主题开发,请查看SitePoint Premium 上的WordPress 主题开发课程 Build Your Own Developer Portfolio 创建自定义帖子类型和主题或插件设置页面时,不存在默认的上下文帮助选项卡。因此,在本教程中,您将学习如何向上述管理页面添加一个。 将上下文帮助选项卡添加到帖子类型屏幕 WP_Screen类的 和 方法用于向管理页面中的帮助选项卡添加上下文帮助菜单和侧边栏下面的函数将向管理页面的上下文帮助选项卡添加三个菜单。 目前,该sp_help_tabs功能不会显示在任何管理页面中,因为您尚未定义显示该 WhatsApp 号码数据 功能的页面。下面是添加到管理页面时上下文帮助选项卡的屏幕截图。 自定义上下文帮助选项卡 该函数get_current_screen()返回WP_Screen当前正在查看的管理页面的对象,并将其值保存到变量中$screen。 该add_help_tab()方法接受以下参数,调用三次以将三个菜单添加到屏幕的上下文帮助中。 Build Your Own Developer Portfolio id:选项卡的唯一 ID。它必须是 HTML 安全的,并且不应包含空格。 title:选项卡的标题。 content:帮助选项卡的内容。可以是纯文本或 HTML。 回调:被调用以输出该页面内容的函数。 从上面参数的描述中,您可以看到第三个和第四个参数是相关的——它们处理显示选项卡的内容。 前者是包含纯文本或 HTML 格式内容的字符串,而后者是要调用的回调函数,用于回显或打印选项卡内容。 回调函数接受两个参数$screen和$tab,其中前者是当前页面的对象,后者是参数及其值WP_Screen的数组。add_help_tab() 如果您想根据某些条件显示选项卡内容,这两个参数会派上用场。例如,您可能已经有了需要输出的内容,这样就可以更轻松地只输出字符串。但是,您可能需要操作某些内容才能获取该内容,因此使用回调更合适。 使用的示例将上下文帮助选项卡添加到设置页面 将帮助选项卡添加到插件或主题设置页面与上面添加的帖子类型屏幕几乎相同的过程。 唯一的区别是action hook包含上下文帮助选项卡设置的函数将被挂钩,在本例中是 如果您正在创建顶级菜单或子菜单。 下面的代码为我们的演示插件创建了一个顶级菜单,并将上下文帮助选项卡添加到了插件设置页面。返回变量中,然后与load前缀一起使用以形成操作,该操作用于将我们的上下文件设置页面。
|
|