Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/ninja-fo.../deprecat.../classes
File: sub.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
/**
[1] Fix | Delete
* Submission.
[2] Fix | Delete
* This class handles storing, retrieving, editing a submission.
[3] Fix | Delete
*
[4] Fix | Delete
* @package Ninja Forms
[5] Fix | Delete
* @subpackage Classes/Submissions
[6] Fix | Delete
* @copyright Copyright (c) 2014, WPNINJAS
[7] Fix | Delete
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
[8] Fix | Delete
* @since 2.7
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
class NF_Sub {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* @var $sub_id store our sub id
[15] Fix | Delete
*/
[16] Fix | Delete
var $sub_id;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* @var $seq_num store our sequential number
[20] Fix | Delete
*/
[21] Fix | Delete
var $seq_num;
[22] Fix | Delete
[23] Fix | Delete
/**
[24] Fix | Delete
* @var $form_id store our form_id
[25] Fix | Delete
*/
[26] Fix | Delete
var $form_id;
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* @var $fields store our user values
[30] Fix | Delete
*/
[31] Fix | Delete
var $fields;
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* @var $action store the action that created this sub
[35] Fix | Delete
*/
[36] Fix | Delete
var $action;
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* @var $user_id store the user ID for this submission
[40] Fix | Delete
*/
[41] Fix | Delete
var $user_id;
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* @var $meta store our non-field meta
[45] Fix | Delete
*/
[46] Fix | Delete
var $meta;
[47] Fix | Delete
[48] Fix | Delete
/**
[49] Fix | Delete
* @var $date_submitted store our submitted date
[50] Fix | Delete
*/
[51] Fix | Delete
var $date_submitted;
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* @var $date_modified store our modified date
[55] Fix | Delete
*/
[56] Fix | Delete
var $date_modified;
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Get things started
[60] Fix | Delete
*
[61] Fix | Delete
* @access public
[62] Fix | Delete
* @since 2.7
[63] Fix | Delete
* @return void/
[64] Fix | Delete
*/
[65] Fix | Delete
public function __construct( $sub_id ) {
[66] Fix | Delete
global $ninja_forms_fields;
[67] Fix | Delete
[68] Fix | Delete
// Bail if the sub doesn't exist.
[69] Fix | Delete
$sub = get_post( $sub_id );
[70] Fix | Delete
if ( ! is_object( $sub ) )
[71] Fix | Delete
return false;
[72] Fix | Delete
[73] Fix | Delete
// Set our sub id
[74] Fix | Delete
$this->sub_id = $sub_id;
[75] Fix | Delete
[76] Fix | Delete
// Populate our fields
[77] Fix | Delete
$this->fields = array();
[78] Fix | Delete
$this->retrieve_fields();
[79] Fix | Delete
[80] Fix | Delete
// Setup our form id var
[81] Fix | Delete
$this->form_id = $this->get_meta( '_form_id' );
[82] Fix | Delete
// Setup our action var
[83] Fix | Delete
$this->action = $this->get_meta( '_action' );
[84] Fix | Delete
// Setup our sequential id
[85] Fix | Delete
$this->seq_num = $this->get_meta( '_seq_num' );
[86] Fix | Delete
// Setup our user_id var
[87] Fix | Delete
$this->user_id = $sub->post_author;
[88] Fix | Delete
// Setup our date submitted var
[89] Fix | Delete
$this->date_submitted = get_the_time( 'Y-m-d G:i:s', $sub_id );
[90] Fix | Delete
// Setup our date modified var
[91] Fix | Delete
$this->date_modified = get_post_modified_time( 'Y-m-d G:i:s', false, $sub_id );
[92] Fix | Delete
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
private function retrieve_fields() {
[96] Fix | Delete
global $ninja_forms_fields;
[97] Fix | Delete
[98] Fix | Delete
// Setup our fields and meta vars.
[99] Fix | Delete
$post_meta = get_post_custom( $this->sub_id );
[100] Fix | Delete
[101] Fix | Delete
foreach ( $post_meta as $key => $array ) {
[102] Fix | Delete
if ( is_serialized( $array[0] ) ) {
[103] Fix | Delete
$meta_value = unserialize( $array[0] );
[104] Fix | Delete
} else {
[105] Fix | Delete
$meta_value = $array[0];
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
if ( strpos( $key, '_field_' ) !== false ) {
[109] Fix | Delete
$field_id = str_replace( '_field_', '', $key );
[110] Fix | Delete
$field = ninja_forms_get_field_by_id( $field_id );
[111] Fix | Delete
$field_type = $field['type'];
[112] Fix | Delete
[113] Fix | Delete
// Check to see if our field type has been set as a "process_field".
[114] Fix | Delete
if ( isset ( $ninja_forms_fields[ $field_type ] ) ) {
[115] Fix | Delete
$reg_field = $ninja_forms_fields[ $field_type ];
[116] Fix | Delete
$process_field = $reg_field['process_field'];
[117] Fix | Delete
} else {
[118] Fix | Delete
$process_field = false;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
if ( $process_field ) {
[122] Fix | Delete
$this->fields[ $field_id ] = $meta_value;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
} else if ( $key != '_form_id' && $key != '_action' ) {
[126] Fix | Delete
$this->meta[ $key ] = $meta_value;
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
/**
[132] Fix | Delete
* Update our form id
[133] Fix | Delete
*
[134] Fix | Delete
* @access public
[135] Fix | Delete
* @since 2.7
[136] Fix | Delete
* @return bool
[137] Fix | Delete
*/
[138] Fix | Delete
public function update_form_id( $form_id ) {
[139] Fix | Delete
if ( update_post_meta( $this->sub_id, '_form_id', $form_id ) ) {
[140] Fix | Delete
$this->form_id = $form_id;
[141] Fix | Delete
return true;
[142] Fix | Delete
} else {
[143] Fix | Delete
return false;
[144] Fix | Delete
}
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
/**
[148] Fix | Delete
* Update our action
[149] Fix | Delete
*
[150] Fix | Delete
* @access public
[151] Fix | Delete
* @since 2.7
[152] Fix | Delete
* @return bool
[153] Fix | Delete
*/
[154] Fix | Delete
public function update_action( $action ) {
[155] Fix | Delete
if ( update_post_meta( $this->sub_id, '_action', $action ) ) {
[156] Fix | Delete
$this->action = $action;
[157] Fix | Delete
return true;
[158] Fix | Delete
} else {
[159] Fix | Delete
return false;
[160] Fix | Delete
}
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
/**
[164] Fix | Delete
* Update our sequential id
[165] Fix | Delete
*
[166] Fix | Delete
* @access public
[167] Fix | Delete
* @since 2.7
[168] Fix | Delete
* @return bool
[169] Fix | Delete
*/
[170] Fix | Delete
public function update_seq_num( $seq_num ) {
[171] Fix | Delete
if ( update_post_meta( $this->sub_id, '_seq_num', $seq_num ) ) {
[172] Fix | Delete
$this->seq_num = $seq_num;
[173] Fix | Delete
return true;
[174] Fix | Delete
} else {
[175] Fix | Delete
return false;
[176] Fix | Delete
}
[177] Fix | Delete
}
[178] Fix | Delete
[179] Fix | Delete
/**
[180] Fix | Delete
* Update our user id
[181] Fix | Delete
*
[182] Fix | Delete
* @access public
[183] Fix | Delete
* @since 2.7
[184] Fix | Delete
* @return bool
[185] Fix | Delete
*/
[186] Fix | Delete
public function update_user_id( $user_id ) {
[187] Fix | Delete
$args = array(
[188] Fix | Delete
'ID' => $this->sub_id,
[189] Fix | Delete
'post_author' => $user_id,
[190] Fix | Delete
);
[191] Fix | Delete
[192] Fix | Delete
// Update the post into the database
[193] Fix | Delete
if ( wp_update_post( $args ) ) {
[194] Fix | Delete
$this->user_id = $user_id;
[195] Fix | Delete
return true;
[196] Fix | Delete
} else {
[197] Fix | Delete
return false;
[198] Fix | Delete
}
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
/**
[202] Fix | Delete
* Update our date submitted
[203] Fix | Delete
*
[204] Fix | Delete
* @access public
[205] Fix | Delete
* @since 2.7
[206] Fix | Delete
* @return bool
[207] Fix | Delete
*/
[208] Fix | Delete
public function update_date_submitted( $date ) {
[209] Fix | Delete
$args = array(
[210] Fix | Delete
'ID' => $this->sub_id,
[211] Fix | Delete
'post_date' => $date,
[212] Fix | Delete
'post_date_gmt' => get_gmt_from_date( $date ),
[213] Fix | Delete
);
[214] Fix | Delete
[215] Fix | Delete
// Update the post into the database
[216] Fix | Delete
if ( wp_update_post( $args ) ) {
[217] Fix | Delete
$this->date_submitted = $date;
[218] Fix | Delete
return true;
[219] Fix | Delete
} else {
[220] Fix | Delete
return false;
[221] Fix | Delete
}
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
/**
[225] Fix | Delete
* Update our date modified
[226] Fix | Delete
*
[227] Fix | Delete
* @access public
[228] Fix | Delete
* @since 2.7
[229] Fix | Delete
* @return bool
[230] Fix | Delete
*/
[231] Fix | Delete
public function update_date_modified( $date ) {
[232] Fix | Delete
$args = array(
[233] Fix | Delete
'ID' => $this->sub_id,
[234] Fix | Delete
'post_modified' => $date,
[235] Fix | Delete
'post_modified_gmt' => get_gmt_from_date( $date ),
[236] Fix | Delete
);
[237] Fix | Delete
[238] Fix | Delete
// Update the post into the database
[239] Fix | Delete
if ( wp_update_post( $args ) ) {
[240] Fix | Delete
$this->date_modified = $date;
[241] Fix | Delete
return true;
[242] Fix | Delete
} else {
[243] Fix | Delete
return false;
[244] Fix | Delete
}
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
/**
[248] Fix | Delete
* Add a meta value to our submission.
[249] Fix | Delete
*
[250] Fix | Delete
* @access public
[251] Fix | Delete
* @since 2.7
[252] Fix | Delete
* @return bool
[253] Fix | Delete
*/
[254] Fix | Delete
public function add_meta( $meta_key, $value ) {
[255] Fix | Delete
if ( update_post_meta( $this->sub_id, $meta_key, $value ) ) {
[256] Fix | Delete
$this->meta[ $meta_key ] = $value;
[257] Fix | Delete
return true;
[258] Fix | Delete
} else {
[259] Fix | Delete
return false;
[260] Fix | Delete
}
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
/**
[264] Fix | Delete
* Update a meta value.
[265] Fix | Delete
* Wrapper for add_field().
[266] Fix | Delete
*
[267] Fix | Delete
* @access public
[268] Fix | Delete
* @since 2.7
[269] Fix | Delete
* @return bool
[270] Fix | Delete
*/
[271] Fix | Delete
public function update_meta( $meta_key, $value ) {
[272] Fix | Delete
return $this->add_meta( $meta_key, $value );
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
/**
[276] Fix | Delete
* Delete a meta value.
[277] Fix | Delete
*
[278] Fix | Delete
* @access public
[279] Fix | Delete
* @since 2.9
[280] Fix | Delete
* @return bool
[281] Fix | Delete
*/
[282] Fix | Delete
public function delete_meta( $meta_key, $value = '' ) {
[283] Fix | Delete
if ( empty( $value ) ) {
[284] Fix | Delete
return delete_post_meta( $this->sub_id, $meta_key );
[285] Fix | Delete
} else {
[286] Fix | Delete
return delete_post_meta( $this->sub_id, $meta_key, $value );
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
/**
[292] Fix | Delete
* Add a field value to our submission.
[293] Fix | Delete
*
[294] Fix | Delete
* @access public
[295] Fix | Delete
* @since 2.7
[296] Fix | Delete
* @return bool
[297] Fix | Delete
*/
[298] Fix | Delete
public function add_field( $field_id, $value ) {
[299] Fix | Delete
$meta_key = '_field_' . $field_id;
[300] Fix | Delete
if ( update_post_meta( $this->sub_id, $meta_key, $value ) ) {
[301] Fix | Delete
$this->field[ $field_id ] = $value;
[302] Fix | Delete
return true;
[303] Fix | Delete
} else {
[304] Fix | Delete
return false;
[305] Fix | Delete
}
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
/**
[309] Fix | Delete
* Update a field value
[310] Fix | Delete
*
[311] Fix | Delete
* @access public
[312] Fix | Delete
* @since 2.7
[313] Fix | Delete
* @return bool
[314] Fix | Delete
*/
[315] Fix | Delete
public function update_field( $field_id, $value ) {
[316] Fix | Delete
return $this->add_field( $field_id, $value );
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
/**
[320] Fix | Delete
* Get a meta value from our submission by meta key
[321] Fix | Delete
*
[322] Fix | Delete
* @access public
[323] Fix | Delete
* @since 2.7
[324] Fix | Delete
* @return array|bool
[325] Fix | Delete
*/
[326] Fix | Delete
public function get_meta( $meta_key ) {
[327] Fix | Delete
if ( ! isset ( $this->meta[ $meta_key ] ) ) {
[328] Fix | Delete
$this->meta[ $meta_key ] = get_post_meta( $this->sub_id, $meta_key, true );
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
return $this->meta[ $meta_key ];
[332] Fix | Delete
}
[333] Fix | Delete
[334] Fix | Delete
/**
[335] Fix | Delete
* Get a field value from our submission by field id
[336] Fix | Delete
*
[337] Fix | Delete
* @access public
[338] Fix | Delete
* @since 2.7
[339] Fix | Delete
* @return array|bool
[340] Fix | Delete
*/
[341] Fix | Delete
public function get_field( $field_id ) {
[342] Fix | Delete
if ( isset ( $this->fields[ $field_id ] ) ) {
[343] Fix | Delete
return $this->fields[ $field_id ];
[344] Fix | Delete
} else {
[345] Fix | Delete
return get_post_meta( $this->sub_id, '_field_' . $field_id, true );
[346] Fix | Delete
}
[347] Fix | Delete
}
[348] Fix | Delete
[349] Fix | Delete
/**
[350] Fix | Delete
* Get a submission from the database, returning all the field data.
[351] Fix | Delete
*
[352] Fix | Delete
* @access public
[353] Fix | Delete
* @since 2.7
[354] Fix | Delete
* @return array $sub
[355] Fix | Delete
*/
[356] Fix | Delete
public function get_all_fields() {
[357] Fix | Delete
if ( empty ( $this->fields ) ) {
[358] Fix | Delete
$this->retrieve_fields();
[359] Fix | Delete
}
[360] Fix | Delete
return $this->fields;
[361] Fix | Delete
}
[362] Fix | Delete
[363] Fix | Delete
/**
[364] Fix | Delete
* Get a submission sequential ID by the post ID.
[365] Fix | Delete
* This function puts together the prefix, sequential number, and postfix
[366] Fix | Delete
*
[367] Fix | Delete
* @access public
[368] Fix | Delete
* @since 2.7
[369] Fix | Delete
* @return string $seq_num
[370] Fix | Delete
*/
[371] Fix | Delete
public function get_seq_num() {
[372] Fix | Delete
return apply_filters( 'nf_subs_seq_num', $this->seq_num, $this->sub_id );
[373] Fix | Delete
}
[374] Fix | Delete
[375] Fix | Delete
/**
[376] Fix | Delete
* Export our current submission.
[377] Fix | Delete
*
[378] Fix | Delete
* @access public
[379] Fix | Delete
* @param array $sub_ids
[380] Fix | Delete
* @param bool @return
[381] Fix | Delete
* @since 2.7
[382] Fix | Delete
* @return void
[383] Fix | Delete
*/
[384] Fix | Delete
public function export( $return = false ){
[385] Fix | Delete
if ( $return ) {
[386] Fix | Delete
return Ninja_Forms()->subs()->export( $this->sub_id, $return );
[387] Fix | Delete
} else {
[388] Fix | Delete
Ninja_Forms()->subs()->export( $this->sub_id, $return );
[389] Fix | Delete
}
[390] Fix | Delete
}
[391] Fix | Delete
[392] Fix | Delete
/**
[393] Fix | Delete
* Delete this submission
[394] Fix | Delete
*
[395] Fix | Delete
* @access public
[396] Fix | Delete
* @since 2.7
[397] Fix | Delete
* @return void
[398] Fix | Delete
*/
[399] Fix | Delete
public function delete() {
[400] Fix | Delete
wp_delete_post( $this->sub_id, true );
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
}
[404] Fix | Delete
[405] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function