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.
Leave a Reply
You must be logged in to post a comment.
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.