Edit File by line
/home/barbar84/www/wp-conte.../plugins/ninja-fo.../includes/Admin/Processe...
File: ImportForm.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Class NF_Abstracts_Batch_Process
[3] Fix | Delete
*/
[4] Fix | Delete
class NF_Admin_Processes_ImportForm extends NF_Abstracts_BatchProcess
[5] Fix | Delete
{
[6] Fix | Delete
protected $_slug = 'import_form';
[7] Fix | Delete
[8] Fix | Delete
private $fields_per_step = 20;
[9] Fix | Delete
[10] Fix | Delete
protected $form;
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Store an array of columns that we want to store in our table rather than meta.
[14] Fix | Delete
*
[15] Fix | Delete
* This array stores the column name and the name of the setting that it maps to.
[16] Fix | Delete
*
[17] Fix | Delete
* The format is:
[18] Fix | Delete
*
[19] Fix | Delete
* array( 'COLUMN_NAME' => 'SETTING_NAME' )
[20] Fix | Delete
*/
[21] Fix | Delete
protected $forms_db_columns = array(
[22] Fix | Delete
'title' => 'title',
[23] Fix | Delete
'created_at' => 'created_at',
[24] Fix | Delete
'form_title' => 'title',
[25] Fix | Delete
'default_label_pos' => 'default_label_pos',
[26] Fix | Delete
'show_title' => 'show_title',
[27] Fix | Delete
'clear_complete' => 'clear_complete',
[28] Fix | Delete
'hide_complete' => 'hide_complete',
[29] Fix | Delete
'logged_in' => 'logged_in',
[30] Fix | Delete
'seq_num' => 'seq_num',
[31] Fix | Delete
);
[32] Fix | Delete
[33] Fix | Delete
protected $fields_db_columns = array(
[34] Fix | Delete
'parent_id' => 'parent_id',
[35] Fix | Delete
'id' => 'id',
[36] Fix | Delete
'key' => 'key',
[37] Fix | Delete
'type' => 'type',
[38] Fix | Delete
'label' => 'label',
[39] Fix | Delete
'field_key' => 'key',
[40] Fix | Delete
'field_label' => 'label',
[41] Fix | Delete
'order' => 'order',
[42] Fix | Delete
'required' => 'required',
[43] Fix | Delete
'default_value' => 'default',
[44] Fix | Delete
'label_pos' => 'label_pos',
[45] Fix | Delete
'personally_identifiable' => 'personally_identifiable',
[46] Fix | Delete
);
[47] Fix | Delete
[48] Fix | Delete
protected $actions_db_columns = array(
[49] Fix | Delete
'title' => 'title',
[50] Fix | Delete
'key' =>'key',
[51] Fix | Delete
'type' =>'type',
[52] Fix | Delete
'active' =>'active',
[53] Fix | Delete
'parent_id' =>'parent_id',
[54] Fix | Delete
'created_at' =>'created_at',
[55] Fix | Delete
'updated_at' =>'updated_at',
[56] Fix | Delete
'label' =>'label',
[57] Fix | Delete
);
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Function to run any setup steps necessary to begin processing.
[61] Fix | Delete
*
[62] Fix | Delete
* @since 3.4.0
[63] Fix | Delete
* @return void
[64] Fix | Delete
*/
[65] Fix | Delete
public function startup()
[66] Fix | Delete
{
[67] Fix | Delete
// If we aren't passed any form content, bail.
[68] Fix | Delete
if ( empty ( $_POST[ 'extraData' ][ 'content' ] ) ) {
[69] Fix | Delete
$this->add_error( 'empty_content', esc_html__( 'No export provided.', 'ninja-forms' ), 'fatal' );
[70] Fix | Delete
$this->batch_complete();
[71] Fix | Delete
}
[72] Fix | Delete
$extra_content = WPN_Helper::esc_html($_POST[ 'extraData' ][ 'content']);
[73] Fix | Delete
$data = explode( ';base64,', $extra_content );
[74] Fix | Delete
$data = base64_decode( $data[ 1 ] );
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* $data could now hold two things, depending on whether this was a 2.9 or 3.0 export.
[78] Fix | Delete
*
[79] Fix | Delete
* If it's a 3.0 export, the data will be json encoded.
[80] Fix | Delete
* If it's a 2.9 export, the data will be serialized.
[81] Fix | Delete
*
[82] Fix | Delete
* We're first going to try to json_decode. If we don't get an array, we'll unserialize.
[83] Fix | Delete
*/
[84] Fix | Delete
[85] Fix | Delete
$decoded_data = json_decode( WPN_Helper::json_cleanup( html_entity_decode( $data, ENT_QUOTES ) ), true );
[86] Fix | Delete
[87] Fix | Delete
// If we don't have an array, try unserializing
[88] Fix | Delete
if ( ! is_array( $decoded_data ) ) {
[89] Fix | Delete
$decoded_data = WPN_Helper::maybe_unserialize( $data );
[90] Fix | Delete
if ( ! is_array( $decoded_data ) ) {
[91] Fix | Delete
$decoded_data = json_decode( $decoded_data, true );
[92] Fix | Delete
}
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
// Try to utf8 decode our results.
[96] Fix | Delete
$data = WPN_Helper::utf8_decode( $decoded_data );
[97] Fix | Delete
[98] Fix | Delete
// If json_encode returns false, then this is an invalid utf8 decode.
[99] Fix | Delete
if ( ! json_encode( $data ) ) {
[100] Fix | Delete
$data = $decoded_data;
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
if ( ! is_array( $data ) ) {
[104] Fix | Delete
$this->add_error( 'decode_failed', esc_html__( 'Failed to read export. Please try again.', 'ninja-forms' ), 'fatal' );
[105] Fix | Delete
$this->batch_complete();
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
$data = $this->import_form_backwards_compatibility( $data );
[109] Fix | Delete
[110] Fix | Delete
// $data is now a form array.
[111] Fix | Delete
$this->form = $data;
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Check to see if we've got new field columns.
[115] Fix | Delete
*
[116] Fix | Delete
* We do this here instead of the get_sql_queries() method so that we don't hit the db multiple times.
[117] Fix | Delete
*/
[118] Fix | Delete
$sql = "SHOW COLUMNS FROM {$this->_db->prefix}nf3_fields LIKE 'field_key'";
[119] Fix | Delete
$results = $this->_db->get_results( $sql );
[120] Fix | Delete
[121] Fix | Delete
/**
[122] Fix | Delete
* If we don't have the field_key column, we need to remove our new columns.
[123] Fix | Delete
*
[124] Fix | Delete
* Also, set our db stage 1 tracker to false.
[125] Fix | Delete
*/
[126] Fix | Delete
if ( empty ( $results ) ) {
[127] Fix | Delete
unset( $this->actions_db_columns[ 'label' ] );
[128] Fix | Delete
$db_stage_one_complete = false;
[129] Fix | Delete
} else {
[130] Fix | Delete
// Add a form value that stores whether or not we have our new DB columns.
[131] Fix | Delete
$db_stage_one_complete = true;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
$this->form[ 'db_stage_one_complete' ] = $db_stage_one_complete;
[135] Fix | Delete
}
[136] Fix | Delete
[137] Fix | Delete
/**
[138] Fix | Delete
* On processing steps after the first, we need to grab our data from our saved option.
[139] Fix | Delete
*
[140] Fix | Delete
* @since 3.4.0
[141] Fix | Delete
* @return void
[142] Fix | Delete
*/
[143] Fix | Delete
public function restart()
[144] Fix | Delete
{
[145] Fix | Delete
// Get our remaining fields from the database.
[146] Fix | Delete
$this->form = get_option( 'nf_import_form', array() );
[147] Fix | Delete
}
[148] Fix | Delete
[149] Fix | Delete
/**
[150] Fix | Delete
* Function to loop over the batch.
[151] Fix | Delete
*
[152] Fix | Delete
* @since 3.4.0
[153] Fix | Delete
* @return void
[154] Fix | Delete
*/
[155] Fix | Delete
public function process()
[156] Fix | Delete
{
[157] Fix | Delete
/**
[158] Fix | Delete
* Check to see if our $this->form var contains an 'ID' index.
[159] Fix | Delete
*
[160] Fix | Delete
* If it doesn't, then we need to:
[161] Fix | Delete
* Insert our Form.
[162] Fix | Delete
* Insert our Form Meta.
[163] Fix | Delete
* Insert our Actions.
[164] Fix | Delete
* Insert our Action Meta.
[165] Fix | Delete
* Unset [ 'settings' ] and [ 'actions' ] from $this->form.
[166] Fix | Delete
* Update $this->form[ 'ID' ].
[167] Fix | Delete
* Save our processing option.
[168] Fix | Delete
* Move on to the next step.
[169] Fix | Delete
*/
[170] Fix | Delete
if ( ! isset( $this->form[ 'ID' ] ) ) {
[171] Fix | Delete
$this->insert_form();
[172] Fix | Delete
} else { // We have a form ID set.
[173] Fix | Delete
$this->insert_fields();
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
// If we don't have any more fields to insert, we're done.
[177] Fix | Delete
if ( empty( $this->form[ 'fields' ] ) ) {
[178] Fix | Delete
// Update our form cache for the new form.
[179] Fix | Delete
WPN_Helper::build_nf_cache( $this->form[ 'ID' ] );
[180] Fix | Delete
// We're done with this batch process.
[181] Fix | Delete
$this->batch_complete();
[182] Fix | Delete
} else { // We have fields left to process.
[183] Fix | Delete
/**
[184] Fix | Delete
* If we have fields left, we need to reset the index.
[185] Fix | Delete
* Since fields is a non-associative array, we are looping over it by sequential numeric index.
[186] Fix | Delete
* Resetting the index ensures we always have a 0 -> COUNT() keys.
[187] Fix | Delete
*/
[188] Fix | Delete
$this->form[ 'fields' ] = array_values( $this->form[ 'fields' ] );
[189] Fix | Delete
// Save our progress.
[190] Fix | Delete
update_option( 'nf_import_form', $this->form, 'no' );
[191] Fix | Delete
// Move on to the next step in processing.
[192] Fix | Delete
$this->next_step();
[193] Fix | Delete
}
[194] Fix | Delete
}
[195] Fix | Delete
[196] Fix | Delete
/**
[197] Fix | Delete
* Function to cleanup any lingering temporary elements of a batch process after completion.
[198] Fix | Delete
*/
[199] Fix | Delete
public function cleanup()
[200] Fix | Delete
{
[201] Fix | Delete
// Remove the option we used to track between
[202] Fix | Delete
delete_option( 'nf_import_form' );
[203] Fix | Delete
// Return our new Form ID
[204] Fix | Delete
$this->response[ 'form_id' ] = $this->form[ 'ID' ];
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
/*
[208] Fix | Delete
* Get Steps
[209] Fix | Delete
* Determines the amount of steps needed for the step processors.
[210] Fix | Delete
*
[211] Fix | Delete
* @return int of the number of steps.
[212] Fix | Delete
*/
[213] Fix | Delete
public function get_steps()
[214] Fix | Delete
{
[215] Fix | Delete
/**
[216] Fix | Delete
* We want to run a step for every $this->fields_per_step fields on this form.
[217] Fix | Delete
*
[218] Fix | Delete
* If we have no fields, then we want to return 0.
[219] Fix | Delete
*/
[220] Fix | Delete
if ( ! isset ( $this->form[ 'fields' ] ) || empty ( $this->form[ 'fields' ] ) ) {
[221] Fix | Delete
return 0;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
$steps = count( $this->form[ 'fields' ] ) / $this->fields_per_step;
[225] Fix | Delete
$steps = ceil( $steps );
[226] Fix | Delete
return $steps;
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
/**
[230] Fix | Delete
* Insert our form using $this->_db->insert by building an array of column => value pairs and %s, %d types.
[231] Fix | Delete
*
[232] Fix | Delete
* @since 3.4.0
[233] Fix | Delete
* @return void
[234] Fix | Delete
*/
[235] Fix | Delete
public function insert_form()
[236] Fix | Delete
{
[237] Fix | Delete
$insert_columns = array();
[238] Fix | Delete
$insert_columns_types = array();
[239] Fix | Delete
foreach ( $this->forms_db_columns as $column_name => $setting_name ) {
[240] Fix | Delete
// Make sure we don't try to set created_at to NULL.
[241] Fix | Delete
if( 'created_at' === $column_name && is_null( $this->form[ 'settings' ][ $setting_name ] ) ) continue;
[242] Fix | Delete
$insert_columns[ $column_name ] = $this->form[ 'settings' ][ $setting_name ];
[243] Fix | Delete
if ( is_numeric( $this->form[ 'settings' ][ $setting_name ] ) ) {
[244] Fix | Delete
array_push( $insert_columns_types, '%d' );
[245] Fix | Delete
} else {
[246] Fix | Delete
array_push( $insert_columns_types, '%s' );
[247] Fix | Delete
}
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
$this->_db->insert( "{$this->_db->prefix}nf3_forms", $insert_columns, $insert_columns_types );
[251] Fix | Delete
[252] Fix | Delete
// Update our form ID with the newly inserted row ID.
[253] Fix | Delete
$this->form[ 'ID' ] = $this->_db->insert_id;
[254] Fix | Delete
[255] Fix | Delete
if ( 0 === $this->form[ 'ID' ] ) {
[256] Fix | Delete
$this->add_error( 'insert_failed', esc_html__( 'Failed to insert new form.', 'ninja-forms' ), 'fatal' );
[257] Fix | Delete
$this->batch_complete();
[258] Fix | Delete
}
[259] Fix | Delete
[260] Fix | Delete
$this->insert_form_meta();
[261] Fix | Delete
$this->insert_actions();
[262] Fix | Delete
[263] Fix | Delete
// Remove our settings and actions array items.
[264] Fix | Delete
unset( $this->form[ 'settings' ], $this->form[ 'actions' ] );
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
/**
[268] Fix | Delete
* Insert Form Meta.
[269] Fix | Delete
*
[270] Fix | Delete
* Loop over our remaining form settings that we need to insert into meta.
[271] Fix | Delete
* Add them to our "Values" string for insertion later.
[272] Fix | Delete
*
[273] Fix | Delete
* @since 3.4.0
[274] Fix | Delete
* @return void
[275] Fix | Delete
*/
[276] Fix | Delete
public function insert_form_meta()
[277] Fix | Delete
{
[278] Fix | Delete
$insert_values = '';
[279] Fix | Delete
[280] Fix | Delete
$blacklist = array(
[281] Fix | Delete
'embed_form',
[282] Fix | Delete
'public_link',
[283] Fix | Delete
'public_link_key',
[284] Fix | Delete
'allow_public_link',
[285] Fix | Delete
);
[286] Fix | Delete
$blacklist = apply_filters( 'ninja_forms_excluded_import_form_settings', $blacklist );
[287] Fix | Delete
[288] Fix | Delete
foreach( $this->form[ 'settings' ] as $meta_key => $meta_value ) {
[289] Fix | Delete
if ( in_array( $meta_key, $blacklist ) ) continue;
[290] Fix | Delete
$meta_value = maybe_serialize( $meta_value );
[291] Fix | Delete
$this->_db->escape_by_ref( $meta_value );
[292] Fix | Delete
$insert_values .= "( {$this->form[ 'ID' ]}, '{$meta_key}', '{$meta_value}'";
[293] Fix | Delete
if ( $this->form[ 'db_stage_one_complete'] ) {
[294] Fix | Delete
$insert_values .= ", '{$meta_key}', '{$meta_value}'";
[295] Fix | Delete
}
[296] Fix | Delete
$insert_values .= "),";
[297] Fix | Delete
}
[298] Fix | Delete
[299] Fix | Delete
// Remove the trailing comma.
[300] Fix | Delete
$insert_values = rtrim( $insert_values, ',' );
[301] Fix | Delete
$insert_columns = '`parent_id`, `key`, `value`';
[302] Fix | Delete
if ( $this->form[ 'db_stage_one_complete'] ) {
[303] Fix | Delete
$insert_columns .= ', `meta_key`, `meta_value`';
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
// Create SQL string.
[307] Fix | Delete
$sql = "INSERT INTO {$this->_db->prefix}nf3_form_meta ( {$insert_columns} ) VALUES {$insert_values}";
[308] Fix | Delete
// Run our SQL query.
[309] Fix | Delete
$this->_db->query( $sql );
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
/**
[313] Fix | Delete
* Insert Actions and Action Meta.
[314] Fix | Delete
*
[315] Fix | Delete
* Loop over actions for this form and insert actions and action meta.
[316] Fix | Delete
*
[317] Fix | Delete
* @since 3.4.0
[318] Fix | Delete
* @return void
[319] Fix | Delete
*/
[320] Fix | Delete
public function insert_actions()
[321] Fix | Delete
{
[322] Fix | Delete
foreach( $this->form[ 'actions' ] as $action_settings ) {
[323] Fix | Delete
$action_settings[ 'parent_id' ] = $this->form[ 'ID' ];
[324] Fix | Delete
// Array that tracks which settings need to be meta and which are columns.
[325] Fix | Delete
$action_meta = $action_settings;
[326] Fix | Delete
$insert_columns = array();
[327] Fix | Delete
$insert_columns_types = array();
[328] Fix | Delete
// Loop over all our action columns to get their values.
[329] Fix | Delete
foreach ( $this->actions_db_columns as $column_name => $setting_name ) {
[330] Fix | Delete
$insert_columns[ $column_name ] = $action_settings[ $setting_name ];
[331] Fix | Delete
if ( is_numeric( $action_settings[ $setting_name ] ) ) {
[332] Fix | Delete
array_push( $insert_columns_types, '%d' );
[333] Fix | Delete
} else {
[334] Fix | Delete
array_push( $insert_columns_types, '%s' );
[335] Fix | Delete
}
[336] Fix | Delete
}
[337] Fix | Delete
[338] Fix | Delete
// Insert Action
[339] Fix | Delete
$this->_db->insert( "{$this->_db->prefix}nf3_actions", $insert_columns, $insert_columns_types );
[340] Fix | Delete
[341] Fix | Delete
// Get our new action ID.
[342] Fix | Delete
$action_id = $this->_db->insert_id;
[343] Fix | Delete
[344] Fix | Delete
// Insert Action Meta.
[345] Fix | Delete
$insert_values = '';
[346] Fix | Delete
/**
[347] Fix | Delete
* Anything left in the $action_meta array should be inserted as meta.
[348] Fix | Delete
*
[349] Fix | Delete
* Loop over each of our settings and add it to our insert sql string.
[350] Fix | Delete
*/
[351] Fix | Delete
$insert_values = '';
[352] Fix | Delete
foreach ( $action_meta as $meta_key => $meta_value ) {
[353] Fix | Delete
$meta_value = maybe_serialize( $meta_value );
[354] Fix | Delete
$this->_db->escape_by_ref( $meta_value );
[355] Fix | Delete
$insert_values .= "( {$action_id}, '{$meta_key}', '{$meta_value}'";
[356] Fix | Delete
if ( $this->form[ 'db_stage_one_complete'] ) {
[357] Fix | Delete
$insert_values .= ", '{$meta_key}', '{$meta_value}'";
[358] Fix | Delete
}
[359] Fix | Delete
$insert_values .= "),";
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
// Remove the trailing comma.
[363] Fix | Delete
$insert_values = rtrim( $insert_values, ',' );
[364] Fix | Delete
$insert_columns = '`parent_id`, `key`, `value`';
[365] Fix | Delete
if ( $this->form[ 'db_stage_one_complete'] ) {
[366] Fix | Delete
$insert_columns .= ', `meta_key`, `meta_value`';
[367] Fix | Delete
}
[368] Fix | Delete
// Create SQL string.
[369] Fix | Delete
$sql = "INSERT INTO {$this->_db->prefix}nf3_action_meta ( {$insert_columns} ) VALUES {$insert_values}";
[370] Fix | Delete
[371] Fix | Delete
// Run our SQL query.
[372] Fix | Delete
$this->_db->query( $sql );
[373] Fix | Delete
}
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
/**
[377] Fix | Delete
* If we have a Form ID set, then we've already inserted our Form, Form Meta, Actions, and Action Meta.
[378] Fix | Delete
* All we have left to insert are fields.
[379] Fix | Delete
*
[380] Fix | Delete
* Loop over our fields array and insert up to $this->fields_per_step.
[381] Fix | Delete
* After we've inserted the field, unset it from our form array.
[382] Fix | Delete
* Update our processing option with $this->form.
[383] Fix | Delete
* Respond with the remaining steps.
[384] Fix | Delete
*
[385] Fix | Delete
* @since 3.4.0
[386] Fix | Delete
* @return void
[387] Fix | Delete
*/
[388] Fix | Delete
public function insert_fields()
[389] Fix | Delete
{
[390] Fix | Delete
// Remove new field table columns if we haven't completed stage one of our DB conversion.
[391] Fix | Delete
if ( ! $this->form[ 'db_stage_one_complete' ] ) {
[392] Fix | Delete
// Remove field columns added after stage one.
[393] Fix | Delete
unset( $this->fields_db_columns[ 'field_key' ] );
[394] Fix | Delete
unset( $this->fields_db_columns[ 'field_label' ] );
[395] Fix | Delete
unset( $this->fields_db_columns[ 'order' ] );
[396] Fix | Delete
unset( $this->fields_db_columns[ 'required' ] );
[397] Fix | Delete
unset( $this->fields_db_columns[ 'default_value' ] );
[398] Fix | Delete
unset( $this->fields_db_columns[ 'label_pos' ] );
[399] Fix | Delete
unset( $this->fields_db_columns[ 'personally_identifiable' ] );
[400] Fix | Delete
}
[401] Fix | Delete
[402] Fix | Delete
/**
[403] Fix | Delete
* Loop over our field array up to $this->fields_per_step.
[404] Fix | Delete
*/
[405] Fix | Delete
for ( $i = 0; $i < $this->fields_per_step; $i++ ) {
[406] Fix | Delete
// If we don't have a field, skip this $i.
[407] Fix | Delete
if ( ! isset ( $this->form[ 'fields' ][ $i ] ) ) {
[408] Fix | Delete
// Remove this field from our fields array.
[409] Fix | Delete
unset( $this->form[ 'fields' ][ $i ] );
[410] Fix | Delete
// If we haven't exceeded the field total...
[411] Fix | Delete
if ( $i < count( $this->form[ 'fields' ] ) ) {
[412] Fix | Delete
$this->add_error( 'empty_field', esc_html__( 'Some fields might not have been imported properly.', 'ninja-forms' ) );
[413] Fix | Delete
}
[414] Fix | Delete
continue;
[415] Fix | Delete
}
[416] Fix | Delete
[417] Fix | Delete
$field_settings = $this->form[ 'fields' ][ $i ];
[418] Fix | Delete
// Remove a field ID if we have one set.
[419] Fix | Delete
unset( $field_settings[ 'id' ] );
[420] Fix | Delete
$field_settings[ 'parent_id' ] = $this->form[ 'ID' ];
[421] Fix | Delete
// Array that tracks which settings need to be meta and which are columns.
[422] Fix | Delete
$field_meta = $field_settings;
[423] Fix | Delete
$insert_columns = array();
[424] Fix | Delete
$insert_columns_types = array();
[425] Fix | Delete
// Loop over all our action columns to get their values.
[426] Fix | Delete
foreach ( $this->fields_db_columns as $column_name => $setting_name ) {
[427] Fix | Delete
$insert_columns[ $column_name ] = $field_settings[ $setting_name ];
[428] Fix | Delete
if ( is_numeric( $field_settings[ $setting_name ] ) ) {
[429] Fix | Delete
array_push( $insert_columns_types, '%d' );
[430] Fix | Delete
} else {
[431] Fix | Delete
array_push( $insert_columns_types, '%s' );
[432] Fix | Delete
}
[433] Fix | Delete
}
[434] Fix | Delete
[435] Fix | Delete
// Add our field to the database.
[436] Fix | Delete
$this->_db->insert( "{$this->_db->prefix}nf3_fields", $insert_columns, $insert_columns_types );
[437] Fix | Delete
[438] Fix | Delete
/**
[439] Fix | Delete
* Get our new field ID.
[440] Fix | Delete
*/
[441] Fix | Delete
$field_id = $this->_db->insert_id;
[442] Fix | Delete
[443] Fix | Delete
$insert_values = '';
[444] Fix | Delete
/**
[445] Fix | Delete
* Anything left in the $field_meta array should be inserted as meta.
[446] Fix | Delete
*
[447] Fix | Delete
* Loop over each of our settings and add it to our insert sql string.
[448] Fix | Delete
*/
[449] Fix | Delete
$insert_values = '';
[450] Fix | Delete
foreach ( $field_meta as $meta_key => $meta_value ) {
[451] Fix | Delete
$meta_value = maybe_serialize( $meta_value );
[452] Fix | Delete
$this->_db->escape_by_ref( $meta_value );
[453] Fix | Delete
$insert_values .= "( {$field_id}, '{$meta_key}', '{$meta_value}'";
[454] Fix | Delete
if ( $this->form[ 'db_stage_one_complete'] ) {
[455] Fix | Delete
$insert_values .= ", '{$meta_key}', '{$meta_value}'";
[456] Fix | Delete
}
[457] Fix | Delete
$insert_values .= "),";
[458] Fix | Delete
}
[459] Fix | Delete
[460] Fix | Delete
// Remove the trailing comma.
[461] Fix | Delete
$insert_values = rtrim( $insert_values, ',' );
[462] Fix | Delete
$insert_columns = '`parent_id`, `key`, `value`';
[463] Fix | Delete
if ( $this->form[ 'db_stage_one_complete'] ) {
[464] Fix | Delete
$insert_columns .= ', `meta_key`, `meta_value`';
[465] Fix | Delete
}
[466] Fix | Delete
// Create SQL string.
[467] Fix | Delete
$sql = "INSERT INTO {$this->_db->prefix}nf3_field_meta ( {$insert_columns} ) VALUES {$insert_values}";
[468] Fix | Delete
[469] Fix | Delete
// Run our SQL query.
[470] Fix | Delete
$this->_db->query( $sql );
[471] Fix | Delete
[472] Fix | Delete
// Remove this field from our fields array.
[473] Fix | Delete
unset( $this->form[ 'fields' ][ $i ] );
[474] Fix | Delete
}
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
/*
[478] Fix | Delete
|--------------------------------------------------------------------------
[479] Fix | Delete
| Backwards Compatibility
[480] Fix | Delete
|--------------------------------------------------------------------------
[481] Fix | Delete
*/
[482] Fix | Delete
[483] Fix | Delete
public function import_form_backwards_compatibility( $import )
[484] Fix | Delete
{
[485] Fix | Delete
// Rename `data` to `settings`
[486] Fix | Delete
if( isset( $import[ 'data' ] ) ){
[487] Fix | Delete
$import[ 'settings' ] = $import[ 'data' ];
[488] Fix | Delete
unset( $import[ 'data' ] );
[489] Fix | Delete
}
[490] Fix | Delete
[491] Fix | Delete
// Rename `notifications` to `actions`
[492] Fix | Delete
if( isset( $import[ 'notifications' ] ) ){
[493] Fix | Delete
$import[ 'actions' ] = $import[ 'notifications' ];
[494] Fix | Delete
unset( $import[ 'notifications' ] );
[495] Fix | Delete
}
[496] Fix | Delete
[497] Fix | Delete
// Rename `form_title` to `title`
[498] Fix | Delete
if( isset( $import[ 'settings' ][ 'form_title' ] ) ){
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function