• Resolved megosoft

    (@megosoft)


    I am using custom post type, created by CPT-UI plugin to power Testimonials.
    In wp-admin everything is OK. Testimonials could be added by admin.
    I need to make a form, very similar to default comment form, where logged-in user can add his own testimonial, submit form, and the admin must approve the testimonial, to start displaying on the page.
    I hope you can simply understand, what I need.

    Here are all testimonials: https://kvitok.sk/referencie/ with pagination, that’s OK. I need to add a new form below the pagination, where logged in user can add his own testimonial and the testimonial must be approved by admin, before they start to displaying on the page.

    How can I do that? I even have no idea, what should I google.

    Thank you a lot.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Looks like you have Contact Form 7 available on the site, so something like https://www.ads-software.com/plugins/post-my-contact-form-7/ could help set up a form to use and allow people to submit new testimonials with.

    I know GravityForms and NinjaForms have this ability as well but both of those are premium level features and I don’t know if you have any purchases with either.

    All in all, it can be done, but just a matter of how you want to achieve it. This is something that CPTUI doesn’t handle on its own though.

    Thread Starter megosoft

    (@megosoft)

    Good to know, that CF7 has something like this ??

    However I have found something simple at stackoverflow.

    Here’s a code for a form:

    <?php if(is_user_logged_in()): ?>
    			<form method="post" name="front_end" action="" class="refere" >
    				<input type="hidden" name="title" value="<?= $current_user->user_nicename; ?>" />
    				<textarea id="custom_2" name="custom_2" required/></textarea>
    				<button type="submit">Odosla?</button>
    				<input type="hidden" name="action" value="references" />
    			</form>
    		<?php endif; ?>

    And here’s the simple code to process

    if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "references" && !empty($_POST['custom_2'])) {
    $success = false;
    //store our post vars into variables for later use
    //now would be a good time to run some basic error checking/validation
    //to ensure that data for these values have been set
    $title     = $_POST['title'];
    $custom_field_2 = $_POST['custom_2']; 
    $post_type = $_POST['action'];   
    
    //the array of arguements to be inserted with wp_insert_post
    $new_post = array(
    'post_title'    => $title,
    'post_content'  => $custom_field_2,
    'post_status'   => 'publish',          
    'post_type'     => $post_type 
    );
    
    //insert the the post into database by passing $new_post to wp_insert_post
    //store our post ID in a variable $pid
    if($pid = wp_insert_post($new_post))
    	$success = true;
    }
    Thread Starter megosoft

    (@megosoft)

    Am I somehow able to include approving mechanism to this custom post types?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I wouldn’t use that code as is verbatim, as it lacks security cleanup and sanitization, etc. As a whole that’d be a way to get thing saved as the post type in question. Won’t be bad to get nonces added as well.

    Regarding reviewing, I’d say change the post status to “draft” at minimum, instead of “publish” and then someone with admin rights can review as needed.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Allow users to add content from front-end’ is closed to new replies.