আমার একটা ওয়ার্ডপ্রেস সাইটে ইউজার প্রোফাইলে একটা কাস্টম ফিল্ড যুক্ত করতে হবে। কাস্টম ফিল্ডের লেবেল হবে: Point এবং user_point কি দিয়ে ডাটা সেভ হবে।
@ai_bot তুমি কি কোড দিয়ে হেল্প করতে পারবা?
আমার একটা ওয়ার্ডপ্রেস সাইটে ইউজার প্রোফাইলে একটা কাস্টম ফিল্ড যুক্ত করতে হবে। কাস্টম ফিল্ডের লেবেল হবে: Point এবং user_point কি দিয়ে ডাটা সেভ হবে।
@ai_bot তুমি কি কোড দিয়ে হেল্প করতে পারবা?
I apologize for the lack of results in our community. Let me provide you with a solution for adding a custom field to the WordPress user profile as you requested. Here’s a code snippet that should help you achieve what you’re looking for:
// Add custom field to user profile
function add_custom_user_profile_fields($user) {
?>
<h3><?php _e("Extra Profile Information", "blank"); ?></h3>
<table class="form-table">
<tr>
<th><label for="user_point"><?php _e("Point"); ?></label></th>
<td>
<input type="text" name="user_point" id="user_point" value="<?php echo esc_attr(get_the_author_meta('user_point', $user->ID)); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Please enter your point."); ?></span>
</td>
</tr>
</table>
<?php
}
add_action('show_user_profile', 'add_custom_user_profile_fields');
add_action('edit_user_profile', 'add_custom_user_profile_fields');
// Save custom field data
function save_custom_user_profile_fields($user_id) {
if (!current_user_can('edit_user', $user_id)) {
return false;
}
update_user_meta($user_id, 'user_point', $_POST['user_point']);
}
add_action('personal_options_update', 'save_custom_user_profile_fields');
add_action('edit_user_profile_update', 'save_custom_user_profile_fields');
এই কোডটি আপনার ওয়ার্ডপ্রেস থিমের functions.php
ফাইলে যোগ করুন। এটি নিম্নলিখিত কাজগুলি করবে:
user_point
মেটা কী হিসেবে সেভ হবে।এই কোড ব্যবহার করার পর, আপনি ইউজার প্রোফাইল পেজে গিয়ে নতুন ফিল্ডটি দেখতে পাবেন এবং এটিতে ডাটা সেভ করতে পারবেন।
যদি আপনি এই ডাটা ব্যবহার করতে চান, তাহলে নিম্নলিখিত ফাংশন ব্যবহার করে আপনি ইউজারের পয়েন্ট পেতে পারেন:
$user_id = get_current_user_id(); // বর্তমান ইউজারের আইডি
$user_point = get_user_meta($user_id, 'user_point', true);
echo "User Point: " . $user_point;
আশা করি এই সমাধান আপনার কাজে লাগবে। যদি আপনার আরও কোন প্রশ্ন থাকে, তাহলে জানাতে দ্বিধা করবেন না।
ধন্যবাদ অ্যাই ষ্যাড়