| Server IP : 52.25.153.185 / Your IP : 216.73.217.131 Web Server : Apache System : Linux ip-172-26-6-158 5.10.0-35-cloud-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64 User : daemon ( 1) PHP Version : 8.1.10 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /bitnami/wordpress/wp-content/plugins/testify/includes/integrations/ |
Upload File : |
<?php
/**
* This file includes code based on and/or copied from WordPress
* See license.txt for copyright and licensing details
*
* This file modified by Jonathan Hall, Dominika Rauk and/or others; last modified 2020-08-28
*
*/
if (!defined('ABSPATH')) die();
class WPForms_Template_Testify_WPForm extends WPForms_Template {
/**
* Primary class constructor.
*
* @since 1.0.0
*/
public function init() {
$choices = array();
$terms = get_terms( array(
'taxonomy' => 'testify-cat',
'hide_empty' => false,
) );
foreach($terms as $term)
{
$choices[] = array('label' => $term->name);
}
$this->name = esc_html__( 'Testify Form', 'testify-testify' );
$this->slug = 'testify_wpform';
$this->description = esc_html__( 'Use this form to create testimonial', 'testify-testify' );
$this->includes = '';
$this->icon = '';
$this->modal = '';
$this->data = array(
'field_id' => '3',
'fields' => array(
'0' => array(
'id' => '0',
'type' => 'text',
'label' => esc_html__( 'Author', 'testify-testify' ),
'required' => '1',
'size' => 'medium',
),
'1' => array(
'id' => '1',
'type' => 'email',
'label' => esc_html__( 'E-mail', 'testify-testify' ),
'required' => '1',
'size' => 'medium',
),
'2' => array(
'id' => '2',
'type' => 'textarea',
'label' => esc_html__( 'Testimonial', 'testify-testify' ),
'description' => '',
'required' => '1',
'size' => 'medium',
'placeholder' => '',
'css' => '',
),
'3' => array(
'id' => '3',
'type' => 'file-upload',
'label' => esc_html__( 'Photo', 'testify-testify' ),
'description' => '',
'required' => '0',
'size' => 'medium',
'extensions' => 'jpg,jpe,png,gif,bmp',
'max_size' => '10',
'placeholder' => '',
'css' => '',
),
'4' => array(
'id' => '4',
'type' => 'checkbox',
'label' => esc_html__( 'Categories', 'testify-testify' ),
'choices' => $choices,
'required' => '1',
),
'5' => array(
'id' => '5',
'type' => 'text',
'label' => esc_html__( 'Tags', 'testify-testify' ),
'description' => '',
'required' => '0',
'size' => 'medium',
'placeholder' => '',
'css' => '',
),
'6' => array(
'id' => '6',
'type' => 'hidden',
'label' => esc_html__( 'Testify Enable', 'testify-testify' ),
'description' => '',
'required' => '0',
'size' => 'medium',
'placeholder' => '',
'css' => '',
),
),
'settings' => array(
'notifications' => array(
'1' => array(
'sender_name' => '{field_id="0"}',
'sender_address' => '{field_id="1"}',
),
),
'honeypot' => '1',
'confirmation_message_scroll' => '1',
'submit_text_processing' => esc_html__( 'Sending...', 'testify-testify' ),
),
'meta' => array(
'template' => $this->slug,
),
);
}
}
class WPFormsIntegration
{
public static function init()
{
add_action('wp', array('WPFormsIntegration', 'wpforms_process' ));
new WPForms_Template_Testify_WPForm;
}
public static function wpforms_process()
{
// phpcs:disable WordPress.Security.NonceVerification -- assuming that the WP Forms plugin is responsible for nonce verification
if (isset($_POST['wpforms']['id']) && $_POST['wpforms']['id'] > 0 && isset($_POST['wpforms']['complete']) )
{
// phpcs:ignore ET.Sniffs.ValidatedSanitizedInput.InputNotSanitized -- individual child keys will be sanitized as needed below
$data = $_POST['wpforms']['complete'];
$author = "";
$content = "";
$email = "";
$tags = "";
$photo = "";
$cats = array();
foreach($data as $val)
{
if ($val['name'] == 'Author')
{
$author = sanitize_text_field($val['value']);
}
if ($val['name'] == 'Testimonial')
{
$content = sanitize_textarea_field($val['value']);
}
if ($val['name'] == 'E-mail')
{
$email = sanitize_email($val['value']);
}
if ($val['name'] == 'Tags')
{
$tags = $val['value']; // will be validated by wp_set_post_terms below
}
if ($val['name'] == 'Categories')
{
$cats = explode("\n", $val['value']); // will be validated when looking up categories below
}
if ($val['name'] == 'Photo')
{
$photo = esc_url_raw($val['value']);
}
}
$testimonialId = wp_insert_post(array(
'post_title' => $author,
'post_type' => 'testify-testimonial',
'post_status' => 'pending',
'post_content' => wp_strip_all_tags($content),
));
if (!empty($testimonialId))
{
update_post_meta($testimonialId, 'testimonial-author', $author);
update_post_meta($testimonialId, 'testimonial-submit-time', current_time('timestamp'));
update_post_meta($testimonialId, 'testimonial-submit-email', wp_strip_all_tags($email));
if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
update_post_meta($testimonialId, 'testimonial-submit-ip', sanitize_text_field( $_SERVER['REMOTE_ADDR'] ) );
}
$categories = array();
foreach ($cats as $value)
{
$term = get_term_by('name', $value, 'testify-cat');
if ($term && $term->term_id > 0)
{
$categories[] = $term->term_id;
}
}
if (!empty($categories))
{
wp_set_post_terms($testimonialId, $categories, 'testify-cat', true);
}
if (!empty($tags))
{
wp_set_post_terms($testimonialId, $tags, 'testify-tag', true);
}
}
if ($photo)
{
require_once(ABSPATH . 'wp-admin/includes/admin.php');
$tempFile = download_url($photo);
if (is_wp_error($tempFile) || empty($tempFile))
{
$success = false;
}
else
{
$attachmentId = media_handle_sideload(array(
'name' => basename($photo),
'tmp_name' => $tempFile
), $testimonialId);
if (!(is_numeric($attachmentId) && update_post_meta($testimonialId, '_thumbnail_id', $attachmentId)))
{
$success = false;
}
unlink($tempFile);
}
}
}
// phpcs:enable WordPress.Security.NonceVerification
}
}