如何限制WordPress中的个人信息长度和内容?
在 WordPress 中,个人资料下有个人信息。我想阻止用户超过 400 个字符的最大长度。此外,他可以在简历信息中放置的超链接数量不应超过三个。我该怎么做?我对 JQuery 非常熟悉,如果这对这个问题有帮助的话。我只是 WordPress 的新手。
In WordPress there is Biographical Info under Profile. I would like to prevent the user from exceeding a maximum length of 400 characters. Also, the number of hyperlinks he can place in the biographical info should not exceed three. How do I do that? I am very familiar with JQuery, if that helps in this question. I am just a newbie with WordPress.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于 Javascript 端,您应该将必要的事件附加到
description
字段。您可以通过wp_enqueue_script
挂钩加载脚本,您可能想要在admin_enqueue_scripts
的处理程序中执行所有这些操作,您可以在其中检查传递的$hook_name
,在本例中是页面名称。当管理员编辑用户时,它是user-edit.php
;当用户编辑自己的信息时,它是profile.php
(在这种情况下,IS_PROFILE_PAGE
> 也将被定义为TRUE
)。对于 PHP 端,您需要
pre_user_description
过滤器。这为您提供了当前的传记文本,您的函数可以更改它并返回其他内容。如果您不想默默地更改描述,而是想显示错误,则应该查看
user_profile_update_errors
挂钩。在那里您可以验证给定的数据并向用户返回错误消息。您可能希望将所有这些都封装在一个插件中,这样您就可以将代码放在一起并轻松启用或禁用它。插件只是
/wp-content/plugins/
目录中的一个文件,很可能位于以您的插件命名的子目录中。For the Javascript side, you should attach the necessary events to the
description
field. You can load your script via thewp_enqueue_script
hook, and you probably want to do all this in your handler foradmin_enqueue_scripts
, where you check for the passed$hook_name
, which in this case is the page name. It isuser-edit.php
when an admin edits a user, andprofile.php
when the user edits their own information (in which caseIS_PROFILE_PAGE
will also be defined asTRUE
).For the PHP side, you need the
pre_user_description
filter. This gives you the current biographical text, and your function can change this and return something else.If, instead of silently changing the description, you want to show an error, you should look into the
user_profile_update_errors
hook. There you can validate the given data and return error messages to the user.You probably want to wrap this all up in a plugin, so you can keep the code together and easily enable or disable it. A plugin is just a file in the
/wp-content/plugins/
directory, most likely in a subdirectory named after your plugin.