Skip to content

Instantly share code, notes, and snippets.

@all4site
Created December 12, 2020 14:23
Show Gist options
  • Save all4site/44d80cf8576587ec6cbf049bac494428 to your computer and use it in GitHub Desktop.
Save all4site/44d80cf8576587ec6cbf049bac494428 to your computer and use it in GitHub Desktop.
<?php
/**
* @return array
*/
function fw_my_user_options() {
return array(
'box' => array(
'title' => false,
'type' => 'box',
'options' => array(
'day' => array(
'type' => 'short-text',
'value' => '',
'label' => __( 'Birth day', 'fw' ),
),
'month' => array(
'type' => 'short-select',
'value' => 'choice',
'label' => __( 'Select birth month', 'fw' ),
'choices' => array(
__( 'January' ),
__( 'February' ),
__( 'March' ),
__( 'April' ),
__( 'May' ),
__( 'June' ),
__( 'July' ),
__( 'August' ),
__( 'September' ),
__( 'October' ),
__( 'November' ),
__( 'December' ),
),
),
'year' => array(
'type' => 'short-text',
'value' => '',
'label' => __( 'Birth year', 'fw' ),
),
'image' => [
'type' => 'upload',
'value' =>[],
'label' => 'Upload file'
]
),
),
);
}
/**
* Add new fields above 'Update' button.
*
* @param WP_User $user User object.
*/
function _action_fw_additional_profile_fields( $user ) {
$data = (array) get_the_author_meta( 'fw-user-options', $user->ID );
echo fw()->backend->render_options( fw_my_user_options(), $data );
}
add_action( 'show_user_profile', '_action_fw_additional_profile_fields' );
add_action( 'edit_user_profile', '_action_fw_additional_profile_fields' );
/**
* Save profile fields.
*
* @param int $user_id
*
* @return bool
*/
function _action_fw_save_profile_fields( $user_id ) {
if ( ! current_user_can( 'edit_user', $user_id ) ) {
return false;
}
return update_user_meta( $user_id, 'fw-user-options', fw_get_options_values_from_input( fw_my_user_options() ) );
}
add_action( 'personal_options_update', '_action_fw_save_profile_fields' );
add_action( 'edit_user_profile_update', '_action_fw_save_profile_fields' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment