Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/ninja-fo.../includes/Actions
File: Akismet.php
<?php
[0] Fix | Delete
[1] Fix | Delete
if ( ! defined( 'ABSPATH' ) || ! class_exists( 'NF_Abstracts_Action' ) ) {
[2] Fix | Delete
exit;
[3] Fix | Delete
}
[4] Fix | Delete
[5] Fix | Delete
/**
[6] Fix | Delete
* Class NF_Actions_Akismet
[7] Fix | Delete
*/
[8] Fix | Delete
final class NF_Actions_Akismet extends NF_Abstracts_Action {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* @var string
[12] Fix | Delete
*/
[13] Fix | Delete
protected $_name = 'akismet';
[14] Fix | Delete
[15] Fix | Delete
/**
[16] Fix | Delete
* @var array
[17] Fix | Delete
*/
[18] Fix | Delete
protected $_tags = array( 'spam', 'filtering', 'akismet' );
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* @var string
[22] Fix | Delete
*/
[23] Fix | Delete
protected $_timing = 'normal';
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* @var int
[27] Fix | Delete
*/
[28] Fix | Delete
protected $_priority = '10';
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Constructor
[32] Fix | Delete
*/
[33] Fix | Delete
public function __construct() {
[34] Fix | Delete
parent::__construct();
[35] Fix | Delete
[36] Fix | Delete
$this->_nicename = esc_html__( 'Akismet Anti-Spam', 'ninja-forms' );
[37] Fix | Delete
$settings = Ninja_Forms::config( 'ActionAkismetSettings' );
[38] Fix | Delete
$this->_settings = array_merge( $this->_settings, $settings );
[39] Fix | Delete
[40] Fix | Delete
add_filter( 'ninja_forms_action_type_settings', array( $this, 'maybe_remove_action' ) );
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Remove the action registration if Akismet functions not available.
[45] Fix | Delete
*
[46] Fix | Delete
* @param array $action_type_settings
[47] Fix | Delete
*
[48] Fix | Delete
* @return array
[49] Fix | Delete
*/
[50] Fix | Delete
public function maybe_remove_action( $action_type_settings ) {
[51] Fix | Delete
if ( ! $this->akismet_available() ) {
[52] Fix | Delete
unset( $action_type_settings[ $this->_name ] );
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
return $action_type_settings;
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Is Akismet installed and connected with a valid key?
[60] Fix | Delete
*
[61] Fix | Delete
* @return bool
[62] Fix | Delete
*/
[63] Fix | Delete
protected function akismet_available() {
[64] Fix | Delete
if ( ! is_callable( array( 'Akismet', 'get_api_key' ) ) ) {
[65] Fix | Delete
// Not installed and activated
[66] Fix | Delete
return false;
[67] Fix | Delete
}
[68] Fix | Delete
[69] Fix | Delete
$akismet_key = Akismet::get_api_key();
[70] Fix | Delete
if ( empty( $akismet_key ) ) {
[71] Fix | Delete
// No key entered
[72] Fix | Delete
return false;
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
return 'valid' === Akismet::verify_key( $akismet_key );
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
/**
[79] Fix | Delete
* Process the action
[80] Fix | Delete
*
[81] Fix | Delete
* @param array $action_settings
[82] Fix | Delete
* @param int $form_id
[83] Fix | Delete
* @param array $data
[84] Fix | Delete
*
[85] Fix | Delete
* @return array
[86] Fix | Delete
*/
[87] Fix | Delete
public function process( $action_settings, $form_id, $data ) {
[88] Fix | Delete
if ( ! $this->akismet_available() ) {
[89] Fix | Delete
return $data;
[90] Fix | Delete
}
[91] Fix | Delete
[92] Fix | Delete
if ( $this->is_submission_spam( $action_settings['name'], $action_settings['email'], $action_settings['url'], $action_settings['message'] ) ) {
[93] Fix | Delete
$data['errors']['form']['spam'] = esc_html__( 'There was an error trying to send your message. Please try again later', 'ninja-forms' );
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
return $data;
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Verify submission
[101] Fix | Delete
*
[102] Fix | Delete
* @param $name
[103] Fix | Delete
* @param $email
[104] Fix | Delete
* @param $url
[105] Fix | Delete
* @param $message
[106] Fix | Delete
*
[107] Fix | Delete
* @return bool
[108] Fix | Delete
*/
[109] Fix | Delete
protected function is_submission_spam( $name, $email, $url, $message ) {
[110] Fix | Delete
$body_request = array(
[111] Fix | Delete
'blog' => get_option( 'home' ),
[112] Fix | Delete
'blog_lang' => get_locale(),
[113] Fix | Delete
'permalink' => get_permalink(),
[114] Fix | Delete
'comment_type' => 'contact-form',
[115] Fix | Delete
'comment_author' => $name,
[116] Fix | Delete
'comment_author_email' => $email,
[117] Fix | Delete
'comment_author_url' => $url,
[118] Fix | Delete
'comment_content' => $message,
[119] Fix | Delete
'user_agent' => ( isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : null ),
[120] Fix | Delete
);
[121] Fix | Delete
[122] Fix | Delete
if ( method_exists( 'Akismet', 'http_post' ) ) {
[123] Fix | Delete
$body_request['user_ip'] = Akismet::get_ip_address();
[124] Fix | Delete
$response = Akismet::http_post( build_query( $body_request ), 'comment-check' );
[125] Fix | Delete
} else {
[126] Fix | Delete
global $akismet_api_host, $akismet_api_port;
[127] Fix | Delete
$body_request['user_ip'] = ( isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : null );
[128] Fix | Delete
$response = akismet_http_post( build_query( $body_request ), $akismet_api_host, '/1.1/comment-check', $akismet_api_port );
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
if ( ! empty( $response ) && isset( $response[1] ) && 'true' == trim( $response[1] ) ) {
[132] Fix | Delete
// Spam!
[133] Fix | Delete
return true;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
return false;
[137] Fix | Delete
}
[138] Fix | Delete
}
[139] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function