Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/ninja-fo.../deprecat.../classes
File: form.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
/**
[1] Fix | Delete
* Handles the output of our form, as well as interacting with its settings.
[2] Fix | Delete
*
[3] Fix | Delete
* @package Ninja Forms
[4] Fix | Delete
* @subpackage Classes/Form
[5] Fix | Delete
* @copyright Copyright (c) 2014, WPNINJAS
[6] Fix | Delete
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
[7] Fix | Delete
* @since 2.7
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
class NF_Form {
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* @var form_id
[14] Fix | Delete
* @since 2.7
[15] Fix | Delete
*/
[16] Fix | Delete
var $form_id;
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* @var settings - Form Settings
[20] Fix | Delete
* @since 2.7
[21] Fix | Delete
*/
[22] Fix | Delete
var $settings = array();
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* @var fields - Form Fields
[26] Fix | Delete
* @since 2.7
[27] Fix | Delete
*/
[28] Fix | Delete
var $fields = array();
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* @var fields - Fields List
[32] Fix | Delete
* @since 2.7
[33] Fix | Delete
*/
[34] Fix | Delete
var $field_keys = array();
[35] Fix | Delete
[36] Fix | Delete
/**
[37] Fix | Delete
* @var errors - Form errors
[38] Fix | Delete
* @since 2.7
[39] Fix | Delete
*/
[40] Fix | Delete
var $errors = array();
[41] Fix | Delete
[42] Fix | Delete
/**
[43] Fix | Delete
* Get things started
[44] Fix | Delete
*
[45] Fix | Delete
* @access public
[46] Fix | Delete
* @since 2.7
[47] Fix | Delete
* @return void
[48] Fix | Delete
*/
[49] Fix | Delete
public function __construct( $form_id = '' ) {
[50] Fix | Delete
if ( ! empty ( $form_id ) ) { // We've been passed a form id.
[51] Fix | Delete
// Set our current form id.
[52] Fix | Delete
$this->form_id = $form_id;
[53] Fix | Delete
$this->update_fields();
[54] Fix | Delete
$this->settings = nf_get_form_settings( $form_id );
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Add a form
[60] Fix | Delete
*
[61] Fix | Delete
* @access public
[62] Fix | Delete
* @since 2.9
[63] Fix | Delete
* @return int $form_id
[64] Fix | Delete
*/
[65] Fix | Delete
public function create( $defaults = array() ) {
[66] Fix | Delete
$form_id = nf_insert_object( 'form' );
[67] Fix | Delete
$date_updated = date( 'Y-m-d', current_time( 'timestamp' ) );
[68] Fix | Delete
nf_update_object_meta( $form_id, 'date_updated', $date_updated );
[69] Fix | Delete
[70] Fix | Delete
foreach( $defaults as $meta_key => $meta_value ) {
[71] Fix | Delete
nf_update_object_meta( $form_id, $meta_key, $meta_value );
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
// Add a single event hook that will check to see if this is an orphaned function.
[75] Fix | Delete
$timestamp = strtotime( '+24 hours', time() );
[76] Fix | Delete
$args = array(
[77] Fix | Delete
'form_id' => $form_id
[78] Fix | Delete
);
[79] Fix | Delete
wp_schedule_single_event( $timestamp, 'nf_maybe_delete_form', $args );
[80] Fix | Delete
return $form_id;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Insert a field into our form
[85] Fix | Delete
*
[86] Fix | Delete
* @access public
[87] Fix | Delete
* @since 2.9
[88] Fix | Delete
* @return bool()
[89] Fix | Delete
*/
[90] Fix | Delete
public function insert_field( $field_id ) {
[91] Fix | Delete
return nf_add_relationship( $field_id, 'field', $this->form_id, 'form' );
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Update our fields
[96] Fix | Delete
*
[97] Fix | Delete
* @access public
[98] Fix | Delete
* @since 2.9
[99] Fix | Delete
* @return void
[100] Fix | Delete
*/
[101] Fix | Delete
public function update_fields() {
[102] Fix | Delete
$this->fields = nf_get_fields_by_form_id( $this->form_id );
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
/**
[106] Fix | Delete
* Get one of our form settings.
[107] Fix | Delete
*
[108] Fix | Delete
* @access public
[109] Fix | Delete
* @since 2.7
[110] Fix | Delete
* @return string $setting
[111] Fix | Delete
*/
[112] Fix | Delete
public function get_setting( $setting, $bypass_cache = false ) {
[113] Fix | Delete
if ( $bypass_cache ) {
[114] Fix | Delete
return nf_get_object_meta_value( $this->form_id, 'last_sub' );
[115] Fix | Delete
}
[116] Fix | Delete
if ( isset ( $this->settings[ $setting ] ) ) {
[117] Fix | Delete
return $this->settings[ $setting ];
[118] Fix | Delete
} else {
[119] Fix | Delete
return false;
[120] Fix | Delete
}
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
/**
[124] Fix | Delete
* Update a form setting (this doesn't update anything in the database)
[125] Fix | Delete
* Changes are only applied to this object.
[126] Fix | Delete
*
[127] Fix | Delete
* @access public
[128] Fix | Delete
* @since 2.8
[129] Fix | Delete
* @param string $setting
[130] Fix | Delete
* @param mixed $value
[131] Fix | Delete
* @return bool
[132] Fix | Delete
*/
[133] Fix | Delete
public function update_setting( $setting, $value ) {
[134] Fix | Delete
$this->settings[ $setting ] = $value;
[135] Fix | Delete
nf_update_object_meta( $this->form_id, $setting, $value );
[136] Fix | Delete
$this->dump_cache();
[137] Fix | Delete
return true;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
/**
[141] Fix | Delete
* Get all of our settings
[142] Fix | Delete
*
[143] Fix | Delete
* @access public
[144] Fix | Delete
* @since 2.9
[145] Fix | Delete
* @return array $settings
[146] Fix | Delete
*/
[147] Fix | Delete
public function get_all_settings() {
[148] Fix | Delete
return $this->settings;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
/**
[152] Fix | Delete
* Get all the submissions for this form
[153] Fix | Delete
*
[154] Fix | Delete
* @access public
[155] Fix | Delete
* @since 2.7
[156] Fix | Delete
* @return array $sub_ids
[157] Fix | Delete
*/
[158] Fix | Delete
public function get_subs( $args = array() ) {
[159] Fix | Delete
$args['form_id'] = $this->form_id;
[160] Fix | Delete
return Ninja_Forms()->subs()->get( $args );
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
/**
[164] Fix | Delete
* Return a count of the submissions this form has had
[165] Fix | Delete
*
[166] Fix | Delete
* @access public
[167] Fix | Delete
* @param array $args
[168] Fix | Delete
* @since 2.7
[169] Fix | Delete
* @return int $count
[170] Fix | Delete
*/
[171] Fix | Delete
public function sub_count( $args = array() ) {
[172] Fix | Delete
return count( $this->get_subs( $args ) );
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* Delete this form
[177] Fix | Delete
*
[178] Fix | Delete
* @access public
[179] Fix | Delete
* @since 2.9
[180] Fix | Delete
*/
[181] Fix | Delete
public function delete() {
[182] Fix | Delete
global $wpdb;
[183] Fix | Delete
// Delete this object.
[184] Fix | Delete
nf_delete_object( $this->form_id );
[185] Fix | Delete
// Delete any fields on this form.
[186] Fix | Delete
$wpdb->query($wpdb->prepare( "DELETE FROM ".NINJA_FORMS_FIELDS_TABLE_NAME." WHERE form_id = %d", $this->form_id ) );
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Delete the cached form object (transient)
[191] Fix | Delete
*
[192] Fix | Delete
* @access public
[193] Fix | Delete
* @since 2.9.17
[194] Fix | Delete
*/
[195] Fix | Delete
public function dump_cache()
[196] Fix | Delete
{
[197] Fix | Delete
delete_transient( 'nf_form_' . $this->form_id );
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Deprecated wrapper for dump_cache()
[202] Fix | Delete
*
[203] Fix | Delete
* @access public
[204] Fix | Delete
* @since 2.9.12
[205] Fix | Delete
*/
[206] Fix | Delete
public function dumpCache()
[207] Fix | Delete
{
[208] Fix | Delete
$this->dump_cache();
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function