Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Snippet to automatically create a new testimonial for the Testimonial Rotator with the submitted data of a KK CUSTOM FORM/CRM - Form
- // KK CUSTOM FORM/CRM: https://elegantmarketplace.com/downloads/kk-custom-formcrm/
- // Testimonial Rotator: https://wordpress.org/plugins/testimonial-rotator/
- add_action( 'kk_cust_form_cap', function( $fFields, $fArgs, $fID )
- {
- if ( 'testimonials' == $fID )
- {
- $host = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . '/';
- $imgURL = ( new SimpleXMLElement( $fArgs['meta']['IMAGE'] ) )['href'];
- $imgPath = str_replace( $host, '', ABSPATH . $imgURL );
- $type = wp_check_filetype( basename( $imgPath ), null );
- $atts =
- [
- 'guid' => $imgURL,
- 'post_mime_type' => wp_check_filetype( basename( $imgPath ), null )['type'],
- 'post_title' => $fFields['FIRSTNAME'] . ' ' . $fFields['LASTNAME'],
- 'post_content' => ( $cont = 'Testimonial image from ' . $fFields['FIRSTNAME'] . ' ' . $fFields['LASTNAME'] ),
- 'post_excerpt' => $cont,
- 'post_status' => 'inherit',
- ];
- $attID = wp_insert_attachment( $atts, $imgPath );
- $alt = $fFields['FIRSTNAME'] . ' ' . $fFields['LASTNAME'] . ' - Testimonial Image';
- update_post_meta( $attID, '_wp_attachment_image_alt', $alt );
- $name = '<p>' . $fFields['FIRSTNAME'] . ' ' . $fFields['LASTNAME'] . '</p>';
- if ( $fFields['WEBSITE'] && $fFields['COMPANY'] )
- {
- $link = '<a href="' . $fFields['WEBSITE'] . '" target="_blank">' . '<p>' . $fFields['COMPANY'] . '</p>' . '</a>';
- } // end if
- else if ( $fFields['WEBSITE'] && empty( $fFields['COMPANY'] ) )
- {
- $link = '<a href="' . $fFields['WEBSITE'] . '" target="_blank">' . $name . '</a>';
- } // end else if
- if ( isset( $link ) && $fFields['COMPANY'] )
- {
- $cite = $link . $name;
- } // end if
- else if ( isset( $link ) && empty( $fFields['COMPANY'] ) )
- {
- $cite = $link;
- } // end else if
- else
- {
- $cite = $name;
- } // end else
- // 1 is a placeholder for the user-id of an anonymous user. Replace it as needed
- $user = is_user_logged_in() ? wp_get_current_user()->ID : ( ( $id = get_user_by( 'email', $fFields['EMAIL'] )->ID ) ? $id : 1 );
- $args =
- [
- 'post_author' => $user,
- 'post_content' => $fFields['CONTENT'],
- 'post_title' => $fFields['TITLE'],
- 'post_status' => 'draft',
- 'comment_status' => 'closed',
- 'post_type' => 'testimonial',
- 'meta_input' =>
- [
- '_thumbnail_id' => $attID,
- '_rotator_id' => '|' . $fFields['ROTATOR'] . '|',
- '_rating' => $fFields['RATING'],
- ],
- ];
- $postID = wp_insert_post( $args );
- $cite = wp_kses( $cite, wp_kses_allowed_html( 'post' ) );
- update_post_meta( $postID, '_cite', $cite );
- require_once( ABSPATH . 'wp-admin/includes/image.php' );
- $attData = wp_generate_attachment_metadata( $attID, $imgPath );
- wp_update_attachment_metadata( $attID, $attData );
- set_post_thumbnail( $postID, $attID );
- } // end if
- }, 10, 3 ); // end add_action
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement