0

Ok, I've customized Sweet Testimonials to add a before and after image to a client testimonial post that is added by clients on the front end of the site I'm working on: http://pictureperfectponds.com/testimonials-submit-your-review/

The "before" image is uploading fine, but the "after" image is giving me an error. I can, however, get the "after" image to load and attach to the post via editing in the dashboard, so the metabox is working fine. Here's my code that handles the front end shortcodes, does anyone see what I'm missing?

        /* -------------------------------*/
        /* Upload & attach client picture - before */
        /* -------------------------------*/

        if( !isset($rc_swt_options['disable_picture']) ) {
            if( trim( $_POST['client_picture'] ) === '' ) {

                require_once(ABSPATH . 'wp-admin/includes/admin.php');
                $id = media_handle_upload( 'client_picture', $post_id );
                unset($_FILES);
                if ( is_wp_error($id) ) {
                    $errors['upload_error'] = $id;
                    $id = false;
                }

                if( $errors ) {
                    $client_picture_error = apply_filters( 'rc_swt_error_upload', __('There was an error uploading your before picture.', 'rc_swt') );
                    $hasError = true;
                } else {
                    $client_picture_url = wp_get_attachment_url( $id );
                    update_post_meta( $post_id, $field_prefix . 'client_picture', $client_picture_url );
                }

            }
        }

        /* -------------------------------*/
        /* Upload & attach client picture - after */
        /* -------------------------------*/

        if( !isset($rc_swt_options['disable_picture_after']) ) {
            if( trim( $_POST['client_picture_after'] ) === '' ) {

                require_once(ABSPATH . 'wp-admin/includes/admin.php');
                $id = media_handle_upload( 'client_picture_after', $post_id );
                unset($_FILES);
                if ( is_wp_error($id) ) {
                    $errors['upload_error'] = $id;
                    $id = false;
                }

                if( $errors ) {
                    $client_picture_after_error = apply_filters( 'rc_swt_error_upload', __('There was an error uploading your after picture.', 'rc_swt') );
                    $hasError = true;
                } else {
                    $client_picture_after_url = wp_get_attachment_url( $id );
                    update_post_meta( $post_id, $field_prefix . 'client_picture_after', $client_picture_after_url );
                }

            }
        }

        /* ----------------------------*/
        /* Thank you / redirection     */
        /* ----------------------------*/

        if( $post_id )
        {
            echo '<span class="success">';
            echo apply_filters( 'rc_swt_error_', __('Thank You! We now need to review your testimonial before publishing it.', 'rc_swt') );
            echo '</span>';
        }

    }
}

ob_start();
?>

        <?php if( !isset($rc_swt_options['disable_picture']) ) { ?>
        <!-- Testimonial before picture -->
        <label for="client_picture"><?php echo apply_filters( 'rc_swt_label_upload_profile', __('Upload your before picture:', 'rc_swt') ); ?></label>
        <input type="file" name="client_picture" id="client_picture" class="rc_swt_testimonials_form_input" />

        <?php if( isset($client_picture_error) && $client_picture_error != '') { ?>
            <span class="error"><?php echo $client_picture_error; ?></span>
            <div class="clearfix"></div>
        <?php } ?>
        <?php } ?>

        <?php if( !isset($rc_swt_options['disable_picture_after']) ) { ?>
        <!-- Testimonial after picture -->
        <label for="client_picture_after"><?php echo apply_filters( 'rc_swt_label_upload_after', __('Upload your after picture:', 'rc_swt') ); ?></label>
        <input type="file" name="client_picture_after" id="client_picture_after" class="rc_swt_testimonials_form_input" />

        <?php if( isset($client_picture_after_error) && $client_picture_after_error != '') { ?>
            <span class="error"><?php echo $client_picture_after_error; ?></span>


        <?php wp_nonce_field('testimonial_nonce', 'testimonial_nonce_field'); ?>

        <input type="hidden" name="submitted" id="submitted" value="true" />
        <button type="submit" id="rc_swt_submit" class="rc_swt_testimonials_form_submit"><?php echo apply_filters( 'rc_swt_post_testimonial', __('Post Testimonial', 'rc_swt') ); ?></button>

    </fieldset>
</form>
<?php
return ob_get_clean();
}

add_shortcode("testimonial-form", "rc_swt_testimonial_form_shortcode");

Any help is appreciated.

Post edited to shorten code relevant images only, can provide full code upon request.

  • That is a huge block of code. Please try to narrow this down to only the relevant section(s). – s_ha_dum Jan 16 '14 at 17:44
  • I cut it down specifically to the section that handles the form, is that better? – mtuttle Jan 16 '14 at 17:50
  • 1
    Probably. Not trying to be a jerk, but you will get better response with short concise code. I doubt that many people here, including me, have time to read through and interpret large chunks of code. – s_ha_dum Jan 16 '14 at 17:52
  • Ok, just code relevant to image uploads left. Better? – mtuttle Jan 16 '14 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.