settings = $settings; add_action( 'wp_enqueue_scripts', array($this,'acform_cst_script_assets'), 999 ); // Add script on front page add_action( 'wp_footer', array($this,'acform_cst_style_assets'), 100); // Add inline style add_action( 'wp_ajax_acform_cst_post_comment', array($this,'submit_ajax_comment') ); // wp_ajax_{action} for registered user add_action( 'wp_ajax_nopriv_acform_cst_post_comment', array($this,'submit_ajax_comment') ); // wp_ajax_nopriv_{action} for not registered users if($this->settings['captcha'] == 'on' && !is_user_logged_in()) add_filter('comment_form_submit_field', array($this, 'addCaptchaField'), 9999); if($this->settings['gdpr'] == 'on' && !is_user_logged_in()) add_filter('comment_form_submit_field', array($this, 'addGDPRField'), 999); } public function acform_cst_script_assets(){ wp_enqueue_script( 'acform-cst', plugin_dir_url( ACFORM_CST_FILE ) . 'js/acform-cst.js', array( 'jquery' ), ACFORM_CST_VERSION, true ); wp_localize_script( 'acform-cst', 'acformcst', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'errorMessage' => $this->settings['em'], 'successMessage' => 'Thanks for your comment. We appreciate your response.', 'mscroll' => $this->settings['mscroll'], 'captcha' => ($this->settings['captcha'] == false ? 'false' : 'true'), 'gdpr' => ($this->settings['gdpr'] == false ? 'false' : 'true'), //'loader_image' => get_stylesheet_directory_uri().'/images/loader.gif' )); //var_dump($this->settings['gdpr']);die; } public function acform_cst_style_assets(){ echo "\n"; } public function addCaptchaField($submitField = '') { $field = apply_filters( 'acform_cst_captcha_field', '

', $submitField ); return $field . $submitField; } /** * @param string $submitField * @return string */ public function addGDPRField($submitField = '') { $field = apply_filters( 'acform_cst_gdprc_field', '

By using this form you agree with the storage and handling of your data by this website.

', $submitField ); return $field . $submitField; } public function submit_ajax_comment(){ session_start(); // Check for captcha code $verification_code = $_POST['security_code']; if($verification_code==''){ $errorArray = "Enter captcha code."; echo json_encode(array("error" => 1, "message" => $errorArray)); wp_die(); } if($verification_code!='' && $verification_code != $_SESSION['captcha_val']){ $errorArray = "Invalid captcha code!"; echo json_encode(array("error" => 1, "message" => $errorArray)); wp_die(); } $comment = wp_handle_comment_submission( wp_unslash( $_POST ) ); if ( is_wp_error( $comment ) ) { $error_data = intval( $comment->get_error_data() ); if ( ! empty( $error_data ) ) { echo json_encode(array("error" => 1, "message" => $comment->get_error_message())); wp_die(); } else { echo json_encode(array("error" => 1, "message" => 'Unknown error')); wp_die(); } } $commentId = $comment->comment_ID; if (isset($_POST['gdpr']) && !empty($commentId)) { add_comment_meta($commentId, '_gdpr', time()); } /* * Set Cookies */ $user = wp_get_current_user(); do_action('set_comment_cookies', $comment, $user); /* * If you do not like this loop, pass the comment depth from JavaScript code */ $comment_depth = 1; $comment_parent = $comment->comment_parent; while( $comment_parent ){ $comment_depth++; $parent_comment = get_comment( $comment_parent ); $comment_parent = $parent_comment->comment_parent; } /* * Set the globals, so our comment functions below will work correctly */ $GLOBALS['comment'] = $comment; $GLOBALS['comment_depth'] = $comment_depth; /* * Here is the comment template, you can configure it for your website * or you can try to find a ready function in your theme files */ $comment_html = '
  • ' . apply_filters( 'comment_text', get_comment_text( $comment ), $comment ) . '
  • '; echo json_encode(array("success" => 1, 'html' => $comment_html, 'moveto' => "comment-" . get_comment_ID())); wp_die(); } } ?>