Answer the question
In order to leave comments, you need to log in
How to transfer a script from a template to a WordPress plugin?
There is a script that creates custom user fields in the WordPress admin, they are displayed via function.php in the template. I transfer it to the function.php of the plugin, it doesn’t work, why is it so, maybe it needs to be done differently there?
// когда пользователь сам редактирует свой профиль
add_action( 'show_user_profile', 'true_show_profile_fields' );
// когда чей-то профиль редактируется админом например
add_action( 'edit_user_profile', 'true_show_profile_fields' );
function true_show_profile_fields( $user ) {
// выводим заголовок для наших полей
echo '<h3>Дополнительная информация</h3>';
// поля в профиле находятся в рамметке таблиц <table>
echo '<table class="form-table">';
// добавляем поле пол
// также можно и установить значение по умолчанию
$gender = ( $gender = get_the_author_meta( 'gender', $user->ID ) ) ? $gender : 'male';
echo '<tr><th><label for="gender">Пол</label></th>
<td><ul>
<li><label><input value="male" name="gender"' . checked( $gender, 'male', false ) . ' type="radio" /> мужской</label></li>
<li><label><input value="female" name="gender"' . checked( $gender, 'female', false ) . ' type="radio" /> женский</label></li>
<li><label><input value="other" name="gender"' . checked( $gender, 'other', false ) . ' type="radio" /> другое</label></li>
</ul></td>
</tr>';
echo '</table>';
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question