page-front-form-edit.php
PHP / Template<?php
/* Template Name: CFS Front-end Edit Form */
if ( ! is_user_logged_in() ) {
auth_redirect();
}
$post_id = absint( $_GET['post_id'] ?? 0 );
$post_type = 'member_entry'; // Post type allowed for editing.
if ( ! $post_id ) {
wp_die( 'No post was selected for editing.', '', array(
'response' => 404,
) );
}
// Prevent a different post type from being selected through the URL.
if ( $post_type !== get_post_type( $post_id ) ) {
wp_die( 'This post type is not allowed.', '', array(
'response' => 404,
) );
}
// Confirm that the current user may edit this post.
if ( ! current_user_can( 'edit_post', $post_id ) ) {
wp_die( 'You are not allowed to edit this post.', '', array(
'response' => 403,
) );
}
get_header();
?>
<main class="front-form">
<h1>Edit entry</h1>
<?php
echo CFS()->form( array(
'post_id' => $post_id, // Update this existing post.
'field_groups' => array( 123 ), // Field group ID.
'submit_label' => 'Save',
'confirmation_url' => get_permalink( $post_id ),
) );
?>
</main>
<?php get_footer(); ?>