I would greatly appreciate any help you can provide regarding the creation of a front end form to allow members to edit custom posts that I have created in their admin panel.
I have successfully created the custom posts with the following code in functions.php as follows:
/**Add custom fields to the user profile**/
<?php
add_action( 'show_user_profile', 'premises_information_users_fields' );
add_action( 'edit_user_profile', 'premises_information_users_fields' );
function premises_information_users_fields( $user ) { ?>
<h3>Premises Self-Inspection Schedule</h3>
<table>
<tr>
<?php
$wheelchair = get_user_meta( $user->ID, 'wheelchair', true );
?>
<th><label for "wheelchair">Do you have wheelchair access for disabled clients? Yes or No</label></th>
<td>
<input type="text" name="wheelchair" id="wheelchair" value="<?php echo esc_attr($wheelchair) ?>" class="regular-text">
</td>
<?php
$wheelchair_comments = get_user_meta($user->ID, 'wheelchair_comments', true);
?>
<th><label for "wheelchair_comments">Comments</label></th>
<td>
<input type="text" name="wheelchair_comments" id="wheelchair_comments" value="<?php echo esc_attr($wheelchair_comments) ?>" class="regular-text">
</td>
</tr>
</table>
<?php }
add_action( 'personal_options_update', 'save_premises_information_users_fields' );
add_action( 'edit_user_profile_update', 'save_premises_information_users_fields' );
function save_premises_information_users_fields( $user_id ) {
if( !isset( $_POST[ '_wpnonce' ] ) || !wp_verify_nonce( $_POST[ '_wpnonce' ], 'update-user_' . $user_id ) ) {
return;
}
if( !current_user_can( 'edit_user', $user_id ) ) {
return;
}
update_user_meta($user_id, 'wheelchair', $_POST['wheelchair'] );
update_user_meta($user_id, 'wheelchair_comments', $_POST['wheelchair_comments']);
}
There are many more fields, but they all follow this format: it works great for the backend, saves and updates within the admin panel.
What I am trying to achieve is a front-end page where users can see and edit the custom fields that have been created in the backend.
I understand that this should be achieved by creating a new template page based on the current page.php and adding in the code to display / allow users to update their own member information from the front end.
The current page.php looks like this:
<?php
/**
* This is the current page.php that needs to be amended
to include the code to allow a member to update
and edit their information with the custom fields
created above.
*/
?>
<?php get_header(); ?>
<div id="main-content"<?php highend_main_content_style(); ?>>
<div class="container">
<div class="row main-row <?php echo highend_get_page_layout(); ?>">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="page-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php do_action( 'highend_main_content_start' ); ?>
<?php
the_content();
wp_link_pages( array(
'before' => '<div id="hb-page-links">' . esc_html__( 'Pages:', 'hbthemes' ),
'after' => '</div>',
) );
if ( comments_open() && highend_option( 'hb_disable_page_comments' ) ) {
comments_template();
}
?>
<?php do_action( 'highend_main_content_end' ); ?>
</div>
<?php endwhile; endif; ?>
</div><!-- END .row -->
</div><!-- END .container -->
</div><!-- END #main-content -->
<?php get_footer(); ?>
Any help with the code to allow the custom fields to be edited by members on the front end would be hugely appreciated!