Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/ninja-fo.../includes/Actions
File: Save.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Class NF_Action_Save
[3] Fix | Delete
*/
[4] Fix | Delete
final class NF_Actions_Save extends NF_Abstracts_Action
[5] Fix | Delete
{
[6] Fix | Delete
/**
[7] Fix | Delete
* @var string
[8] Fix | Delete
*/
[9] Fix | Delete
protected $_name = 'save';
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* @var array
[13] Fix | Delete
*/
[14] Fix | Delete
protected $_tags = array();
[15] Fix | Delete
[16] Fix | Delete
/**
[17] Fix | Delete
* @var string
[18] Fix | Delete
*/
[19] Fix | Delete
protected $_timing = 'late';
[20] Fix | Delete
[21] Fix | Delete
/**
[22] Fix | Delete
* @var int
[23] Fix | Delete
*/
[24] Fix | Delete
protected $_priority = '-1';
[25] Fix | Delete
[26] Fix | Delete
/**
[27] Fix | Delete
* Constructor
[28] Fix | Delete
*/
[29] Fix | Delete
public function __construct()
[30] Fix | Delete
{
[31] Fix | Delete
parent::__construct();
[32] Fix | Delete
[33] Fix | Delete
$this->_nicename = esc_html__( 'Store Submission', 'ninja-forms' );
[34] Fix | Delete
[35] Fix | Delete
$settings = Ninja_Forms::config( 'ActionSaveSettings' );
[36] Fix | Delete
[37] Fix | Delete
$this->_settings = array_merge( $this->_settings, $settings );
[38] Fix | Delete
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
/*
[42] Fix | Delete
* PUBLIC METHODS
[43] Fix | Delete
*/
[44] Fix | Delete
[45] Fix | Delete
public function save( $action_settings )
[46] Fix | Delete
{
[47] Fix | Delete
if( ! isset( $_POST[ 'form' ] ) ) return;
[48] Fix | Delete
// Get the form data from the Post variable and send it off for processing.
[49] Fix | Delete
$form = json_decode( stripslashes( $_POST[ 'form' ] ) );
[50] Fix | Delete
$this->submission_expiration_processing( $action_settings, $form->id );
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* Submission Expiration Processing
[55] Fix | Delete
* Decides if the submission expiration data should be added to the
[56] Fix | Delete
* submission expiration option or not.
[57] Fix | Delete
*
[58] Fix | Delete
* @param $action_settings - array.
[59] Fix | Delete
* @param $form_id - ( int ) The ID of the Form.
[60] Fix | Delete
*
[61] Fix | Delete
* @return void
[62] Fix | Delete
*/
[63] Fix | Delete
public function submission_expiration_processing( $action_settings, $form_id )
[64] Fix | Delete
{
[65] Fix | Delete
/*
[66] Fix | Delete
* Comma separated value of the form id and action setting.
[67] Fix | Delete
* Example: 5,90
[68] Fix | Delete
*/
[69] Fix | Delete
$expiration_value = $form_id . ',' . $action_settings[ 'subs_expire_time' ];
[70] Fix | Delete
[71] Fix | Delete
// Check for option value...
[72] Fix | Delete
$option = get_option( 'nf_sub_expiration', array() );
[73] Fix | Delete
[74] Fix | Delete
// If our expiration setting is turned on...
[75] Fix | Delete
if( 1 == $action_settings[ 'set_subs_to_expire' ] ) {
[76] Fix | Delete
// Send our data to the compare method to be added to the expiration option
[77] Fix | Delete
$this->compare_expiration_option( $expiration_value, $option );
[78] Fix | Delete
} else {
[79] Fix | Delete
// Otherwise send the data to be removed from the expiration option.
[80] Fix | Delete
$this->remove_expiration_option( $expiration_value, $option );
[81] Fix | Delete
}
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Compare Expiration Option
[86] Fix | Delete
* Accepts $expiration_data and checks to see if the values already exist in the array.
[87] Fix | Delete
* @since 3.3.2
[88] Fix | Delete
*
[89] Fix | Delete
* @param array $expiration_value - key/value pair
[90] Fix | Delete
* $expiration_value[ 'form_id' ] = form_id(int)
[91] Fix | Delete
* $expiration_value[ 'expire_time' ] = subs_expire_time(int)
[92] Fix | Delete
* @param array $expiration_option - list of key/value pairs of the expiration options.
[93] Fix | Delete
*
[94] Fix | Delete
* @return void
[95] Fix | Delete
*/
[96] Fix | Delete
public function compare_expiration_option( $expiration_value, $expiration_option )
[97] Fix | Delete
{
[98] Fix | Delete
/*
[99] Fix | Delete
* Breaks a part our options.
[100] Fix | Delete
* $value[ 0 ] - ( int ) Form ID
[101] Fix | Delete
* $value[ 1 ] - ( int ) Expiration time in days
[102] Fix | Delete
*/
[103] Fix | Delete
$values = explode( ',', $expiration_value );
[104] Fix | Delete
[105] Fix | Delete
// Find the position of the value we are tyring to update.
[106] Fix | Delete
$array_position = array_search( ( int ) $values[ 0 ], $expiration_option );
[107] Fix | Delete
[108] Fix | Delete
/*
[109] Fix | Delete
* TODO: Refactor this to only run when needed.
[110] Fix | Delete
* Remove this value from the array.
[111] Fix | Delete
*/
[112] Fix | Delete
if( isset( $array_position ) ) {
[113] Fix | Delete
unset( $expiration_option[ $array_position ] );
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
// Check for our value in the options and then add it if it doesn't exist.
[117] Fix | Delete
if( ! in_array( $expiration_value, $expiration_option ) ) {
[118] Fix | Delete
$expiration_option[] = $expiration_value;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
// Update our option.
[122] Fix | Delete
update_option( 'nf_sub_expiration', $expiration_option );
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
/**
[126] Fix | Delete
* Remove Expiration Option
[127] Fix | Delete
* If the expiration action setting is turned off this helper method
[128] Fix | Delete
* removes the form id and expiration time from the option.
[129] Fix | Delete
*
[130] Fix | Delete
* @param array $expiration_value - key/value pair
[131] Fix | Delete
* $expiration_value[ 'form_id' ] = form_id(int)
[132] Fix | Delete
* $expiration_value[ 'expire_time' ] = subs_expire_time(int)
[133] Fix | Delete
* @param array $expiration_option - list of key/value pairs of the expiration options.
[134] Fix | Delete
*
[135] Fix | Delete
* @return void
[136] Fix | Delete
*/
[137] Fix | Delete
public function remove_expiration_option( $expiration_value, $expiration_option )
[138] Fix | Delete
{
[139] Fix | Delete
$values = explode( ',', $expiration_value );
[140] Fix | Delete
[141] Fix | Delete
// Find the position of the value we are tyring to update.
[142] Fix | Delete
$array_position = array_search( ( int ) $values[ 0 ], $expiration_option );
[143] Fix | Delete
[144] Fix | Delete
/*
[145] Fix | Delete
* TODO: Refactor this to only run when needed.
[146] Fix | Delete
* Remove this value from the array.
[147] Fix | Delete
*/
[148] Fix | Delete
if( isset( $array_position ) ) {
[149] Fix | Delete
unset( $expiration_option[ $array_position ] );
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
// Update our option.
[153] Fix | Delete
update_option( 'nf_sub_expiration', $expiration_option );
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
public function process( $action_settings, $form_id, $data )
[157] Fix | Delete
{
[158] Fix | Delete
if( isset( $data['settings']['is_preview'] ) && $data['settings']['is_preview'] ){
[159] Fix | Delete
return $data;
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
if( ! apply_filters ( 'ninja_forms_save_submission', true, $form_id ) ) return $data;
[163] Fix | Delete
[164] Fix | Delete
$sub = Ninja_Forms()->form( $form_id )->sub()->get();
[165] Fix | Delete
[166] Fix | Delete
$hidden_field_types = apply_filters( 'nf_sub_hidden_field_types', array() );
[167] Fix | Delete
[168] Fix | Delete
// For each field on the form...
[169] Fix | Delete
foreach( $data['fields'] as $field ){
[170] Fix | Delete
[171] Fix | Delete
// If this is a "hidden" field type.
[172] Fix | Delete
if( in_array( $field[ 'type' ], array_values( $hidden_field_types ) ) ) {
[173] Fix | Delete
// Do not save it.
[174] Fix | Delete
$data[ 'actions' ][ 'save' ][ 'hidden' ][] = $field[ 'type' ];
[175] Fix | Delete
continue;
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
$field[ 'value' ] = apply_filters( 'nf_save_sub_user_value', $field[ 'value' ], $field[ 'id' ] );
[179] Fix | Delete
[180] Fix | Delete
$save_all_none = $action_settings[ 'fields-save-toggle' ];
[181] Fix | Delete
$save_field = true;
[182] Fix | Delete
[183] Fix | Delete
// If we were told to save all fields...
[184] Fix | Delete
if( 'save_all' == $save_all_none ) {
[185] Fix | Delete
$save_field = true;
[186] Fix | Delete
// For each exception to that rule...
[187] Fix | Delete
foreach( $action_settings[ 'exception_fields' ] as $exception_field ) {
[188] Fix | Delete
// Remove it from the list.
[189] Fix | Delete
if( $field[ 'key' ] == $exception_field[ 'field'] ) {
[190] Fix | Delete
$save_field = false;
[191] Fix | Delete
break;
[192] Fix | Delete
}
[193] Fix | Delete
}
[194] Fix | Delete
} // Otherwise... (We were told to save no fields.)
[195] Fix | Delete
else if( 'save_none' == $save_all_none ) {
[196] Fix | Delete
$save_field = false;
[197] Fix | Delete
// For each exception to that rule...
[198] Fix | Delete
foreach( $action_settings[ 'exception_fields' ] as
[199] Fix | Delete
$exception_field ) {
[200] Fix | Delete
// Add it to the list.
[201] Fix | Delete
if( $field[ 'key' ] == $exception_field[ 'field'] ) {
[202] Fix | Delete
$save_field = true;
[203] Fix | Delete
break;
[204] Fix | Delete
}
[205] Fix | Delete
}
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
// If we're supposed to save this field...
[209] Fix | Delete
if( $save_field ) {
[210] Fix | Delete
// Do so.
[211] Fix | Delete
$sub->update_field_value( $field[ 'id' ], $field[ 'value' ] );
[212] Fix | Delete
} // Otherwise...
[213] Fix | Delete
else {
[214] Fix | Delete
// If this field is not a list...
[215] Fix | Delete
// AND If this field is not a checkbox...
[216] Fix | Delete
// AND If this field is not a product...
[217] Fix | Delete
// AND If this field is not a termslist...
[218] Fix | Delete
if ( false == strpos( $field[ 'type' ], 'list' ) &&
[219] Fix | Delete
false == strpos( $field[ 'type' ], 'checkbox' ) &&
[220] Fix | Delete
'products' !== $field[ 'type' ] &&
[221] Fix | Delete
'terms' !== $field[ 'type' ] ) {
[222] Fix | Delete
// Anonymize it.
[223] Fix | Delete
$sub->update_field_value( $field[ 'id' ], '(redacted)' );
[224] Fix | Delete
}
[225] Fix | Delete
}
[226] Fix | Delete
}
[227] Fix | Delete
[228] Fix | Delete
// If we have extra data...
[229] Fix | Delete
if( isset( $data[ 'extra' ] ) ) {
[230] Fix | Delete
// Save that.
[231] Fix | Delete
$sub->update_extra_values( $data[ 'extra' ] );
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
do_action( 'nf_before_save_sub', $sub->get_id() );
[235] Fix | Delete
[236] Fix | Delete
$sub->save();
[237] Fix | Delete
[238] Fix | Delete
do_action( 'nf_save_sub', $sub->get_id() );
[239] Fix | Delete
do_action( 'nf_create_sub', $sub->get_id() );
[240] Fix | Delete
do_action( 'ninja_forms_save_sub', $sub->get_id() );
[241] Fix | Delete
[242] Fix | Delete
$data[ 'actions' ][ 'save' ][ 'sub_id' ] = $sub->get_id();
[243] Fix | Delete
[244] Fix | Delete
return $data;
[245] Fix | Delete
}
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function