Changeset 3204929
- Timestamp:
- 12/09/2024 02:37:33 PM (14 months ago)
- Location:
- ninja-forms
- Files:
-
- 12 added
- 32 edited
- 1 copied
-
tags/3.8.21 (copied) (copied from ninja-forms/trunk)
-
tags/3.8.21/includes/Abstracts/Metabox.php (modified) (2 diffs)
-
tags/3.8.21/includes/Abstracts/SotAction.php (added)
-
tags/3.8.21/includes/Abstracts/SotActionNewsletter.php (added)
-
tags/3.8.21/includes/Abstracts/SubmissionMetabox.php (modified) (2 diffs)
-
tags/3.8.21/includes/Actions/Akismet.php (modified) (8 diffs)
-
tags/3.8.21/includes/Actions/CollectPayment.php (modified) (4 diffs)
-
tags/3.8.21/includes/Actions/Custom.php (modified) (4 diffs)
-
tags/3.8.21/includes/Actions/DeleteDataRequest.php (modified) (6 diffs)
-
tags/3.8.21/includes/Actions/Email.php (modified) (14 diffs)
-
tags/3.8.21/includes/Actions/ExportDataRequest.php (modified) (6 diffs)
-
tags/3.8.21/includes/Actions/Recaptcha.php (modified) (23 diffs)
-
tags/3.8.21/includes/Actions/Redirect.php (modified) (1 diff)
-
tags/3.8.21/includes/Actions/Save.php (modified) (11 diffs)
-
tags/3.8.21/includes/Actions/SuccessMessage.php (modified) (3 diffs)
-
tags/3.8.21/includes/Admin/VersionCompatibilityCheck.php (modified) (1 diff)
-
tags/3.8.21/includes/Interfaces (added)
-
tags/3.8.21/includes/Interfaces/SotAction.php (added)
-
tags/3.8.21/includes/Traits (added)
-
tags/3.8.21/includes/Traits/SotGetActionProperties.php (added)
-
tags/3.8.21/ninja-forms.php (modified) (9 diffs)
-
tags/3.8.21/readme.txt (modified) (2 diffs)
-
tags/3.8.21/vendor/composer/installed.php (modified) (2 diffs)
-
trunk/includes/Abstracts/Metabox.php (modified) (2 diffs)
-
trunk/includes/Abstracts/SotAction.php (added)
-
trunk/includes/Abstracts/SotActionNewsletter.php (added)
-
trunk/includes/Abstracts/SubmissionMetabox.php (modified) (2 diffs)
-
trunk/includes/Actions/Akismet.php (modified) (8 diffs)
-
trunk/includes/Actions/CollectPayment.php (modified) (4 diffs)
-
trunk/includes/Actions/Custom.php (modified) (4 diffs)
-
trunk/includes/Actions/DeleteDataRequest.php (modified) (6 diffs)
-
trunk/includes/Actions/Email.php (modified) (14 diffs)
-
trunk/includes/Actions/ExportDataRequest.php (modified) (6 diffs)
-
trunk/includes/Actions/Recaptcha.php (modified) (23 diffs)
-
trunk/includes/Actions/Redirect.php (modified) (1 diff)
-
trunk/includes/Actions/Save.php (modified) (11 diffs)
-
trunk/includes/Actions/SuccessMessage.php (modified) (3 diffs)
-
trunk/includes/Admin/VersionCompatibilityCheck.php (modified) (1 diff)
-
trunk/includes/Interfaces (added)
-
trunk/includes/Interfaces/SotAction.php (added)
-
trunk/includes/Traits (added)
-
trunk/includes/Traits/SotGetActionProperties.php (added)
-
trunk/ninja-forms.php (modified) (9 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/vendor/composer/installed.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
ninja-forms/tags/3.8.21/includes/Abstracts/Metabox.php
r2238469 r3204929 5 5 protected $_id = ''; // Dynamically set in constructor using the class name. 6 6 7 protected $_title = ''; // Should be set (and translated) in the constructor.7 protected $_title = ''; // Should be set (and translated) at action hook init-10 8 8 9 9 protected $_callback = 'render_metabox'; … … 23 23 $this->_id = strtolower( get_class( $this ) ); 24 24 25 $this->_title = esc_html__( 'Metabox', 'ninja-forms');25 add_action('init', [$this, 'abstractInit'], 5); 26 26 27 27 add_action( 'save_post', array( $this, '_save_post' ) ); 28 28 29 29 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); 30 } 31 32 /** 33 * Initialize properties at WP `init-5` action hook 34 * 35 * Set translatable properties - _title 36 * 37 * @return void 38 */ 39 public function abstractInit(): void 40 { 41 $this->_title = esc_html__( 'Metabox', 'ninja-forms' ); 30 42 } 31 43 -
ninja-forms/tags/3.8.21/includes/Abstracts/SubmissionMetabox.php
r2238469 r3204929 19 19 if( ! isset( $_GET[ 'post' ] ) ) return; 20 20 21 $this->_title = esc_html__( 'Submission Metabox', 'ninja-forms');21 add_action('init', [$this, 'abstractSubmissionInit'], 8); 22 22 23 23 $post_id = absint( $_GET[ 'post' ] ); … … 28 28 add_action( 'save_post', array( $this, '_save_post' ) ); 29 29 } 30 31 /** 32 * Initialize properties at WP `init-8` action hook 33 * 34 * Set translatable properties - _title 35 * 36 * @return void 37 */ 38 public function abstractSubmissionInit(): void 39 { 40 $this->_title = esc_html__('Submission Metabox', 'ninja-forms'); 41 } 30 42 } -
ninja-forms/tags/3.8.21/includes/Actions/Akismet.php
r3101843 r3204929 1 1 <?php 2 2 3 if ( ! defined( 'ABSPATH' ) || ! class_exists( 'NF_Abstracts_Action' ) ) { 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH') ) { 4 8 exit; 5 9 } … … 8 12 * Class NF_Actions_Akismet 9 13 */ 10 final class NF_Actions_Akismet extends NF_Abstracts_Action { 11 12 /** 13 * @var string 14 */ 15 protected $_name = 'akismet'; 14 final class NF_Actions_Akismet extends SotAction implements InterfacesSotAction 15 { 16 use SotGetActionProperties; 16 17 17 18 /** 18 19 * @var array 19 20 */ 20 protected $_tags = array( 'spam', 'filtering', 'akismet' ); 21 22 /** 23 * @var string 24 */ 25 protected $_timing = 'normal'; 26 27 /** 28 * @var int 29 */ 30 protected $_priority = '10'; 31 32 /** 33 * @var string 34 */ 35 protected $_group = 'core'; 21 protected $_tags = array('spam', 'filtering', 'akismet'); 36 22 37 23 /** 38 24 * Constructor 39 25 */ 40 public function __construct() { 26 public function __construct() 27 { 41 28 parent::__construct(); 42 29 43 $this->_nicename = esc_html__( 'Akismet Anti-Spam', 'ninja-forms' ); 44 $settings = Ninja_Forms::config( 'ActionAkismetSettings' ); 45 $this->_settings = array_merge( $this->_settings, $settings ); 30 $this->_name = 'akismet'; 31 $this->_group = 'core'; 32 $this->_timing = 'normal'; 33 $this->_priority = '10'; 46 34 47 add_filter( 'ninja_forms_action_type_settings', array( $this, 'maybe_remove_action' ) ); 35 add_action('init', [$this, 'initHook']); 36 add_filter('ninja_forms_action_type_settings', array($this, 'maybe_remove_action')); 37 } 38 39 public function initHook(): void 40 { 41 $this->_nicename = esc_html__('Akismet Anti-Spam', 'ninja-forms'); 42 43 $settings = Ninja_Forms::config('ActionAkismetSettings'); 44 $this->_settings = array_merge($this->_settings, $settings); 48 45 } 49 46 … … 55 52 * @return array 56 53 */ 57 public function maybe_remove_action( $action_type_settings ) { 58 if ( ! $this->akismet_available() ) { 59 unset( $action_type_settings[ $this->_name ] ); 54 public function maybe_remove_action($action_type_settings) 55 { 56 if (! $this->akismet_available()) { 57 unset($action_type_settings[$this->_name]); 60 58 } 61 59 … … 68 66 * @return bool 69 67 */ 70 protected function akismet_available() { 71 if ( ! is_callable( array( 'Akismet', 'get_api_key' ) ) ) { 68 protected function akismet_available() 69 { 70 if (! is_callable(array('Akismet', 'get_api_key'))) { 72 71 // Not installed and activated 73 72 return false; … … 75 74 76 75 $akismet_key = Akismet::get_api_key(); 77 if ( empty( $akismet_key )) {76 if (empty($akismet_key)) { 78 77 // No key entered 79 78 return false; 80 79 } 81 80 82 return 'valid' === Akismet::verify_key( $akismet_key);81 return 'valid' === Akismet::verify_key($akismet_key); 83 82 } 84 83 … … 92 91 * @return array 93 92 */ 94 public function process( $action_settings, $form_id, $data ) { 95 if ( ! $this->akismet_available() ) { 93 public function process(array $action_settings, int $form_id, array $data): array 94 { 95 if (! $this->akismet_available()) { 96 96 return $data; 97 97 } 98 98 99 if ( $this->is_submission_spam( $action_settings['name'], $action_settings['email'], $action_settings['url'], $action_settings['message'] )) {100 $data['errors']['form']['spam'] = esc_html__( 'There was an error trying to send your message. Please try again later', 'ninja-forms');99 if ($this->is_submission_spam($action_settings['name'], $action_settings['email'], $action_settings['url'], $action_settings['message'])) { 100 $data['errors']['form']['spam'] = esc_html__('There was an error trying to send your message. Please try again later', 'ninja-forms'); 101 101 } 102 102 … … 114 114 * @return bool 115 115 */ 116 protected function is_submission_spam( $name, $email, $url, $message ) { 116 protected function is_submission_spam($name, $email, $url, $message) 117 { 117 118 $body_request = array( 118 'blog' => get_option( 'home'),119 'blog' => get_option('home'), 119 120 'blog_lang' => get_locale(), 120 121 'permalink' => get_permalink(), … … 124 125 'comment_author_url' => $url, 125 126 'comment_content' => $message, 126 'user_agent' => ( isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : null),127 'user_agent' => (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null), 127 128 ); 128 129 129 if ( method_exists( 'Akismet', 'http_post' )) {130 if (method_exists('Akismet', 'http_post')) { 130 131 $body_request['user_ip'] = Akismet::get_ip_address(); 131 $response = Akismet::http_post( build_query( $body_request ), 'comment-check');132 $response = Akismet::http_post(build_query($body_request), 'comment-check'); 132 133 } else { 133 134 global $akismet_api_host, $akismet_api_port; 134 $body_request['user_ip'] = ( isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : null);135 $response = akismet_http_post( build_query( $body_request ), $akismet_api_host, '/1.1/comment-check', $akismet_api_port);135 $body_request['user_ip'] = (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null); 136 $response = akismet_http_post(build_query($body_request), $akismet_api_host, '/1.1/comment-check', $akismet_api_port); 136 137 } 137 138 138 if ( ! empty( $response ) && isset( $response[1] ) && 'true' == trim( $response[1] )) {139 if (! empty($response) && isset($response[1]) && 'true' == trim($response[1])) { 139 140 // Spam! 140 141 return true; -
ninja-forms/tags/3.8.21/includes/Actions/CollectPayment.php
r2238469 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Action_CollectPayment 5 11 */ 6 final class NF_Actions_CollectPayment extends NF_Abstracts_Action12 final class NF_Actions_CollectPayment extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'collectpayment'; 14 use SotGetActionProperties; 12 15 13 16 /** … … 17 20 18 21 /** 19 * @var string20 */21 protected $_timing = 'late';22 23 /**24 * @var int25 */26 protected $_priority = 0;27 28 /**29 22 * @var array 30 23 */ 31 24 protected $payment_gateways = array(); 32 25 26 protected $tempCpNiceName; 27 protected $tempCpName; 33 28 /** 34 29 * Constructor … … 37 32 * @param string $cp_name 38 33 */ 39 public function __construct( $cp_nice_name = 'Collect Payment', 40 $cp_name = 'collectpayment' ) 34 public function __construct( 35 $cp_nice_name = 'Collect Payment', 36 $cp_name = 'collectpayment' 37 ) { 38 $this->_name = 'collectpayment'; 39 $this->_timing = 'late'; 40 $this->_priority = 0; 41 42 add_action('init', [$this, 'initHook']); 43 44 $this->tempCpNiceName = $cp_nice_name; 45 $this->tempCpName = $cp_name; 46 47 add_action('ninja_forms_loaded', array($this, 'register_payment_gateways'), -1); 48 49 add_filter('ninja_forms_action_type_settings', array($this, 'maybe_remove_action')); 50 } 51 52 public function initHook(): void 41 53 { 42 parent::__construct();54 $this->initializeSettings(); 43 55 44 56 // Set the nice name to what we passed in. 'Collect Payment' is default 45 if( 'Collect Payment' == $cp_nice_name ) { 46 $cp_nice_name = esc_html__( 'Collect Payment', 'ninja-forms' ); 47 } 48 $this->_nicename = $cp_nice_name; 57 if ('Collect Payment' == $this->tempCpNiceName) { 58 $this->tempCpNiceName = esc_html__('Collect Payment', 'ninja-forms'); 59 } 60 61 $this->_nicename = $this->tempCpNiceName; 49 62 // Set name to what we passed in. 'collectpayment' is default 50 $this->_name = strtolower( $cp_name);63 $this->_name = strtolower($this->tempCpName); 51 64 52 $settings = Ninja_Forms::config( 'ActionCollectPaymentSettings');65 $settings = Ninja_Forms::config('ActionCollectPaymentSettings'); 53 66 54 67 /** … … 56 69 * of the gateway drop-down 57 70 **/ 58 if ( 'collectpayment' != $this->_name) {59 $settings[ 'payment_gateways' ][ 'value'] = $this->_name;71 if ('collectpayment' != $this->_name) { 72 $settings['payment_gateways']['value'] = $this->_name; 60 73 } 61 74 62 $this->_settings = array_merge( $this->_settings, $settings ); 63 64 add_action( 'ninja_forms_loaded', array( $this, 'register_payment_gateways' ), -1 ); 65 66 add_filter( 'ninja_forms_action_type_settings', array( $this, 'maybe_remove_action' ) ); 75 $this->_settings = array_merge($this->_settings, $settings); 67 76 } 68 77 69 public function save( $action_settings ) 78 function initializeSettings(): void 79 { 80 $this->_settings_all = apply_filters( 'ninja_forms_actions_settings_all', $this->_settings_all ); 81 82 if( ! empty( $this->_settings_only ) ){ 83 84 $this->_settings = array_merge( $this->_settings, $this->_settings_only ); 85 } else { 86 87 $this->_settings = array_merge( $this->_settings_all, $this->_settings ); 88 $this->_settings = array_diff( $this->_settings, $this->_settings_exclude ); 89 } 90 91 $this->_settings = $this->load_settings( $this->_settings_all ); 92 } 93 94 /** @inheritDoc */ 95 public function process(array $action_settings, int $form_id, array $data): array 70 96 { 71 97 72 }98 $payment_gateway = $action_settings['payment_gateways']; 73 99 74 public function process( $action_settings, $form_id, $data ) 75 { 76 77 $payment_gateway = $action_settings[ 'payment_gateways' ]; 78 79 $payment_gateway_class = $this->payment_gateways[ $payment_gateway ]; 100 $payment_gateway_class = $this->payment_gateways[$payment_gateway]; 80 101 81 102 $handler = NF_Handlers_LocaleNumberFormatting::create(); 82 $converted = $handler->locale_decode_number( $action_settings['payment_total']);103 $converted = $handler->locale_decode_number($action_settings['payment_total']); 83 104 $action_settings['payment_total'] = $converted; 84 105 85 return $payment_gateway_class->process( $action_settings, $form_id, $data);106 return $payment_gateway_class->process($action_settings, $form_id, $data); 86 107 } 87 108 88 109 public function register_payment_gateways() 89 110 { 90 $this->payment_gateways = apply_filters( 'ninja_forms_register_payment_gateways', array());111 $this->payment_gateways = apply_filters('ninja_forms_register_payment_gateways', array()); 91 112 92 foreach( $this->payment_gateways as $gateway ){113 add_action('init',[$this,'buildPaymentGatewayOptions'],15); 93 114 94 if( ! is_subclass_of( $gateway, 'NF_Abstracts_PaymentGateway' ) ){ 115 } 116 117 /** 118 * Build gateway options for CollectPayment dropdown 119 * 120 * Done at `init-15` to ensure that object can populate translations 121 * 122 * @return void 123 */ 124 public function buildPaymentGatewayOptions(): void 125 { 126 foreach ($this->payment_gateways as $gateway) { 127 128 if (! is_subclass_of($gateway, 'NF_Abstracts_PaymentGateway')) { 95 129 continue; 96 130 } 97 131 98 $this->_settings[ 'payment_gateways' ][ 'options'][] = array(132 $this->_settings['payment_gateways']['options'][] = array( 99 133 'label' => $gateway->get_name(), 100 134 'value' => $gateway->get_slug(), 101 135 ); 102 136 103 $this->_settings = array_merge( $this->_settings, $gateway->get_settings());137 $this->_settings = array_merge($this->_settings, $gateway->get_settings()); 104 138 } 105 139 } 106 140 107 public function maybe_remove_action( $action_type_settings)141 public function maybe_remove_action($action_type_settings) 108 142 { 109 if ( empty( $this->payment_gateways ) ){110 unset( $action_type_settings[ $this->_name ]);143 if (empty($this->payment_gateways)) { 144 unset($action_type_settings[$this->_name]); 111 145 } 112 146 -
ninja-forms/tags/3.8.21/includes/Actions/Custom.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Action_Custom 5 11 */ 6 final class NF_Actions_Custom extends NF_Abstracts_Action12 final class NF_Actions_Custom extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'custom'; 14 use SotGetActionProperties; 12 15 13 16 /** … … 15 18 */ 16 19 protected $_tags = array(); 17 18 /**19 * @var string20 */21 protected $_documentation_url = 'https://ninjaforms.com/docs/wp-hook/';22 23 /**24 * @var string25 */26 protected $_timing = 'normal';27 28 /**29 * @var int30 */31 protected $_priority = 10;32 33 /**34 * @var string35 */36 protected $_group = 'core';37 20 38 21 /** … … 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'WP Hook', 'ninja-forms' ); 28 $this->_name = 'custom'; 29 $this->_priority = 10; 30 $this->_timing = 'normal'; 31 $this->_documentation_url = 'https://ninjaforms.com/docs/wp-hook/'; 32 $this->_group = 'core'; 46 33 47 $settings = Ninja_Forms::config( 'ActionCustomSettings' ); 34 add_action('init', [$this, 'initHook']); 35 } 48 36 49 $this->_settings = array_merge( $this->_settings, $settings ); 37 public function initHook() 38 { 39 $this->_nicename = esc_html__('WP Hook', 'ninja-forms'); 40 41 $settings = Ninja_Forms::config('ActionCustomSettings'); 42 43 $this->_settings = array_merge($this->_settings, $settings); 50 44 } 51 45 … … 54 48 */ 55 49 56 public function save( $action_settings ) 50 /** @inheritDoc */ 51 public function process(array $action_settings, int $form_id, array $data): array 57 52 { 58 59 } 60 61 public function process( $action_settings, $form_id, $data ) 62 { 63 if( isset( $action_settings[ 'tag' ] ) ) { 53 if (isset($action_settings['tag'])) { 64 54 ob_start(); // Use the Output Buffer to suppress output 65 55 66 do_action($action_settings[ 'tag'], $data);56 do_action($action_settings['tag'], $data); 67 57 68 58 ob_end_clean(); -
ninja-forms/tags/3.8.21/includes/Actions/DeleteDataRequest.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Actions_DataRemoval 5 11 */ 6 final class NF_Actions_DeleteDataRequest extends NF_Abstracts_Action12 final class NF_Actions_DeleteDataRequest extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'deletedatarequest'; 14 use SotGetActionProperties; 12 15 13 16 /** … … 15 18 */ 16 19 protected $_tags = array(); 17 18 /**19 * @var string20 */21 protected $_documentation_url = 'https://ninjaforms.com/docs/delete-data-request-action/';22 23 /**24 * @var string25 */26 protected $_timing = 'late';27 28 /**29 * @var int30 */31 protected $_priority = 10;32 33 /**34 * @var string35 */36 protected $_group = 'core';37 20 38 21 /** … … 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'Delete Data Request', 'ninja-forms' ); 28 $this->_name = 'deletedatarequest'; 29 $this->_priority = 10; 30 $this->_documentation_url = 'https://ninjaforms.com/docs/delete-data-request-action/'; 31 $this->_timing = 'late'; 32 $this->_group = 'core'; 46 33 47 $settings = Ninja_Forms::config( 'ActionDeleteDataRequestSettings' ); 48 $this->_settings = array_merge( $this->_settings, $settings ); 34 add_action('init', [$this, 'initHook']); 35 } 36 37 public function initHook() 38 { 39 $this->_nicename = esc_html__('Delete Data Request', 'ninja-forms'); 40 41 $settings = Ninja_Forms::config('ActionDeleteDataRequestSettings'); 42 $this->_settings = array_merge($this->_settings, $settings); 49 43 } 50 44 … … 52 46 * PUBLIC METHODS 53 47 */ 54 55 public function save( $action_settings )56 {57 58 }59 48 60 49 /** … … 68 57 * @return array 69 58 */ 70 public function process( $action_settings, $form_id, $data )59 public function process(array $action_settings, int $form_id, array $data): array 71 60 { 72 61 $data = array(); 73 62 74 if ( isset( $data['settings']['is_preview'] ) && $data['settings']['is_preview'] ){63 if (isset($data['settings']['is_preview']) && $data['settings']['is_preview']) { 75 64 return $data; 76 65 } 77 66 78 67 // get the email setting 79 $email = $action_settings[ 'email'];68 $email = $action_settings['email']; 80 69 81 70 // create request for user 82 $request_id = wp_create_user_request( $email, 83 'remove_personal_data' ); 71 $request_id = wp_create_user_request( 72 $email, 73 'remove_personal_data' 74 ); 84 75 85 76 /** … … 89 80 * 1) The email in question is already in the erase data request queue 90 81 * 2) The email does not belong to an actual user. 91 */92 if ( ! $request_id instanceof WP_Error) {82 */ 83 if (! $request_id instanceof WP_Error) { 93 84 // send the request if it's not an error. 94 85 95 86 // to anonymize or not to anonymize, that is the question 96 add_post_meta( $request_id, 87 add_post_meta( 88 $request_id, 97 89 'nf_anonymize_data', 98 $action_settings[ 'anonymize' ] ); 90 $action_settings['anonymize'] 91 ); 99 92 100 wp_send_user_request( $request_id);93 wp_send_user_request($request_id); 101 94 } 102 95 -
ninja-forms/tags/3.8.21/includes/Actions/Email.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Action_Email 5 11 */ 6 final class NF_Actions_Email extends NF_Abstracts_Action12 final class NF_Actions_Email extends SotAction implements InterfacesSotAction 7 13 { 14 use SotGetActionProperties; 15 8 16 /** 9 * @var string10 */11 protected $_ name = 'email';17 * @var array 18 */ 19 protected $_tags = array(); 12 20 13 21 /** 14 * @var array 15 */ 16 protected $_tags = array(); 17 18 /** 19 * @var string 22 * Constructor 20 23 */ 21 protected $_documentation_url = 'https://ninjaforms.com/docs/email/';22 23 /**24 * @var string25 */26 protected $_timing = 'late';27 28 /**29 * @var int30 */31 protected $_priority = 10;32 33 /**34 * @var string35 */36 protected $_group = 'core';37 38 /**39 * Constructor40 */41 24 public function __construct() 42 25 { 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'Email', 'ninja-forms' ); 46 47 $settings = Ninja_Forms::config( 'ActionEmailSettings' ); 48 49 $this->_settings = array_merge( $this->_settings, $settings ); 28 $this->_name = 'email'; 29 $this->_timing = 'late'; 30 $this->_priority = 10; 31 $this->_documentation_url = 'https://ninjaforms.com/docs/email/'; 32 $this->_group = 'core'; 33 34 add_action('init', [$this, 'initHook']); 35 } 36 37 public function initHook() 38 { 39 $this->_nicename = esc_html__('Email', 'ninja-forms'); 40 41 $settings = Ninja_Forms::config('ActionEmailSettings'); 42 43 $this->_settings = array_merge($this->_settings, $settings); 50 44 51 45 $this->_backwards_compatibility(); … … 55 49 * PUBLIC METHODS 56 50 */ 57 58 public function process( $action_settings, $form_id, $data )59 { 60 $action_settings = $this->sanitize_address_fields( $action_settings);61 62 $errors = $this->check_for_errors( $action_settings);63 64 $headers = $this->_get_headers( $action_settings);65 66 if ( has_filter( 'ninja_forms_get_fields_sorted' )) {51 /** @inheritDoc */ 52 public function process(array $action_settings, int $form_id, array $data): array 53 { 54 $action_settings = $this->sanitize_address_fields($action_settings); 55 56 $errors = $this->check_for_errors($action_settings); 57 58 $headers = $this->_get_headers($action_settings); 59 60 if (has_filter('ninja_forms_get_fields_sorted')) { 67 61 $fields_by_key = array(); 68 62 69 foreach ( $data[ 'fields' ] as $fieldId=>$field ){70 71 if ( is_null( $field )) continue;72 73 if ( is_array( $field ) ){74 if ( ! isset( $field[ 'key' ] )) continue;75 $key = $field[ 'key'];63 foreach ($data['fields'] as $fieldId => $field) { 64 65 if (is_null($field)) continue; 66 67 if (is_array($field)) { 68 if (! isset($field['key'])) continue; 69 $key = $field['key']; 76 70 77 71 // add field id if it isn't already set 78 if (!isset($field['id'])){79 $field['id'] =$fieldId;72 if (!isset($field['id'])) { 73 $field['id'] = $fieldId; 80 74 } 81 82 75 } else { 83 76 $key = $field->get_setting('key'); 84 77 } 85 $fields_by_key[ $key] = $field;86 } 87 $sorted = apply_filters( 'ninja_forms_get_fields_sorted', array(), $data[ 'fields' ], $fields_by_key, $form_id);88 if ( ! empty( $sorted ))89 $data[ 'fields'] = $sorted;90 } 91 92 $attachments = $this->_get_attachments( $action_settings, $data);93 94 if ( 'html' == $action_settings[ 'email_format' ]) {95 $message = wpautop( $action_settings['email_message']);78 $fields_by_key[$key] = $field; 79 } 80 $sorted = apply_filters('ninja_forms_get_fields_sorted', array(), $data['fields'], $fields_by_key, $form_id); 81 if (! empty($sorted)) 82 $data['fields'] = $sorted; 83 } 84 85 $attachments = $this->_get_attachments($action_settings, $data); 86 87 if ('html' == $action_settings['email_format']) { 88 $message = wpautop($action_settings['email_message']); 96 89 } else { 97 $message = $this->format_plain_text_message( $action_settings[ 'email_message_plain' ]);98 } 99 100 $message = apply_filters( 'ninja_forms_action_email_message', $message, $data, $action_settings);90 $message = $this->format_plain_text_message($action_settings['email_message_plain']); 91 } 92 93 $message = apply_filters('ninja_forms_action_email_message', $message, $data, $action_settings); 101 94 102 95 try { … … 105 98 * @return bool True if already sent. False to fallback to default behavior. Throw a new Exception if there is an error. 106 99 */ 107 if ( ! $sent = apply_filters( 'ninja_forms_action_email_send', false, $action_settings, $message, $headers, $attachments ) ){108 $sent = wp_mail($action_settings['to'], strip_tags( $action_settings['email_subject']), $message, $headers, $attachments);109 } 110 } catch ( Exception $e ){100 if (! $sent = apply_filters('ninja_forms_action_email_send', false, $action_settings, $message, $headers, $attachments)) { 101 $sent = wp_mail($action_settings['to'], strip_tags($action_settings['email_subject']), $message, $headers, $attachments); 102 } 103 } catch (Exception $e) { 111 104 $sent = false; 112 $errors[ 'email_not_sent'] = $e->getMessage();113 } 114 115 if ( is_user_logged_in() && current_user_can( 'manage_options' )) {116 $data[ 'actions' ][ 'email' ][ 'to' ] = $action_settings[ 'to'];117 $data[ 'actions' ][ 'email' ][ 'headers'] = $headers;118 $data[ 'actions' ][ 'email' ][ 'attachments'] = $attachments;119 } 120 121 $data[ 'actions' ][ 'email' ][ 'sent'] = $sent;105 $errors['email_not_sent'] = $e->getMessage(); 106 } 107 108 if (is_user_logged_in() && current_user_can('manage_options')) { 109 $data['actions']['email']['to'] = $action_settings['to']; 110 $data['actions']['email']['headers'] = $headers; 111 $data['actions']['email']['attachments'] = $attachments; 112 } 113 114 $data['actions']['email']['sent'] = $sent; 122 115 123 116 // Only show errors to Administrators. 124 if ( $errors && current_user_can( 'manage_options' ) ){125 $data[ 'errors' ][ 'form'] = $errors;126 } 127 128 if ( ! empty( $attachments )) {117 if ($errors && current_user_can('manage_options')) { 118 $data['errors']['form'] = $errors; 119 } 120 121 if (! empty($attachments)) { 129 122 $this->_drop_csv(); 130 123 } … … 140 133 * @return array 141 134 */ 142 protected function sanitize_address_fields( $action_settings)135 protected function sanitize_address_fields($action_settings) 143 136 { 144 137 // Build a look array to compare our email address settings to. 145 $email_address_settings = array( 'to', 'from_address', 'reply_to', 'cc', 'bcc');138 $email_address_settings = array('to', 'from_address', 'reply_to', 'cc', 'bcc'); 146 139 147 140 // Loop over the look up values. 148 foreach ( $email_address_settings as $setting) {141 foreach ($email_address_settings as $setting) { 149 142 // If the loop up values are not set in the action settings continue. 150 if ( ! isset( $action_settings[ $setting ] )) continue;143 if (! isset($action_settings[$setting])) continue; 151 144 152 145 // If action settings do not match the look up values continue. 153 if ( ! $action_settings[ $setting ]) continue;146 if (! $action_settings[$setting]) continue; 154 147 155 148 // This is the array that will contain the sanitized email address values. … … 160 153 * if not explodes to comma delimited array. 161 154 */ 162 if ( is_array( $action_settings[ $setting ] )) {163 $email_addresses = $action_settings[ $setting];155 if (is_array($action_settings[$setting])) { 156 $email_addresses = $action_settings[$setting]; 164 157 } else { 165 $email_addresses = explode( ',', $action_settings[ $setting ]);158 $email_addresses = explode(',', $action_settings[$setting]); 166 159 } 167 160 168 161 // Loop over our email addresses. 169 foreach ( $email_addresses as $email) {162 foreach ($email_addresses as $email) { 170 163 171 164 // Updated to trim values in case there is a value with spaces/tabs/etc to remove whitespace 172 $email = trim( $email);173 if ( empty( $email )) continue;165 $email = trim($email); 166 if (empty($email)) continue; 174 167 175 168 // Build our array of the email addresses. … … 177 170 } 178 171 // Sanitized our array of settings. 179 $action_settings[ $setting ] = implode( ',' ,$sanitized_array);172 $action_settings[$setting] = implode(',', $sanitized_array); 180 173 } 181 174 return $action_settings; 182 175 } 183 176 184 protected function check_for_errors( $action_settings)177 protected function check_for_errors($action_settings) 185 178 { 186 179 $errors = array(); 187 180 188 $email_address_settings = array( 'to', 'from_address', 'reply_to', 'cc', 'bcc');189 190 foreach ( $email_address_settings as $setting ){191 if ( ! isset( $action_settings[ $setting ] )) continue;192 if ( ! $action_settings[ $setting ]) continue;193 194 195 $email_addresses = is_array( $action_settings[ $setting ] ) ? $action_settings[ $setting ] : explode( ',', $action_settings[ $setting ]);196 197 foreach ( (array) $email_addresses as $email ){198 $email = trim( $email);199 if ( false !== strpos( $email, '<' ) && false !== strpos( $email, '>' )) {181 $email_address_settings = array('to', 'from_address', 'reply_to', 'cc', 'bcc'); 182 183 foreach ($email_address_settings as $setting) { 184 if (! isset($action_settings[$setting])) continue; 185 if (! $action_settings[$setting]) continue; 186 187 188 $email_addresses = is_array($action_settings[$setting]) ? $action_settings[$setting] : explode(',', $action_settings[$setting]); 189 190 foreach ((array) $email_addresses as $email) { 191 $email = trim($email); 192 if (false !== strpos($email, '<') && false !== strpos($email, '>')) { 200 193 preg_match('/(?:<)([^>]*)(?:>)/', $email, $email); 201 $email = $email[ 1];202 } 203 if ( ! is_email( $email )) {204 $errors[ 'invalid_email' ] = sprintf( esc_html__( 'Your email action "%s" has an invalid value for the "%s" setting. Please check this setting and try again.', 'ninja-forms'), $action_settings[ 'label' ], $setting);194 $email = $email[1]; 195 } 196 if (! is_email($email)) { 197 $errors['invalid_email'] = sprintf(esc_html__('Your email action "%s" has an invalid value for the "%s" setting. Please check this setting and try again.', 'ninja-forms'), $action_settings['label'], $setting); 205 198 } 206 199 } … … 210 203 } 211 204 212 private function _get_headers( $settings)205 private function _get_headers($settings) 213 206 { 214 207 $headers = array(); 215 208 216 $headers[] = 'Content-Type: text/' . $settings[ 'email_format'];209 $headers[] = 'Content-Type: text/' . $settings['email_format']; 217 210 $headers[] = 'charset=UTF-8'; 218 211 $headers[] = 'X-Ninja-Forms:ninja-forms'; // Flag for transactional email. 219 212 220 $headers[] = $this->_format_from( $settings);221 222 $headers = array_merge( $headers, $this->_format_recipients( $settings ));213 $headers[] = $this->_format_from($settings); 214 215 $headers = array_merge($headers, $this->_format_recipients($settings)); 223 216 224 217 return $headers; 225 218 } 226 219 227 private function _get_attachments( $settings, $data)220 private function _get_attachments($settings, $data) 228 221 { 229 222 $attachments = array(); 230 223 231 if ( isset( $settings[ 'attach_csv' ] ) && 1 == $settings[ 'attach_csv' ] ){232 $attachments[] = $this->_create_csv( $data[ 'fields' ]);233 } 234 235 if ( ! isset( $settings[ 'id' ] ) ) $settings[ 'id'] = '';224 if (isset($settings['attach_csv']) && 1 == $settings['attach_csv']) { 225 $attachments[] = $this->_create_csv($data['fields']); 226 } 227 228 if (! isset($settings['id'])) $settings['id'] = ''; 236 229 237 230 // Allow admins to attach files from media library … … 240 233 $media_id = attachment_url_to_postid($settings['file_attachment']); 241 234 242 if ($media_id !== 0) {235 if ($media_id !== 0) { 243 236 $file_path = get_attached_file($media_id); 244 237 if (0 < strlen($file_path)) { … … 248 241 } 249 242 250 $attachments = apply_filters( 'ninja_forms_action_email_attachments', $attachments, $data, $settings);243 $attachments = apply_filters('ninja_forms_action_email_attachments', $attachments, $data, $settings); 251 244 252 245 return $attachments; 253 246 } 254 247 255 private function _format_from( $settings)256 { 257 $from_name = get_bloginfo( 'name', 'raw');258 $from_name = apply_filters( 'ninja_forms_action_email_from_name', $from_name);259 $from_name = ( $settings[ 'from_name' ] ) ? $settings[ 'from_name'] : $from_name;260 261 $from_address = get_bloginfo( 'admin_email');262 $from_address = apply_filters( 'ninja_forms_action_email_from_address', $from_address);263 $from_address = ( $settings[ 'from_address' ] ) ? $settings[ 'from_address'] : $from_address;264 265 return $this->_format_recipient( 'from', $from_address, $from_name);266 } 267 268 private function _format_recipients( $settings)248 private function _format_from($settings) 249 { 250 $from_name = get_bloginfo('name', 'raw'); 251 $from_name = apply_filters('ninja_forms_action_email_from_name', $from_name); 252 $from_name = ($settings['from_name']) ? $settings['from_name'] : $from_name; 253 254 $from_address = get_bloginfo('admin_email'); 255 $from_address = apply_filters('ninja_forms_action_email_from_address', $from_address); 256 $from_address = ($settings['from_address']) ? $settings['from_address'] : $from_address; 257 258 return $this->_format_recipient('from', $from_address, $from_name); 259 } 260 261 private function _format_recipients($settings) 269 262 { 270 263 $headers = array(); 271 264 272 265 $recipient_settings = array( 273 'Cc' => $settings[ 'cc'],274 'Bcc' => $settings[ 'bcc'],275 'Reply-to' => $settings[ 'reply_to'],266 'Cc' => $settings['cc'], 267 'Bcc' => $settings['bcc'], 268 'Reply-to' => $settings['reply_to'], 276 269 ); 277 270 278 foreach ( $recipient_settings as $type => $emails ){279 280 $emails = explode( ',', $emails);281 282 foreach ( $emails as $email) {283 284 if ( ! $email) continue;271 foreach ($recipient_settings as $type => $emails) { 272 273 $emails = explode(',', $emails); 274 275 foreach ($emails as $email) { 276 277 if (! $email) continue; 285 278 286 279 $matches = array(); … … 296 289 } 297 290 298 private function _format_recipient( $type, $email, $name = '')299 { 300 $type = ucfirst( $type);301 302 if ( ! $name) $name = $email;291 private function _format_recipient($type, $email, $name = '') 292 { 293 $type = ucfirst($type); 294 295 if (! $name) $name = $email; 303 296 304 297 $recipient = "$type: $name <$email>"; … … 307 300 } 308 301 309 private function _create_csv( $fields)302 private function _create_csv($fields) 310 303 { 311 304 $csv_array = array(); 312 305 313 306 // Get our current date. 314 $date_format = Ninja_Forms()->get_setting( 'date_format');315 $today = date( $date_format, current_time( 'timestamp' ));316 $csv_array[ 0][] = 'Date Submitted';317 $csv_array[ 1][] = $today;318 319 foreach ( $fields as $field ){307 $date_format = Ninja_Forms()->get_setting('date_format'); 308 $today = date($date_format, current_time('timestamp')); 309 $csv_array[0][] = 'Date Submitted'; 310 $csv_array[1][] = $today; 311 312 foreach ($fields as $field) { 320 313 321 314 $ignore = array( … … 330 323 ); 331 324 332 $ignore = apply_filters( 'ninja_forms_csv_ignore_fields', $ignore);333 334 if ( ! isset( $field[ 'label' ] )) continue;335 if ( in_array( $field[ 'type' ], $ignore )) continue;336 337 $label = ( '' != $field[ 'admin_label' ] ) ? $field[ 'admin_label' ] : $field[ 'label'];325 $ignore = apply_filters('ninja_forms_csv_ignore_fields', $ignore); 326 327 if (! isset($field['label'])) continue; 328 if (in_array($field['type'], $ignore)) continue; 329 330 $label = ('' != $field['admin_label']) ? $field['admin_label'] : $field['label']; 338 331 // Escape labels. 339 332 $label = WPN_Helper::maybe_escape_csv_column($label); 340 333 341 if ($field["type"] === "repeater" && isset($field['fields'])){334 if ($field["type"] === "repeater" && isset($field['fields'])) { 342 335 $value = ""; 343 foreach ($field['fields'] as $field_model){344 foreach ($field['value'] as $in_field_value) {336 foreach ($field['fields'] as $field_model) { 337 foreach ($field['value'] as $in_field_value) { 345 338 $matching_value = substr($in_field_value['id'], 0, strlen($field_model['id'])) === $field_model['id']; 346 339 $index_found = substr($in_field_value['id'], strpos($in_field_value['id'], "_") + 1); 347 if ( $matching_value ){340 if ($matching_value) { 348 341 //Catch specific file uploeds data 349 if (isset($in_field_value["files"])){342 if (isset($in_field_value["files"])) { 350 343 $field_files_names = []; 351 foreach ($in_field_value["files"] as $file_data){352 $field_files_names []= $file_data["data"]["file_url"];344 foreach ($in_field_value["files"] as $file_data) { 345 $field_files_names[] = $file_data["data"]["file_url"]; 353 346 } 354 347 $in_field_value['value'] = implode(" , ", $field_files_names); 355 348 } 356 349 357 $value .= $field_model['label'] . "#" . $index_found . " : " . WPN_Helper::stripslashes( $in_field_value['value']) . " \n";350 $value .= $field_model['label'] . "#" . $index_found . " : " . WPN_Helper::stripslashes($in_field_value['value']) . " \n"; 358 351 }; 359 352 } 360 353 } 361 362 354 } else { 363 $value = WPN_Helper::stripslashes( $field[ 'value' ]);364 if ( empty( $value ) && ! isset( $value )) {355 $value = WPN_Helper::stripslashes($field['value']); 356 if (empty($value) && ! isset($value)) { 365 357 $value = ''; 366 358 } 367 if ( is_array( $value )) {368 $value = implode( ',', $value);359 if (is_array($value)) { 360 $value = implode(',', $value); 369 361 } 370 362 } 371 363 372 364 // add filter to add single quote if first character in value is '=' 373 $value = apply_filters( 'ninja_forms_subs_export_field_value_' . $field[ 'type' ], $value, $field ); 374 375 $csv_array[ 0 ][] = $label; 376 $csv_array[ 1 ][] = $value; 377 } 378 379 $csv_content = WPN_Helper::str_putcsv( $csv_array, 380 apply_filters( 'ninja_forms_sub_csv_delimiter', ',' ), 381 apply_filters( 'ninja_forms_sub_csv_enclosure', '"' ), 382 apply_filters( 'ninja_forms_sub_csv_terminator', "\n" ) 365 $value = apply_filters('ninja_forms_subs_export_field_value_' . $field['type'], $value, $field); 366 367 $csv_array[0][] = $label; 368 $csv_array[1][] = $value; 369 } 370 371 $csv_content = WPN_Helper::str_putcsv( 372 $csv_array, 373 apply_filters('ninja_forms_sub_csv_delimiter', ','), 374 apply_filters('ninja_forms_sub_csv_enclosure', '"'), 375 apply_filters('ninja_forms_sub_csv_terminator', "\n") 383 376 ); 384 377 385 378 $upload_dir = wp_upload_dir(); 386 $path = trailingslashit( $upload_dir['path']);379 $path = trailingslashit($upload_dir['path']); 387 380 388 381 // create temporary file 389 $path = tempnam( $path, 'Sub');390 $temp_file = fopen( $path, 'r+');382 $path = tempnam($path, 'Sub'); 383 $temp_file = fopen($path, 'r+'); 391 384 392 385 // write to temp file 393 fwrite( $temp_file, $csv_content);394 fclose( $temp_file);386 fwrite($temp_file, $csv_content); 387 fclose($temp_file); 395 388 396 389 // find the directory we will be using for the final file 397 $path = pathinfo( $path);390 $path = pathinfo($path); 398 391 $dir = $path['dirname']; 399 392 $basename = $path['basename']; 400 393 401 394 // create name for file 402 $new_name = apply_filters( 'ninja_forms_submission_csv_name', 'ninja-forms-submission');395 $new_name = apply_filters('ninja_forms_submission_csv_name', 'ninja-forms-submission'); 403 396 404 397 // remove a file if it already exists 405 if ( file_exists( $dir.'/'.$new_name.'.csv' )) {406 unlink( $dir.'/'.$new_name.'.csv');398 if (file_exists($dir . '/' . $new_name . '.csv')) { 399 unlink($dir . '/' . $new_name . '.csv'); 407 400 } 408 401 409 402 // move file 410 rename( $dir.'/'.$basename, $dir.'/'.$new_name.'.csv');411 return $dir .'/'.$new_name.'.csv';403 rename($dir . '/' . $basename, $dir . '/' . $new_name . '.csv'); 404 return $dir . '/' . $new_name . '.csv'; 412 405 } 413 406 … … 418 411 { 419 412 $upload_dir = wp_upload_dir(); 420 $path = trailingslashit( $upload_dir['path']);413 $path = trailingslashit($upload_dir['path']); 421 414 422 415 // create name for file 423 $new_name = apply_filters( 'ninja_forms_submission_csv_name', 'ninja-forms-submission');416 $new_name = apply_filters('ninja_forms_submission_csv_name', 'ninja-forms-submission'); 424 417 425 418 // remove a file if it already exists 426 if ( file_exists( $path.'/'.$new_name.'.csv' )) {427 unlink( $path.'/'.$new_name.'.csv');419 if (file_exists($path . '/' . $new_name . '.csv')) { 420 unlink($path . '/' . $new_name . '.csv'); 428 421 } 429 422 } … … 435 428 private function _backwards_compatibility() 436 429 { 437 add_filter( 'ninja_forms_sub_csv_delimiter', array( $this, 'ninja_forms_sub_csv_delimiter' ), 10, 1);438 add_filter( 'ninja_sub_csv_enclosure', array( $this, 'ninja_sub_csv_enclosure' ), 10, 1);439 add_filter( 'ninja_sub_csv_terminator', array( $this, 'ninja_sub_csv_terminator' ), 10, 1);440 add_filter( 'ninja_forms_action_email_attachments', array( $this, 'ninja_forms_action_email_attachments' ), 10, 3);441 } 442 443 public function ninja_forms_sub_csv_delimiter( $delimiter)444 { 445 return apply_filters( 'nf_sub_csv_delimiter', $delimiter);446 } 447 448 public function ninja_sub_csv_enclosure( $enclosure)449 { 450 return apply_filters( 'nf_sub_csv_enclosure', $enclosure);451 } 452 453 public function ninja_sub_csv_terminator( $terminator)454 { 455 return apply_filters( 'nf_sub_csv_terminator', $terminator);456 } 457 458 public function ninja_forms_action_email_attachments( $attachments, $form_data, $action_settings)459 { 460 return apply_filters( 'nf_email_notification_attachments', $attachments, $action_settings[ 'id' ]);461 } 462 463 private function format_plain_text_message( $message)464 { 465 $message = str_replace( array( '<table>', '</table>', '<tr><td>', '' ), '', $message);466 $message = str_replace( '</td><td>', ' ', $message);467 $message = str_replace( '</td></tr>', "\r\n", $message);468 return strip_tags( $message);430 add_filter('ninja_forms_sub_csv_delimiter', array($this, 'ninja_forms_sub_csv_delimiter'), 10, 1); 431 add_filter('ninja_sub_csv_enclosure', array($this, 'ninja_sub_csv_enclosure'), 10, 1); 432 add_filter('ninja_sub_csv_terminator', array($this, 'ninja_sub_csv_terminator'), 10, 1); 433 add_filter('ninja_forms_action_email_attachments', array($this, 'ninja_forms_action_email_attachments'), 10, 3); 434 } 435 436 public function ninja_forms_sub_csv_delimiter($delimiter) 437 { 438 return apply_filters('nf_sub_csv_delimiter', $delimiter); 439 } 440 441 public function ninja_sub_csv_enclosure($enclosure) 442 { 443 return apply_filters('nf_sub_csv_enclosure', $enclosure); 444 } 445 446 public function ninja_sub_csv_terminator($terminator) 447 { 448 return apply_filters('nf_sub_csv_terminator', $terminator); 449 } 450 451 public function ninja_forms_action_email_attachments($attachments, $form_data, $action_settings) 452 { 453 return apply_filters('nf_email_notification_attachments', $attachments, $action_settings['id']); 454 } 455 456 private function format_plain_text_message($message) 457 { 458 $message = str_replace(array('<table>', '</table>', '<tr><td>', ''), '', $message); 459 $message = str_replace('</td><td>', ' ', $message); 460 $message = str_replace('</td></tr>', "\r\n", $message); 461 return strip_tags($message); 469 462 } 470 463 } -
ninja-forms/tags/3.8.21/includes/Actions/ExportDataRequest.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Actions_ExportPersonalData 5 11 */ 6 final class NF_Actions_ExportDataRequest extends NF_Abstracts_Action12 final class NF_Actions_ExportDataRequest extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'exportdatarequest'; 14 use SotGetActionProperties; 12 15 13 16 /** … … 15 18 */ 16 19 protected $_tags = array(); 17 18 /**19 * @var string20 */21 protected $_documentation_url = 'https://ninjaforms.com/docs/export-data-request-action/';22 23 /**24 * @var string25 */26 protected $_timing = 'late';27 28 /**29 * @var int30 */31 protected $_priority = 10;32 33 /**34 * @var string35 */36 protected $_group = 'core';37 20 38 21 /** … … 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'Export Data Request', 'ninja-forms' ); 28 $this->_name = 'exportdatarequest'; 29 $this->_timing = 'late'; 30 $this->_priority = 10; 31 $this->_documentation_url = 'https://ninjaforms.com/docs/export-data-request-action/'; 32 $this->_group = 'core'; 46 33 47 $settings = Ninja_Forms::config( 'ActionExportDataRequestSettings' ); 48 $this->_settings = array_merge( $this->_settings, $settings ); 34 add_action('init', [$this, 'initHook']); 35 } 36 37 public function initHook() 38 { 39 $this->_nicename = esc_html__('Export Data Request', 'ninja-forms'); 40 41 $settings = Ninja_Forms::config('ActionExportDataRequestSettings'); 42 $this->_settings = array_merge($this->_settings, $settings); 49 43 } 50 44 … … 53 47 */ 54 48 55 public function save( $action_settings )56 {57 58 }59 49 60 50 /** … … 68 58 * @return array 69 59 */ 70 public function process( $action_settings, $form_id, $data )60 public function process(array $action_settings, int $form_id, array $data): array 71 61 { 72 62 $data = array(); 73 63 74 if ( isset( $data['settings']['is_preview'] ) && $data['settings']['is_preview'] ){64 if (isset($data['settings']['is_preview']) && $data['settings']['is_preview']) { 75 65 return $data; 76 66 } 77 67 78 68 // get the email setting 79 $email = $action_settings[ 'email'];69 $email = $action_settings['email']; 80 70 81 71 // create request for user 82 $request_id = wp_create_user_request( $email, 83 'export_personal_data' ); 72 $request_id = wp_create_user_request( 73 $email, 74 'export_personal_data' 75 ); 84 76 85 77 /** … … 90 82 * 2) The email does not belong to an actual user. 91 83 */ 92 if ( ! $request_id instanceof WP_Error) {93 wp_send_user_request( $request_id);84 if (! $request_id instanceof WP_Error) { 85 wp_send_user_request($request_id); 94 86 } 95 87 -
ninja-forms/tags/3.8.21/includes/Actions/Recaptcha.php
r3101843 r3204929 1 1 <?php 2 2 3 if ( ! defined( 'ABSPATH' ) || ! class_exists( 'NF_Abstracts_Action' ) ) { 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH') ) { 4 8 exit; 5 9 } … … 8 12 * Class NF_Actions_Recaptcha 9 13 */ 10 final class NF_Actions_Recaptcha extends NF_Abstracts_Action { 14 final class NF_Actions_Recaptcha extends SotAction implements InterfacesSotAction 15 { 16 use SotGetActionProperties; 17 18 /** 19 * @var array 20 */ 21 protected $_tags = array('spam', 'filtering', 'recaptcha'); 11 22 12 23 /** 13 24 * @var string 14 25 */ 15 protected $_name = 'recaptcha'; 26 protected $site_key; 27 28 /** 29 * @var string 30 */ 31 protected $site_secret; 32 33 /** 34 * @var int 35 */ 36 protected $form_id; 16 37 17 38 /** 18 39 * @var array 19 40 */ 20 protected $_tags = array( 'spam', 'filtering', 'recaptcha' ); 21 22 /** 23 * @var string 24 */ 25 protected $_timing = 'normal'; 26 27 /** 28 * @var int 29 */ 30 protected $_priority = '10'; 31 32 /** 33 * @var string 34 */ 35 protected $_group = 'core'; 36 37 /** 38 * @var string 39 */ 40 protected $site_key; 41 42 /** 43 * @var string 44 */ 45 protected $site_secret; 46 47 /** 48 * @var int 49 */ 50 protected $form_id; 41 protected $forms_with_action; 51 42 52 43 /** 53 44 * @var array 54 45 */ 55 protected $forms_with_action; 56 57 /** 58 * @var array 59 */ 60 protected $_settings_exclude = array( 'conditions' ); 46 protected $_settings_exclude = array('conditions'); 61 47 62 48 /** 63 49 * Constructor 64 50 */ 65 public function __construct() { 51 public function __construct() 52 { 66 53 parent::__construct(); 67 54 68 $this->_nicename = esc_html__( 'reCAPTCHA v3', 'ninja-forms' ); 69 $settings = Ninja_Forms::config( 'ActionRecaptchaV3Settings' ); 70 $this->_settings = array_merge( $this->_settings, $settings ); 71 72 $this->site_key = Ninja_Forms()->get_setting( 'recaptcha_site_key_3' ); 73 $this->site_secret = Ninja_Forms()->get_setting( 'recaptcha_secret_key_3' ); 74 75 add_filter( 'ninja_forms_action_type_settings', array( $this, 'maybe_remove_action' ) ); 76 77 add_action( 'nf_get_form_id', array( $this, 'set_form_id' ), 15, 1 ); 78 79 add_filter( 'ninja_forms_display_fields', array( $this, 'maybe_inject_field'), 10, 2 ); 80 add_filter( 'ninja_forms_form_fields', array( $this, 'maybe_remove_v2_field') ); 81 add_filter( 'ninja_forms_field_show_in_builder', array( $this, 'maybe_remove_v2_field_from_builder'), 10, 2 ); 82 add_action( 'ninja_forms_output_templates', array( $this, 'maybe_output_field_template') ); 83 add_filter( 'nf_display_enqueue_scripts', array( $this, 'enqueue_script' ) ); 55 $this->_name = 'recaptcha'; 56 $this->_timing = 'normal'; 57 $this->_priority = '10'; 58 $this->_group = 'core'; 59 60 add_action('init', [$this, 'initHook']); 61 62 add_filter('ninja_forms_action_type_settings', array($this, 'maybe_remove_action')); 63 64 add_action('nf_get_form_id', array($this, 'set_form_id'), 15, 1); 65 66 add_filter('ninja_forms_display_fields', array($this, 'maybe_inject_field'), 10, 2); 67 add_filter('ninja_forms_form_fields', array($this, 'maybe_remove_v2_field')); 68 add_filter('ninja_forms_field_show_in_builder', array($this, 'maybe_remove_v2_field_from_builder'), 10, 2); 69 add_action('ninja_forms_output_templates', array($this, 'maybe_output_field_template')); 70 add_filter('nf_display_enqueue_scripts', array($this, 'enqueue_script')); 71 } 72 73 public function initHook() 74 { 75 76 $this->_nicename = esc_html__('reCAPTCHA v3', 'ninja-forms'); 77 $settings = Ninja_Forms::config('ActionRecaptchaV3Settings'); 78 $this->_settings = array_merge($this->_settings, $settings); 79 80 $this->site_key = Ninja_Forms()->get_setting('recaptcha_site_key_3'); 81 $this->site_secret = Ninja_Forms()->get_setting('recaptcha_secret_key_3'); 84 82 } 85 83 … … 91 89 * @return void 92 90 */ 93 public function set_form_id( $form_id)91 public function set_form_id($form_id) 94 92 { 95 93 $this->form_id = $form_id; 96 94 } 97 95 98 public function get_form_id() { 99 if ( $this->form_id ) { 96 public function get_form_id() 97 { 98 if ($this->form_id) { 100 99 return $this->form_id; 101 100 } 102 101 103 $this->form_id = filter_input( INPUT_GET, 'form_id', FILTER_VALIDATE_INT);102 $this->form_id = filter_input(INPUT_GET, 'form_id', FILTER_VALIDATE_INT); 104 103 105 104 return $this->form_id; … … 113 112 * @return array 114 113 */ 115 public function maybe_remove_action( $action_type_settings ) { 116 if ( ! $this->is_recaptcha_configured() ) { 117 unset( $action_type_settings[ $this->_name ] ); 114 public function maybe_remove_action($action_type_settings) 115 { 116 if (! $this->is_recaptcha_configured()) { 117 unset($action_type_settings[$this->_name]); 118 118 } 119 119 … … 124 124 * @return bool 125 125 */ 126 protected function is_action_enabled_for_form() { 126 protected function is_action_enabled_for_form() 127 { 127 128 $form_id = $this->get_form_id(); 128 129 129 if ( isset( $this->forms_with_action[ $form_id ] )) {130 return $this->forms_with_action[ $form_id];131 } 132 133 $actions = Ninja_Forms()->form( $form_id)->get_actions();130 if (isset($this->forms_with_action[$form_id])) { 131 return $this->forms_with_action[$form_id]; 132 } 133 134 $actions = Ninja_Forms()->form($form_id)->get_actions(); 134 135 135 136 $enabled = false; 136 foreach ( $actions as $action) {137 if ( $this->_name == $action->get_settings('type') && 1 == $action->get_setting( 'active' )) {137 foreach ($actions as $action) { 138 if ($this->_name == $action->get_settings('type') && 1 == $action->get_setting('active')) { 138 139 $enabled = true; 139 140 break; … … 141 142 } 142 143 143 $this->forms_with_action[ $form_id] = $enabled;144 $this->forms_with_action[$form_id] = $enabled; 144 145 145 146 return $enabled; … … 151 152 * @return bool 152 153 */ 153 protected function is_recaptcha_configured() { 154 if ( empty( $this->site_key ) || empty( $this->site_secret) ) { 154 protected function is_recaptcha_configured() 155 { 156 if (empty($this->site_key) || empty($this->site_secret)) { 155 157 return false; 156 158 } … … 164 166 * @return bool 165 167 */ 166 protected function is_action_configured() { 167 if ( ! $this->is_recaptcha_configured() ) { 168 return false; 169 } 170 171 if ( ! $this->is_action_enabled_for_form() ) { 168 protected function is_action_configured() 169 { 170 if (! $this->is_recaptcha_configured()) { 171 return false; 172 } 173 174 if (! $this->is_action_enabled_for_form()) { 172 175 return false; 173 176 } … … 176 179 } 177 180 178 public function maybe_output_field_template() { 179 if ( ! $this->is_action_configured() ) { 181 public function maybe_output_field_template() 182 { 183 if (! $this->is_action_configured()) { 180 184 return; 181 185 } … … 183 187 $file_path = Ninja_Forms::$dir . 'includes/Templates/'; 184 188 185 echo file_get_contents( $file_path . "fields-recaptcha-v3.html" ); 186 } 187 188 protected function get_field_id_hash( $form_id ) { 189 return substr( base_convert( md5( $form_id ), 16, 10 ), - 5 ); 189 echo file_get_contents($file_path . "fields-recaptcha-v3.html"); 190 } 191 192 protected function get_field_id_hash($form_id) 193 { 194 return substr(base_convert(md5($form_id), 16, 10), -5); 190 195 } 191 196 … … 197 202 * @return array 198 203 */ 199 public function maybe_remove_v2_field( $fields ) { 200 if ( ! $this->is_action_configured() ) { 204 public function maybe_remove_v2_field($fields) 205 { 206 if (! $this->is_action_configured()) { 201 207 return $fields; 202 208 } 203 209 204 foreach ( $fields as $key => $field) {205 if ( 'recaptcha' === $field->get_setting('type')) {210 foreach ($fields as $key => $field) { 211 if ('recaptcha' === $field->get_setting('type')) { 206 212 // Remove v2 reCAPTCHA fields if still configured 207 unset( $fields[ $key ]);213 unset($fields[$key]); 208 214 } 209 215 } … … 220 226 * @return bool 221 227 */ 222 public function maybe_remove_v2_field_from_builder( $show, $field ) { 223 if ( ! $this->is_action_configured() ) { 228 public function maybe_remove_v2_field_from_builder($show, $field) 229 { 230 if (! $this->is_action_configured()) { 224 231 return $show; 225 232 } 226 233 227 if ( 'recaptcha' !== $field->get_type()) {234 if ('recaptcha' !== $field->get_type()) { 228 235 return $show; 229 236 } 230 237 231 $saved_fields = Ninja_Forms()->form( $this->get_form_id() )->get_fields( array( 'saved' => 1 ), true);232 233 foreach ( $saved_fields as $key => $field) {234 if ( 'recaptcha' === $field->get_setting( 'type' )) {238 $saved_fields = Ninja_Forms()->form($this->get_form_id())->get_fields(array('saved' => 1), true); 239 240 foreach ($saved_fields as $key => $field) { 241 if ('recaptcha' === $field->get_setting('type')) { 235 242 // recaptcha v2 field exists on form, don't hide it as it will break the JS 236 243 return $show; … … 248 255 * @return array 249 256 */ 250 public function maybe_inject_field( $fields, $form_id ) { 251 if ( ! $this->is_action_configured() ) { 257 public function maybe_inject_field($fields, $form_id) 258 { 259 if (! $this->is_action_configured()) { 252 260 return $fields; 253 261 } 254 262 255 $field_id = $this->get_field_id_hash( $form_id);263 $field_id = $this->get_field_id_hash($form_id); 256 264 257 265 $field = array( … … 259 267 'objectDomain' => 'fields', 260 268 'editActive' => false, 261 'order' => number_format( count( $fields ) + 1, 1),269 'order' => number_format(count($fields) + 1, 1), 262 270 'type' => 'recaptcha_v3', 263 271 'label' => 'Hidden', … … 287 295 } 288 296 289 public function enqueue_script() { 290 if ( ! $this->is_action_configured() ) { 297 public function enqueue_script() 298 { 299 if (! $this->is_action_configured()) { 291 300 return; 292 301 } 293 302 294 $recaptcha_lang = Ninja_Forms()->get_setting( 'recaptcha_lang', 'en');295 296 if ( $this->maybe_enqueue_recaptcha_js()) {297 wp_enqueue_script( 'nf-google-recaptcha', 'https://www.google.com/recaptcha/api.js?hl=' . $recaptcha_lang . '&render=' . $this->site_key, array( 'jquery' ), '3.0', true);303 $recaptcha_lang = Ninja_Forms()->get_setting('recaptcha_lang', 'en'); 304 305 if ($this->maybe_enqueue_recaptcha_js()) { 306 wp_enqueue_script('nf-google-recaptcha', 'https://www.google.com/recaptcha/api.js?hl=' . $recaptcha_lang . '&render=' . $this->site_key, array('jquery'), '3.0', true); 298 307 } 299 308 } … … 304 313 * @return bool 305 314 */ 306 protected function maybe_enqueue_recaptcha_js() { 307 if ( false !== apply_filters( 'ninja_forms_pre_enqueue_recaptcha_v3_js', false ) ) { 315 protected function maybe_enqueue_recaptcha_js() 316 { 317 if (false !== apply_filters('ninja_forms_pre_enqueue_recaptcha_v3_js', false)) { 308 318 // Allow other plugins to tell Ninja Forms not to load the Google JS script, if they are doing that 309 319 return false; … … 312 322 $scripts = wp_scripts(); 313 323 314 foreach ( $scripts->registered as $script) {315 if ( false !== strpos( $script->src, 'google.com/recaptcha/api.js' )) {324 foreach ($scripts->registered as $script) { 325 if (false !== strpos($script->src, 'google.com/recaptcha/api.js')) { 316 326 return false; 317 327 } … … 321 331 } 322 332 323 protected function get_form_data() { 324 if ( empty( $_POST['formData'] ) ) { 325 return false; 326 } 327 328 $form_data = json_decode( $_POST['formData'], true ); 333 protected function get_form_data() 334 { 335 if (empty($_POST['formData'])) { 336 return false; 337 } 338 339 $form_data = json_decode($_POST['formData'], true); 329 340 330 341 // php5.2 fallback 331 if ( ! $form_data) {332 $form_data = json_decode( stripslashes( $_POST['formData'] ), true);342 if (! $form_data) { 343 $form_data = json_decode(stripslashes($_POST['formData']), true); 333 344 } 334 345 … … 336 347 } 337 348 338 protected function get_recaptcha_response() { 349 protected function get_recaptcha_response() 350 { 339 351 $form_data = $this->get_form_data(); 340 352 341 if ( ! $form_data || ! isset( $form_data['id'] )) {342 return false; 343 } 344 345 $field_id = $this->get_field_id_hash( $form_data['id']);346 347 if ( ! isset( $form_data['fields'] ) || ! isset( $form_data['fields'][ $field_id ] )) {348 return false; 349 } 350 351 return $form_data['fields'][ $field_id]['value'];353 if (! $form_data || ! isset($form_data['id'])) { 354 return false; 355 } 356 357 $field_id = $this->get_field_id_hash($form_data['id']); 358 359 if (! isset($form_data['fields']) || ! isset($form_data['fields'][$field_id])) { 360 return false; 361 } 362 363 return $form_data['fields'][$field_id]['value']; 352 364 } 353 365 … … 361 373 * @return array 362 374 */ 363 public function process( $action_settings, $form_id, $data ) { 364 if ( ! $this->is_recaptcha_configured() ) { 375 public function process(array $action_settings, int $form_id, array $data): array 376 { 377 if (! $this->is_recaptcha_configured()) { 365 378 return $data; 366 379 } … … 368 381 $recaptcha_response = $this->get_recaptcha_response(); 369 382 370 if ( ! $recaptcha_response) {371 $data['errors']['form']['recaptcha'] = esc_html__( 'Recaptcha validation failed. Please try again later', 'ninja-forms');383 if (! $recaptcha_response) { 384 $data['errors']['form']['recaptcha'] = esc_html__('Recaptcha validation failed. Please try again later', 'ninja-forms'); 372 385 373 386 return $data; 374 387 } 375 388 376 if ( $this->is_submission_human( $recaptcha_response, $action_settings['score'] )) {389 if ($this->is_submission_human($recaptcha_response, $action_settings['score'])) { 377 390 return $data; 378 391 } 379 392 380 $data['errors']['form']['recaptcha'] = esc_html__( 'Recaptcha validation failed. Please try again later', 'ninja-forms');393 $data['errors']['form']['recaptcha'] = esc_html__('Recaptcha validation failed. Please try again later', 'ninja-forms'); 381 394 382 395 return $data; 383 396 } 384 397 385 protected function is_submission_human( $token, $score_threshold ) { 398 protected function is_submission_human($token, $score_threshold) 399 { 386 400 $endpoint = 'https://www.google.com/recaptcha/api/siteverify'; 387 401 … … 389 403 'body' => array( 390 404 'secret' => $this->site_secret, 391 'response' => esc_html( $token),405 'response' => esc_html($token), 392 406 ), 393 407 ); 394 408 395 $response = wp_remote_post( esc_url_raw( $endpoint ), $request);396 397 if ( 200 != wp_remote_retrieve_response_code( $response )) {398 if ( WP_DEBUG) {399 error_log( print_r( $response, true ));409 $response = wp_remote_post(esc_url_raw($endpoint), $request); 410 411 if (200 != wp_remote_retrieve_response_code($response)) { 412 if (WP_DEBUG) { 413 error_log(print_r($response, true)); 400 414 } 401 415 … … 403 417 } 404 418 405 $response_body = wp_remote_retrieve_body( $response);406 $response_body = json_decode( $response_body, true);407 408 $score = isset( $response_body['score']) ? $response_body['score'] : 0;409 410 $threshold = apply_filters( 'ninja_forms_action_recaptcha_score_threshold', $score_threshold);419 $response_body = wp_remote_retrieve_body($response); 420 $response_body = json_decode($response_body, true); 421 422 $score = isset($response_body['score']) ? $response_body['score'] : 0; 423 424 $threshold = apply_filters('ninja_forms_action_recaptcha_score_threshold', $score_threshold); 411 425 $is_human = $threshold < $score; 412 426 413 $is_human = apply_filters( 'ninja_forms_action_recaptcha__verify_response', $is_human, $response_body);427 $is_human = apply_filters('ninja_forms_action_recaptcha__verify_response', $is_human, $response_body); 414 428 415 429 return $is_human; -
ninja-forms/tags/3.8.21/includes/Actions/Redirect.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Action_Redirect 5 11 */ 6 final class NF_Actions_Redirect extends NF_Abstracts_Action12 final class NF_Actions_Redirect extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'redirect'; 14 use SotGetActionProperties; 12 15 13 16 /** 14 * @var array15 */17 * @var array 18 */ 16 19 protected $_tags = array(); 17 20 18 21 /** 19 * @var string22 * Constructor 20 23 */ 21 protected $_documentation_url = 'https://ninjaforms.com/docs/redirect-action/';22 23 /**24 * @var string25 */26 protected $_timing = 'late';27 28 /**29 * @var int30 */31 protected $_priority = 20;32 33 /**34 * @var string35 */36 protected $_group = 'core';37 38 /**39 * Constructor40 */41 24 public function __construct() 42 25 { 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'Redirect', 'ninja-forms' ); 28 $this->_name = 'redirect'; 29 $this->_timing = 'late'; 30 $this->_priority = 20; 31 $this->_documentation_url = 'https://ninjaforms.com/docs/redirect-action/'; 32 $this->_group = 'core'; 46 33 47 $settings = Ninja_Forms::config( 'ActionRedirectSettings' ); 48 49 $this->_settings = array_merge( $this->_settings, $settings ); 34 add_action('init', [$this, 'initHook']); 50 35 } 51 36 37 public function initHook() 38 { 39 40 $this->_nicename = esc_html__('Redirect', 'ninja-forms'); 41 42 $settings = Ninja_Forms::config('ActionRedirectSettings'); 43 44 $this->_settings = array_merge($this->_settings, $settings); 45 } 52 46 /* 53 47 * PUBLIC METHODS 54 48 */ 55 49 56 public function save( $action_settings ) 50 51 /** @inheritDoc */ 52 public function process(array $action_settings, int $form_id, array $data): array 57 53 { 58 59 } 60 61 public function process( $action_settings, $form_id, $data ) 62 { 63 $data[ 'actions' ][ 'redirect' ] = $action_settings[ 'redirect_url' ]; 54 $data['actions']['redirect'] = $action_settings['redirect_url']; 64 55 65 56 return $data; -
ninja-forms/tags/3.8.21/includes/Actions/Save.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Action_Save 5 11 */ 6 class NF_Actions_Save extends NF_Abstracts_Action12 class NF_Actions_Save extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'save'; 12 13 /** 14 * @var array 15 */ 14 use SotGetActionProperties; 15 16 /** 17 * @var array 18 */ 16 19 protected $_tags = array(); 17 20 18 21 /** 19 * @var string 20 */ 21 protected $_documentation_url = 'https://ninjaforms.com/docs/record-submission-action/'; 22 23 /** 24 * @var string 25 */ 26 protected $_timing = 'late'; 27 28 /** 29 * @var int 30 */ 31 protected $_priority = '-1'; 32 33 /** 34 * @var string 35 */ 36 protected $_group = 'core'; 37 38 /** 39 * Constructor 40 */ 22 * Constructor 23 */ 41 24 public function __construct() 42 25 { 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'Record Submission', 'ninja-forms' ); 46 47 $settings = Ninja_Forms::config( 'ActionSaveSettings' ); 48 49 $this->_settings = array_merge( $this->_settings, $settings ); 50 28 $this->_name = 'save'; 29 $this->_timing = 'late'; 30 $this->_priority = '-1'; 31 $this->_documentation_url = 'https://ninjaforms.com/docs/record-submission-action/'; 32 $this->_group = 'core'; 33 34 add_action('init', [$this, 'initHook']); 35 } 36 37 public function initHook() 38 { 39 $this->_nicename = esc_html__('Record Submission', 'ninja-forms'); 40 41 $settings = Ninja_Forms::config('ActionSaveSettings'); 42 43 $this->_settings = array_merge($this->_settings, $settings); 51 44 } 52 45 … … 55 48 */ 56 49 57 public function save( $action_settings ) 58 { 59 if( ! isset( $_POST[ 'form' ] ) ) return; 50 /** @inheritDoc */ 51 public function save(array $action_settings) 52 { 53 if (! isset($_POST['form'])) return; 60 54 // Get the form data from the Post variable and send it off for processing. 61 $form = json_decode( stripslashes( $_POST[ 'form' ] ));62 $this->submission_expiration_processing( $action_settings, $form->id);55 $form = json_decode(stripslashes($_POST['form'])); 56 $this->submission_expiration_processing($action_settings, $form->id); 63 57 } 64 58 … … 73 67 * @return void 74 68 */ 75 public function submission_expiration_processing( $action_settings, $form_id)69 public function submission_expiration_processing($action_settings, $form_id) 76 70 { 77 71 /* … … 79 73 * Example: 5,90 80 74 */ 81 $expiration_value = $form_id . ',' . $action_settings[ 'subs_expire_time'];75 $expiration_value = $form_id . ',' . $action_settings['subs_expire_time']; 82 76 83 77 // Get our expiration option. 84 $option = $this->getOption( 'nf_sub_expiration', array());78 $option = $this->getOption('nf_sub_expiration', array()); 85 79 86 80 // Check if form is already listed in the option and remove it if it is 87 $expiration_option = $this->clean_form_option( $expiration_value, $option);88 81 $expiration_option = $this->clean_form_option($expiration_value, $option); 82 89 83 // If our expiration setting is turned on, add current cron interval to the form entry in the option. 90 if ( 1 == $action_settings[ 'set_subs_to_expire' ]) {84 if (1 == $action_settings['set_subs_to_expire']) { 91 85 $expiration_option[] = $expiration_value; 92 86 } 93 87 94 88 // Update our option. 95 $this->updateOption( 'nf_sub_expiration', $expiration_option);89 $this->updateOption('nf_sub_expiration', $expiration_option); 96 90 } 97 91 … … 105 99 protected function getOption(string $key, $default) 106 100 { 107 $return = get_option( $key, $default);101 $return = get_option($key, $default); 108 102 109 103 return $return; … … 117 111 * @return void 118 112 */ 119 protected function updateOption(string $key, $value): void120 { 121 update_option( $key, $value);113 protected function updateOption(string $key, $value): void 114 { 115 update_option($key, $value); 122 116 } 123 117 /** … … 134 128 * @return array $expiration_option without current saved form 135 129 */ 136 public function clean_form_option( $expiration_value, $expiration_option ){ 130 public function clean_form_option($expiration_value, $expiration_option) 131 { 137 132 /* 138 133 * Breaks a part our options. … … 140 135 * $value[ 1 ] - ( int ) Expiration time in days 141 136 */ 142 $values = explode( ',', $expiration_value);137 $values = explode(',', $expiration_value); 143 138 144 139 // Find the position of the value we are tyring to update. 145 140 //This checks if this form is already in the expiration options, removes the form from the option's array and adds it again with the new expiration time 146 foreach ($expiration_option as $index => $form_option){147 $form_option = explode( ',', $form_option);148 if ($form_option[0] == $values[0]){141 foreach ($expiration_option as $index => $form_option) { 142 $form_option = explode(',', $form_option); 143 if ($form_option[0] == $values[0]) { 149 144 unset($expiration_option[$index]); 150 145 } 151 146 } 152 147 153 148 return $expiration_option; 154 149 } 155 150 156 public function process( $action_settings, $form_id, $data ) 157 { 158 159 if( isset( $data['settings']['is_preview'] ) && $data['settings']['is_preview'] ){ 151 /** @inheritDoc */ 152 public function process(array $action_settings, int $form_id, array $data): array 153 { 154 155 if (isset($data['settings']['is_preview']) && $data['settings']['is_preview']) { 160 156 return $data; 161 157 } 162 158 163 if ( ! apply_filters ( 'ninja_forms_save_submission', true, $form_id )) return $data;164 165 $sub = Ninja_Forms()->form( $form_id)->sub()->get();166 167 $hidden_field_types = apply_filters( 'nf_sub_hidden_field_types', array());159 if (! apply_filters('ninja_forms_save_submission', true, $form_id)) return $data; 160 161 $sub = Ninja_Forms()->form($form_id)->sub()->get(); 162 163 $hidden_field_types = apply_filters('nf_sub_hidden_field_types', array()); 168 164 169 165 // For each field on the form... 170 foreach ( $data['fields'] as $field ){166 foreach ($data['fields'] as $field) { 171 167 172 168 // If this is a "hidden" field type. 173 if ( in_array( $field[ 'type' ], array_values( $hidden_field_types ) )) {169 if (in_array($field['type'], array_values($hidden_field_types))) { 174 170 // Do not save it. 175 $data[ 'actions' ][ 'save' ][ 'hidden' ][] = $field[ 'type'];171 $data['actions']['save']['hidden'][] = $field['type']; 176 172 continue; 177 173 } 178 174 179 $field[ 'value' ] = apply_filters( 'nf_save_sub_user_value', $field[ 'value' ], $field[ 'id' ]);180 181 $save_all_none = $action_settings[ 'fields-save-toggle'];175 $field['value'] = apply_filters('nf_save_sub_user_value', $field['value'], $field['id']); 176 177 $save_all_none = $action_settings['fields-save-toggle']; 182 178 $save_field = true; 183 179 184 180 // If we were told to save all fields... 185 if ( 'save_all' == $save_all_none) {186 $save_field = true;181 if ('save_all' == $save_all_none) { 182 $save_field = true; 187 183 // For each exception to that rule... 188 foreach( $action_settings[ 'exception_fields' ] as $exception_field) {184 foreach ($action_settings['exception_fields'] as $exception_field) { 189 185 // Remove it from the list. 190 if( $field[ 'key' ] == $exception_field[ 'field']) {191 $save_field = false;192 break;193 }194 }186 if ($field['key'] == $exception_field['field']) { 187 $save_field = false; 188 break; 189 } 190 } 195 191 } // Otherwise... (We were told to save no fields.) 196 else if ( 'save_none' == $save_all_none) {197 $save_field = false;192 else if ('save_none' == $save_all_none) { 193 $save_field = false; 198 194 // For each exception to that rule... 199 foreach( $action_settings[ 'exception_fields' ] as 200 $exception_field ) { 195 foreach ( 196 $action_settings['exception_fields'] as 197 $exception_field 198 ) { 201 199 // Add it to the list. 202 if( $field[ 'key' ] == $exception_field[ 'field']) {203 $save_field = true;204 break;205 }206 }200 if ($field['key'] == $exception_field['field']) { 201 $save_field = true; 202 break; 203 } 204 } 207 205 } 208 206 209 207 // If we're supposed to save this field... 210 if ( $save_field) {208 if ($save_field) { 211 209 // Do so. 212 $sub->update_field_value( $field[ 'id' ], $field[ 'value' ]);210 $sub->update_field_value($field['id'], $field['value']); 213 211 } // Otherwise... 214 212 else { … … 217 215 // AND If this field is not a product... 218 216 // AND If this field is not a termslist... 219 if ( false == strpos( $field[ 'type' ], 'list' ) && 220 false == strpos( $field[ 'type' ], 'checkbox' ) && 221 'products' !== $field[ 'type' ] && 222 'terms' !== $field[ 'type' ] ) { 217 if ( 218 false == strpos($field['type'], 'list') && 219 false == strpos($field['type'], 'checkbox') && 220 'products' !== $field['type'] && 221 'terms' !== $field['type'] 222 ) { 223 223 // Anonymize it. 224 $sub->update_field_value( $field[ 'id' ], '(redacted)');224 $sub->update_field_value($field['id'], '(redacted)'); 225 225 } 226 226 } … … 228 228 229 229 // If we have extra data... 230 if ( isset( $data[ 'extra' ] )) {231 232 $data['extra'] =$this->validateExtraData($data['extra'], $form_id);230 if (isset($data['extra'])) { 231 232 $data['extra'] = $this->validateExtraData($data['extra'], $form_id); 233 233 234 234 // Save that. 235 $sub->update_extra_values( $data[ 'extra' ]);236 } 237 238 do_action( 'nf_before_save_sub', $sub->get_id());235 $sub->update_extra_values($data['extra']); 236 } 237 238 do_action('nf_before_save_sub', $sub->get_id()); 239 239 240 240 $sub->save(); 241 241 242 do_action( 'nf_save_sub', $sub->get_id());243 do_action( 'nf_create_sub', $sub->get_id());244 do_action( 'ninja_forms_save_sub', $sub->get_id());245 246 $data[ 'actions' ][ 'save' ][ 'sub_id'] = $sub->get_id();242 do_action('nf_save_sub', $sub->get_id()); 243 do_action('nf_create_sub', $sub->get_id()); 244 do_action('ninja_forms_save_sub', $sub->get_id()); 245 246 $data['actions']['save']['sub_id'] = $sub->get_id(); 247 247 248 248 return $data; … … 262 262 * @return array 263 263 */ 264 protected function validateExtraData( $dataExtra, $form_id): array264 protected function validateExtraData($dataExtra, $form_id): array 265 265 { 266 266 return $dataExtra; 267 267 $return = []; 268 269 if (!is_array($dataExtra)){268 269 if (!is_array($dataExtra)) { 270 270 return $return; 271 271 } 272 272 273 $maxCount = apply_filters('ninja_forms_max_extra_data_count', 200,$form_id);274 275 if ($maxCount<count($dataExtra)){276 277 $return['extraDataOverflowOnSave'] =json_encode($dataExtra);273 $maxCount = apply_filters('ninja_forms_max_extra_data_count', 200, $form_id); 274 275 if ($maxCount < count($dataExtra)) { 276 277 $return['extraDataOverflowOnSave'] = json_encode($dataExtra); 278 278 } 279 279 280 280 return $return; 281 282 281 } 283 282 } -
ninja-forms/tags/3.8.21/includes/Actions/SuccessMessage.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Action_SuccessMessage 5 11 */ 6 final class NF_Actions_SuccessMessage extends NF_Abstracts_Action12 final class NF_Actions_SuccessMessage extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'successmessage'; 14 use SotGetActionProperties; 12 15 13 16 /** 14 * @var array15 */17 * @var array 18 */ 16 19 protected $_tags = array(); 17 20 18 21 /** 19 * @var string22 * Constructor 20 23 */ 21 protected $_documentation_url = 'https://ninjaforms.com/docs/success-message/';22 23 /**24 * @var string25 */26 protected $_timing = 'late';27 28 /**29 * @var int30 */31 protected $_priority = 10;32 33 /**34 * @var string35 */36 protected $_group = 'core';37 38 /**39 * Constructor40 */41 24 public function __construct() 42 25 { 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'Success Message', 'ninja-forms' ); 28 $this->_name = 'successmessage'; 29 $this->_timing = 'late'; 30 $this->_priority = 10; 31 $this->_documentation_url = 'https://ninjaforms.com/docs/success-message/'; 32 $this->_group = 'core'; 46 33 47 $settings = Ninja_Forms::config( 'ActionSuccessMessageSettings');34 add_action('init', [$this, 'initHook']); 48 35 49 $this->_settings = array_merge( $this->_settings, $settings ); 36 add_action('nf_before_import_form', array($this, 'import_form_action_success_message'), 11); 37 } 50 38 51 add_action( 'nf_before_import_form', array( $this, 'import_form_action_success_message' ), 11 ); 39 public function initHook() 40 { 41 $this->_nicename = esc_html__('Success Message', 'ninja-forms'); 42 43 $settings = Ninja_Forms::config('ActionSuccessMessageSettings'); 44 45 $this->_settings = array_merge($this->_settings, $settings); 52 46 } 53 47 … … 56 50 */ 57 51 58 public function save( $action_settings ) 52 53 /** @inheritDoc */ 54 public function process(array $action_settings, int $form_id, array $data): array 59 55 { 56 if (isset($action_settings['success_msg'])) { 60 57 61 } 62 63 public function process( $action_settings, $form_id, $data ) 64 { 65 if( isset( $action_settings[ 'success_msg' ] ) ) { 66 67 if( ! isset( $data[ 'actions' ] ) || ! isset( $data[ 'actions' ][ 'success_message' ] ) ) { 68 $data[ 'actions' ][ 'success_message' ] = ''; 58 if (! isset($data['actions']) || ! isset($data['actions']['success_message'])) { 59 $data['actions']['success_message'] = ''; 69 60 } 70 61 71 62 ob_start(); 72 do_shortcode( $action_settings['success_msg']);63 do_shortcode($action_settings['success_msg']); 73 64 $ob = ob_get_clean(); 74 65 75 if ( $ob) {76 $data[ 'debug' ][ 'console' ][] = sprintf( esc_html__( 'Shortcodes should return and not echo, see: %s', 'ninja-forms' ), 'https://codex.wordpress.org/Shortcode_API#Output');66 if ($ob) { 67 $data['debug']['console'][] = sprintf(esc_html__('Shortcodes should return and not echo, see: %s', 'ninja-forms'), 'https://codex.wordpress.org/Shortcode_API#Output'); 77 68 $data['actions']['success_message'] .= $action_settings['success_msg']; 78 69 } else { 79 $message = do_shortcode( $action_settings['success_msg']);80 $data['actions']['success_message'] .= wpautop( $message);70 $message = do_shortcode($action_settings['success_msg']); 71 $data['actions']['success_message'] .= wpautop($message); 81 72 } 82 73 } … … 85 76 } 86 77 87 public function import_form_action_success_message( $import)78 public function import_form_action_success_message($import) 88 79 { 89 if ( ! isset( $import[ 'actions' ] )) return $import;80 if (! isset($import['actions'])) return $import; 90 81 91 foreach ( $import[ 'actions' ] as &$action ){82 foreach ($import['actions'] as &$action) { 92 83 93 if ( 'success_message' == $action[ 'type' ] ){84 if ('success_message' == $action['type']) { 94 85 95 $action[ 'type'] = 'successmessage';86 $action['type'] = 'successmessage'; 96 87 } 97 88 } -
ninja-forms/tags/3.8.21/includes/Admin/VersionCompatibilityCheck.php
r2869579 r3204929 42 42 public function activate(): void 43 43 { 44 add_action(' ninja_forms_loaded', array($this, 'ensureVersionCompatibility'), 0);44 add_action('init', array($this, 'ensureVersionCompatibility'), 0); 45 45 } 46 46 -
ninja-forms/tags/3.8.21/ninja-forms.php
r3197483 r3204929 4 4 Plugin URI: http://ninjaforms.com/?utm_source=WordPress&utm_medium=readme 5 5 Description: Ninja Forms is a webform builder with unparalleled ease of use and features. 6 Version: 3.8.2 06 Version: 3.8.21 7 7 Author: Saturday Drive 8 8 Author URI: http://ninjaforms.com/?utm_source=Ninja+Forms+Plugin&utm_medium=Plugins+WP+Dashboard … … 44 44 */ 45 45 46 const VERSION = '3.8.2 0';46 const VERSION = '3.8.21'; 47 47 48 48 /** … … 362 362 require_once Ninja_Forms::$dir . 'blocks/ninja-forms-blocks.php'; 363 363 364 /*365 * Submission Metabox366 */367 new NF_Admin_Metaboxes_Calculations();368 364 369 365 /* … … 382 378 self::$instance->_dispatcher = new NF_Dispatcher(); 383 379 384 /*385 * Merge Tags386 */387 self::$instance->merge_tags[ 'wp' ] = new NF_MergeTags_WP();388 self::$instance->merge_tags[ 'fields' ] = new NF_MergeTags_Fields();389 self::$instance->merge_tags[ 'calcs' ] = new NF_MergeTags_Calcs();390 self::$instance->merge_tags[ 'form' ] = new NF_MergeTags_Form();391 self::$instance->merge_tags[ 'other' ] = new NF_MergeTags_Other();392 self::$instance->merge_tags[ 'deprecated' ] = new NF_MergeTags_Deprecated();393 380 394 381 /* … … 409 396 (new VersionCompatibilityCheck())->activate(); 410 397 411 self::$instance->widgets[] = new NF_Widget();412 398 413 399 /* … … 429 415 register_activation_hook( __FILE__, array( self::$instance, 'activation' ) ); 430 416 431 self::$instance->metaboxes[ 'append-form' ] = new NF_Admin_Metaboxes_AppendAForm();432 417 433 418 … … 462 447 add_action( 'ninja_forms_available_actions', array( self::$instance, 'scrub_available_actions' ) ); 463 448 449 add_action( 'init', array( self::$instance, 'instantiateTranslatableObjects' ), 5 ); 464 450 add_action( 'init', array( self::$instance, 'init' ), 5 ); 465 451 add_action( 'admin_init', array( self::$instance, 'admin_init' ), 5 ); … … 492 478 } 493 479 480 public function instantiateTranslatableObjects(): void 481 { 482 new NF_Admin_Metaboxes_Calculations(); 483 484 /* 485 * Merge Tags 486 */ 487 self::$instance->merge_tags['wp'] = new NF_MergeTags_WP(); 488 self::$instance->merge_tags['fields'] = new NF_MergeTags_Fields(); 489 self::$instance->merge_tags['calcs'] = new NF_MergeTags_Calcs(); 490 self::$instance->merge_tags['form'] = new NF_MergeTags_Form(); 491 self::$instance->merge_tags['other'] = new NF_MergeTags_Other(); 492 self::$instance->merge_tags['deprecated'] = new NF_MergeTags_Deprecated(); 493 494 self::$instance->widgets[] = new NF_Widget(); 495 496 self::$instance->metaboxes['append-form'] = new NF_Admin_Metaboxes_AppendAForm(); 497 498 499 /* 500 * Field Class Registration 501 */ 502 self::$instance->fields = apply_filters('ninja_forms_register_fields', self::load_classes('Fields')); 503 504 if (! apply_filters('ninja_forms_enable_credit_card_fields', false)) { 505 unset(self::$instance->fields['creditcard']); 506 unset(self::$instance->fields['creditcardcvc']); 507 unset(self::$instance->fields['creditcardexpiration']); 508 unset(self::$instance->fields['creditcardfullname']); 509 unset(self::$instance->fields['creditcardnumber']); 510 unset(self::$instance->fields['creditcardzip']); 511 } 512 } 513 494 514 public function register_rewrite_rules() 495 515 { … … 743 763 load_plugin_textdomain( 'ninja-forms', false, basename( dirname( __FILE__ ) ) . '/lang' ); 744 764 745 /* 746 * Field Class Registration 747 */ 748 self::$instance->fields = apply_filters( 'ninja_forms_register_fields', self::load_classes( 'Fields' ) ); 749 750 if( ! apply_filters( 'ninja_forms_enable_credit_card_fields', false ) ){ 751 unset( self::$instance->fields[ 'creditcard' ] ); 752 unset( self::$instance->fields[ 'creditcardcvc' ] ); 753 unset( self::$instance->fields[ 'creditcardexpiration' ] ); 754 unset( self::$instance->fields[ 'creditcardfullname' ] ); 755 unset( self::$instance->fields[ 'creditcardnumber' ] ); 756 unset( self::$instance->fields[ 'creditcardzip' ] ); 757 } 765 758 766 759 767 /* -
ninja-forms/tags/3.8.21/readme.txt
r3197483 r3204929 6 6 Requires at least: 6.5 7 7 Tested up to: 6.7 8 Stable tag: 3.8.2 08 Stable tag: 3.8.21 9 9 10 10 Requires PHP: 7.4 … … 313 313 314 314 == Upgrade Notice == 315 = 3.8.2 0 (26 November 2024) =316 *Bug Fixes:* 317 - Sanitize calculations input315 = 3.8.21 (09 December 2024) = 316 *Bug Fixes:* 317 - Update timing to load translations after init 318 318 319 319 == Changelog == 320 = 3.8.21 (09 December 2024) = 321 *Bug Fixes:* 322 - Update timing to load translations after init 323 320 324 = 3.8.20 (26 November 2024) = 321 325 *Bug Fixes:* -
ninja-forms/tags/3.8.21/vendor/composer/installed.php
r3197483 r3204929 2 2 'root' => array( 3 3 'name' => 'saturday-drive/ninja-forms', 4 'pretty_version' => 'dev- b0cd47df4b44987478308def65bbe3b17e0b514e',5 'version' => 'dev- b0cd47df4b44987478308def65bbe3b17e0b514e',6 'reference' => ' b0cd47df4b44987478308def65bbe3b17e0b514e',4 'pretty_version' => 'dev-6a161b40aa68c448aa95e54728c43048ffe78955', 5 'version' => 'dev-6a161b40aa68c448aa95e54728c43048ffe78955', 6 'reference' => '6a161b40aa68c448aa95e54728c43048ffe78955', 7 7 'type' => 'library', 8 8 'install_path' => __DIR__ . '/../../', … … 12 12 'versions' => array( 13 13 'saturday-drive/ninja-forms' => array( 14 'pretty_version' => 'dev- b0cd47df4b44987478308def65bbe3b17e0b514e',15 'version' => 'dev- b0cd47df4b44987478308def65bbe3b17e0b514e',16 'reference' => ' b0cd47df4b44987478308def65bbe3b17e0b514e',14 'pretty_version' => 'dev-6a161b40aa68c448aa95e54728c43048ffe78955', 15 'version' => 'dev-6a161b40aa68c448aa95e54728c43048ffe78955', 16 'reference' => '6a161b40aa68c448aa95e54728c43048ffe78955', 17 17 'type' => 'library', 18 18 'install_path' => __DIR__ . '/../../', -
ninja-forms/trunk/includes/Abstracts/Metabox.php
r2238469 r3204929 5 5 protected $_id = ''; // Dynamically set in constructor using the class name. 6 6 7 protected $_title = ''; // Should be set (and translated) in the constructor.7 protected $_title = ''; // Should be set (and translated) at action hook init-10 8 8 9 9 protected $_callback = 'render_metabox'; … … 23 23 $this->_id = strtolower( get_class( $this ) ); 24 24 25 $this->_title = esc_html__( 'Metabox', 'ninja-forms');25 add_action('init', [$this, 'abstractInit'], 5); 26 26 27 27 add_action( 'save_post', array( $this, '_save_post' ) ); 28 28 29 29 add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); 30 } 31 32 /** 33 * Initialize properties at WP `init-5` action hook 34 * 35 * Set translatable properties - _title 36 * 37 * @return void 38 */ 39 public function abstractInit(): void 40 { 41 $this->_title = esc_html__( 'Metabox', 'ninja-forms' ); 30 42 } 31 43 -
ninja-forms/trunk/includes/Abstracts/SubmissionMetabox.php
r2238469 r3204929 19 19 if( ! isset( $_GET[ 'post' ] ) ) return; 20 20 21 $this->_title = esc_html__( 'Submission Metabox', 'ninja-forms');21 add_action('init', [$this, 'abstractSubmissionInit'], 8); 22 22 23 23 $post_id = absint( $_GET[ 'post' ] ); … … 28 28 add_action( 'save_post', array( $this, '_save_post' ) ); 29 29 } 30 31 /** 32 * Initialize properties at WP `init-8` action hook 33 * 34 * Set translatable properties - _title 35 * 36 * @return void 37 */ 38 public function abstractSubmissionInit(): void 39 { 40 $this->_title = esc_html__('Submission Metabox', 'ninja-forms'); 41 } 30 42 } -
ninja-forms/trunk/includes/Actions/Akismet.php
r3101843 r3204929 1 1 <?php 2 2 3 if ( ! defined( 'ABSPATH' ) || ! class_exists( 'NF_Abstracts_Action' ) ) { 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH') ) { 4 8 exit; 5 9 } … … 8 12 * Class NF_Actions_Akismet 9 13 */ 10 final class NF_Actions_Akismet extends NF_Abstracts_Action { 11 12 /** 13 * @var string 14 */ 15 protected $_name = 'akismet'; 14 final class NF_Actions_Akismet extends SotAction implements InterfacesSotAction 15 { 16 use SotGetActionProperties; 16 17 17 18 /** 18 19 * @var array 19 20 */ 20 protected $_tags = array( 'spam', 'filtering', 'akismet' ); 21 22 /** 23 * @var string 24 */ 25 protected $_timing = 'normal'; 26 27 /** 28 * @var int 29 */ 30 protected $_priority = '10'; 31 32 /** 33 * @var string 34 */ 35 protected $_group = 'core'; 21 protected $_tags = array('spam', 'filtering', 'akismet'); 36 22 37 23 /** 38 24 * Constructor 39 25 */ 40 public function __construct() { 26 public function __construct() 27 { 41 28 parent::__construct(); 42 29 43 $this->_nicename = esc_html__( 'Akismet Anti-Spam', 'ninja-forms' ); 44 $settings = Ninja_Forms::config( 'ActionAkismetSettings' ); 45 $this->_settings = array_merge( $this->_settings, $settings ); 30 $this->_name = 'akismet'; 31 $this->_group = 'core'; 32 $this->_timing = 'normal'; 33 $this->_priority = '10'; 46 34 47 add_filter( 'ninja_forms_action_type_settings', array( $this, 'maybe_remove_action' ) ); 35 add_action('init', [$this, 'initHook']); 36 add_filter('ninja_forms_action_type_settings', array($this, 'maybe_remove_action')); 37 } 38 39 public function initHook(): void 40 { 41 $this->_nicename = esc_html__('Akismet Anti-Spam', 'ninja-forms'); 42 43 $settings = Ninja_Forms::config('ActionAkismetSettings'); 44 $this->_settings = array_merge($this->_settings, $settings); 48 45 } 49 46 … … 55 52 * @return array 56 53 */ 57 public function maybe_remove_action( $action_type_settings ) { 58 if ( ! $this->akismet_available() ) { 59 unset( $action_type_settings[ $this->_name ] ); 54 public function maybe_remove_action($action_type_settings) 55 { 56 if (! $this->akismet_available()) { 57 unset($action_type_settings[$this->_name]); 60 58 } 61 59 … … 68 66 * @return bool 69 67 */ 70 protected function akismet_available() { 71 if ( ! is_callable( array( 'Akismet', 'get_api_key' ) ) ) { 68 protected function akismet_available() 69 { 70 if (! is_callable(array('Akismet', 'get_api_key'))) { 72 71 // Not installed and activated 73 72 return false; … … 75 74 76 75 $akismet_key = Akismet::get_api_key(); 77 if ( empty( $akismet_key )) {76 if (empty($akismet_key)) { 78 77 // No key entered 79 78 return false; 80 79 } 81 80 82 return 'valid' === Akismet::verify_key( $akismet_key);81 return 'valid' === Akismet::verify_key($akismet_key); 83 82 } 84 83 … … 92 91 * @return array 93 92 */ 94 public function process( $action_settings, $form_id, $data ) { 95 if ( ! $this->akismet_available() ) { 93 public function process(array $action_settings, int $form_id, array $data): array 94 { 95 if (! $this->akismet_available()) { 96 96 return $data; 97 97 } 98 98 99 if ( $this->is_submission_spam( $action_settings['name'], $action_settings['email'], $action_settings['url'], $action_settings['message'] )) {100 $data['errors']['form']['spam'] = esc_html__( 'There was an error trying to send your message. Please try again later', 'ninja-forms');99 if ($this->is_submission_spam($action_settings['name'], $action_settings['email'], $action_settings['url'], $action_settings['message'])) { 100 $data['errors']['form']['spam'] = esc_html__('There was an error trying to send your message. Please try again later', 'ninja-forms'); 101 101 } 102 102 … … 114 114 * @return bool 115 115 */ 116 protected function is_submission_spam( $name, $email, $url, $message ) { 116 protected function is_submission_spam($name, $email, $url, $message) 117 { 117 118 $body_request = array( 118 'blog' => get_option( 'home'),119 'blog' => get_option('home'), 119 120 'blog_lang' => get_locale(), 120 121 'permalink' => get_permalink(), … … 124 125 'comment_author_url' => $url, 125 126 'comment_content' => $message, 126 'user_agent' => ( isset( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : null),127 'user_agent' => (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null), 127 128 ); 128 129 129 if ( method_exists( 'Akismet', 'http_post' )) {130 if (method_exists('Akismet', 'http_post')) { 130 131 $body_request['user_ip'] = Akismet::get_ip_address(); 131 $response = Akismet::http_post( build_query( $body_request ), 'comment-check');132 $response = Akismet::http_post(build_query($body_request), 'comment-check'); 132 133 } else { 133 134 global $akismet_api_host, $akismet_api_port; 134 $body_request['user_ip'] = ( isset( $_SERVER['REMOTE_ADDR'] ) ? $_SERVER['REMOTE_ADDR'] : null);135 $response = akismet_http_post( build_query( $body_request ), $akismet_api_host, '/1.1/comment-check', $akismet_api_port);135 $body_request['user_ip'] = (isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null); 136 $response = akismet_http_post(build_query($body_request), $akismet_api_host, '/1.1/comment-check', $akismet_api_port); 136 137 } 137 138 138 if ( ! empty( $response ) && isset( $response[1] ) && 'true' == trim( $response[1] )) {139 if (! empty($response) && isset($response[1]) && 'true' == trim($response[1])) { 139 140 // Spam! 140 141 return true; -
ninja-forms/trunk/includes/Actions/CollectPayment.php
r2238469 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Action_CollectPayment 5 11 */ 6 final class NF_Actions_CollectPayment extends NF_Abstracts_Action12 final class NF_Actions_CollectPayment extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'collectpayment'; 14 use SotGetActionProperties; 12 15 13 16 /** … … 17 20 18 21 /** 19 * @var string20 */21 protected $_timing = 'late';22 23 /**24 * @var int25 */26 protected $_priority = 0;27 28 /**29 22 * @var array 30 23 */ 31 24 protected $payment_gateways = array(); 32 25 26 protected $tempCpNiceName; 27 protected $tempCpName; 33 28 /** 34 29 * Constructor … … 37 32 * @param string $cp_name 38 33 */ 39 public function __construct( $cp_nice_name = 'Collect Payment', 40 $cp_name = 'collectpayment' ) 34 public function __construct( 35 $cp_nice_name = 'Collect Payment', 36 $cp_name = 'collectpayment' 37 ) { 38 $this->_name = 'collectpayment'; 39 $this->_timing = 'late'; 40 $this->_priority = 0; 41 42 add_action('init', [$this, 'initHook']); 43 44 $this->tempCpNiceName = $cp_nice_name; 45 $this->tempCpName = $cp_name; 46 47 add_action('ninja_forms_loaded', array($this, 'register_payment_gateways'), -1); 48 49 add_filter('ninja_forms_action_type_settings', array($this, 'maybe_remove_action')); 50 } 51 52 public function initHook(): void 41 53 { 42 parent::__construct();54 $this->initializeSettings(); 43 55 44 56 // Set the nice name to what we passed in. 'Collect Payment' is default 45 if( 'Collect Payment' == $cp_nice_name ) { 46 $cp_nice_name = esc_html__( 'Collect Payment', 'ninja-forms' ); 47 } 48 $this->_nicename = $cp_nice_name; 57 if ('Collect Payment' == $this->tempCpNiceName) { 58 $this->tempCpNiceName = esc_html__('Collect Payment', 'ninja-forms'); 59 } 60 61 $this->_nicename = $this->tempCpNiceName; 49 62 // Set name to what we passed in. 'collectpayment' is default 50 $this->_name = strtolower( $cp_name);63 $this->_name = strtolower($this->tempCpName); 51 64 52 $settings = Ninja_Forms::config( 'ActionCollectPaymentSettings');65 $settings = Ninja_Forms::config('ActionCollectPaymentSettings'); 53 66 54 67 /** … … 56 69 * of the gateway drop-down 57 70 **/ 58 if ( 'collectpayment' != $this->_name) {59 $settings[ 'payment_gateways' ][ 'value'] = $this->_name;71 if ('collectpayment' != $this->_name) { 72 $settings['payment_gateways']['value'] = $this->_name; 60 73 } 61 74 62 $this->_settings = array_merge( $this->_settings, $settings ); 63 64 add_action( 'ninja_forms_loaded', array( $this, 'register_payment_gateways' ), -1 ); 65 66 add_filter( 'ninja_forms_action_type_settings', array( $this, 'maybe_remove_action' ) ); 75 $this->_settings = array_merge($this->_settings, $settings); 67 76 } 68 77 69 public function save( $action_settings ) 78 function initializeSettings(): void 79 { 80 $this->_settings_all = apply_filters( 'ninja_forms_actions_settings_all', $this->_settings_all ); 81 82 if( ! empty( $this->_settings_only ) ){ 83 84 $this->_settings = array_merge( $this->_settings, $this->_settings_only ); 85 } else { 86 87 $this->_settings = array_merge( $this->_settings_all, $this->_settings ); 88 $this->_settings = array_diff( $this->_settings, $this->_settings_exclude ); 89 } 90 91 $this->_settings = $this->load_settings( $this->_settings_all ); 92 } 93 94 /** @inheritDoc */ 95 public function process(array $action_settings, int $form_id, array $data): array 70 96 { 71 97 72 }98 $payment_gateway = $action_settings['payment_gateways']; 73 99 74 public function process( $action_settings, $form_id, $data ) 75 { 76 77 $payment_gateway = $action_settings[ 'payment_gateways' ]; 78 79 $payment_gateway_class = $this->payment_gateways[ $payment_gateway ]; 100 $payment_gateway_class = $this->payment_gateways[$payment_gateway]; 80 101 81 102 $handler = NF_Handlers_LocaleNumberFormatting::create(); 82 $converted = $handler->locale_decode_number( $action_settings['payment_total']);103 $converted = $handler->locale_decode_number($action_settings['payment_total']); 83 104 $action_settings['payment_total'] = $converted; 84 105 85 return $payment_gateway_class->process( $action_settings, $form_id, $data);106 return $payment_gateway_class->process($action_settings, $form_id, $data); 86 107 } 87 108 88 109 public function register_payment_gateways() 89 110 { 90 $this->payment_gateways = apply_filters( 'ninja_forms_register_payment_gateways', array());111 $this->payment_gateways = apply_filters('ninja_forms_register_payment_gateways', array()); 91 112 92 foreach( $this->payment_gateways as $gateway ){113 add_action('init',[$this,'buildPaymentGatewayOptions'],15); 93 114 94 if( ! is_subclass_of( $gateway, 'NF_Abstracts_PaymentGateway' ) ){ 115 } 116 117 /** 118 * Build gateway options for CollectPayment dropdown 119 * 120 * Done at `init-15` to ensure that object can populate translations 121 * 122 * @return void 123 */ 124 public function buildPaymentGatewayOptions(): void 125 { 126 foreach ($this->payment_gateways as $gateway) { 127 128 if (! is_subclass_of($gateway, 'NF_Abstracts_PaymentGateway')) { 95 129 continue; 96 130 } 97 131 98 $this->_settings[ 'payment_gateways' ][ 'options'][] = array(132 $this->_settings['payment_gateways']['options'][] = array( 99 133 'label' => $gateway->get_name(), 100 134 'value' => $gateway->get_slug(), 101 135 ); 102 136 103 $this->_settings = array_merge( $this->_settings, $gateway->get_settings());137 $this->_settings = array_merge($this->_settings, $gateway->get_settings()); 104 138 } 105 139 } 106 140 107 public function maybe_remove_action( $action_type_settings)141 public function maybe_remove_action($action_type_settings) 108 142 { 109 if ( empty( $this->payment_gateways ) ){110 unset( $action_type_settings[ $this->_name ]);143 if (empty($this->payment_gateways)) { 144 unset($action_type_settings[$this->_name]); 111 145 } 112 146 -
ninja-forms/trunk/includes/Actions/Custom.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Action_Custom 5 11 */ 6 final class NF_Actions_Custom extends NF_Abstracts_Action12 final class NF_Actions_Custom extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'custom'; 14 use SotGetActionProperties; 12 15 13 16 /** … … 15 18 */ 16 19 protected $_tags = array(); 17 18 /**19 * @var string20 */21 protected $_documentation_url = 'https://ninjaforms.com/docs/wp-hook/';22 23 /**24 * @var string25 */26 protected $_timing = 'normal';27 28 /**29 * @var int30 */31 protected $_priority = 10;32 33 /**34 * @var string35 */36 protected $_group = 'core';37 20 38 21 /** … … 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'WP Hook', 'ninja-forms' ); 28 $this->_name = 'custom'; 29 $this->_priority = 10; 30 $this->_timing = 'normal'; 31 $this->_documentation_url = 'https://ninjaforms.com/docs/wp-hook/'; 32 $this->_group = 'core'; 46 33 47 $settings = Ninja_Forms::config( 'ActionCustomSettings' ); 34 add_action('init', [$this, 'initHook']); 35 } 48 36 49 $this->_settings = array_merge( $this->_settings, $settings ); 37 public function initHook() 38 { 39 $this->_nicename = esc_html__('WP Hook', 'ninja-forms'); 40 41 $settings = Ninja_Forms::config('ActionCustomSettings'); 42 43 $this->_settings = array_merge($this->_settings, $settings); 50 44 } 51 45 … … 54 48 */ 55 49 56 public function save( $action_settings ) 50 /** @inheritDoc */ 51 public function process(array $action_settings, int $form_id, array $data): array 57 52 { 58 59 } 60 61 public function process( $action_settings, $form_id, $data ) 62 { 63 if( isset( $action_settings[ 'tag' ] ) ) { 53 if (isset($action_settings['tag'])) { 64 54 ob_start(); // Use the Output Buffer to suppress output 65 55 66 do_action($action_settings[ 'tag'], $data);56 do_action($action_settings['tag'], $data); 67 57 68 58 ob_end_clean(); -
ninja-forms/trunk/includes/Actions/DeleteDataRequest.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Actions_DataRemoval 5 11 */ 6 final class NF_Actions_DeleteDataRequest extends NF_Abstracts_Action12 final class NF_Actions_DeleteDataRequest extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'deletedatarequest'; 14 use SotGetActionProperties; 12 15 13 16 /** … … 15 18 */ 16 19 protected $_tags = array(); 17 18 /**19 * @var string20 */21 protected $_documentation_url = 'https://ninjaforms.com/docs/delete-data-request-action/';22 23 /**24 * @var string25 */26 protected $_timing = 'late';27 28 /**29 * @var int30 */31 protected $_priority = 10;32 33 /**34 * @var string35 */36 protected $_group = 'core';37 20 38 21 /** … … 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'Delete Data Request', 'ninja-forms' ); 28 $this->_name = 'deletedatarequest'; 29 $this->_priority = 10; 30 $this->_documentation_url = 'https://ninjaforms.com/docs/delete-data-request-action/'; 31 $this->_timing = 'late'; 32 $this->_group = 'core'; 46 33 47 $settings = Ninja_Forms::config( 'ActionDeleteDataRequestSettings' ); 48 $this->_settings = array_merge( $this->_settings, $settings ); 34 add_action('init', [$this, 'initHook']); 35 } 36 37 public function initHook() 38 { 39 $this->_nicename = esc_html__('Delete Data Request', 'ninja-forms'); 40 41 $settings = Ninja_Forms::config('ActionDeleteDataRequestSettings'); 42 $this->_settings = array_merge($this->_settings, $settings); 49 43 } 50 44 … … 52 46 * PUBLIC METHODS 53 47 */ 54 55 public function save( $action_settings )56 {57 58 }59 48 60 49 /** … … 68 57 * @return array 69 58 */ 70 public function process( $action_settings, $form_id, $data )59 public function process(array $action_settings, int $form_id, array $data): array 71 60 { 72 61 $data = array(); 73 62 74 if ( isset( $data['settings']['is_preview'] ) && $data['settings']['is_preview'] ){63 if (isset($data['settings']['is_preview']) && $data['settings']['is_preview']) { 75 64 return $data; 76 65 } 77 66 78 67 // get the email setting 79 $email = $action_settings[ 'email'];68 $email = $action_settings['email']; 80 69 81 70 // create request for user 82 $request_id = wp_create_user_request( $email, 83 'remove_personal_data' ); 71 $request_id = wp_create_user_request( 72 $email, 73 'remove_personal_data' 74 ); 84 75 85 76 /** … … 89 80 * 1) The email in question is already in the erase data request queue 90 81 * 2) The email does not belong to an actual user. 91 */92 if ( ! $request_id instanceof WP_Error) {82 */ 83 if (! $request_id instanceof WP_Error) { 93 84 // send the request if it's not an error. 94 85 95 86 // to anonymize or not to anonymize, that is the question 96 add_post_meta( $request_id, 87 add_post_meta( 88 $request_id, 97 89 'nf_anonymize_data', 98 $action_settings[ 'anonymize' ] ); 90 $action_settings['anonymize'] 91 ); 99 92 100 wp_send_user_request( $request_id);93 wp_send_user_request($request_id); 101 94 } 102 95 -
ninja-forms/trunk/includes/Actions/Email.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Action_Email 5 11 */ 6 final class NF_Actions_Email extends NF_Abstracts_Action12 final class NF_Actions_Email extends SotAction implements InterfacesSotAction 7 13 { 14 use SotGetActionProperties; 15 8 16 /** 9 * @var string10 */11 protected $_ name = 'email';17 * @var array 18 */ 19 protected $_tags = array(); 12 20 13 21 /** 14 * @var array 15 */ 16 protected $_tags = array(); 17 18 /** 19 * @var string 22 * Constructor 20 23 */ 21 protected $_documentation_url = 'https://ninjaforms.com/docs/email/';22 23 /**24 * @var string25 */26 protected $_timing = 'late';27 28 /**29 * @var int30 */31 protected $_priority = 10;32 33 /**34 * @var string35 */36 protected $_group = 'core';37 38 /**39 * Constructor40 */41 24 public function __construct() 42 25 { 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'Email', 'ninja-forms' ); 46 47 $settings = Ninja_Forms::config( 'ActionEmailSettings' ); 48 49 $this->_settings = array_merge( $this->_settings, $settings ); 28 $this->_name = 'email'; 29 $this->_timing = 'late'; 30 $this->_priority = 10; 31 $this->_documentation_url = 'https://ninjaforms.com/docs/email/'; 32 $this->_group = 'core'; 33 34 add_action('init', [$this, 'initHook']); 35 } 36 37 public function initHook() 38 { 39 $this->_nicename = esc_html__('Email', 'ninja-forms'); 40 41 $settings = Ninja_Forms::config('ActionEmailSettings'); 42 43 $this->_settings = array_merge($this->_settings, $settings); 50 44 51 45 $this->_backwards_compatibility(); … … 55 49 * PUBLIC METHODS 56 50 */ 57 58 public function process( $action_settings, $form_id, $data )59 { 60 $action_settings = $this->sanitize_address_fields( $action_settings);61 62 $errors = $this->check_for_errors( $action_settings);63 64 $headers = $this->_get_headers( $action_settings);65 66 if ( has_filter( 'ninja_forms_get_fields_sorted' )) {51 /** @inheritDoc */ 52 public function process(array $action_settings, int $form_id, array $data): array 53 { 54 $action_settings = $this->sanitize_address_fields($action_settings); 55 56 $errors = $this->check_for_errors($action_settings); 57 58 $headers = $this->_get_headers($action_settings); 59 60 if (has_filter('ninja_forms_get_fields_sorted')) { 67 61 $fields_by_key = array(); 68 62 69 foreach ( $data[ 'fields' ] as $fieldId=>$field ){70 71 if ( is_null( $field )) continue;72 73 if ( is_array( $field ) ){74 if ( ! isset( $field[ 'key' ] )) continue;75 $key = $field[ 'key'];63 foreach ($data['fields'] as $fieldId => $field) { 64 65 if (is_null($field)) continue; 66 67 if (is_array($field)) { 68 if (! isset($field['key'])) continue; 69 $key = $field['key']; 76 70 77 71 // add field id if it isn't already set 78 if (!isset($field['id'])){79 $field['id'] =$fieldId;72 if (!isset($field['id'])) { 73 $field['id'] = $fieldId; 80 74 } 81 82 75 } else { 83 76 $key = $field->get_setting('key'); 84 77 } 85 $fields_by_key[ $key] = $field;86 } 87 $sorted = apply_filters( 'ninja_forms_get_fields_sorted', array(), $data[ 'fields' ], $fields_by_key, $form_id);88 if ( ! empty( $sorted ))89 $data[ 'fields'] = $sorted;90 } 91 92 $attachments = $this->_get_attachments( $action_settings, $data);93 94 if ( 'html' == $action_settings[ 'email_format' ]) {95 $message = wpautop( $action_settings['email_message']);78 $fields_by_key[$key] = $field; 79 } 80 $sorted = apply_filters('ninja_forms_get_fields_sorted', array(), $data['fields'], $fields_by_key, $form_id); 81 if (! empty($sorted)) 82 $data['fields'] = $sorted; 83 } 84 85 $attachments = $this->_get_attachments($action_settings, $data); 86 87 if ('html' == $action_settings['email_format']) { 88 $message = wpautop($action_settings['email_message']); 96 89 } else { 97 $message = $this->format_plain_text_message( $action_settings[ 'email_message_plain' ]);98 } 99 100 $message = apply_filters( 'ninja_forms_action_email_message', $message, $data, $action_settings);90 $message = $this->format_plain_text_message($action_settings['email_message_plain']); 91 } 92 93 $message = apply_filters('ninja_forms_action_email_message', $message, $data, $action_settings); 101 94 102 95 try { … … 105 98 * @return bool True if already sent. False to fallback to default behavior. Throw a new Exception if there is an error. 106 99 */ 107 if ( ! $sent = apply_filters( 'ninja_forms_action_email_send', false, $action_settings, $message, $headers, $attachments ) ){108 $sent = wp_mail($action_settings['to'], strip_tags( $action_settings['email_subject']), $message, $headers, $attachments);109 } 110 } catch ( Exception $e ){100 if (! $sent = apply_filters('ninja_forms_action_email_send', false, $action_settings, $message, $headers, $attachments)) { 101 $sent = wp_mail($action_settings['to'], strip_tags($action_settings['email_subject']), $message, $headers, $attachments); 102 } 103 } catch (Exception $e) { 111 104 $sent = false; 112 $errors[ 'email_not_sent'] = $e->getMessage();113 } 114 115 if ( is_user_logged_in() && current_user_can( 'manage_options' )) {116 $data[ 'actions' ][ 'email' ][ 'to' ] = $action_settings[ 'to'];117 $data[ 'actions' ][ 'email' ][ 'headers'] = $headers;118 $data[ 'actions' ][ 'email' ][ 'attachments'] = $attachments;119 } 120 121 $data[ 'actions' ][ 'email' ][ 'sent'] = $sent;105 $errors['email_not_sent'] = $e->getMessage(); 106 } 107 108 if (is_user_logged_in() && current_user_can('manage_options')) { 109 $data['actions']['email']['to'] = $action_settings['to']; 110 $data['actions']['email']['headers'] = $headers; 111 $data['actions']['email']['attachments'] = $attachments; 112 } 113 114 $data['actions']['email']['sent'] = $sent; 122 115 123 116 // Only show errors to Administrators. 124 if ( $errors && current_user_can( 'manage_options' ) ){125 $data[ 'errors' ][ 'form'] = $errors;126 } 127 128 if ( ! empty( $attachments )) {117 if ($errors && current_user_can('manage_options')) { 118 $data['errors']['form'] = $errors; 119 } 120 121 if (! empty($attachments)) { 129 122 $this->_drop_csv(); 130 123 } … … 140 133 * @return array 141 134 */ 142 protected function sanitize_address_fields( $action_settings)135 protected function sanitize_address_fields($action_settings) 143 136 { 144 137 // Build a look array to compare our email address settings to. 145 $email_address_settings = array( 'to', 'from_address', 'reply_to', 'cc', 'bcc');138 $email_address_settings = array('to', 'from_address', 'reply_to', 'cc', 'bcc'); 146 139 147 140 // Loop over the look up values. 148 foreach ( $email_address_settings as $setting) {141 foreach ($email_address_settings as $setting) { 149 142 // If the loop up values are not set in the action settings continue. 150 if ( ! isset( $action_settings[ $setting ] )) continue;143 if (! isset($action_settings[$setting])) continue; 151 144 152 145 // If action settings do not match the look up values continue. 153 if ( ! $action_settings[ $setting ]) continue;146 if (! $action_settings[$setting]) continue; 154 147 155 148 // This is the array that will contain the sanitized email address values. … … 160 153 * if not explodes to comma delimited array. 161 154 */ 162 if ( is_array( $action_settings[ $setting ] )) {163 $email_addresses = $action_settings[ $setting];155 if (is_array($action_settings[$setting])) { 156 $email_addresses = $action_settings[$setting]; 164 157 } else { 165 $email_addresses = explode( ',', $action_settings[ $setting ]);158 $email_addresses = explode(',', $action_settings[$setting]); 166 159 } 167 160 168 161 // Loop over our email addresses. 169 foreach ( $email_addresses as $email) {162 foreach ($email_addresses as $email) { 170 163 171 164 // Updated to trim values in case there is a value with spaces/tabs/etc to remove whitespace 172 $email = trim( $email);173 if ( empty( $email )) continue;165 $email = trim($email); 166 if (empty($email)) continue; 174 167 175 168 // Build our array of the email addresses. … … 177 170 } 178 171 // Sanitized our array of settings. 179 $action_settings[ $setting ] = implode( ',' ,$sanitized_array);172 $action_settings[$setting] = implode(',', $sanitized_array); 180 173 } 181 174 return $action_settings; 182 175 } 183 176 184 protected function check_for_errors( $action_settings)177 protected function check_for_errors($action_settings) 185 178 { 186 179 $errors = array(); 187 180 188 $email_address_settings = array( 'to', 'from_address', 'reply_to', 'cc', 'bcc');189 190 foreach ( $email_address_settings as $setting ){191 if ( ! isset( $action_settings[ $setting ] )) continue;192 if ( ! $action_settings[ $setting ]) continue;193 194 195 $email_addresses = is_array( $action_settings[ $setting ] ) ? $action_settings[ $setting ] : explode( ',', $action_settings[ $setting ]);196 197 foreach ( (array) $email_addresses as $email ){198 $email = trim( $email);199 if ( false !== strpos( $email, '<' ) && false !== strpos( $email, '>' )) {181 $email_address_settings = array('to', 'from_address', 'reply_to', 'cc', 'bcc'); 182 183 foreach ($email_address_settings as $setting) { 184 if (! isset($action_settings[$setting])) continue; 185 if (! $action_settings[$setting]) continue; 186 187 188 $email_addresses = is_array($action_settings[$setting]) ? $action_settings[$setting] : explode(',', $action_settings[$setting]); 189 190 foreach ((array) $email_addresses as $email) { 191 $email = trim($email); 192 if (false !== strpos($email, '<') && false !== strpos($email, '>')) { 200 193 preg_match('/(?:<)([^>]*)(?:>)/', $email, $email); 201 $email = $email[ 1];202 } 203 if ( ! is_email( $email )) {204 $errors[ 'invalid_email' ] = sprintf( esc_html__( 'Your email action "%s" has an invalid value for the "%s" setting. Please check this setting and try again.', 'ninja-forms'), $action_settings[ 'label' ], $setting);194 $email = $email[1]; 195 } 196 if (! is_email($email)) { 197 $errors['invalid_email'] = sprintf(esc_html__('Your email action "%s" has an invalid value for the "%s" setting. Please check this setting and try again.', 'ninja-forms'), $action_settings['label'], $setting); 205 198 } 206 199 } … … 210 203 } 211 204 212 private function _get_headers( $settings)205 private function _get_headers($settings) 213 206 { 214 207 $headers = array(); 215 208 216 $headers[] = 'Content-Type: text/' . $settings[ 'email_format'];209 $headers[] = 'Content-Type: text/' . $settings['email_format']; 217 210 $headers[] = 'charset=UTF-8'; 218 211 $headers[] = 'X-Ninja-Forms:ninja-forms'; // Flag for transactional email. 219 212 220 $headers[] = $this->_format_from( $settings);221 222 $headers = array_merge( $headers, $this->_format_recipients( $settings ));213 $headers[] = $this->_format_from($settings); 214 215 $headers = array_merge($headers, $this->_format_recipients($settings)); 223 216 224 217 return $headers; 225 218 } 226 219 227 private function _get_attachments( $settings, $data)220 private function _get_attachments($settings, $data) 228 221 { 229 222 $attachments = array(); 230 223 231 if ( isset( $settings[ 'attach_csv' ] ) && 1 == $settings[ 'attach_csv' ] ){232 $attachments[] = $this->_create_csv( $data[ 'fields' ]);233 } 234 235 if ( ! isset( $settings[ 'id' ] ) ) $settings[ 'id'] = '';224 if (isset($settings['attach_csv']) && 1 == $settings['attach_csv']) { 225 $attachments[] = $this->_create_csv($data['fields']); 226 } 227 228 if (! isset($settings['id'])) $settings['id'] = ''; 236 229 237 230 // Allow admins to attach files from media library … … 240 233 $media_id = attachment_url_to_postid($settings['file_attachment']); 241 234 242 if ($media_id !== 0) {235 if ($media_id !== 0) { 243 236 $file_path = get_attached_file($media_id); 244 237 if (0 < strlen($file_path)) { … … 248 241 } 249 242 250 $attachments = apply_filters( 'ninja_forms_action_email_attachments', $attachments, $data, $settings);243 $attachments = apply_filters('ninja_forms_action_email_attachments', $attachments, $data, $settings); 251 244 252 245 return $attachments; 253 246 } 254 247 255 private function _format_from( $settings)256 { 257 $from_name = get_bloginfo( 'name', 'raw');258 $from_name = apply_filters( 'ninja_forms_action_email_from_name', $from_name);259 $from_name = ( $settings[ 'from_name' ] ) ? $settings[ 'from_name'] : $from_name;260 261 $from_address = get_bloginfo( 'admin_email');262 $from_address = apply_filters( 'ninja_forms_action_email_from_address', $from_address);263 $from_address = ( $settings[ 'from_address' ] ) ? $settings[ 'from_address'] : $from_address;264 265 return $this->_format_recipient( 'from', $from_address, $from_name);266 } 267 268 private function _format_recipients( $settings)248 private function _format_from($settings) 249 { 250 $from_name = get_bloginfo('name', 'raw'); 251 $from_name = apply_filters('ninja_forms_action_email_from_name', $from_name); 252 $from_name = ($settings['from_name']) ? $settings['from_name'] : $from_name; 253 254 $from_address = get_bloginfo('admin_email'); 255 $from_address = apply_filters('ninja_forms_action_email_from_address', $from_address); 256 $from_address = ($settings['from_address']) ? $settings['from_address'] : $from_address; 257 258 return $this->_format_recipient('from', $from_address, $from_name); 259 } 260 261 private function _format_recipients($settings) 269 262 { 270 263 $headers = array(); 271 264 272 265 $recipient_settings = array( 273 'Cc' => $settings[ 'cc'],274 'Bcc' => $settings[ 'bcc'],275 'Reply-to' => $settings[ 'reply_to'],266 'Cc' => $settings['cc'], 267 'Bcc' => $settings['bcc'], 268 'Reply-to' => $settings['reply_to'], 276 269 ); 277 270 278 foreach ( $recipient_settings as $type => $emails ){279 280 $emails = explode( ',', $emails);281 282 foreach ( $emails as $email) {283 284 if ( ! $email) continue;271 foreach ($recipient_settings as $type => $emails) { 272 273 $emails = explode(',', $emails); 274 275 foreach ($emails as $email) { 276 277 if (! $email) continue; 285 278 286 279 $matches = array(); … … 296 289 } 297 290 298 private function _format_recipient( $type, $email, $name = '')299 { 300 $type = ucfirst( $type);301 302 if ( ! $name) $name = $email;291 private function _format_recipient($type, $email, $name = '') 292 { 293 $type = ucfirst($type); 294 295 if (! $name) $name = $email; 303 296 304 297 $recipient = "$type: $name <$email>"; … … 307 300 } 308 301 309 private function _create_csv( $fields)302 private function _create_csv($fields) 310 303 { 311 304 $csv_array = array(); 312 305 313 306 // Get our current date. 314 $date_format = Ninja_Forms()->get_setting( 'date_format');315 $today = date( $date_format, current_time( 'timestamp' ));316 $csv_array[ 0][] = 'Date Submitted';317 $csv_array[ 1][] = $today;318 319 foreach ( $fields as $field ){307 $date_format = Ninja_Forms()->get_setting('date_format'); 308 $today = date($date_format, current_time('timestamp')); 309 $csv_array[0][] = 'Date Submitted'; 310 $csv_array[1][] = $today; 311 312 foreach ($fields as $field) { 320 313 321 314 $ignore = array( … … 330 323 ); 331 324 332 $ignore = apply_filters( 'ninja_forms_csv_ignore_fields', $ignore);333 334 if ( ! isset( $field[ 'label' ] )) continue;335 if ( in_array( $field[ 'type' ], $ignore )) continue;336 337 $label = ( '' != $field[ 'admin_label' ] ) ? $field[ 'admin_label' ] : $field[ 'label'];325 $ignore = apply_filters('ninja_forms_csv_ignore_fields', $ignore); 326 327 if (! isset($field['label'])) continue; 328 if (in_array($field['type'], $ignore)) continue; 329 330 $label = ('' != $field['admin_label']) ? $field['admin_label'] : $field['label']; 338 331 // Escape labels. 339 332 $label = WPN_Helper::maybe_escape_csv_column($label); 340 333 341 if ($field["type"] === "repeater" && isset($field['fields'])){334 if ($field["type"] === "repeater" && isset($field['fields'])) { 342 335 $value = ""; 343 foreach ($field['fields'] as $field_model){344 foreach ($field['value'] as $in_field_value) {336 foreach ($field['fields'] as $field_model) { 337 foreach ($field['value'] as $in_field_value) { 345 338 $matching_value = substr($in_field_value['id'], 0, strlen($field_model['id'])) === $field_model['id']; 346 339 $index_found = substr($in_field_value['id'], strpos($in_field_value['id'], "_") + 1); 347 if ( $matching_value ){340 if ($matching_value) { 348 341 //Catch specific file uploeds data 349 if (isset($in_field_value["files"])){342 if (isset($in_field_value["files"])) { 350 343 $field_files_names = []; 351 foreach ($in_field_value["files"] as $file_data){352 $field_files_names []= $file_data["data"]["file_url"];344 foreach ($in_field_value["files"] as $file_data) { 345 $field_files_names[] = $file_data["data"]["file_url"]; 353 346 } 354 347 $in_field_value['value'] = implode(" , ", $field_files_names); 355 348 } 356 349 357 $value .= $field_model['label'] . "#" . $index_found . " : " . WPN_Helper::stripslashes( $in_field_value['value']) . " \n";350 $value .= $field_model['label'] . "#" . $index_found . " : " . WPN_Helper::stripslashes($in_field_value['value']) . " \n"; 358 351 }; 359 352 } 360 353 } 361 362 354 } else { 363 $value = WPN_Helper::stripslashes( $field[ 'value' ]);364 if ( empty( $value ) && ! isset( $value )) {355 $value = WPN_Helper::stripslashes($field['value']); 356 if (empty($value) && ! isset($value)) { 365 357 $value = ''; 366 358 } 367 if ( is_array( $value )) {368 $value = implode( ',', $value);359 if (is_array($value)) { 360 $value = implode(',', $value); 369 361 } 370 362 } 371 363 372 364 // add filter to add single quote if first character in value is '=' 373 $value = apply_filters( 'ninja_forms_subs_export_field_value_' . $field[ 'type' ], $value, $field ); 374 375 $csv_array[ 0 ][] = $label; 376 $csv_array[ 1 ][] = $value; 377 } 378 379 $csv_content = WPN_Helper::str_putcsv( $csv_array, 380 apply_filters( 'ninja_forms_sub_csv_delimiter', ',' ), 381 apply_filters( 'ninja_forms_sub_csv_enclosure', '"' ), 382 apply_filters( 'ninja_forms_sub_csv_terminator', "\n" ) 365 $value = apply_filters('ninja_forms_subs_export_field_value_' . $field['type'], $value, $field); 366 367 $csv_array[0][] = $label; 368 $csv_array[1][] = $value; 369 } 370 371 $csv_content = WPN_Helper::str_putcsv( 372 $csv_array, 373 apply_filters('ninja_forms_sub_csv_delimiter', ','), 374 apply_filters('ninja_forms_sub_csv_enclosure', '"'), 375 apply_filters('ninja_forms_sub_csv_terminator', "\n") 383 376 ); 384 377 385 378 $upload_dir = wp_upload_dir(); 386 $path = trailingslashit( $upload_dir['path']);379 $path = trailingslashit($upload_dir['path']); 387 380 388 381 // create temporary file 389 $path = tempnam( $path, 'Sub');390 $temp_file = fopen( $path, 'r+');382 $path = tempnam($path, 'Sub'); 383 $temp_file = fopen($path, 'r+'); 391 384 392 385 // write to temp file 393 fwrite( $temp_file, $csv_content);394 fclose( $temp_file);386 fwrite($temp_file, $csv_content); 387 fclose($temp_file); 395 388 396 389 // find the directory we will be using for the final file 397 $path = pathinfo( $path);390 $path = pathinfo($path); 398 391 $dir = $path['dirname']; 399 392 $basename = $path['basename']; 400 393 401 394 // create name for file 402 $new_name = apply_filters( 'ninja_forms_submission_csv_name', 'ninja-forms-submission');395 $new_name = apply_filters('ninja_forms_submission_csv_name', 'ninja-forms-submission'); 403 396 404 397 // remove a file if it already exists 405 if ( file_exists( $dir.'/'.$new_name.'.csv' )) {406 unlink( $dir.'/'.$new_name.'.csv');398 if (file_exists($dir . '/' . $new_name . '.csv')) { 399 unlink($dir . '/' . $new_name . '.csv'); 407 400 } 408 401 409 402 // move file 410 rename( $dir.'/'.$basename, $dir.'/'.$new_name.'.csv');411 return $dir .'/'.$new_name.'.csv';403 rename($dir . '/' . $basename, $dir . '/' . $new_name . '.csv'); 404 return $dir . '/' . $new_name . '.csv'; 412 405 } 413 406 … … 418 411 { 419 412 $upload_dir = wp_upload_dir(); 420 $path = trailingslashit( $upload_dir['path']);413 $path = trailingslashit($upload_dir['path']); 421 414 422 415 // create name for file 423 $new_name = apply_filters( 'ninja_forms_submission_csv_name', 'ninja-forms-submission');416 $new_name = apply_filters('ninja_forms_submission_csv_name', 'ninja-forms-submission'); 424 417 425 418 // remove a file if it already exists 426 if ( file_exists( $path.'/'.$new_name.'.csv' )) {427 unlink( $path.'/'.$new_name.'.csv');419 if (file_exists($path . '/' . $new_name . '.csv')) { 420 unlink($path . '/' . $new_name . '.csv'); 428 421 } 429 422 } … … 435 428 private function _backwards_compatibility() 436 429 { 437 add_filter( 'ninja_forms_sub_csv_delimiter', array( $this, 'ninja_forms_sub_csv_delimiter' ), 10, 1);438 add_filter( 'ninja_sub_csv_enclosure', array( $this, 'ninja_sub_csv_enclosure' ), 10, 1);439 add_filter( 'ninja_sub_csv_terminator', array( $this, 'ninja_sub_csv_terminator' ), 10, 1);440 add_filter( 'ninja_forms_action_email_attachments', array( $this, 'ninja_forms_action_email_attachments' ), 10, 3);441 } 442 443 public function ninja_forms_sub_csv_delimiter( $delimiter)444 { 445 return apply_filters( 'nf_sub_csv_delimiter', $delimiter);446 } 447 448 public function ninja_sub_csv_enclosure( $enclosure)449 { 450 return apply_filters( 'nf_sub_csv_enclosure', $enclosure);451 } 452 453 public function ninja_sub_csv_terminator( $terminator)454 { 455 return apply_filters( 'nf_sub_csv_terminator', $terminator);456 } 457 458 public function ninja_forms_action_email_attachments( $attachments, $form_data, $action_settings)459 { 460 return apply_filters( 'nf_email_notification_attachments', $attachments, $action_settings[ 'id' ]);461 } 462 463 private function format_plain_text_message( $message)464 { 465 $message = str_replace( array( '<table>', '</table>', '<tr><td>', '' ), '', $message);466 $message = str_replace( '</td><td>', ' ', $message);467 $message = str_replace( '</td></tr>', "\r\n", $message);468 return strip_tags( $message);430 add_filter('ninja_forms_sub_csv_delimiter', array($this, 'ninja_forms_sub_csv_delimiter'), 10, 1); 431 add_filter('ninja_sub_csv_enclosure', array($this, 'ninja_sub_csv_enclosure'), 10, 1); 432 add_filter('ninja_sub_csv_terminator', array($this, 'ninja_sub_csv_terminator'), 10, 1); 433 add_filter('ninja_forms_action_email_attachments', array($this, 'ninja_forms_action_email_attachments'), 10, 3); 434 } 435 436 public function ninja_forms_sub_csv_delimiter($delimiter) 437 { 438 return apply_filters('nf_sub_csv_delimiter', $delimiter); 439 } 440 441 public function ninja_sub_csv_enclosure($enclosure) 442 { 443 return apply_filters('nf_sub_csv_enclosure', $enclosure); 444 } 445 446 public function ninja_sub_csv_terminator($terminator) 447 { 448 return apply_filters('nf_sub_csv_terminator', $terminator); 449 } 450 451 public function ninja_forms_action_email_attachments($attachments, $form_data, $action_settings) 452 { 453 return apply_filters('nf_email_notification_attachments', $attachments, $action_settings['id']); 454 } 455 456 private function format_plain_text_message($message) 457 { 458 $message = str_replace(array('<table>', '</table>', '<tr><td>', ''), '', $message); 459 $message = str_replace('</td><td>', ' ', $message); 460 $message = str_replace('</td></tr>', "\r\n", $message); 461 return strip_tags($message); 469 462 } 470 463 } -
ninja-forms/trunk/includes/Actions/ExportDataRequest.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Actions_ExportPersonalData 5 11 */ 6 final class NF_Actions_ExportDataRequest extends NF_Abstracts_Action12 final class NF_Actions_ExportDataRequest extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'exportdatarequest'; 14 use SotGetActionProperties; 12 15 13 16 /** … … 15 18 */ 16 19 protected $_tags = array(); 17 18 /**19 * @var string20 */21 protected $_documentation_url = 'https://ninjaforms.com/docs/export-data-request-action/';22 23 /**24 * @var string25 */26 protected $_timing = 'late';27 28 /**29 * @var int30 */31 protected $_priority = 10;32 33 /**34 * @var string35 */36 protected $_group = 'core';37 20 38 21 /** … … 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'Export Data Request', 'ninja-forms' ); 28 $this->_name = 'exportdatarequest'; 29 $this->_timing = 'late'; 30 $this->_priority = 10; 31 $this->_documentation_url = 'https://ninjaforms.com/docs/export-data-request-action/'; 32 $this->_group = 'core'; 46 33 47 $settings = Ninja_Forms::config( 'ActionExportDataRequestSettings' ); 48 $this->_settings = array_merge( $this->_settings, $settings ); 34 add_action('init', [$this, 'initHook']); 35 } 36 37 public function initHook() 38 { 39 $this->_nicename = esc_html__('Export Data Request', 'ninja-forms'); 40 41 $settings = Ninja_Forms::config('ActionExportDataRequestSettings'); 42 $this->_settings = array_merge($this->_settings, $settings); 49 43 } 50 44 … … 53 47 */ 54 48 55 public function save( $action_settings )56 {57 58 }59 49 60 50 /** … … 68 58 * @return array 69 59 */ 70 public function process( $action_settings, $form_id, $data )60 public function process(array $action_settings, int $form_id, array $data): array 71 61 { 72 62 $data = array(); 73 63 74 if ( isset( $data['settings']['is_preview'] ) && $data['settings']['is_preview'] ){64 if (isset($data['settings']['is_preview']) && $data['settings']['is_preview']) { 75 65 return $data; 76 66 } 77 67 78 68 // get the email setting 79 $email = $action_settings[ 'email'];69 $email = $action_settings['email']; 80 70 81 71 // create request for user 82 $request_id = wp_create_user_request( $email, 83 'export_personal_data' ); 72 $request_id = wp_create_user_request( 73 $email, 74 'export_personal_data' 75 ); 84 76 85 77 /** … … 90 82 * 2) The email does not belong to an actual user. 91 83 */ 92 if ( ! $request_id instanceof WP_Error) {93 wp_send_user_request( $request_id);84 if (! $request_id instanceof WP_Error) { 85 wp_send_user_request($request_id); 94 86 } 95 87 -
ninja-forms/trunk/includes/Actions/Recaptcha.php
r3101843 r3204929 1 1 <?php 2 2 3 if ( ! defined( 'ABSPATH' ) || ! class_exists( 'NF_Abstracts_Action' ) ) { 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH') ) { 4 8 exit; 5 9 } … … 8 12 * Class NF_Actions_Recaptcha 9 13 */ 10 final class NF_Actions_Recaptcha extends NF_Abstracts_Action { 14 final class NF_Actions_Recaptcha extends SotAction implements InterfacesSotAction 15 { 16 use SotGetActionProperties; 17 18 /** 19 * @var array 20 */ 21 protected $_tags = array('spam', 'filtering', 'recaptcha'); 11 22 12 23 /** 13 24 * @var string 14 25 */ 15 protected $_name = 'recaptcha'; 26 protected $site_key; 27 28 /** 29 * @var string 30 */ 31 protected $site_secret; 32 33 /** 34 * @var int 35 */ 36 protected $form_id; 16 37 17 38 /** 18 39 * @var array 19 40 */ 20 protected $_tags = array( 'spam', 'filtering', 'recaptcha' ); 21 22 /** 23 * @var string 24 */ 25 protected $_timing = 'normal'; 26 27 /** 28 * @var int 29 */ 30 protected $_priority = '10'; 31 32 /** 33 * @var string 34 */ 35 protected $_group = 'core'; 36 37 /** 38 * @var string 39 */ 40 protected $site_key; 41 42 /** 43 * @var string 44 */ 45 protected $site_secret; 46 47 /** 48 * @var int 49 */ 50 protected $form_id; 41 protected $forms_with_action; 51 42 52 43 /** 53 44 * @var array 54 45 */ 55 protected $forms_with_action; 56 57 /** 58 * @var array 59 */ 60 protected $_settings_exclude = array( 'conditions' ); 46 protected $_settings_exclude = array('conditions'); 61 47 62 48 /** 63 49 * Constructor 64 50 */ 65 public function __construct() { 51 public function __construct() 52 { 66 53 parent::__construct(); 67 54 68 $this->_nicename = esc_html__( 'reCAPTCHA v3', 'ninja-forms' ); 69 $settings = Ninja_Forms::config( 'ActionRecaptchaV3Settings' ); 70 $this->_settings = array_merge( $this->_settings, $settings ); 71 72 $this->site_key = Ninja_Forms()->get_setting( 'recaptcha_site_key_3' ); 73 $this->site_secret = Ninja_Forms()->get_setting( 'recaptcha_secret_key_3' ); 74 75 add_filter( 'ninja_forms_action_type_settings', array( $this, 'maybe_remove_action' ) ); 76 77 add_action( 'nf_get_form_id', array( $this, 'set_form_id' ), 15, 1 ); 78 79 add_filter( 'ninja_forms_display_fields', array( $this, 'maybe_inject_field'), 10, 2 ); 80 add_filter( 'ninja_forms_form_fields', array( $this, 'maybe_remove_v2_field') ); 81 add_filter( 'ninja_forms_field_show_in_builder', array( $this, 'maybe_remove_v2_field_from_builder'), 10, 2 ); 82 add_action( 'ninja_forms_output_templates', array( $this, 'maybe_output_field_template') ); 83 add_filter( 'nf_display_enqueue_scripts', array( $this, 'enqueue_script' ) ); 55 $this->_name = 'recaptcha'; 56 $this->_timing = 'normal'; 57 $this->_priority = '10'; 58 $this->_group = 'core'; 59 60 add_action('init', [$this, 'initHook']); 61 62 add_filter('ninja_forms_action_type_settings', array($this, 'maybe_remove_action')); 63 64 add_action('nf_get_form_id', array($this, 'set_form_id'), 15, 1); 65 66 add_filter('ninja_forms_display_fields', array($this, 'maybe_inject_field'), 10, 2); 67 add_filter('ninja_forms_form_fields', array($this, 'maybe_remove_v2_field')); 68 add_filter('ninja_forms_field_show_in_builder', array($this, 'maybe_remove_v2_field_from_builder'), 10, 2); 69 add_action('ninja_forms_output_templates', array($this, 'maybe_output_field_template')); 70 add_filter('nf_display_enqueue_scripts', array($this, 'enqueue_script')); 71 } 72 73 public function initHook() 74 { 75 76 $this->_nicename = esc_html__('reCAPTCHA v3', 'ninja-forms'); 77 $settings = Ninja_Forms::config('ActionRecaptchaV3Settings'); 78 $this->_settings = array_merge($this->_settings, $settings); 79 80 $this->site_key = Ninja_Forms()->get_setting('recaptcha_site_key_3'); 81 $this->site_secret = Ninja_Forms()->get_setting('recaptcha_secret_key_3'); 84 82 } 85 83 … … 91 89 * @return void 92 90 */ 93 public function set_form_id( $form_id)91 public function set_form_id($form_id) 94 92 { 95 93 $this->form_id = $form_id; 96 94 } 97 95 98 public function get_form_id() { 99 if ( $this->form_id ) { 96 public function get_form_id() 97 { 98 if ($this->form_id) { 100 99 return $this->form_id; 101 100 } 102 101 103 $this->form_id = filter_input( INPUT_GET, 'form_id', FILTER_VALIDATE_INT);102 $this->form_id = filter_input(INPUT_GET, 'form_id', FILTER_VALIDATE_INT); 104 103 105 104 return $this->form_id; … … 113 112 * @return array 114 113 */ 115 public function maybe_remove_action( $action_type_settings ) { 116 if ( ! $this->is_recaptcha_configured() ) { 117 unset( $action_type_settings[ $this->_name ] ); 114 public function maybe_remove_action($action_type_settings) 115 { 116 if (! $this->is_recaptcha_configured()) { 117 unset($action_type_settings[$this->_name]); 118 118 } 119 119 … … 124 124 * @return bool 125 125 */ 126 protected function is_action_enabled_for_form() { 126 protected function is_action_enabled_for_form() 127 { 127 128 $form_id = $this->get_form_id(); 128 129 129 if ( isset( $this->forms_with_action[ $form_id ] )) {130 return $this->forms_with_action[ $form_id];131 } 132 133 $actions = Ninja_Forms()->form( $form_id)->get_actions();130 if (isset($this->forms_with_action[$form_id])) { 131 return $this->forms_with_action[$form_id]; 132 } 133 134 $actions = Ninja_Forms()->form($form_id)->get_actions(); 134 135 135 136 $enabled = false; 136 foreach ( $actions as $action) {137 if ( $this->_name == $action->get_settings('type') && 1 == $action->get_setting( 'active' )) {137 foreach ($actions as $action) { 138 if ($this->_name == $action->get_settings('type') && 1 == $action->get_setting('active')) { 138 139 $enabled = true; 139 140 break; … … 141 142 } 142 143 143 $this->forms_with_action[ $form_id] = $enabled;144 $this->forms_with_action[$form_id] = $enabled; 144 145 145 146 return $enabled; … … 151 152 * @return bool 152 153 */ 153 protected function is_recaptcha_configured() { 154 if ( empty( $this->site_key ) || empty( $this->site_secret) ) { 154 protected function is_recaptcha_configured() 155 { 156 if (empty($this->site_key) || empty($this->site_secret)) { 155 157 return false; 156 158 } … … 164 166 * @return bool 165 167 */ 166 protected function is_action_configured() { 167 if ( ! $this->is_recaptcha_configured() ) { 168 return false; 169 } 170 171 if ( ! $this->is_action_enabled_for_form() ) { 168 protected function is_action_configured() 169 { 170 if (! $this->is_recaptcha_configured()) { 171 return false; 172 } 173 174 if (! $this->is_action_enabled_for_form()) { 172 175 return false; 173 176 } … … 176 179 } 177 180 178 public function maybe_output_field_template() { 179 if ( ! $this->is_action_configured() ) { 181 public function maybe_output_field_template() 182 { 183 if (! $this->is_action_configured()) { 180 184 return; 181 185 } … … 183 187 $file_path = Ninja_Forms::$dir . 'includes/Templates/'; 184 188 185 echo file_get_contents( $file_path . "fields-recaptcha-v3.html" ); 186 } 187 188 protected function get_field_id_hash( $form_id ) { 189 return substr( base_convert( md5( $form_id ), 16, 10 ), - 5 ); 189 echo file_get_contents($file_path . "fields-recaptcha-v3.html"); 190 } 191 192 protected function get_field_id_hash($form_id) 193 { 194 return substr(base_convert(md5($form_id), 16, 10), -5); 190 195 } 191 196 … … 197 202 * @return array 198 203 */ 199 public function maybe_remove_v2_field( $fields ) { 200 if ( ! $this->is_action_configured() ) { 204 public function maybe_remove_v2_field($fields) 205 { 206 if (! $this->is_action_configured()) { 201 207 return $fields; 202 208 } 203 209 204 foreach ( $fields as $key => $field) {205 if ( 'recaptcha' === $field->get_setting('type')) {210 foreach ($fields as $key => $field) { 211 if ('recaptcha' === $field->get_setting('type')) { 206 212 // Remove v2 reCAPTCHA fields if still configured 207 unset( $fields[ $key ]);213 unset($fields[$key]); 208 214 } 209 215 } … … 220 226 * @return bool 221 227 */ 222 public function maybe_remove_v2_field_from_builder( $show, $field ) { 223 if ( ! $this->is_action_configured() ) { 228 public function maybe_remove_v2_field_from_builder($show, $field) 229 { 230 if (! $this->is_action_configured()) { 224 231 return $show; 225 232 } 226 233 227 if ( 'recaptcha' !== $field->get_type()) {234 if ('recaptcha' !== $field->get_type()) { 228 235 return $show; 229 236 } 230 237 231 $saved_fields = Ninja_Forms()->form( $this->get_form_id() )->get_fields( array( 'saved' => 1 ), true);232 233 foreach ( $saved_fields as $key => $field) {234 if ( 'recaptcha' === $field->get_setting( 'type' )) {238 $saved_fields = Ninja_Forms()->form($this->get_form_id())->get_fields(array('saved' => 1), true); 239 240 foreach ($saved_fields as $key => $field) { 241 if ('recaptcha' === $field->get_setting('type')) { 235 242 // recaptcha v2 field exists on form, don't hide it as it will break the JS 236 243 return $show; … … 248 255 * @return array 249 256 */ 250 public function maybe_inject_field( $fields, $form_id ) { 251 if ( ! $this->is_action_configured() ) { 257 public function maybe_inject_field($fields, $form_id) 258 { 259 if (! $this->is_action_configured()) { 252 260 return $fields; 253 261 } 254 262 255 $field_id = $this->get_field_id_hash( $form_id);263 $field_id = $this->get_field_id_hash($form_id); 256 264 257 265 $field = array( … … 259 267 'objectDomain' => 'fields', 260 268 'editActive' => false, 261 'order' => number_format( count( $fields ) + 1, 1),269 'order' => number_format(count($fields) + 1, 1), 262 270 'type' => 'recaptcha_v3', 263 271 'label' => 'Hidden', … … 287 295 } 288 296 289 public function enqueue_script() { 290 if ( ! $this->is_action_configured() ) { 297 public function enqueue_script() 298 { 299 if (! $this->is_action_configured()) { 291 300 return; 292 301 } 293 302 294 $recaptcha_lang = Ninja_Forms()->get_setting( 'recaptcha_lang', 'en');295 296 if ( $this->maybe_enqueue_recaptcha_js()) {297 wp_enqueue_script( 'nf-google-recaptcha', 'https://www.google.com/recaptcha/api.js?hl=' . $recaptcha_lang . '&render=' . $this->site_key, array( 'jquery' ), '3.0', true);303 $recaptcha_lang = Ninja_Forms()->get_setting('recaptcha_lang', 'en'); 304 305 if ($this->maybe_enqueue_recaptcha_js()) { 306 wp_enqueue_script('nf-google-recaptcha', 'https://www.google.com/recaptcha/api.js?hl=' . $recaptcha_lang . '&render=' . $this->site_key, array('jquery'), '3.0', true); 298 307 } 299 308 } … … 304 313 * @return bool 305 314 */ 306 protected function maybe_enqueue_recaptcha_js() { 307 if ( false !== apply_filters( 'ninja_forms_pre_enqueue_recaptcha_v3_js', false ) ) { 315 protected function maybe_enqueue_recaptcha_js() 316 { 317 if (false !== apply_filters('ninja_forms_pre_enqueue_recaptcha_v3_js', false)) { 308 318 // Allow other plugins to tell Ninja Forms not to load the Google JS script, if they are doing that 309 319 return false; … … 312 322 $scripts = wp_scripts(); 313 323 314 foreach ( $scripts->registered as $script) {315 if ( false !== strpos( $script->src, 'google.com/recaptcha/api.js' )) {324 foreach ($scripts->registered as $script) { 325 if (false !== strpos($script->src, 'google.com/recaptcha/api.js')) { 316 326 return false; 317 327 } … … 321 331 } 322 332 323 protected function get_form_data() { 324 if ( empty( $_POST['formData'] ) ) { 325 return false; 326 } 327 328 $form_data = json_decode( $_POST['formData'], true ); 333 protected function get_form_data() 334 { 335 if (empty($_POST['formData'])) { 336 return false; 337 } 338 339 $form_data = json_decode($_POST['formData'], true); 329 340 330 341 // php5.2 fallback 331 if ( ! $form_data) {332 $form_data = json_decode( stripslashes( $_POST['formData'] ), true);342 if (! $form_data) { 343 $form_data = json_decode(stripslashes($_POST['formData']), true); 333 344 } 334 345 … … 336 347 } 337 348 338 protected function get_recaptcha_response() { 349 protected function get_recaptcha_response() 350 { 339 351 $form_data = $this->get_form_data(); 340 352 341 if ( ! $form_data || ! isset( $form_data['id'] )) {342 return false; 343 } 344 345 $field_id = $this->get_field_id_hash( $form_data['id']);346 347 if ( ! isset( $form_data['fields'] ) || ! isset( $form_data['fields'][ $field_id ] )) {348 return false; 349 } 350 351 return $form_data['fields'][ $field_id]['value'];353 if (! $form_data || ! isset($form_data['id'])) { 354 return false; 355 } 356 357 $field_id = $this->get_field_id_hash($form_data['id']); 358 359 if (! isset($form_data['fields']) || ! isset($form_data['fields'][$field_id])) { 360 return false; 361 } 362 363 return $form_data['fields'][$field_id]['value']; 352 364 } 353 365 … … 361 373 * @return array 362 374 */ 363 public function process( $action_settings, $form_id, $data ) { 364 if ( ! $this->is_recaptcha_configured() ) { 375 public function process(array $action_settings, int $form_id, array $data): array 376 { 377 if (! $this->is_recaptcha_configured()) { 365 378 return $data; 366 379 } … … 368 381 $recaptcha_response = $this->get_recaptcha_response(); 369 382 370 if ( ! $recaptcha_response) {371 $data['errors']['form']['recaptcha'] = esc_html__( 'Recaptcha validation failed. Please try again later', 'ninja-forms');383 if (! $recaptcha_response) { 384 $data['errors']['form']['recaptcha'] = esc_html__('Recaptcha validation failed. Please try again later', 'ninja-forms'); 372 385 373 386 return $data; 374 387 } 375 388 376 if ( $this->is_submission_human( $recaptcha_response, $action_settings['score'] )) {389 if ($this->is_submission_human($recaptcha_response, $action_settings['score'])) { 377 390 return $data; 378 391 } 379 392 380 $data['errors']['form']['recaptcha'] = esc_html__( 'Recaptcha validation failed. Please try again later', 'ninja-forms');393 $data['errors']['form']['recaptcha'] = esc_html__('Recaptcha validation failed. Please try again later', 'ninja-forms'); 381 394 382 395 return $data; 383 396 } 384 397 385 protected function is_submission_human( $token, $score_threshold ) { 398 protected function is_submission_human($token, $score_threshold) 399 { 386 400 $endpoint = 'https://www.google.com/recaptcha/api/siteverify'; 387 401 … … 389 403 'body' => array( 390 404 'secret' => $this->site_secret, 391 'response' => esc_html( $token),405 'response' => esc_html($token), 392 406 ), 393 407 ); 394 408 395 $response = wp_remote_post( esc_url_raw( $endpoint ), $request);396 397 if ( 200 != wp_remote_retrieve_response_code( $response )) {398 if ( WP_DEBUG) {399 error_log( print_r( $response, true ));409 $response = wp_remote_post(esc_url_raw($endpoint), $request); 410 411 if (200 != wp_remote_retrieve_response_code($response)) { 412 if (WP_DEBUG) { 413 error_log(print_r($response, true)); 400 414 } 401 415 … … 403 417 } 404 418 405 $response_body = wp_remote_retrieve_body( $response);406 $response_body = json_decode( $response_body, true);407 408 $score = isset( $response_body['score']) ? $response_body['score'] : 0;409 410 $threshold = apply_filters( 'ninja_forms_action_recaptcha_score_threshold', $score_threshold);419 $response_body = wp_remote_retrieve_body($response); 420 $response_body = json_decode($response_body, true); 421 422 $score = isset($response_body['score']) ? $response_body['score'] : 0; 423 424 $threshold = apply_filters('ninja_forms_action_recaptcha_score_threshold', $score_threshold); 411 425 $is_human = $threshold < $score; 412 426 413 $is_human = apply_filters( 'ninja_forms_action_recaptcha__verify_response', $is_human, $response_body);427 $is_human = apply_filters('ninja_forms_action_recaptcha__verify_response', $is_human, $response_body); 414 428 415 429 return $is_human; -
ninja-forms/trunk/includes/Actions/Redirect.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Action_Redirect 5 11 */ 6 final class NF_Actions_Redirect extends NF_Abstracts_Action12 final class NF_Actions_Redirect extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'redirect'; 14 use SotGetActionProperties; 12 15 13 16 /** 14 * @var array15 */17 * @var array 18 */ 16 19 protected $_tags = array(); 17 20 18 21 /** 19 * @var string22 * Constructor 20 23 */ 21 protected $_documentation_url = 'https://ninjaforms.com/docs/redirect-action/';22 23 /**24 * @var string25 */26 protected $_timing = 'late';27 28 /**29 * @var int30 */31 protected $_priority = 20;32 33 /**34 * @var string35 */36 protected $_group = 'core';37 38 /**39 * Constructor40 */41 24 public function __construct() 42 25 { 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'Redirect', 'ninja-forms' ); 28 $this->_name = 'redirect'; 29 $this->_timing = 'late'; 30 $this->_priority = 20; 31 $this->_documentation_url = 'https://ninjaforms.com/docs/redirect-action/'; 32 $this->_group = 'core'; 46 33 47 $settings = Ninja_Forms::config( 'ActionRedirectSettings' ); 48 49 $this->_settings = array_merge( $this->_settings, $settings ); 34 add_action('init', [$this, 'initHook']); 50 35 } 51 36 37 public function initHook() 38 { 39 40 $this->_nicename = esc_html__('Redirect', 'ninja-forms'); 41 42 $settings = Ninja_Forms::config('ActionRedirectSettings'); 43 44 $this->_settings = array_merge($this->_settings, $settings); 45 } 52 46 /* 53 47 * PUBLIC METHODS 54 48 */ 55 49 56 public function save( $action_settings ) 50 51 /** @inheritDoc */ 52 public function process(array $action_settings, int $form_id, array $data): array 57 53 { 58 59 } 60 61 public function process( $action_settings, $form_id, $data ) 62 { 63 $data[ 'actions' ][ 'redirect' ] = $action_settings[ 'redirect_url' ]; 54 $data['actions']['redirect'] = $action_settings['redirect_url']; 64 55 65 56 return $data; -
ninja-forms/trunk/includes/Actions/Save.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Action_Save 5 11 */ 6 class NF_Actions_Save extends NF_Abstracts_Action12 class NF_Actions_Save extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'save'; 12 13 /** 14 * @var array 15 */ 14 use SotGetActionProperties; 15 16 /** 17 * @var array 18 */ 16 19 protected $_tags = array(); 17 20 18 21 /** 19 * @var string 20 */ 21 protected $_documentation_url = 'https://ninjaforms.com/docs/record-submission-action/'; 22 23 /** 24 * @var string 25 */ 26 protected $_timing = 'late'; 27 28 /** 29 * @var int 30 */ 31 protected $_priority = '-1'; 32 33 /** 34 * @var string 35 */ 36 protected $_group = 'core'; 37 38 /** 39 * Constructor 40 */ 22 * Constructor 23 */ 41 24 public function __construct() 42 25 { 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'Record Submission', 'ninja-forms' ); 46 47 $settings = Ninja_Forms::config( 'ActionSaveSettings' ); 48 49 $this->_settings = array_merge( $this->_settings, $settings ); 50 28 $this->_name = 'save'; 29 $this->_timing = 'late'; 30 $this->_priority = '-1'; 31 $this->_documentation_url = 'https://ninjaforms.com/docs/record-submission-action/'; 32 $this->_group = 'core'; 33 34 add_action('init', [$this, 'initHook']); 35 } 36 37 public function initHook() 38 { 39 $this->_nicename = esc_html__('Record Submission', 'ninja-forms'); 40 41 $settings = Ninja_Forms::config('ActionSaveSettings'); 42 43 $this->_settings = array_merge($this->_settings, $settings); 51 44 } 52 45 … … 55 48 */ 56 49 57 public function save( $action_settings ) 58 { 59 if( ! isset( $_POST[ 'form' ] ) ) return; 50 /** @inheritDoc */ 51 public function save(array $action_settings) 52 { 53 if (! isset($_POST['form'])) return; 60 54 // Get the form data from the Post variable and send it off for processing. 61 $form = json_decode( stripslashes( $_POST[ 'form' ] ));62 $this->submission_expiration_processing( $action_settings, $form->id);55 $form = json_decode(stripslashes($_POST['form'])); 56 $this->submission_expiration_processing($action_settings, $form->id); 63 57 } 64 58 … … 73 67 * @return void 74 68 */ 75 public function submission_expiration_processing( $action_settings, $form_id)69 public function submission_expiration_processing($action_settings, $form_id) 76 70 { 77 71 /* … … 79 73 * Example: 5,90 80 74 */ 81 $expiration_value = $form_id . ',' . $action_settings[ 'subs_expire_time'];75 $expiration_value = $form_id . ',' . $action_settings['subs_expire_time']; 82 76 83 77 // Get our expiration option. 84 $option = $this->getOption( 'nf_sub_expiration', array());78 $option = $this->getOption('nf_sub_expiration', array()); 85 79 86 80 // Check if form is already listed in the option and remove it if it is 87 $expiration_option = $this->clean_form_option( $expiration_value, $option);88 81 $expiration_option = $this->clean_form_option($expiration_value, $option); 82 89 83 // If our expiration setting is turned on, add current cron interval to the form entry in the option. 90 if ( 1 == $action_settings[ 'set_subs_to_expire' ]) {84 if (1 == $action_settings['set_subs_to_expire']) { 91 85 $expiration_option[] = $expiration_value; 92 86 } 93 87 94 88 // Update our option. 95 $this->updateOption( 'nf_sub_expiration', $expiration_option);89 $this->updateOption('nf_sub_expiration', $expiration_option); 96 90 } 97 91 … … 105 99 protected function getOption(string $key, $default) 106 100 { 107 $return = get_option( $key, $default);101 $return = get_option($key, $default); 108 102 109 103 return $return; … … 117 111 * @return void 118 112 */ 119 protected function updateOption(string $key, $value): void120 { 121 update_option( $key, $value);113 protected function updateOption(string $key, $value): void 114 { 115 update_option($key, $value); 122 116 } 123 117 /** … … 134 128 * @return array $expiration_option without current saved form 135 129 */ 136 public function clean_form_option( $expiration_value, $expiration_option ){ 130 public function clean_form_option($expiration_value, $expiration_option) 131 { 137 132 /* 138 133 * Breaks a part our options. … … 140 135 * $value[ 1 ] - ( int ) Expiration time in days 141 136 */ 142 $values = explode( ',', $expiration_value);137 $values = explode(',', $expiration_value); 143 138 144 139 // Find the position of the value we are tyring to update. 145 140 //This checks if this form is already in the expiration options, removes the form from the option's array and adds it again with the new expiration time 146 foreach ($expiration_option as $index => $form_option){147 $form_option = explode( ',', $form_option);148 if ($form_option[0] == $values[0]){141 foreach ($expiration_option as $index => $form_option) { 142 $form_option = explode(',', $form_option); 143 if ($form_option[0] == $values[0]) { 149 144 unset($expiration_option[$index]); 150 145 } 151 146 } 152 147 153 148 return $expiration_option; 154 149 } 155 150 156 public function process( $action_settings, $form_id, $data ) 157 { 158 159 if( isset( $data['settings']['is_preview'] ) && $data['settings']['is_preview'] ){ 151 /** @inheritDoc */ 152 public function process(array $action_settings, int $form_id, array $data): array 153 { 154 155 if (isset($data['settings']['is_preview']) && $data['settings']['is_preview']) { 160 156 return $data; 161 157 } 162 158 163 if ( ! apply_filters ( 'ninja_forms_save_submission', true, $form_id )) return $data;164 165 $sub = Ninja_Forms()->form( $form_id)->sub()->get();166 167 $hidden_field_types = apply_filters( 'nf_sub_hidden_field_types', array());159 if (! apply_filters('ninja_forms_save_submission', true, $form_id)) return $data; 160 161 $sub = Ninja_Forms()->form($form_id)->sub()->get(); 162 163 $hidden_field_types = apply_filters('nf_sub_hidden_field_types', array()); 168 164 169 165 // For each field on the form... 170 foreach ( $data['fields'] as $field ){166 foreach ($data['fields'] as $field) { 171 167 172 168 // If this is a "hidden" field type. 173 if ( in_array( $field[ 'type' ], array_values( $hidden_field_types ) )) {169 if (in_array($field['type'], array_values($hidden_field_types))) { 174 170 // Do not save it. 175 $data[ 'actions' ][ 'save' ][ 'hidden' ][] = $field[ 'type'];171 $data['actions']['save']['hidden'][] = $field['type']; 176 172 continue; 177 173 } 178 174 179 $field[ 'value' ] = apply_filters( 'nf_save_sub_user_value', $field[ 'value' ], $field[ 'id' ]);180 181 $save_all_none = $action_settings[ 'fields-save-toggle'];175 $field['value'] = apply_filters('nf_save_sub_user_value', $field['value'], $field['id']); 176 177 $save_all_none = $action_settings['fields-save-toggle']; 182 178 $save_field = true; 183 179 184 180 // If we were told to save all fields... 185 if ( 'save_all' == $save_all_none) {186 $save_field = true;181 if ('save_all' == $save_all_none) { 182 $save_field = true; 187 183 // For each exception to that rule... 188 foreach( $action_settings[ 'exception_fields' ] as $exception_field) {184 foreach ($action_settings['exception_fields'] as $exception_field) { 189 185 // Remove it from the list. 190 if( $field[ 'key' ] == $exception_field[ 'field']) {191 $save_field = false;192 break;193 }194 }186 if ($field['key'] == $exception_field['field']) { 187 $save_field = false; 188 break; 189 } 190 } 195 191 } // Otherwise... (We were told to save no fields.) 196 else if ( 'save_none' == $save_all_none) {197 $save_field = false;192 else if ('save_none' == $save_all_none) { 193 $save_field = false; 198 194 // For each exception to that rule... 199 foreach( $action_settings[ 'exception_fields' ] as 200 $exception_field ) { 195 foreach ( 196 $action_settings['exception_fields'] as 197 $exception_field 198 ) { 201 199 // Add it to the list. 202 if( $field[ 'key' ] == $exception_field[ 'field']) {203 $save_field = true;204 break;205 }206 }200 if ($field['key'] == $exception_field['field']) { 201 $save_field = true; 202 break; 203 } 204 } 207 205 } 208 206 209 207 // If we're supposed to save this field... 210 if ( $save_field) {208 if ($save_field) { 211 209 // Do so. 212 $sub->update_field_value( $field[ 'id' ], $field[ 'value' ]);210 $sub->update_field_value($field['id'], $field['value']); 213 211 } // Otherwise... 214 212 else { … … 217 215 // AND If this field is not a product... 218 216 // AND If this field is not a termslist... 219 if ( false == strpos( $field[ 'type' ], 'list' ) && 220 false == strpos( $field[ 'type' ], 'checkbox' ) && 221 'products' !== $field[ 'type' ] && 222 'terms' !== $field[ 'type' ] ) { 217 if ( 218 false == strpos($field['type'], 'list') && 219 false == strpos($field['type'], 'checkbox') && 220 'products' !== $field['type'] && 221 'terms' !== $field['type'] 222 ) { 223 223 // Anonymize it. 224 $sub->update_field_value( $field[ 'id' ], '(redacted)');224 $sub->update_field_value($field['id'], '(redacted)'); 225 225 } 226 226 } … … 228 228 229 229 // If we have extra data... 230 if ( isset( $data[ 'extra' ] )) {231 232 $data['extra'] =$this->validateExtraData($data['extra'], $form_id);230 if (isset($data['extra'])) { 231 232 $data['extra'] = $this->validateExtraData($data['extra'], $form_id); 233 233 234 234 // Save that. 235 $sub->update_extra_values( $data[ 'extra' ]);236 } 237 238 do_action( 'nf_before_save_sub', $sub->get_id());235 $sub->update_extra_values($data['extra']); 236 } 237 238 do_action('nf_before_save_sub', $sub->get_id()); 239 239 240 240 $sub->save(); 241 241 242 do_action( 'nf_save_sub', $sub->get_id());243 do_action( 'nf_create_sub', $sub->get_id());244 do_action( 'ninja_forms_save_sub', $sub->get_id());245 246 $data[ 'actions' ][ 'save' ][ 'sub_id'] = $sub->get_id();242 do_action('nf_save_sub', $sub->get_id()); 243 do_action('nf_create_sub', $sub->get_id()); 244 do_action('ninja_forms_save_sub', $sub->get_id()); 245 246 $data['actions']['save']['sub_id'] = $sub->get_id(); 247 247 248 248 return $data; … … 262 262 * @return array 263 263 */ 264 protected function validateExtraData( $dataExtra, $form_id): array264 protected function validateExtraData($dataExtra, $form_id): array 265 265 { 266 266 return $dataExtra; 267 267 $return = []; 268 269 if (!is_array($dataExtra)){268 269 if (!is_array($dataExtra)) { 270 270 return $return; 271 271 } 272 272 273 $maxCount = apply_filters('ninja_forms_max_extra_data_count', 200,$form_id);274 275 if ($maxCount<count($dataExtra)){276 277 $return['extraDataOverflowOnSave'] =json_encode($dataExtra);273 $maxCount = apply_filters('ninja_forms_max_extra_data_count', 200, $form_id); 274 275 if ($maxCount < count($dataExtra)) { 276 277 $return['extraDataOverflowOnSave'] = json_encode($dataExtra); 278 278 } 279 279 280 280 return $return; 281 282 281 } 283 282 } -
ninja-forms/trunk/includes/Actions/SuccessMessage.php
r3115129 r3204929 1 <?php if ( ! defined( 'ABSPATH' ) ) exit; 1 <?php 2 3 use NinjaForms\Includes\Abstracts\SotAction; 4 use NinjaForms\Includes\Traits\SotGetActionProperties; 5 use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction; 6 7 if (! defined('ABSPATH')) exit; 2 8 3 9 /** 4 10 * Class NF_Action_SuccessMessage 5 11 */ 6 final class NF_Actions_SuccessMessage extends NF_Abstracts_Action12 final class NF_Actions_SuccessMessage extends SotAction implements InterfacesSotAction 7 13 { 8 /** 9 * @var string 10 */ 11 protected $_name = 'successmessage'; 14 use SotGetActionProperties; 12 15 13 16 /** 14 * @var array15 */17 * @var array 18 */ 16 19 protected $_tags = array(); 17 20 18 21 /** 19 * @var string22 * Constructor 20 23 */ 21 protected $_documentation_url = 'https://ninjaforms.com/docs/success-message/';22 23 /**24 * @var string25 */26 protected $_timing = 'late';27 28 /**29 * @var int30 */31 protected $_priority = 10;32 33 /**34 * @var string35 */36 protected $_group = 'core';37 38 /**39 * Constructor40 */41 24 public function __construct() 42 25 { 43 26 parent::__construct(); 44 27 45 $this->_nicename = esc_html__( 'Success Message', 'ninja-forms' ); 28 $this->_name = 'successmessage'; 29 $this->_timing = 'late'; 30 $this->_priority = 10; 31 $this->_documentation_url = 'https://ninjaforms.com/docs/success-message/'; 32 $this->_group = 'core'; 46 33 47 $settings = Ninja_Forms::config( 'ActionSuccessMessageSettings');34 add_action('init', [$this, 'initHook']); 48 35 49 $this->_settings = array_merge( $this->_settings, $settings ); 36 add_action('nf_before_import_form', array($this, 'import_form_action_success_message'), 11); 37 } 50 38 51 add_action( 'nf_before_import_form', array( $this, 'import_form_action_success_message' ), 11 ); 39 public function initHook() 40 { 41 $this->_nicename = esc_html__('Success Message', 'ninja-forms'); 42 43 $settings = Ninja_Forms::config('ActionSuccessMessageSettings'); 44 45 $this->_settings = array_merge($this->_settings, $settings); 52 46 } 53 47 … … 56 50 */ 57 51 58 public function save( $action_settings ) 52 53 /** @inheritDoc */ 54 public function process(array $action_settings, int $form_id, array $data): array 59 55 { 56 if (isset($action_settings['success_msg'])) { 60 57 61 } 62 63 public function process( $action_settings, $form_id, $data ) 64 { 65 if( isset( $action_settings[ 'success_msg' ] ) ) { 66 67 if( ! isset( $data[ 'actions' ] ) || ! isset( $data[ 'actions' ][ 'success_message' ] ) ) { 68 $data[ 'actions' ][ 'success_message' ] = ''; 58 if (! isset($data['actions']) || ! isset($data['actions']['success_message'])) { 59 $data['actions']['success_message'] = ''; 69 60 } 70 61 71 62 ob_start(); 72 do_shortcode( $action_settings['success_msg']);63 do_shortcode($action_settings['success_msg']); 73 64 $ob = ob_get_clean(); 74 65 75 if ( $ob) {76 $data[ 'debug' ][ 'console' ][] = sprintf( esc_html__( 'Shortcodes should return and not echo, see: %s', 'ninja-forms' ), 'https://codex.wordpress.org/Shortcode_API#Output');66 if ($ob) { 67 $data['debug']['console'][] = sprintf(esc_html__('Shortcodes should return and not echo, see: %s', 'ninja-forms'), 'https://codex.wordpress.org/Shortcode_API#Output'); 77 68 $data['actions']['success_message'] .= $action_settings['success_msg']; 78 69 } else { 79 $message = do_shortcode( $action_settings['success_msg']);80 $data['actions']['success_message'] .= wpautop( $message);70 $message = do_shortcode($action_settings['success_msg']); 71 $data['actions']['success_message'] .= wpautop($message); 81 72 } 82 73 } … … 85 76 } 86 77 87 public function import_form_action_success_message( $import)78 public function import_form_action_success_message($import) 88 79 { 89 if ( ! isset( $import[ 'actions' ] )) return $import;80 if (! isset($import['actions'])) return $import; 90 81 91 foreach ( $import[ 'actions' ] as &$action ){82 foreach ($import['actions'] as &$action) { 92 83 93 if ( 'success_message' == $action[ 'type' ] ){84 if ('success_message' == $action['type']) { 94 85 95 $action[ 'type'] = 'successmessage';86 $action['type'] = 'successmessage'; 96 87 } 97 88 } -
ninja-forms/trunk/includes/Admin/VersionCompatibilityCheck.php
r2869579 r3204929 42 42 public function activate(): void 43 43 { 44 add_action(' ninja_forms_loaded', array($this, 'ensureVersionCompatibility'), 0);44 add_action('init', array($this, 'ensureVersionCompatibility'), 0); 45 45 } 46 46 -
ninja-forms/trunk/ninja-forms.php
r3197483 r3204929 4 4 Plugin URI: http://ninjaforms.com/?utm_source=WordPress&utm_medium=readme 5 5 Description: Ninja Forms is a webform builder with unparalleled ease of use and features. 6 Version: 3.8.2 06 Version: 3.8.21 7 7 Author: Saturday Drive 8 8 Author URI: http://ninjaforms.com/?utm_source=Ninja+Forms+Plugin&utm_medium=Plugins+WP+Dashboard … … 44 44 */ 45 45 46 const VERSION = '3.8.2 0';46 const VERSION = '3.8.21'; 47 47 48 48 /** … … 362 362 require_once Ninja_Forms::$dir . 'blocks/ninja-forms-blocks.php'; 363 363 364 /*365 * Submission Metabox366 */367 new NF_Admin_Metaboxes_Calculations();368 364 369 365 /* … … 382 378 self::$instance->_dispatcher = new NF_Dispatcher(); 383 379 384 /*385 * Merge Tags386 */387 self::$instance->merge_tags[ 'wp' ] = new NF_MergeTags_WP();388 self::$instance->merge_tags[ 'fields' ] = new NF_MergeTags_Fields();389 self::$instance->merge_tags[ 'calcs' ] = new NF_MergeTags_Calcs();390 self::$instance->merge_tags[ 'form' ] = new NF_MergeTags_Form();391 self::$instance->merge_tags[ 'other' ] = new NF_MergeTags_Other();392 self::$instance->merge_tags[ 'deprecated' ] = new NF_MergeTags_Deprecated();393 380 394 381 /* … … 409 396 (new VersionCompatibilityCheck())->activate(); 410 397 411 self::$instance->widgets[] = new NF_Widget();412 398 413 399 /* … … 429 415 register_activation_hook( __FILE__, array( self::$instance, 'activation' ) ); 430 416 431 self::$instance->metaboxes[ 'append-form' ] = new NF_Admin_Metaboxes_AppendAForm();432 417 433 418 … … 462 447 add_action( 'ninja_forms_available_actions', array( self::$instance, 'scrub_available_actions' ) ); 463 448 449 add_action( 'init', array( self::$instance, 'instantiateTranslatableObjects' ), 5 ); 464 450 add_action( 'init', array( self::$instance, 'init' ), 5 ); 465 451 add_action( 'admin_init', array( self::$instance, 'admin_init' ), 5 ); … … 492 478 } 493 479 480 public function instantiateTranslatableObjects(): void 481 { 482 new NF_Admin_Metaboxes_Calculations(); 483 484 /* 485 * Merge Tags 486 */ 487 self::$instance->merge_tags['wp'] = new NF_MergeTags_WP(); 488 self::$instance->merge_tags['fields'] = new NF_MergeTags_Fields(); 489 self::$instance->merge_tags['calcs'] = new NF_MergeTags_Calcs(); 490 self::$instance->merge_tags['form'] = new NF_MergeTags_Form(); 491 self::$instance->merge_tags['other'] = new NF_MergeTags_Other(); 492 self::$instance->merge_tags['deprecated'] = new NF_MergeTags_Deprecated(); 493 494 self::$instance->widgets[] = new NF_Widget(); 495 496 self::$instance->metaboxes['append-form'] = new NF_Admin_Metaboxes_AppendAForm(); 497 498 499 /* 500 * Field Class Registration 501 */ 502 self::$instance->fields = apply_filters('ninja_forms_register_fields', self::load_classes('Fields')); 503 504 if (! apply_filters('ninja_forms_enable_credit_card_fields', false)) { 505 unset(self::$instance->fields['creditcard']); 506 unset(self::$instance->fields['creditcardcvc']); 507 unset(self::$instance->fields['creditcardexpiration']); 508 unset(self::$instance->fields['creditcardfullname']); 509 unset(self::$instance->fields['creditcardnumber']); 510 unset(self::$instance->fields['creditcardzip']); 511 } 512 } 513 494 514 public function register_rewrite_rules() 495 515 { … … 743 763 load_plugin_textdomain( 'ninja-forms', false, basename( dirname( __FILE__ ) ) . '/lang' ); 744 764 745 /* 746 * Field Class Registration 747 */ 748 self::$instance->fields = apply_filters( 'ninja_forms_register_fields', self::load_classes( 'Fields' ) ); 749 750 if( ! apply_filters( 'ninja_forms_enable_credit_card_fields', false ) ){ 751 unset( self::$instance->fields[ 'creditcard' ] ); 752 unset( self::$instance->fields[ 'creditcardcvc' ] ); 753 unset( self::$instance->fields[ 'creditcardexpiration' ] ); 754 unset( self::$instance->fields[ 'creditcardfullname' ] ); 755 unset( self::$instance->fields[ 'creditcardnumber' ] ); 756 unset( self::$instance->fields[ 'creditcardzip' ] ); 757 } 765 758 766 759 767 /* -
ninja-forms/trunk/readme.txt
r3197483 r3204929 6 6 Requires at least: 6.5 7 7 Tested up to: 6.7 8 Stable tag: 3.8.2 08 Stable tag: 3.8.21 9 9 10 10 Requires PHP: 7.4 … … 313 313 314 314 == Upgrade Notice == 315 = 3.8.2 0 (26 November 2024) =316 *Bug Fixes:* 317 - Sanitize calculations input315 = 3.8.21 (09 December 2024) = 316 *Bug Fixes:* 317 - Update timing to load translations after init 318 318 319 319 == Changelog == 320 = 3.8.21 (09 December 2024) = 321 *Bug Fixes:* 322 - Update timing to load translations after init 323 320 324 = 3.8.20 (26 November 2024) = 321 325 *Bug Fixes:* -
ninja-forms/trunk/vendor/composer/installed.php
r3197483 r3204929 2 2 'root' => array( 3 3 'name' => 'saturday-drive/ninja-forms', 4 'pretty_version' => 'dev- b0cd47df4b44987478308def65bbe3b17e0b514e',5 'version' => 'dev- b0cd47df4b44987478308def65bbe3b17e0b514e',6 'reference' => ' b0cd47df4b44987478308def65bbe3b17e0b514e',4 'pretty_version' => 'dev-6a161b40aa68c448aa95e54728c43048ffe78955', 5 'version' => 'dev-6a161b40aa68c448aa95e54728c43048ffe78955', 6 'reference' => '6a161b40aa68c448aa95e54728c43048ffe78955', 7 7 'type' => 'library', 8 8 'install_path' => __DIR__ . '/../../', … … 12 12 'versions' => array( 13 13 'saturday-drive/ninja-forms' => array( 14 'pretty_version' => 'dev- b0cd47df4b44987478308def65bbe3b17e0b514e',15 'version' => 'dev- b0cd47df4b44987478308def65bbe3b17e0b514e',16 'reference' => ' b0cd47df4b44987478308def65bbe3b17e0b514e',14 'pretty_version' => 'dev-6a161b40aa68c448aa95e54728c43048ffe78955', 15 'version' => 'dev-6a161b40aa68c448aa95e54728c43048ffe78955', 16 'reference' => '6a161b40aa68c448aa95e54728c43048ffe78955', 17 17 'type' => 'library', 18 18 'install_path' => __DIR__ . '/../../',
Note: See TracChangeset
for help on using the changeset viewer.