This is what I got so far.
Function to make form-ID=2 to create a page instead of post (thanks to Chris):
add_filter("gform_post_data", "change_post_type", 10, 2);
function change_post_type($post_data, $form){
//only change post type on form id 1
if($form["id"] != 2)
return $post_data;
$post_data["post_type"] = "page";
return $post_data;
}
Code in my page.php to determine what to display depending if user is signed in (or not) and if user do have a page created or not:
<?php if ( is_user_logged_in() ) { ?>
<?php global $wpdb;
$user = wp_get_current_user();
$where = get_posts_by_author_sql( 'page', true, $user->ID );
$count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
if ( $count >= 1 ) { ?>
// This is what user see if form is submitted, where '{entry-ID}' should be replaced by the user's entry iD
<h2>Hey <?php echo $current_user->display_name ?>, thank you for submitting the form. Visit your page here: http://www.example.com/{entry-ID}</h2>
<?php } else { ?>
// If user have not submitted a form, user is shown the info below with the form to submit
<h2>Hey <?php echo $current_user->display_name ?>, Thank you for joining. To create a page please submit the form below:</h2><?php echo do_shortcode('[gravityform id="2" name="Join the movement of Gooders" title="false" description="false"]'); ?>
<?php } } else { ?>
// if user is not logged in, user is urged to log in to submit form
<h2><Please log in to create a page <?php do_action( 'wordpress_social_login' ); ?></h2>
<?php } ?>
Question that is left now:
What code/function should I use to display the user's entry ID (on form 2) into the url on the second option like: http://www.example.com/{entry-ID} ??
Posted 11 years ago on Saturday April 20, 2013 |
Permalink