admin管理员组文章数量:1334283
I have an e-learning website that issues an official certificate of completion when a students complete their training course. The user profile name on the account can be used as the student name when generating the certificate, but if the user updates their profile name it also updates the name on the certificate. This is a problem since it would allow a user to complete a course once and then update their user profile name multiple times to generate official certificates for several other people(without completing the training or paying for it).
I created a set of custom user meta fields for the student name that are only exposed on the back end and I changed the certificate setup so that it uses these custom meta fields to add the student name to the certificate. The custom meta field remains blank if I don't manually update it on the back end, but I want the user to be able to enter this information on the front end for themselves once and then prevent any future updates from the front end (only allow me to make approved updates on the back end).
How do I expose a custom user meta input field on the front end user profile page only if it is empty and then hide it if it's not null?
I have an e-learning website that issues an official certificate of completion when a students complete their training course. The user profile name on the account can be used as the student name when generating the certificate, but if the user updates their profile name it also updates the name on the certificate. This is a problem since it would allow a user to complete a course once and then update their user profile name multiple times to generate official certificates for several other people(without completing the training or paying for it).
I created a set of custom user meta fields for the student name that are only exposed on the back end and I changed the certificate setup so that it uses these custom meta fields to add the student name to the certificate. The custom meta field remains blank if I don't manually update it on the back end, but I want the user to be able to enter this information on the front end for themselves once and then prevent any future updates from the front end (only allow me to make approved updates on the back end).
How do I expose a custom user meta input field on the front end user profile page only if it is empty and then hide it if it's not null?
Share Improve this question asked Jun 5, 2020 at 19:45 Carey RobinsonCarey Robinson 132 bronze badges 1- You can just check for meta value and hide the meta field if value exists. – Sabbir Hasan Commented Jun 6, 2020 at 15:25
1 Answer
Reset to default 0You could very easily do a check to see if that field already had a value in the database and if it does, display the name, if it doesn't, display a form field. You haven't provided any code so my example below is a really loose snippet of pseudo-code showing the the method.
<?php
$current_user = get_current_user_id();
$student_name = get_user_meta( $current_user, 'student_name', true );
if( !empty( $student_name ) ) :
echo '<span class="student_name_provided">' . $student_name . '</span>';
else :
echo '<input type="text" name="student_name" id="student_name" value=""/>';
endif;
?>
So if !empty()
or not empty, then it displays the value of the student_name
user meta in a span tag that you can style however you like.
But, if the check returns an empty value for student_name
it instead loads a text input field where the student can then provide their name.
Now all of this would need to be incorporated with whatever other front end editable stuff you've got set up, but the if( !empty() ) :
conditional check is the key aspect because it allows you to change what you provide the user with on the front end.
Hope that helps.
本文标签: Prevent update of custom user profile meta field on the front end after 1st entry
版权声明:本文标题:Prevent update of custom user profile meta field on the front end after 1st entry 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742372083a2462418.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论