Plugin Directory

Changeset 3204929


Ignore:
Timestamp:
12/09/2024 02:37:33 PM (14 months ago)
Author:
nahuelmahe
Message:

Update to version 3.8.21 from GitHub

Location:
ninja-forms
Files:
12 added
32 edited
1 copied

Legend:

Unmodified
Added
Removed
  • ninja-forms/tags/3.8.21/includes/Abstracts/Metabox.php

    r2238469 r3204929  
    55    protected $_id = ''; // Dynamically set in constructor using the class name.
    66
    7     protected $_title = ''; // Should be set (and translated) in the constructor.
     7    protected $_title = ''; // Should be set (and translated) at action hook init-10
    88
    99    protected $_callback = 'render_metabox';
     
    2323        $this->_id = strtolower( get_class( $this ) );
    2424
    25         $this->_title = esc_html__( 'Metabox', 'ninja-forms' );
     25        add_action('init', [$this, 'abstractInit'], 5);
    2626
    2727        add_action( 'save_post', array( $this, '_save_post' ) );
    2828
    2929        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' );
    3042    }
    3143
  • ninja-forms/tags/3.8.21/includes/Abstracts/SubmissionMetabox.php

    r2238469 r3204929  
    1919        if( ! isset( $_GET[ 'post' ] ) ) return;
    2020
    21         $this->_title = esc_html__( 'Submission Metabox', 'ninja-forms' );
     21        add_action('init', [$this, 'abstractSubmissionInit'], 8);
    2222
    2323        $post_id = absint( $_GET[ 'post' ] );
     
    2828        add_action( 'save_post', array( $this, '_save_post' ) );
    2929    }
     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    }
    3042}
  • ninja-forms/tags/3.8.21/includes/Actions/Akismet.php

    r3101843 r3204929  
    11<?php
    22
    3 if ( ! defined( 'ABSPATH' ) || ! class_exists( 'NF_Abstracts_Action' ) ) {
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH') ) {
    48    exit;
    59}
     
    812 * Class NF_Actions_Akismet
    913 */
    10 final class NF_Actions_Akismet extends NF_Abstracts_Action {
    11 
    12     /**
    13      * @var string
    14      */
    15     protected $_name = 'akismet';
     14final class NF_Actions_Akismet extends SotAction implements InterfacesSotAction
     15{
     16    use SotGetActionProperties;
    1617
    1718    /**
    1819     * @var array
    1920     */
    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');
    3622
    3723    /**
    3824     * Constructor
    3925     */
    40     public function __construct() {
     26    public function __construct()
     27    {
    4128        parent::__construct();
    4229
    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';
    4634
    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);
    4845    }
    4946
     
    5552     * @return array
    5653     */
    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]);
    6058        }
    6159
     
    6866     * @return bool
    6967     */
    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'))) {
    7271            // Not installed and activated
    7372            return false;
     
    7574
    7675        $akismet_key = Akismet::get_api_key();
    77         if ( empty( $akismet_key ) ) {
     76        if (empty($akismet_key)) {
    7877            // No key entered
    7978            return false;
    8079        }
    8180
    82         return 'valid' === Akismet::verify_key( $akismet_key );
     81        return 'valid' === Akismet::verify_key($akismet_key);
    8382    }
    8483
     
    9291     * @return array
    9392     */
    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()) {
    9696            return $data;
    9797        }
    9898
    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');
    101101        }
    102102
     
    114114     * @return bool
    115115     */
    116     protected function is_submission_spam( $name, $email, $url, $message ) {
     116    protected function is_submission_spam($name, $email, $url, $message)
     117    {
    117118        $body_request = array(
    118             'blog'                 => get_option( 'home' ),
     119            'blog'                 => get_option('home'),
    119120            'blog_lang'            => get_locale(),
    120121            'permalink'            => get_permalink(),
     
    124125            'comment_author_url'   => $url,
    125126            '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),
    127128        );
    128129
    129         if ( method_exists( 'Akismet', 'http_post' ) ) {
     130        if (method_exists('Akismet', 'http_post')) {
    130131            $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');
    132133        } else {
    133134            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);
    136137        }
    137138
    138         if ( ! empty( $response ) && isset( $response[1] ) && 'true' == trim( $response[1] ) ) {
     139        if (! empty($response) && isset($response[1]) && 'true' == trim($response[1])) {
    139140            // Spam!
    140141            return true;
  • ninja-forms/tags/3.8.21/includes/Actions/CollectPayment.php

    r2238469 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Action_CollectPayment
    511 */
    6 final class NF_Actions_CollectPayment extends NF_Abstracts_Action
     12final class NF_Actions_CollectPayment extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9      * @var string
    10      */
    11     protected $_name  = 'collectpayment';
     14    use SotGetActionProperties;
    1215
    1316    /**
     
    1720
    1821    /**
    19      * @var string
    20      */
    21     protected $_timing = 'late';
    22 
    23     /**
    24      * @var int
    25      */
    26     protected $_priority = 0;
    27 
    28     /**
    2922     * @var array
    3023     */
    3124    protected $payment_gateways = array();
    3225
     26    protected $tempCpNiceName;
     27    protected $tempCpName;
    3328    /**
    3429     * Constructor
     
    3732     * @param string $cp_name
    3833     */
    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
    4153    {
    42         parent::__construct();
     54        $this->initializeSettings();
    4355
    4456        // 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;
    4962        // Set name to what we passed in. 'collectpayment' is default
    50         $this->_name = strtolower( $cp_name );
     63        $this->_name = strtolower($this->tempCpName);
    5164
    52         $settings = Ninja_Forms::config( 'ActionCollectPaymentSettings' );
     65        $settings = Ninja_Forms::config('ActionCollectPaymentSettings');
    5366
    5467        /**
     
    5669         * of the gateway drop-down
    5770         **/
    58         if ( 'collectpayment' != $this->_name ) {
    59             $settings[ 'payment_gateways' ][ 'value' ] = $this->_name;
     71        if ('collectpayment' != $this->_name) {
     72            $settings['payment_gateways']['value'] = $this->_name;
    6073        }
    6174
    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);
    6776    }
    6877
    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
    7096    {
    7197
    72     }
     98        $payment_gateway = $action_settings['payment_gateways'];
    7399
    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];
    80101
    81102        $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']);
    83104        $action_settings['payment_total'] = $converted;
    84105
    85         return $payment_gateway_class->process( $action_settings, $form_id, $data );
     106        return $payment_gateway_class->process($action_settings, $form_id, $data);
    86107    }
    87108
    88109    public function register_payment_gateways()
    89110    {
    90         $this->payment_gateways = apply_filters( 'ninja_forms_register_payment_gateways', array() );
     111        $this->payment_gateways = apply_filters('ninja_forms_register_payment_gateways', array());
    91112
    92         foreach( $this->payment_gateways as $gateway ){
     113        add_action('init',[$this,'buildPaymentGatewayOptions'],15);
    93114
    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')) {
    95129                continue;
    96130            }
    97131
    98             $this->_settings[ 'payment_gateways' ][ 'options' ][] = array(
     132            $this->_settings['payment_gateways']['options'][] = array(
    99133                'label' => $gateway->get_name(),
    100134                'value' => $gateway->get_slug(),
    101135            );
    102136
    103             $this->_settings = array_merge( $this->_settings, $gateway->get_settings() );
     137            $this->_settings = array_merge($this->_settings, $gateway->get_settings());
    104138        }
    105139    }
    106140
    107     public function maybe_remove_action( $action_type_settings )
     141    public function maybe_remove_action($action_type_settings)
    108142    {
    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]);
    111145        }
    112146
  • ninja-forms/tags/3.8.21/includes/Actions/Custom.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Action_Custom
    511 */
    6 final class NF_Actions_Custom extends NF_Abstracts_Action
     12final class NF_Actions_Custom extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9      * @var string
    10      */
    11     protected $_name  = 'custom';
     14    use SotGetActionProperties;
    1215
    1316    /**
     
    1518     */
    1619    protected $_tags = array();
    17 
    18     /**
    19      * @var string
    20      */
    21     protected $_documentation_url = 'https://ninjaforms.com/docs/wp-hook/';
    22 
    23     /**
    24      * @var string
    25      */
    26     protected $_timing = 'normal';
    27 
    28     /**
    29      * @var int
    30      */
    31     protected $_priority = 10;
    32 
    33     /**
    34      * @var string
    35      */
    36     protected $_group = 'core';
    3720
    3821    /**
     
    4326        parent::__construct();
    4427
    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';
    4633
    47         $settings = Ninja_Forms::config( 'ActionCustomSettings' );
     34        add_action('init', [$this, 'initHook']);
     35    }
    4836
    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);
    5044    }
    5145
     
    5448    */
    5549
    56     public function save( $action_settings )
     50    /** @inheritDoc */
     51    public function process(array $action_settings, int $form_id, array $data): array
    5752    {
    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'])) {
    6454            ob_start(); // Use the Output Buffer to suppress output
    6555
    66             do_action($action_settings[ 'tag' ], $data);
     56            do_action($action_settings['tag'], $data);
    6757
    6858            ob_end_clean();
  • ninja-forms/tags/3.8.21/includes/Actions/DeleteDataRequest.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Actions_DataRemoval
    511 */
    6 final class NF_Actions_DeleteDataRequest extends NF_Abstracts_Action
     12final class NF_Actions_DeleteDataRequest extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9      * @var string
    10      */
    11     protected $_name  = 'deletedatarequest';
     14    use SotGetActionProperties;
    1215
    1316    /**
     
    1518     */
    1619    protected $_tags = array();
    17 
    18     /**
    19      * @var string
    20      */
    21     protected $_documentation_url = 'https://ninjaforms.com/docs/delete-data-request-action/';
    22 
    23     /**
    24      * @var string
    25      */
    26     protected $_timing = 'late';
    27 
    28     /**
    29      * @var int
    30      */
    31     protected $_priority = 10;
    32 
    33     /**
    34      * @var string
    35      */
    36     protected $_group = 'core';
    3720
    3821    /**
     
    4326        parent::__construct();
    4427
    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';
    4633
    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);
    4943    }
    5044
     
    5246    * PUBLIC METHODS
    5347    */
    54 
    55     public function save( $action_settings )
    56     {
    57 
    58     }
    5948
    6049    /**
     
    6857     * @return array
    6958     */
    70     public function process( $action_settings, $form_id, $data )
     59    public function process(array $action_settings, int $form_id, array $data): array
    7160    {
    7261        $data = array();
    7362
    74         if( isset( $data['settings']['is_preview'] ) && $data['settings']['is_preview'] ){
     63        if (isset($data['settings']['is_preview']) && $data['settings']['is_preview']) {
    7564            return $data;
    7665        }
    7766
    7867        // get the email setting
    79         $email = $action_settings[ 'email' ];
     68        $email = $action_settings['email'];
    8069
    8170        // 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        );
    8475
    8576        /**
     
    8980         * 1) The email in question is already in the erase data request queue
    9081         * 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) {
    9384            // send the request if it's not an error.
    9485
    9586            // to anonymize or not to anonymize, that is the question
    96             add_post_meta( $request_id,
     87            add_post_meta(
     88                $request_id,
    9789                'nf_anonymize_data',
    98                 $action_settings[ 'anonymize' ] );
     90                $action_settings['anonymize']
     91            );
    9992
    100             wp_send_user_request( $request_id );
     93            wp_send_user_request($request_id);
    10194        }
    10295
  • ninja-forms/tags/3.8.21/includes/Actions/Email.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Action_Email
    511 */
    6 final class NF_Actions_Email extends NF_Abstracts_Action
     12final class NF_Actions_Email extends SotAction implements InterfacesSotAction
    713{
     14    use SotGetActionProperties;
     15
    816    /**
    9     * @var string
    10     */
    11     protected $_name  = 'email';
     17     * @var array
     18     */
     19    protected $_tags = array();
    1220
    1321    /**
    14     * @var array
    15     */
    16     protected $_tags = array();
    17 
    18     /**
    19      * @var string
     22     * Constructor
    2023     */
    21     protected $_documentation_url = 'https://ninjaforms.com/docs/email/';
    22 
    23     /**
    24     * @var string
    25     */
    26     protected $_timing = 'late';
    27 
    28     /**
    29     * @var int
    30     */
    31     protected $_priority = 10;
    32 
    33     /**
    34      * @var string
    35      */
    36     protected $_group = 'core';
    37 
    38     /**
    39     * Constructor
    40     */
    4124    public function __construct()
    4225    {
    4326        parent::__construct();
    4427
    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);
    5044
    5145        $this->_backwards_compatibility();
     
    5549    * PUBLIC METHODS
    5650    */
    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')) {
    6761            $fields_by_key = array();
    6862
    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'];
    7670
    7771                    // 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;
    8074                    }
    81 
    8275                } else {
    8376                    $key = $field->get_setting('key');
    8477                }
    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']);
    9689        } 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);
    10194
    10295        try {
     
    10598             * @return bool True if already sent. False to fallback to default behavior. Throw a new Exception if there is an error.
    10699             */
    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) {
    111104            $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;
    122115
    123116        // 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)) {
    129122            $this->_drop_csv();
    130123        }
     
    140133     * @return array
    141134     */
    142     protected function sanitize_address_fields( $action_settings )
     135    protected function sanitize_address_fields($action_settings)
    143136    {
    144137        // 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');
    146139
    147140        // Loop over the look up values.
    148         foreach( $email_address_settings as $setting ) {
     141        foreach ($email_address_settings as $setting) {
    149142            // 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;
    151144
    152145            // If action settings do not match the look up values continue.
    153             if ( ! $action_settings[ $setting ] ) continue;
     146            if (! $action_settings[$setting]) continue;
    154147
    155148            // This is the array that will contain the sanitized email address values.
     
    160153             * if not explodes to comma delimited array.
    161154             */
    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];
    164157            } else {
    165                 $email_addresses = explode( ',', $action_settings[ $setting ] );
     158                $email_addresses = explode(',', $action_settings[$setting]);
    166159            }
    167160
    168161            // Loop over our email addresses.
    169             foreach( $email_addresses as $email ) {
     162            foreach ($email_addresses as $email) {
    170163
    171164                // 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;
    174167
    175168                // Build our array of the email addresses.
     
    177170            }
    178171            // Sanitized our array of settings.
    179             $action_settings[ $setting ] = implode( ',' ,$sanitized_array );
     172            $action_settings[$setting] = implode(',', $sanitized_array);
    180173        }
    181174        return $action_settings;
    182175    }
    183176
    184     protected function check_for_errors( $action_settings )
     177    protected function check_for_errors($action_settings)
    185178    {
    186179        $errors = array();
    187180
    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, '>')) {
    200193                    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);
    205198                }
    206199            }
     
    210203    }
    211204
    212     private function _get_headers( $settings )
     205    private function _get_headers($settings)
    213206    {
    214207        $headers = array();
    215208
    216         $headers[] = 'Content-Type: text/' . $settings[ 'email_format' ];
     209        $headers[] = 'Content-Type: text/' . $settings['email_format'];
    217210        $headers[] = 'charset=UTF-8';
    218211        $headers[] = 'X-Ninja-Forms:ninja-forms'; // Flag for transactional email.
    219212
    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));
    223216
    224217        return $headers;
    225218    }
    226219
    227     private function _get_attachments( $settings, $data )
     220    private function _get_attachments($settings, $data)
    228221    {
    229222        $attachments = array();
    230223
    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'] = '';
    236229
    237230        // Allow admins to attach files from media library
     
    240233            $media_id = attachment_url_to_postid($settings['file_attachment']);
    241234
    242             if($media_id !== 0) {
     235            if ($media_id !== 0) {
    243236                $file_path = get_attached_file($media_id);
    244237                if (0 < strlen($file_path)) {
     
    248241        }
    249242
    250         $attachments = apply_filters( 'ninja_forms_action_email_attachments', $attachments, $data, $settings );
     243        $attachments = apply_filters('ninja_forms_action_email_attachments', $attachments, $data, $settings);
    251244
    252245        return $attachments;
    253246    }
    254247
    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)
    269262    {
    270263        $headers = array();
    271264
    272265        $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'],
    276269        );
    277270
    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;
    285278
    286279                $matches = array();
     
    296289    }
    297290
    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;
    303296
    304297        $recipient = "$type: $name <$email>";
     
    307300    }
    308301
    309     private function _create_csv( $fields )
     302    private function _create_csv($fields)
    310303    {
    311304        $csv_array = array();
    312305
    313306        // 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) {
    320313
    321314            $ignore = array(
     
    330323            );
    331324
    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'];
    338331            // Escape labels.
    339332            $label = WPN_Helper::maybe_escape_csv_column($label);
    340333
    341             if($field["type"] === "repeater" && isset($field['fields'])){
     334            if ($field["type"] === "repeater" && isset($field['fields'])) {
    342335                $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) {
    345338                        $matching_value = substr($in_field_value['id'], 0, strlen($field_model['id'])) === $field_model['id'];
    346339                        $index_found = substr($in_field_value['id'], strpos($in_field_value['id'], "_") + 1);
    347                         if( $matching_value ){
     340                        if ($matching_value) {
    348341                            //Catch specific file uploeds data
    349                             if(isset($in_field_value["files"])){
     342                            if (isset($in_field_value["files"])) {
    350343                                $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"];
    353346                                }
    354347                                $in_field_value['value'] = implode(" , ", $field_files_names);
    355348                            }
    356349
    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";
    358351                        };
    359352                    }
    360353                }
    361 
    362354            } 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)) {
    365357                    $value = '';
    366358                }
    367                 if ( is_array( $value ) ) {
    368                     $value = implode( ',', $value );
     359                if (is_array($value)) {
     360                    $value = implode(',', $value);
    369361                }
    370362            }
    371363
    372364            // 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")
    383376        );
    384377
    385378        $upload_dir = wp_upload_dir();
    386         $path = trailingslashit( $upload_dir['path'] );
     379        $path = trailingslashit($upload_dir['path']);
    387380
    388381        // 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+');
    391384
    392385        // write to temp file
    393         fwrite( $temp_file, $csv_content );
    394         fclose( $temp_file );
     386        fwrite($temp_file, $csv_content);
     387        fclose($temp_file);
    395388
    396389        // find the directory we will be using for the final file
    397         $path = pathinfo( $path );
     390        $path = pathinfo($path);
    398391        $dir = $path['dirname'];
    399392        $basename = $path['basename'];
    400393
    401394        // 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');
    403396
    404397        // 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');
    407400        }
    408401
    409402        // 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';
    412405    }
    413406
     
    418411    {
    419412        $upload_dir = wp_upload_dir();
    420         $path = trailingslashit( $upload_dir['path'] );
     413        $path = trailingslashit($upload_dir['path']);
    421414
    422415        // 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');
    424417
    425418        // 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');
    428421        }
    429422    }
     
    435428    private function _backwards_compatibility()
    436429    {
    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);
    469462    }
    470463}
  • ninja-forms/tags/3.8.21/includes/Actions/ExportDataRequest.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Actions_ExportPersonalData
    511 */
    6 final class NF_Actions_ExportDataRequest extends NF_Abstracts_Action
     12final class NF_Actions_ExportDataRequest extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9      * @var string
    10      */
    11     protected $_name  = 'exportdatarequest';
     14    use SotGetActionProperties;
    1215
    1316    /**
     
    1518     */
    1619    protected $_tags = array();
    17 
    18     /**
    19      * @var string
    20      */
    21     protected $_documentation_url = 'https://ninjaforms.com/docs/export-data-request-action/';
    22 
    23     /**
    24      * @var string
    25      */
    26     protected $_timing = 'late';
    27 
    28     /**
    29      * @var int
    30      */
    31     protected $_priority = 10;
    32 
    33     /**
    34      * @var string
    35      */
    36     protected $_group = 'core';
    3720
    3821    /**
     
    4326        parent::__construct();
    4427
    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';
    4633
    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);
    4943    }
    5044
     
    5347    */
    5448
    55     public function save( $action_settings )
    56     {
    57 
    58     }
    5949
    6050    /**
     
    6858     * @return array
    6959     */
    70     public function process( $action_settings, $form_id, $data )
     60    public function process(array  $action_settings, int $form_id, array $data): array
    7161    {
    7262        $data = array();
    7363
    74         if( isset( $data['settings']['is_preview'] ) && $data['settings']['is_preview'] ){
     64        if (isset($data['settings']['is_preview']) && $data['settings']['is_preview']) {
    7565            return $data;
    7666        }
    7767
    7868        // get the email setting
    79         $email = $action_settings[ 'email' ];
     69        $email = $action_settings['email'];
    8070
    8171        // 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        );
    8476
    8577        /**
     
    9082         * 2) The email does not belong to an actual user.
    9183         */
    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);
    9486        }
    9587
  • ninja-forms/tags/3.8.21/includes/Actions/Recaptcha.php

    r3101843 r3204929  
    11<?php
    22
    3 if ( ! defined( 'ABSPATH' ) || ! class_exists( 'NF_Abstracts_Action' ) ) {
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH') ) {
    48    exit;
    59}
     
    812 * Class NF_Actions_Recaptcha
    913 */
    10 final class NF_Actions_Recaptcha extends NF_Abstracts_Action {
     14final 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');
    1122
    1223    /**
    1324     * @var string
    1425     */
    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;
    1637
    1738    /**
    1839     * @var array
    1940     */
    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;
    5142
    5243    /**
    5344     * @var array
    5445     */
    55     protected $forms_with_action;
    56 
    57     /**
    58      * @var array
    59      */
    60     protected $_settings_exclude = array( 'conditions' );
     46    protected $_settings_exclude = array('conditions');
    6147
    6248    /**
    6349     * Constructor
    6450     */
    65     public function __construct() {
     51    public function __construct()
     52    {
    6653        parent::__construct();
    6754
    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');
    8482    }
    8583
     
    9189     * @return void
    9290     */
    93     public function set_form_id( $form_id )
     91    public function set_form_id($form_id)
    9492    {
    9593        $this->form_id = $form_id;
    9694    }
    9795
    98     public function get_form_id() {
    99         if ( $this->form_id ) {
     96    public function get_form_id()
     97    {
     98        if ($this->form_id) {
    10099            return $this->form_id;
    101100        }
    102101
    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);
    104103
    105104        return $this->form_id;
     
    113112     * @return array
    114113     */
    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]);
    118118        }
    119119
     
    124124     * @return bool
    125125     */
    126     protected function is_action_enabled_for_form() {
     126    protected function is_action_enabled_for_form()
     127    {
    127128        $form_id = $this->get_form_id();
    128129
    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();
    134135
    135136        $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')) {
    138139                $enabled = true;
    139140                break;
     
    141142        }
    142143
    143         $this->forms_with_action[ $form_id ] = $enabled;
     144        $this->forms_with_action[$form_id] = $enabled;
    144145
    145146        return $enabled;
     
    151152     * @return bool
    152153     */
    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)) {
    155157            return false;
    156158        }
     
    164166     * @return bool
    165167     */
    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()) {
    172175            return false;
    173176        }
     
    176179    }
    177180
    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()) {
    180184            return;
    181185        }
     
    183187        $file_path = Ninja_Forms::$dir . 'includes/Templates/';
    184188
    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);
    190195    }
    191196
     
    197202     * @return array
    198203     */
    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()) {
    201207            return $fields;
    202208        }
    203209
    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')) {
    206212                // Remove v2 reCAPTCHA fields if still configured
    207                 unset( $fields[ $key ] );
     213                unset($fields[$key]);
    208214            }
    209215        }
     
    220226     * @return bool
    221227     */
    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()) {
    224231            return $show;
    225232        }
    226233
    227         if ( 'recaptcha' !== $field->get_type() ) {
     234        if ('recaptcha' !== $field->get_type()) {
    228235            return $show;
    229236        }
    230237
    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')) {
    235242                // recaptcha v2 field exists on form, don't hide it as it will break the JS
    236243                return $show;
     
    248255     * @return array
    249256     */
    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()) {
    252260            return $fields;
    253261        }
    254262
    255         $field_id = $this->get_field_id_hash( $form_id );
     263        $field_id = $this->get_field_id_hash($form_id);
    256264
    257265        $field = array(
     
    259267            'objectDomain'      => 'fields',
    260268            'editActive'        => false,
    261             'order'             => number_format( count( $fields ) + 1, 1 ),
     269            'order'             => number_format(count($fields) + 1, 1),
    262270            'type'              => 'recaptcha_v3',
    263271            'label'             => 'Hidden',
     
    287295    }
    288296
    289     public function enqueue_script() {
    290         if ( ! $this->is_action_configured() ) {
     297    public function enqueue_script()
     298    {
     299        if (! $this->is_action_configured()) {
    291300            return;
    292301        }
    293302
    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);
    298307        }
    299308    }
     
    304313     * @return bool
    305314     */
    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)) {
    308318            // Allow other plugins to tell Ninja Forms not to load the Google JS script, if they are doing that
    309319            return false;
     
    312322        $scripts = wp_scripts();
    313323
    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')) {
    316326                return false;
    317327            }
     
    321331    }
    322332
    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);
    329340
    330341        // 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);
    333344        }
    334345
     
    336347    }
    337348
    338     protected function get_recaptcha_response() {
     349    protected function get_recaptcha_response()
     350    {
    339351        $form_data = $this->get_form_data();
    340352
    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'];
    352364    }
    353365
     
    361373     * @return array
    362374     */
    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()) {
    365378            return $data;
    366379        }
     
    368381        $recaptcha_response = $this->get_recaptcha_response();
    369382
    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');
    372385
    373386            return $data;
    374387        }
    375388
    376         if ( $this->is_submission_human( $recaptcha_response, $action_settings['score'] ) ) {
     389        if ($this->is_submission_human($recaptcha_response, $action_settings['score'])) {
    377390            return $data;
    378391        }
    379392
    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');
    381394
    382395        return $data;
    383396    }
    384397
    385     protected function is_submission_human( $token, $score_threshold ) {
     398    protected function is_submission_human($token, $score_threshold)
     399    {
    386400        $endpoint = 'https://www.google.com/recaptcha/api/siteverify';
    387401
     
    389403            'body' => array(
    390404                'secret'   => $this->site_secret,
    391                 'response' => esc_html( $token ),
     405                'response' => esc_html($token),
    392406            ),
    393407        );
    394408
    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));
    400414            }
    401415
     
    403417        }
    404418
    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);
    411425        $is_human  = $threshold < $score;
    412426
    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);
    414428
    415429        return $is_human;
  • ninja-forms/tags/3.8.21/includes/Actions/Redirect.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Action_Redirect
    511 */
    6 final class NF_Actions_Redirect extends NF_Abstracts_Action
     12final class NF_Actions_Redirect extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9     * @var string
    10     */
    11     protected $_name  = 'redirect';
     14    use SotGetActionProperties;
    1215
    1316    /**
    14     * @var array
    15     */
     17     * @var array
     18     */
    1619    protected $_tags = array();
    1720
    1821    /**
    19      * @var string
     22     * Constructor
    2023     */
    21     protected $_documentation_url = 'https://ninjaforms.com/docs/redirect-action/';
    22 
    23     /**
    24     * @var string
    25     */
    26     protected $_timing = 'late';
    27 
    28     /**
    29     * @var int
    30     */
    31     protected $_priority = 20;
    32 
    33     /**
    34      * @var string
    35      */
    36     protected $_group = 'core';
    37 
    38     /**
    39     * Constructor
    40     */
    4124    public function __construct()
    4225    {
    4326        parent::__construct();
    4427
    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';
    4633
    47         $settings = Ninja_Forms::config( 'ActionRedirectSettings' );
    48 
    49         $this->_settings = array_merge( $this->_settings, $settings );
     34        add_action('init', [$this, 'initHook']);
    5035    }
    5136
     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    }
    5246    /*
    5347    * PUBLIC METHODS
    5448    */
    5549
    56     public function save( $action_settings )
     50
     51    /** @inheritDoc */
     52    public function process(array $action_settings, int $form_id, array $data): array
    5753    {
    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'];
    6455
    6556        return $data;
  • ninja-forms/tags/3.8.21/includes/Actions/Save.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Action_Save
    511 */
    6 class NF_Actions_Save extends NF_Abstracts_Action
     12class NF_Actions_Save extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9     * @var string
    10     */
    11     protected $_name  = 'save';
    12 
    13     /**
    14     * @var array
    15     */
     14    use SotGetActionProperties;
     15
     16    /**
     17     * @var array
     18     */
    1619    protected $_tags = array();
    1720
    1821    /**
    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     */
    4124    public function __construct()
    4225    {
    4326        parent::__construct();
    4427
    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);
    5144    }
    5245
     
    5548    */
    5649
    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;
    6054        // 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);
    6357    }
    6458
     
    7367     * @return void
    7468     */
    75     public function submission_expiration_processing( $action_settings, $form_id )
     69    public function submission_expiration_processing($action_settings, $form_id)
    7670    {
    7771        /*
     
    7973         * Example: 5,90
    8074         */
    81         $expiration_value = $form_id . ',' . $action_settings[ 'subs_expire_time' ];
     75        $expiration_value = $form_id . ',' . $action_settings['subs_expire_time'];
    8276
    8377        // Get our expiration option.
    84         $option = $this->getOption( 'nf_sub_expiration', array() );
     78        $option = $this->getOption('nf_sub_expiration', array());
    8579
    8680        // 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
    8983        // 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']) {
    9185            $expiration_option[] = $expiration_value;
    9286        }
    9387
    9488        // Update our option.
    95         $this->updateOption( 'nf_sub_expiration', $expiration_option  );
     89        $this->updateOption('nf_sub_expiration', $expiration_option);
    9690    }
    9791
     
    10599    protected function getOption(string $key, $default)
    106100    {
    107         $return = get_option( $key, $default );
     101        $return = get_option($key, $default);
    108102
    109103        return $return;
     
    117111     * @return void
    118112     */
    119     protected function updateOption(string $key,$value): void
    120     {
    121         update_option( $key, $value );
     113    protected function updateOption(string $key, $value): void
     114    {
     115        update_option($key, $value);
    122116    }
    123117    /**
     
    134128     * @return array $expiration_option without current saved form
    135129     */
    136     public function clean_form_option( $expiration_value, $expiration_option ){
     130    public function clean_form_option($expiration_value, $expiration_option)
     131    {
    137132        /*
    138133         * Breaks a part our options.
     
    140135         *      $value[ 1 ] - ( int ) Expiration time in days
    141136         */
    142         $values = explode( ',', $expiration_value );
     137        $values = explode(',', $expiration_value);
    143138
    144139        // Find the position of the value we are tyring to update.
    145140        //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]) {
    149144                unset($expiration_option[$index]);
    150145            }
    151146        }
    152        
     147
    153148        return $expiration_option;
    154149    }
    155150
    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']) {
    160156            return $data;
    161157        }
    162158
    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());
    168164
    169165        // For each field on the form...
    170         foreach( $data['fields'] as $field ){
     166        foreach ($data['fields'] as $field) {
    171167
    172168            // 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))) {
    174170                // Do not save it.
    175                 $data[ 'actions' ][ 'save' ][ 'hidden' ][] = $field[ 'type' ];
     171                $data['actions']['save']['hidden'][] = $field['type'];
    176172                continue;
    177173            }
    178174
    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'];
    182178            $save_field = true;
    183179
    184180            // 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;
    187183                // For each exception to that rule...
    188                 foreach( $action_settings[ 'exception_fields' ] as $exception_field ) {
     184                foreach ($action_settings['exception_fields'] as $exception_field) {
    189185                    // 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                }
    195191            } // 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;
    198194                // 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                ) {
    201199                    // 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                }
    207205            }
    208206
    209207            // If we're supposed to save this field...
    210             if( $save_field ) {
     208            if ($save_field) {
    211209                // Do so.
    212                 $sub->update_field_value( $field[ 'id' ], $field[ 'value' ] );
     210                $sub->update_field_value($field['id'], $field['value']);
    213211            } // Otherwise...
    214212            else {
     
    217215                // AND If this field is not a product...
    218216                // 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                ) {
    223223                    // Anonymize it.
    224                     $sub->update_field_value( $field[ 'id' ], '(redacted)' );
     224                    $sub->update_field_value($field['id'], '(redacted)');
    225225                }
    226226            }
     
    228228
    229229        // 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);
    233233
    234234            // 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());
    239239
    240240        $sub->save();
    241241
    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();
    247247
    248248        return $data;
     
    262262     * @return array
    263263     */
    264     protected function validateExtraData( $dataExtra, $form_id): array
     264    protected function validateExtraData($dataExtra, $form_id): array
    265265    {
    266266        return $dataExtra;
    267267        $return = [];
    268        
    269         if(!is_array($dataExtra)){
     268
     269        if (!is_array($dataExtra)) {
    270270            return $return;
    271271        }
    272272
    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);
    278278        }
    279279
    280280        return $return;
    281 
    282281    }
    283282}
  • ninja-forms/tags/3.8.21/includes/Actions/SuccessMessage.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Action_SuccessMessage
    511 */
    6 final class NF_Actions_SuccessMessage extends NF_Abstracts_Action
     12final class NF_Actions_SuccessMessage extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9     * @var string
    10     */
    11     protected $_name  = 'successmessage';
     14    use SotGetActionProperties;
    1215
    1316    /**
    14     * @var array
    15     */
     17     * @var array
     18     */
    1619    protected $_tags = array();
    1720
    1821    /**
    19      * @var string
     22     * Constructor
    2023     */
    21     protected $_documentation_url = 'https://ninjaforms.com/docs/success-message/';
    22 
    23     /**
    24     * @var string
    25     */
    26     protected $_timing = 'late';
    27 
    28     /**
    29     * @var int
    30     */
    31     protected $_priority = 10;
    32 
    33     /**
    34      * @var string
    35      */
    36     protected $_group = 'core';
    37 
    38     /**
    39     * Constructor
    40     */
    4124    public function __construct()
    4225    {
    4326        parent::__construct();
    4427
    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';
    4633
    47         $settings = Ninja_Forms::config( 'ActionSuccessMessageSettings' );
     34        add_action('init', [$this, 'initHook']);
    4835
    49         $this->_settings = array_merge( $this->_settings, $settings );
     36        add_action('nf_before_import_form', array($this, 'import_form_action_success_message'), 11);
     37    }
    5038
    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);
    5246    }
    5347
     
    5650    */
    5751
    58     public function save( $action_settings )
     52
     53    /** @inheritDoc */
     54    public function process(array $action_settings, int $form_id, array $data): array
    5955    {
     56        if (isset($action_settings['success_msg'])) {
    6057
    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'] = '';
    6960            }
    7061
    7162            ob_start();
    72             do_shortcode( $action_settings['success_msg'] );
     63            do_shortcode($action_settings['success_msg']);
    7364            $ob = ob_get_clean();
    7465
    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');
    7768                $data['actions']['success_message'] .= $action_settings['success_msg'];
    7869            } 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);
    8172            }
    8273        }
     
    8576    }
    8677
    87     public function import_form_action_success_message( $import )
     78    public function import_form_action_success_message($import)
    8879    {
    89         if( ! isset( $import[ 'actions' ] ) ) return $import;
     80        if (! isset($import['actions'])) return $import;
    9081
    91         foreach( $import[ 'actions' ] as &$action ){
     82        foreach ($import['actions'] as &$action) {
    9283
    93             if( 'success_message' == $action[ 'type' ] ){
     84            if ('success_message' == $action['type']) {
    9485
    95                 $action[ 'type' ] = 'successmessage';
     86                $action['type'] = 'successmessage';
    9687            }
    9788        }
  • ninja-forms/tags/3.8.21/includes/Admin/VersionCompatibilityCheck.php

    r2869579 r3204929  
    4242  public function activate(): void
    4343  {
    44     add_action('ninja_forms_loaded', array($this, 'ensureVersionCompatibility'), 0);
     44    add_action('init', array($this, 'ensureVersionCompatibility'), 0);
    4545  }
    4646
  • ninja-forms/tags/3.8.21/ninja-forms.php

    r3197483 r3204929  
    44Plugin URI: http://ninjaforms.com/?utm_source=WordPress&utm_medium=readme
    55Description: Ninja Forms is a webform builder with unparalleled ease of use and features.
    6 Version: 3.8.20
     6Version: 3.8.21
    77Author: Saturday Drive
    88Author URI: http://ninjaforms.com/?utm_source=Ninja+Forms+Plugin&utm_medium=Plugins+WP+Dashboard
     
    4444     */
    4545
    46     const VERSION = '3.8.20';
     46    const VERSION = '3.8.21';
    4747
    4848    /**
     
    362362            require_once Ninja_Forms::$dir . 'blocks/ninja-forms-blocks.php';
    363363
    364             /*
    365                 * Submission Metabox
    366                 */
    367             new NF_Admin_Metaboxes_Calculations();
    368364
    369365            /*
     
    382378            self::$instance->_dispatcher = new NF_Dispatcher();
    383379
    384             /*
    385                 * Merge Tags
    386                 */
    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();
    393380
    394381            /*
     
    409396            (new VersionCompatibilityCheck())->activate();
    410397
    411             self::$instance->widgets[] = new NF_Widget();
    412398
    413399            /*
     
    429415            register_activation_hook( __FILE__, array( self::$instance, 'activation' ) );
    430416
    431             self::$instance->metaboxes[ 'append-form' ] = new NF_Admin_Metaboxes_AppendAForm();
    432417
    433418
     
    462447        add_action( 'ninja_forms_available_actions', array( self::$instance, 'scrub_available_actions' ) );
    463448
     449        add_action( 'init', array( self::$instance, 'instantiateTranslatableObjects' ), 5 );
    464450        add_action( 'init', array( self::$instance, 'init' ), 5 );
    465451        add_action( 'admin_init', array( self::$instance, 'admin_init' ), 5 );
     
    492478    }
    493479
     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   
    494514    public function register_rewrite_rules()
    495515    {
     
    743763        load_plugin_textdomain( 'ninja-forms', false, basename( dirname( __FILE__ ) ) . '/lang' );
    744764
    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
    758766
    759767        /*
  • ninja-forms/tags/3.8.21/readme.txt

    r3197483 r3204929  
    66Requires at least: 6.5
    77Tested up to: 6.7
    8 Stable tag: 3.8.20
     8Stable tag: 3.8.21
    99
    1010Requires PHP: 7.4
     
    313313
    314314== Upgrade Notice ==
    315 = 3.8.20 (26 November 2024) =
    316 *Bug Fixes:*
    317 - Sanitize calculations input
     315= 3.8.21 (09 December 2024) =
     316*Bug Fixes:*
     317- Update timing to load translations after init
    318318
    319319== Changelog ==
     320= 3.8.21 (09 December 2024) =
     321*Bug Fixes:*
     322- Update timing to load translations after init
     323
    320324= 3.8.20 (26 November 2024) =
    321325*Bug Fixes:*
  • ninja-forms/tags/3.8.21/vendor/composer/installed.php

    r3197483 r3204929  
    22    'root' => array(
    33        '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',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1212    'versions' => array(
    1313        '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',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
  • ninja-forms/trunk/includes/Abstracts/Metabox.php

    r2238469 r3204929  
    55    protected $_id = ''; // Dynamically set in constructor using the class name.
    66
    7     protected $_title = ''; // Should be set (and translated) in the constructor.
     7    protected $_title = ''; // Should be set (and translated) at action hook init-10
    88
    99    protected $_callback = 'render_metabox';
     
    2323        $this->_id = strtolower( get_class( $this ) );
    2424
    25         $this->_title = esc_html__( 'Metabox', 'ninja-forms' );
     25        add_action('init', [$this, 'abstractInit'], 5);
    2626
    2727        add_action( 'save_post', array( $this, '_save_post' ) );
    2828
    2929        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' );
    3042    }
    3143
  • ninja-forms/trunk/includes/Abstracts/SubmissionMetabox.php

    r2238469 r3204929  
    1919        if( ! isset( $_GET[ 'post' ] ) ) return;
    2020
    21         $this->_title = esc_html__( 'Submission Metabox', 'ninja-forms' );
     21        add_action('init', [$this, 'abstractSubmissionInit'], 8);
    2222
    2323        $post_id = absint( $_GET[ 'post' ] );
     
    2828        add_action( 'save_post', array( $this, '_save_post' ) );
    2929    }
     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    }
    3042}
  • ninja-forms/trunk/includes/Actions/Akismet.php

    r3101843 r3204929  
    11<?php
    22
    3 if ( ! defined( 'ABSPATH' ) || ! class_exists( 'NF_Abstracts_Action' ) ) {
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH') ) {
    48    exit;
    59}
     
    812 * Class NF_Actions_Akismet
    913 */
    10 final class NF_Actions_Akismet extends NF_Abstracts_Action {
    11 
    12     /**
    13      * @var string
    14      */
    15     protected $_name = 'akismet';
     14final class NF_Actions_Akismet extends SotAction implements InterfacesSotAction
     15{
     16    use SotGetActionProperties;
    1617
    1718    /**
    1819     * @var array
    1920     */
    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');
    3622
    3723    /**
    3824     * Constructor
    3925     */
    40     public function __construct() {
     26    public function __construct()
     27    {
    4128        parent::__construct();
    4229
    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';
    4634
    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);
    4845    }
    4946
     
    5552     * @return array
    5653     */
    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]);
    6058        }
    6159
     
    6866     * @return bool
    6967     */
    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'))) {
    7271            // Not installed and activated
    7372            return false;
     
    7574
    7675        $akismet_key = Akismet::get_api_key();
    77         if ( empty( $akismet_key ) ) {
     76        if (empty($akismet_key)) {
    7877            // No key entered
    7978            return false;
    8079        }
    8180
    82         return 'valid' === Akismet::verify_key( $akismet_key );
     81        return 'valid' === Akismet::verify_key($akismet_key);
    8382    }
    8483
     
    9291     * @return array
    9392     */
    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()) {
    9696            return $data;
    9797        }
    9898
    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');
    101101        }
    102102
     
    114114     * @return bool
    115115     */
    116     protected function is_submission_spam( $name, $email, $url, $message ) {
     116    protected function is_submission_spam($name, $email, $url, $message)
     117    {
    117118        $body_request = array(
    118             'blog'                 => get_option( 'home' ),
     119            'blog'                 => get_option('home'),
    119120            'blog_lang'            => get_locale(),
    120121            'permalink'            => get_permalink(),
     
    124125            'comment_author_url'   => $url,
    125126            '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),
    127128        );
    128129
    129         if ( method_exists( 'Akismet', 'http_post' ) ) {
     130        if (method_exists('Akismet', 'http_post')) {
    130131            $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');
    132133        } else {
    133134            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);
    136137        }
    137138
    138         if ( ! empty( $response ) && isset( $response[1] ) && 'true' == trim( $response[1] ) ) {
     139        if (! empty($response) && isset($response[1]) && 'true' == trim($response[1])) {
    139140            // Spam!
    140141            return true;
  • ninja-forms/trunk/includes/Actions/CollectPayment.php

    r2238469 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Action_CollectPayment
    511 */
    6 final class NF_Actions_CollectPayment extends NF_Abstracts_Action
     12final class NF_Actions_CollectPayment extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9      * @var string
    10      */
    11     protected $_name  = 'collectpayment';
     14    use SotGetActionProperties;
    1215
    1316    /**
     
    1720
    1821    /**
    19      * @var string
    20      */
    21     protected $_timing = 'late';
    22 
    23     /**
    24      * @var int
    25      */
    26     protected $_priority = 0;
    27 
    28     /**
    2922     * @var array
    3023     */
    3124    protected $payment_gateways = array();
    3225
     26    protected $tempCpNiceName;
     27    protected $tempCpName;
    3328    /**
    3429     * Constructor
     
    3732     * @param string $cp_name
    3833     */
    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
    4153    {
    42         parent::__construct();
     54        $this->initializeSettings();
    4355
    4456        // 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;
    4962        // Set name to what we passed in. 'collectpayment' is default
    50         $this->_name = strtolower( $cp_name );
     63        $this->_name = strtolower($this->tempCpName);
    5164
    52         $settings = Ninja_Forms::config( 'ActionCollectPaymentSettings' );
     65        $settings = Ninja_Forms::config('ActionCollectPaymentSettings');
    5366
    5467        /**
     
    5669         * of the gateway drop-down
    5770         **/
    58         if ( 'collectpayment' != $this->_name ) {
    59             $settings[ 'payment_gateways' ][ 'value' ] = $this->_name;
     71        if ('collectpayment' != $this->_name) {
     72            $settings['payment_gateways']['value'] = $this->_name;
    6073        }
    6174
    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);
    6776    }
    6877
    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
    7096    {
    7197
    72     }
     98        $payment_gateway = $action_settings['payment_gateways'];
    7399
    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];
    80101
    81102        $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']);
    83104        $action_settings['payment_total'] = $converted;
    84105
    85         return $payment_gateway_class->process( $action_settings, $form_id, $data );
     106        return $payment_gateway_class->process($action_settings, $form_id, $data);
    86107    }
    87108
    88109    public function register_payment_gateways()
    89110    {
    90         $this->payment_gateways = apply_filters( 'ninja_forms_register_payment_gateways', array() );
     111        $this->payment_gateways = apply_filters('ninja_forms_register_payment_gateways', array());
    91112
    92         foreach( $this->payment_gateways as $gateway ){
     113        add_action('init',[$this,'buildPaymentGatewayOptions'],15);
    93114
    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')) {
    95129                continue;
    96130            }
    97131
    98             $this->_settings[ 'payment_gateways' ][ 'options' ][] = array(
     132            $this->_settings['payment_gateways']['options'][] = array(
    99133                'label' => $gateway->get_name(),
    100134                'value' => $gateway->get_slug(),
    101135            );
    102136
    103             $this->_settings = array_merge( $this->_settings, $gateway->get_settings() );
     137            $this->_settings = array_merge($this->_settings, $gateway->get_settings());
    104138        }
    105139    }
    106140
    107     public function maybe_remove_action( $action_type_settings )
     141    public function maybe_remove_action($action_type_settings)
    108142    {
    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]);
    111145        }
    112146
  • ninja-forms/trunk/includes/Actions/Custom.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Action_Custom
    511 */
    6 final class NF_Actions_Custom extends NF_Abstracts_Action
     12final class NF_Actions_Custom extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9      * @var string
    10      */
    11     protected $_name  = 'custom';
     14    use SotGetActionProperties;
    1215
    1316    /**
     
    1518     */
    1619    protected $_tags = array();
    17 
    18     /**
    19      * @var string
    20      */
    21     protected $_documentation_url = 'https://ninjaforms.com/docs/wp-hook/';
    22 
    23     /**
    24      * @var string
    25      */
    26     protected $_timing = 'normal';
    27 
    28     /**
    29      * @var int
    30      */
    31     protected $_priority = 10;
    32 
    33     /**
    34      * @var string
    35      */
    36     protected $_group = 'core';
    3720
    3821    /**
     
    4326        parent::__construct();
    4427
    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';
    4633
    47         $settings = Ninja_Forms::config( 'ActionCustomSettings' );
     34        add_action('init', [$this, 'initHook']);
     35    }
    4836
    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);
    5044    }
    5145
     
    5448    */
    5549
    56     public function save( $action_settings )
     50    /** @inheritDoc */
     51    public function process(array $action_settings, int $form_id, array $data): array
    5752    {
    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'])) {
    6454            ob_start(); // Use the Output Buffer to suppress output
    6555
    66             do_action($action_settings[ 'tag' ], $data);
     56            do_action($action_settings['tag'], $data);
    6757
    6858            ob_end_clean();
  • ninja-forms/trunk/includes/Actions/DeleteDataRequest.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Actions_DataRemoval
    511 */
    6 final class NF_Actions_DeleteDataRequest extends NF_Abstracts_Action
     12final class NF_Actions_DeleteDataRequest extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9      * @var string
    10      */
    11     protected $_name  = 'deletedatarequest';
     14    use SotGetActionProperties;
    1215
    1316    /**
     
    1518     */
    1619    protected $_tags = array();
    17 
    18     /**
    19      * @var string
    20      */
    21     protected $_documentation_url = 'https://ninjaforms.com/docs/delete-data-request-action/';
    22 
    23     /**
    24      * @var string
    25      */
    26     protected $_timing = 'late';
    27 
    28     /**
    29      * @var int
    30      */
    31     protected $_priority = 10;
    32 
    33     /**
    34      * @var string
    35      */
    36     protected $_group = 'core';
    3720
    3821    /**
     
    4326        parent::__construct();
    4427
    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';
    4633
    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);
    4943    }
    5044
     
    5246    * PUBLIC METHODS
    5347    */
    54 
    55     public function save( $action_settings )
    56     {
    57 
    58     }
    5948
    6049    /**
     
    6857     * @return array
    6958     */
    70     public function process( $action_settings, $form_id, $data )
     59    public function process(array $action_settings, int $form_id, array $data): array
    7160    {
    7261        $data = array();
    7362
    74         if( isset( $data['settings']['is_preview'] ) && $data['settings']['is_preview'] ){
     63        if (isset($data['settings']['is_preview']) && $data['settings']['is_preview']) {
    7564            return $data;
    7665        }
    7766
    7867        // get the email setting
    79         $email = $action_settings[ 'email' ];
     68        $email = $action_settings['email'];
    8069
    8170        // 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        );
    8475
    8576        /**
     
    8980         * 1) The email in question is already in the erase data request queue
    9081         * 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) {
    9384            // send the request if it's not an error.
    9485
    9586            // to anonymize or not to anonymize, that is the question
    96             add_post_meta( $request_id,
     87            add_post_meta(
     88                $request_id,
    9789                'nf_anonymize_data',
    98                 $action_settings[ 'anonymize' ] );
     90                $action_settings['anonymize']
     91            );
    9992
    100             wp_send_user_request( $request_id );
     93            wp_send_user_request($request_id);
    10194        }
    10295
  • ninja-forms/trunk/includes/Actions/Email.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Action_Email
    511 */
    6 final class NF_Actions_Email extends NF_Abstracts_Action
     12final class NF_Actions_Email extends SotAction implements InterfacesSotAction
    713{
     14    use SotGetActionProperties;
     15
    816    /**
    9     * @var string
    10     */
    11     protected $_name  = 'email';
     17     * @var array
     18     */
     19    protected $_tags = array();
    1220
    1321    /**
    14     * @var array
    15     */
    16     protected $_tags = array();
    17 
    18     /**
    19      * @var string
     22     * Constructor
    2023     */
    21     protected $_documentation_url = 'https://ninjaforms.com/docs/email/';
    22 
    23     /**
    24     * @var string
    25     */
    26     protected $_timing = 'late';
    27 
    28     /**
    29     * @var int
    30     */
    31     protected $_priority = 10;
    32 
    33     /**
    34      * @var string
    35      */
    36     protected $_group = 'core';
    37 
    38     /**
    39     * Constructor
    40     */
    4124    public function __construct()
    4225    {
    4326        parent::__construct();
    4427
    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);
    5044
    5145        $this->_backwards_compatibility();
     
    5549    * PUBLIC METHODS
    5650    */
    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')) {
    6761            $fields_by_key = array();
    6862
    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'];
    7670
    7771                    // 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;
    8074                    }
    81 
    8275                } else {
    8376                    $key = $field->get_setting('key');
    8477                }
    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']);
    9689        } 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);
    10194
    10295        try {
     
    10598             * @return bool True if already sent. False to fallback to default behavior. Throw a new Exception if there is an error.
    10699             */
    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) {
    111104            $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;
    122115
    123116        // 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)) {
    129122            $this->_drop_csv();
    130123        }
     
    140133     * @return array
    141134     */
    142     protected function sanitize_address_fields( $action_settings )
     135    protected function sanitize_address_fields($action_settings)
    143136    {
    144137        // 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');
    146139
    147140        // Loop over the look up values.
    148         foreach( $email_address_settings as $setting ) {
     141        foreach ($email_address_settings as $setting) {
    149142            // 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;
    151144
    152145            // If action settings do not match the look up values continue.
    153             if ( ! $action_settings[ $setting ] ) continue;
     146            if (! $action_settings[$setting]) continue;
    154147
    155148            // This is the array that will contain the sanitized email address values.
     
    160153             * if not explodes to comma delimited array.
    161154             */
    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];
    164157            } else {
    165                 $email_addresses = explode( ',', $action_settings[ $setting ] );
     158                $email_addresses = explode(',', $action_settings[$setting]);
    166159            }
    167160
    168161            // Loop over our email addresses.
    169             foreach( $email_addresses as $email ) {
     162            foreach ($email_addresses as $email) {
    170163
    171164                // 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;
    174167
    175168                // Build our array of the email addresses.
     
    177170            }
    178171            // Sanitized our array of settings.
    179             $action_settings[ $setting ] = implode( ',' ,$sanitized_array );
     172            $action_settings[$setting] = implode(',', $sanitized_array);
    180173        }
    181174        return $action_settings;
    182175    }
    183176
    184     protected function check_for_errors( $action_settings )
     177    protected function check_for_errors($action_settings)
    185178    {
    186179        $errors = array();
    187180
    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, '>')) {
    200193                    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);
    205198                }
    206199            }
     
    210203    }
    211204
    212     private function _get_headers( $settings )
     205    private function _get_headers($settings)
    213206    {
    214207        $headers = array();
    215208
    216         $headers[] = 'Content-Type: text/' . $settings[ 'email_format' ];
     209        $headers[] = 'Content-Type: text/' . $settings['email_format'];
    217210        $headers[] = 'charset=UTF-8';
    218211        $headers[] = 'X-Ninja-Forms:ninja-forms'; // Flag for transactional email.
    219212
    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));
    223216
    224217        return $headers;
    225218    }
    226219
    227     private function _get_attachments( $settings, $data )
     220    private function _get_attachments($settings, $data)
    228221    {
    229222        $attachments = array();
    230223
    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'] = '';
    236229
    237230        // Allow admins to attach files from media library
     
    240233            $media_id = attachment_url_to_postid($settings['file_attachment']);
    241234
    242             if($media_id !== 0) {
     235            if ($media_id !== 0) {
    243236                $file_path = get_attached_file($media_id);
    244237                if (0 < strlen($file_path)) {
     
    248241        }
    249242
    250         $attachments = apply_filters( 'ninja_forms_action_email_attachments', $attachments, $data, $settings );
     243        $attachments = apply_filters('ninja_forms_action_email_attachments', $attachments, $data, $settings);
    251244
    252245        return $attachments;
    253246    }
    254247
    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)
    269262    {
    270263        $headers = array();
    271264
    272265        $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'],
    276269        );
    277270
    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;
    285278
    286279                $matches = array();
     
    296289    }
    297290
    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;
    303296
    304297        $recipient = "$type: $name <$email>";
     
    307300    }
    308301
    309     private function _create_csv( $fields )
     302    private function _create_csv($fields)
    310303    {
    311304        $csv_array = array();
    312305
    313306        // 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) {
    320313
    321314            $ignore = array(
     
    330323            );
    331324
    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'];
    338331            // Escape labels.
    339332            $label = WPN_Helper::maybe_escape_csv_column($label);
    340333
    341             if($field["type"] === "repeater" && isset($field['fields'])){
     334            if ($field["type"] === "repeater" && isset($field['fields'])) {
    342335                $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) {
    345338                        $matching_value = substr($in_field_value['id'], 0, strlen($field_model['id'])) === $field_model['id'];
    346339                        $index_found = substr($in_field_value['id'], strpos($in_field_value['id'], "_") + 1);
    347                         if( $matching_value ){
     340                        if ($matching_value) {
    348341                            //Catch specific file uploeds data
    349                             if(isset($in_field_value["files"])){
     342                            if (isset($in_field_value["files"])) {
    350343                                $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"];
    353346                                }
    354347                                $in_field_value['value'] = implode(" , ", $field_files_names);
    355348                            }
    356349
    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";
    358351                        };
    359352                    }
    360353                }
    361 
    362354            } 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)) {
    365357                    $value = '';
    366358                }
    367                 if ( is_array( $value ) ) {
    368                     $value = implode( ',', $value );
     359                if (is_array($value)) {
     360                    $value = implode(',', $value);
    369361                }
    370362            }
    371363
    372364            // 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")
    383376        );
    384377
    385378        $upload_dir = wp_upload_dir();
    386         $path = trailingslashit( $upload_dir['path'] );
     379        $path = trailingslashit($upload_dir['path']);
    387380
    388381        // 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+');
    391384
    392385        // write to temp file
    393         fwrite( $temp_file, $csv_content );
    394         fclose( $temp_file );
     386        fwrite($temp_file, $csv_content);
     387        fclose($temp_file);
    395388
    396389        // find the directory we will be using for the final file
    397         $path = pathinfo( $path );
     390        $path = pathinfo($path);
    398391        $dir = $path['dirname'];
    399392        $basename = $path['basename'];
    400393
    401394        // 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');
    403396
    404397        // 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');
    407400        }
    408401
    409402        // 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';
    412405    }
    413406
     
    418411    {
    419412        $upload_dir = wp_upload_dir();
    420         $path = trailingslashit( $upload_dir['path'] );
     413        $path = trailingslashit($upload_dir['path']);
    421414
    422415        // 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');
    424417
    425418        // 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');
    428421        }
    429422    }
     
    435428    private function _backwards_compatibility()
    436429    {
    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);
    469462    }
    470463}
  • ninja-forms/trunk/includes/Actions/ExportDataRequest.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Actions_ExportPersonalData
    511 */
    6 final class NF_Actions_ExportDataRequest extends NF_Abstracts_Action
     12final class NF_Actions_ExportDataRequest extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9      * @var string
    10      */
    11     protected $_name  = 'exportdatarequest';
     14    use SotGetActionProperties;
    1215
    1316    /**
     
    1518     */
    1619    protected $_tags = array();
    17 
    18     /**
    19      * @var string
    20      */
    21     protected $_documentation_url = 'https://ninjaforms.com/docs/export-data-request-action/';
    22 
    23     /**
    24      * @var string
    25      */
    26     protected $_timing = 'late';
    27 
    28     /**
    29      * @var int
    30      */
    31     protected $_priority = 10;
    32 
    33     /**
    34      * @var string
    35      */
    36     protected $_group = 'core';
    3720
    3821    /**
     
    4326        parent::__construct();
    4427
    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';
    4633
    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);
    4943    }
    5044
     
    5347    */
    5448
    55     public function save( $action_settings )
    56     {
    57 
    58     }
    5949
    6050    /**
     
    6858     * @return array
    6959     */
    70     public function process( $action_settings, $form_id, $data )
     60    public function process(array  $action_settings, int $form_id, array $data): array
    7161    {
    7262        $data = array();
    7363
    74         if( isset( $data['settings']['is_preview'] ) && $data['settings']['is_preview'] ){
     64        if (isset($data['settings']['is_preview']) && $data['settings']['is_preview']) {
    7565            return $data;
    7666        }
    7767
    7868        // get the email setting
    79         $email = $action_settings[ 'email' ];
     69        $email = $action_settings['email'];
    8070
    8171        // 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        );
    8476
    8577        /**
     
    9082         * 2) The email does not belong to an actual user.
    9183         */
    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);
    9486        }
    9587
  • ninja-forms/trunk/includes/Actions/Recaptcha.php

    r3101843 r3204929  
    11<?php
    22
    3 if ( ! defined( 'ABSPATH' ) || ! class_exists( 'NF_Abstracts_Action' ) ) {
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH') ) {
    48    exit;
    59}
     
    812 * Class NF_Actions_Recaptcha
    913 */
    10 final class NF_Actions_Recaptcha extends NF_Abstracts_Action {
     14final 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');
    1122
    1223    /**
    1324     * @var string
    1425     */
    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;
    1637
    1738    /**
    1839     * @var array
    1940     */
    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;
    5142
    5243    /**
    5344     * @var array
    5445     */
    55     protected $forms_with_action;
    56 
    57     /**
    58      * @var array
    59      */
    60     protected $_settings_exclude = array( 'conditions' );
     46    protected $_settings_exclude = array('conditions');
    6147
    6248    /**
    6349     * Constructor
    6450     */
    65     public function __construct() {
     51    public function __construct()
     52    {
    6653        parent::__construct();
    6754
    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');
    8482    }
    8583
     
    9189     * @return void
    9290     */
    93     public function set_form_id( $form_id )
     91    public function set_form_id($form_id)
    9492    {
    9593        $this->form_id = $form_id;
    9694    }
    9795
    98     public function get_form_id() {
    99         if ( $this->form_id ) {
     96    public function get_form_id()
     97    {
     98        if ($this->form_id) {
    10099            return $this->form_id;
    101100        }
    102101
    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);
    104103
    105104        return $this->form_id;
     
    113112     * @return array
    114113     */
    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]);
    118118        }
    119119
     
    124124     * @return bool
    125125     */
    126     protected function is_action_enabled_for_form() {
     126    protected function is_action_enabled_for_form()
     127    {
    127128        $form_id = $this->get_form_id();
    128129
    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();
    134135
    135136        $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')) {
    138139                $enabled = true;
    139140                break;
     
    141142        }
    142143
    143         $this->forms_with_action[ $form_id ] = $enabled;
     144        $this->forms_with_action[$form_id] = $enabled;
    144145
    145146        return $enabled;
     
    151152     * @return bool
    152153     */
    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)) {
    155157            return false;
    156158        }
     
    164166     * @return bool
    165167     */
    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()) {
    172175            return false;
    173176        }
     
    176179    }
    177180
    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()) {
    180184            return;
    181185        }
     
    183187        $file_path = Ninja_Forms::$dir . 'includes/Templates/';
    184188
    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);
    190195    }
    191196
     
    197202     * @return array
    198203     */
    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()) {
    201207            return $fields;
    202208        }
    203209
    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')) {
    206212                // Remove v2 reCAPTCHA fields if still configured
    207                 unset( $fields[ $key ] );
     213                unset($fields[$key]);
    208214            }
    209215        }
     
    220226     * @return bool
    221227     */
    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()) {
    224231            return $show;
    225232        }
    226233
    227         if ( 'recaptcha' !== $field->get_type() ) {
     234        if ('recaptcha' !== $field->get_type()) {
    228235            return $show;
    229236        }
    230237
    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')) {
    235242                // recaptcha v2 field exists on form, don't hide it as it will break the JS
    236243                return $show;
     
    248255     * @return array
    249256     */
    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()) {
    252260            return $fields;
    253261        }
    254262
    255         $field_id = $this->get_field_id_hash( $form_id );
     263        $field_id = $this->get_field_id_hash($form_id);
    256264
    257265        $field = array(
     
    259267            'objectDomain'      => 'fields',
    260268            'editActive'        => false,
    261             'order'             => number_format( count( $fields ) + 1, 1 ),
     269            'order'             => number_format(count($fields) + 1, 1),
    262270            'type'              => 'recaptcha_v3',
    263271            'label'             => 'Hidden',
     
    287295    }
    288296
    289     public function enqueue_script() {
    290         if ( ! $this->is_action_configured() ) {
     297    public function enqueue_script()
     298    {
     299        if (! $this->is_action_configured()) {
    291300            return;
    292301        }
    293302
    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);
    298307        }
    299308    }
     
    304313     * @return bool
    305314     */
    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)) {
    308318            // Allow other plugins to tell Ninja Forms not to load the Google JS script, if they are doing that
    309319            return false;
     
    312322        $scripts = wp_scripts();
    313323
    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')) {
    316326                return false;
    317327            }
     
    321331    }
    322332
    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);
    329340
    330341        // 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);
    333344        }
    334345
     
    336347    }
    337348
    338     protected function get_recaptcha_response() {
     349    protected function get_recaptcha_response()
     350    {
    339351        $form_data = $this->get_form_data();
    340352
    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'];
    352364    }
    353365
     
    361373     * @return array
    362374     */
    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()) {
    365378            return $data;
    366379        }
     
    368381        $recaptcha_response = $this->get_recaptcha_response();
    369382
    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');
    372385
    373386            return $data;
    374387        }
    375388
    376         if ( $this->is_submission_human( $recaptcha_response, $action_settings['score'] ) ) {
     389        if ($this->is_submission_human($recaptcha_response, $action_settings['score'])) {
    377390            return $data;
    378391        }
    379392
    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');
    381394
    382395        return $data;
    383396    }
    384397
    385     protected function is_submission_human( $token, $score_threshold ) {
     398    protected function is_submission_human($token, $score_threshold)
     399    {
    386400        $endpoint = 'https://www.google.com/recaptcha/api/siteverify';
    387401
     
    389403            'body' => array(
    390404                'secret'   => $this->site_secret,
    391                 'response' => esc_html( $token ),
     405                'response' => esc_html($token),
    392406            ),
    393407        );
    394408
    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));
    400414            }
    401415
     
    403417        }
    404418
    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);
    411425        $is_human  = $threshold < $score;
    412426
    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);
    414428
    415429        return $is_human;
  • ninja-forms/trunk/includes/Actions/Redirect.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Action_Redirect
    511 */
    6 final class NF_Actions_Redirect extends NF_Abstracts_Action
     12final class NF_Actions_Redirect extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9     * @var string
    10     */
    11     protected $_name  = 'redirect';
     14    use SotGetActionProperties;
    1215
    1316    /**
    14     * @var array
    15     */
     17     * @var array
     18     */
    1619    protected $_tags = array();
    1720
    1821    /**
    19      * @var string
     22     * Constructor
    2023     */
    21     protected $_documentation_url = 'https://ninjaforms.com/docs/redirect-action/';
    22 
    23     /**
    24     * @var string
    25     */
    26     protected $_timing = 'late';
    27 
    28     /**
    29     * @var int
    30     */
    31     protected $_priority = 20;
    32 
    33     /**
    34      * @var string
    35      */
    36     protected $_group = 'core';
    37 
    38     /**
    39     * Constructor
    40     */
    4124    public function __construct()
    4225    {
    4326        parent::__construct();
    4427
    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';
    4633
    47         $settings = Ninja_Forms::config( 'ActionRedirectSettings' );
    48 
    49         $this->_settings = array_merge( $this->_settings, $settings );
     34        add_action('init', [$this, 'initHook']);
    5035    }
    5136
     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    }
    5246    /*
    5347    * PUBLIC METHODS
    5448    */
    5549
    56     public function save( $action_settings )
     50
     51    /** @inheritDoc */
     52    public function process(array $action_settings, int $form_id, array $data): array
    5753    {
    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'];
    6455
    6556        return $data;
  • ninja-forms/trunk/includes/Actions/Save.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Action_Save
    511 */
    6 class NF_Actions_Save extends NF_Abstracts_Action
     12class NF_Actions_Save extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9     * @var string
    10     */
    11     protected $_name  = 'save';
    12 
    13     /**
    14     * @var array
    15     */
     14    use SotGetActionProperties;
     15
     16    /**
     17     * @var array
     18     */
    1619    protected $_tags = array();
    1720
    1821    /**
    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     */
    4124    public function __construct()
    4225    {
    4326        parent::__construct();
    4427
    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);
    5144    }
    5245
     
    5548    */
    5649
    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;
    6054        // 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);
    6357    }
    6458
     
    7367     * @return void
    7468     */
    75     public function submission_expiration_processing( $action_settings, $form_id )
     69    public function submission_expiration_processing($action_settings, $form_id)
    7670    {
    7771        /*
     
    7973         * Example: 5,90
    8074         */
    81         $expiration_value = $form_id . ',' . $action_settings[ 'subs_expire_time' ];
     75        $expiration_value = $form_id . ',' . $action_settings['subs_expire_time'];
    8276
    8377        // Get our expiration option.
    84         $option = $this->getOption( 'nf_sub_expiration', array() );
     78        $option = $this->getOption('nf_sub_expiration', array());
    8579
    8680        // 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
    8983        // 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']) {
    9185            $expiration_option[] = $expiration_value;
    9286        }
    9387
    9488        // Update our option.
    95         $this->updateOption( 'nf_sub_expiration', $expiration_option  );
     89        $this->updateOption('nf_sub_expiration', $expiration_option);
    9690    }
    9791
     
    10599    protected function getOption(string $key, $default)
    106100    {
    107         $return = get_option( $key, $default );
     101        $return = get_option($key, $default);
    108102
    109103        return $return;
     
    117111     * @return void
    118112     */
    119     protected function updateOption(string $key,$value): void
    120     {
    121         update_option( $key, $value );
     113    protected function updateOption(string $key, $value): void
     114    {
     115        update_option($key, $value);
    122116    }
    123117    /**
     
    134128     * @return array $expiration_option without current saved form
    135129     */
    136     public function clean_form_option( $expiration_value, $expiration_option ){
     130    public function clean_form_option($expiration_value, $expiration_option)
     131    {
    137132        /*
    138133         * Breaks a part our options.
     
    140135         *      $value[ 1 ] - ( int ) Expiration time in days
    141136         */
    142         $values = explode( ',', $expiration_value );
     137        $values = explode(',', $expiration_value);
    143138
    144139        // Find the position of the value we are tyring to update.
    145140        //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]) {
    149144                unset($expiration_option[$index]);
    150145            }
    151146        }
    152        
     147
    153148        return $expiration_option;
    154149    }
    155150
    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']) {
    160156            return $data;
    161157        }
    162158
    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());
    168164
    169165        // For each field on the form...
    170         foreach( $data['fields'] as $field ){
     166        foreach ($data['fields'] as $field) {
    171167
    172168            // 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))) {
    174170                // Do not save it.
    175                 $data[ 'actions' ][ 'save' ][ 'hidden' ][] = $field[ 'type' ];
     171                $data['actions']['save']['hidden'][] = $field['type'];
    176172                continue;
    177173            }
    178174
    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'];
    182178            $save_field = true;
    183179
    184180            // 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;
    187183                // For each exception to that rule...
    188                 foreach( $action_settings[ 'exception_fields' ] as $exception_field ) {
     184                foreach ($action_settings['exception_fields'] as $exception_field) {
    189185                    // 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                }
    195191            } // 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;
    198194                // 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                ) {
    201199                    // 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                }
    207205            }
    208206
    209207            // If we're supposed to save this field...
    210             if( $save_field ) {
     208            if ($save_field) {
    211209                // Do so.
    212                 $sub->update_field_value( $field[ 'id' ], $field[ 'value' ] );
     210                $sub->update_field_value($field['id'], $field['value']);
    213211            } // Otherwise...
    214212            else {
     
    217215                // AND If this field is not a product...
    218216                // 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                ) {
    223223                    // Anonymize it.
    224                     $sub->update_field_value( $field[ 'id' ], '(redacted)' );
     224                    $sub->update_field_value($field['id'], '(redacted)');
    225225                }
    226226            }
     
    228228
    229229        // 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);
    233233
    234234            // 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());
    239239
    240240        $sub->save();
    241241
    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();
    247247
    248248        return $data;
     
    262262     * @return array
    263263     */
    264     protected function validateExtraData( $dataExtra, $form_id): array
     264    protected function validateExtraData($dataExtra, $form_id): array
    265265    {
    266266        return $dataExtra;
    267267        $return = [];
    268        
    269         if(!is_array($dataExtra)){
     268
     269        if (!is_array($dataExtra)) {
    270270            return $return;
    271271        }
    272272
    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);
    278278        }
    279279
    280280        return $return;
    281 
    282281    }
    283282}
  • ninja-forms/trunk/includes/Actions/SuccessMessage.php

    r3115129 r3204929  
    1 <?php if ( ! defined( 'ABSPATH' ) ) exit;
     1<?php
     2
     3use NinjaForms\Includes\Abstracts\SotAction;
     4use NinjaForms\Includes\Traits\SotGetActionProperties;
     5use NinjaForms\Includes\Interfaces\SotAction as InterfacesSotAction;
     6
     7if (! defined('ABSPATH')) exit;
    28
    39/**
    410 * Class NF_Action_SuccessMessage
    511 */
    6 final class NF_Actions_SuccessMessage extends NF_Abstracts_Action
     12final class NF_Actions_SuccessMessage extends SotAction implements InterfacesSotAction
    713{
    8     /**
    9     * @var string
    10     */
    11     protected $_name  = 'successmessage';
     14    use SotGetActionProperties;
    1215
    1316    /**
    14     * @var array
    15     */
     17     * @var array
     18     */
    1619    protected $_tags = array();
    1720
    1821    /**
    19      * @var string
     22     * Constructor
    2023     */
    21     protected $_documentation_url = 'https://ninjaforms.com/docs/success-message/';
    22 
    23     /**
    24     * @var string
    25     */
    26     protected $_timing = 'late';
    27 
    28     /**
    29     * @var int
    30     */
    31     protected $_priority = 10;
    32 
    33     /**
    34      * @var string
    35      */
    36     protected $_group = 'core';
    37 
    38     /**
    39     * Constructor
    40     */
    4124    public function __construct()
    4225    {
    4326        parent::__construct();
    4427
    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';
    4633
    47         $settings = Ninja_Forms::config( 'ActionSuccessMessageSettings' );
     34        add_action('init', [$this, 'initHook']);
    4835
    49         $this->_settings = array_merge( $this->_settings, $settings );
     36        add_action('nf_before_import_form', array($this, 'import_form_action_success_message'), 11);
     37    }
    5038
    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);
    5246    }
    5347
     
    5650    */
    5751
    58     public function save( $action_settings )
     52
     53    /** @inheritDoc */
     54    public function process(array $action_settings, int $form_id, array $data): array
    5955    {
     56        if (isset($action_settings['success_msg'])) {
    6057
    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'] = '';
    6960            }
    7061
    7162            ob_start();
    72             do_shortcode( $action_settings['success_msg'] );
     63            do_shortcode($action_settings['success_msg']);
    7364            $ob = ob_get_clean();
    7465
    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');
    7768                $data['actions']['success_message'] .= $action_settings['success_msg'];
    7869            } 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);
    8172            }
    8273        }
     
    8576    }
    8677
    87     public function import_form_action_success_message( $import )
     78    public function import_form_action_success_message($import)
    8879    {
    89         if( ! isset( $import[ 'actions' ] ) ) return $import;
     80        if (! isset($import['actions'])) return $import;
    9081
    91         foreach( $import[ 'actions' ] as &$action ){
     82        foreach ($import['actions'] as &$action) {
    9283
    93             if( 'success_message' == $action[ 'type' ] ){
     84            if ('success_message' == $action['type']) {
    9485
    95                 $action[ 'type' ] = 'successmessage';
     86                $action['type'] = 'successmessage';
    9687            }
    9788        }
  • ninja-forms/trunk/includes/Admin/VersionCompatibilityCheck.php

    r2869579 r3204929  
    4242  public function activate(): void
    4343  {
    44     add_action('ninja_forms_loaded', array($this, 'ensureVersionCompatibility'), 0);
     44    add_action('init', array($this, 'ensureVersionCompatibility'), 0);
    4545  }
    4646
  • ninja-forms/trunk/ninja-forms.php

    r3197483 r3204929  
    44Plugin URI: http://ninjaforms.com/?utm_source=WordPress&utm_medium=readme
    55Description: Ninja Forms is a webform builder with unparalleled ease of use and features.
    6 Version: 3.8.20
     6Version: 3.8.21
    77Author: Saturday Drive
    88Author URI: http://ninjaforms.com/?utm_source=Ninja+Forms+Plugin&utm_medium=Plugins+WP+Dashboard
     
    4444     */
    4545
    46     const VERSION = '3.8.20';
     46    const VERSION = '3.8.21';
    4747
    4848    /**
     
    362362            require_once Ninja_Forms::$dir . 'blocks/ninja-forms-blocks.php';
    363363
    364             /*
    365                 * Submission Metabox
    366                 */
    367             new NF_Admin_Metaboxes_Calculations();
    368364
    369365            /*
     
    382378            self::$instance->_dispatcher = new NF_Dispatcher();
    383379
    384             /*
    385                 * Merge Tags
    386                 */
    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();
    393380
    394381            /*
     
    409396            (new VersionCompatibilityCheck())->activate();
    410397
    411             self::$instance->widgets[] = new NF_Widget();
    412398
    413399            /*
     
    429415            register_activation_hook( __FILE__, array( self::$instance, 'activation' ) );
    430416
    431             self::$instance->metaboxes[ 'append-form' ] = new NF_Admin_Metaboxes_AppendAForm();
    432417
    433418
     
    462447        add_action( 'ninja_forms_available_actions', array( self::$instance, 'scrub_available_actions' ) );
    463448
     449        add_action( 'init', array( self::$instance, 'instantiateTranslatableObjects' ), 5 );
    464450        add_action( 'init', array( self::$instance, 'init' ), 5 );
    465451        add_action( 'admin_init', array( self::$instance, 'admin_init' ), 5 );
     
    492478    }
    493479
     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   
    494514    public function register_rewrite_rules()
    495515    {
     
    743763        load_plugin_textdomain( 'ninja-forms', false, basename( dirname( __FILE__ ) ) . '/lang' );
    744764
    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
    758766
    759767        /*
  • ninja-forms/trunk/readme.txt

    r3197483 r3204929  
    66Requires at least: 6.5
    77Tested up to: 6.7
    8 Stable tag: 3.8.20
     8Stable tag: 3.8.21
    99
    1010Requires PHP: 7.4
     
    313313
    314314== Upgrade Notice ==
    315 = 3.8.20 (26 November 2024) =
    316 *Bug Fixes:*
    317 - Sanitize calculations input
     315= 3.8.21 (09 December 2024) =
     316*Bug Fixes:*
     317- Update timing to load translations after init
    318318
    319319== Changelog ==
     320= 3.8.21 (09 December 2024) =
     321*Bug Fixes:*
     322- Update timing to load translations after init
     323
    320324= 3.8.20 (26 November 2024) =
    321325*Bug Fixes:*
  • ninja-forms/trunk/vendor/composer/installed.php

    r3197483 r3204929  
    22    'root' => array(
    33        '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',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1212    'versions' => array(
    1313        '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',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.