Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/ninja-fo.../includes/Fields
File: Checkbox.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Class NF_Fields_Checkbox
[3] Fix | Delete
*/
[4] Fix | Delete
class NF_Fields_Checkbox extends NF_Abstracts_Input
[5] Fix | Delete
{
[6] Fix | Delete
protected $_name = 'checkbox';
[7] Fix | Delete
[8] Fix | Delete
protected $_nicename = 'Checkbox';
[9] Fix | Delete
[10] Fix | Delete
protected $_section = 'common';
[11] Fix | Delete
[12] Fix | Delete
protected $_icon = 'check-square-o';
[13] Fix | Delete
[14] Fix | Delete
protected $_type = 'checkbox';
[15] Fix | Delete
[16] Fix | Delete
protected $_templates = 'checkbox';
[17] Fix | Delete
[18] Fix | Delete
protected $_test_value = 0;
[19] Fix | Delete
[20] Fix | Delete
protected $_settings = array( 'checkbox_default_value', 'checkbox_values', 'checked_calc_value', 'unchecked_calc_value' );
[21] Fix | Delete
[22] Fix | Delete
protected $_settings_exclude = array( 'default', 'placeholder', 'input_limit_set' );
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* NF_Fields_Checkbox constructor.
[26] Fix | Delete
* @since 3.0
[27] Fix | Delete
*/
[28] Fix | Delete
public function __construct()
[29] Fix | Delete
{
[30] Fix | Delete
parent::__construct();
[31] Fix | Delete
[32] Fix | Delete
$this->_nicename = esc_html__( 'Single Checkbox', 'ninja-forms' );
[33] Fix | Delete
[34] Fix | Delete
$this->_settings[ 'label_pos' ][ 'value' ] = 'right';
[35] Fix | Delete
[36] Fix | Delete
add_filter( 'ninja_forms_custom_columns', array( $this, 'custom_columns' ), 10, 2 );
[37] Fix | Delete
[38] Fix | Delete
add_filter( 'ninja_forms_merge_tag_value_' . $this->_name, array( $this, 'filter_merge_tag_value' ), 10, 2 );
[39] Fix | Delete
add_filter( 'ninja_forms_merge_tag_calc_value_' . $this->_name, array( $this, 'filter_merge_tag_value_calc' ), 10, 2 );
[40] Fix | Delete
add_filter( 'ninja_forms_subs_export_field_value_' . $this->_type, array( $this, 'export_value' ), 10, 2 );
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Admin Form Element
[45] Fix | Delete
* Display the checkbox on the edit submissions area.
[46] Fix | Delete
* @since 3.0
[47] Fix | Delete
*
[48] Fix | Delete
* @param $id Field ID.
[49] Fix | Delete
* @param $value Field value.
[50] Fix | Delete
* @return string HTML used for display of checkbox.
[51] Fix | Delete
*/
[52] Fix | Delete
public function admin_form_element( $id, $value )
[53] Fix | Delete
{
[54] Fix | Delete
// If the checkboxes value is 1 or on...
[55] Fix | Delete
if( 'on' == $value || 1 == $value ) {
[56] Fix | Delete
// ...this variable to checked.
[57] Fix | Delete
$checked = 'checked';
[58] Fix | Delete
} else {
[59] Fix | Delete
// ...else leave the variable empty.
[60] Fix | Delete
$checked = '';
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
// Return HTML to be output to the submission edit page.
[64] Fix | Delete
return "<input type='hidden' name='fields[$id]' value='0' >
[65] Fix | Delete
<input type='checkbox' name='fields[$id]' id='' $checked>";
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Custom Columns
[70] Fix | Delete
* Creates what is displayed in the columns on the submissions page.
[71] Fix | Delete
* @since 3.0
[72] Fix | Delete
*nf_subs_export_pre_value
[73] Fix | Delete
* @param $value checkbox value
[74] Fix | Delete
* @param $field field model.
[75] Fix | Delete
* @return $value string|void
[76] Fix | Delete
*/
[77] Fix | Delete
public function custom_columns( $value, $field )
[78] Fix | Delete
{
[79] Fix | Delete
// If the field type is equal to checkbox...
[80] Fix | Delete
if( 'checkbox' == $field->get_setting( 'type' ) ) {
[81] Fix | Delete
// Backwards compatibility check for the new checked value setting.
[82] Fix | Delete
if( null == $field->get_setting( 'checked_value' ) && 1 == $value || 'on' == $value ) {
[83] Fix | Delete
return esc_html__( 'Checked', 'ninja-forms' );
[84] Fix | Delete
} elseif( null == $field->get_setting( 'unchecked_value' ) && 0 == $value ) {
[85] Fix | Delete
return esc_html__( 'Unchecked', 'ninja-forms');
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
// If the field value is set to 1....
[89] Fix | Delete
if( 1 == $value || 'on' == $value) {
[90] Fix | Delete
// Set the value to the checked value setting.
[91] Fix | Delete
$value = $field->get_setting( 'checked_value' );
[92] Fix | Delete
} else {
[93] Fix | Delete
// Else set the value to the unchecked value setting.
[94] Fix | Delete
$value = $field->get_setting( 'unchecked_value' );
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
return $value;
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
/**
[101] Fix | Delete
* Filter Merge Tag Value
[102] Fix | Delete
* This is what provides the merge tag with the fields value.
[103] Fix | Delete
* @since 3.0
[104] Fix | Delete
*
[105] Fix | Delete
* @param $value Field value
[106] Fix | Delete
* @param $field field model
[107] Fix | Delete
* @return string|void
[108] Fix | Delete
*/
[109] Fix | Delete
public function filter_merge_tag_value( $value, $field )
[110] Fix | Delete
{
[111] Fix | Delete
// If value is true, return checked value setting.
[112] Fix | Delete
if( $value ) return $field[ 'settings' ][ 'checked_value' ];
[113] Fix | Delete
// Else return unchecked value setting.
[114] Fix | Delete
return $field[ 'settings' ][ 'unchecked_value' ];;
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Filter Merge Tag Value Calc
[119] Fix | Delete
* Provides the calculation value when the merge tag is used.
[120] Fix | Delete
* @since 3.0
[121] Fix | Delete
*
[122] Fix | Delete
* @param $value checkbox value
[123] Fix | Delete
* @param $field field model
[124] Fix | Delete
* @return $field
[125] Fix | Delete
*/
[126] Fix | Delete
public function filter_merge_tag_value_calc( $value, $field )
[127] Fix | Delete
{
[128] Fix | Delete
// If value is equal to 1...
[129] Fix | Delete
if ( 1 == $value ) {
[130] Fix | Delete
// ...return the checked calc value of the field model.
[131] Fix | Delete
return $field[ 'checked_calc_value' ];
[132] Fix | Delete
} else {
[133] Fix | Delete
// ...else return the unchecked calc value of the field model.
[134] Fix | Delete
return $field[ 'unchecked_calc_value' ];
[135] Fix | Delete
}
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Export Value
[140] Fix | Delete
* Determines the value to send to submission export.
[141] Fix | Delete
* @since 3.0
[142] Fix | Delete
*
[143] Fix | Delete
* @param $value checkbox field value
[144] Fix | Delete
* @param $field checkbox field model
[145] Fix | Delete
* @return string|void
[146] Fix | Delete
*/
[147] Fix | Delete
public function export_value( $value, $field )
[148] Fix | Delete
{
[149] Fix | Delete
// @TODO: Why were these values translated in the first place?
[150] Fix | Delete
// If value is equal to checked or unchecked return the value
[151] Fix | Delete
if ( __( 'checked', 'ninja-forms' ) == $value ||
[152] Fix | Delete
__( 'unchecked', 'ninja-forms' ) == $value ) return $value;
[153] Fix | Delete
[154] Fix | Delete
// Creating settings variables for our check.
[155] Fix | Delete
if( is_array( $field ) ) {
[156] Fix | Delete
// The email action sends teh field variable as an array
[157] Fix | Delete
$checked_setting = $field[ 'setting' ][ 'checked_value' ];
[158] Fix | Delete
$unchecked_setting = $field[ 'setting' ][ 'unchecked_value' ];
[159] Fix | Delete
} else {
[160] Fix | Delete
$checked_setting = $field->get_setting( 'checked_value' );
[161] Fix | Delete
$unchecked_setting = $field->get_setting( 'unchecked_value' );
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
// If the the value and check to see if we have checked and unchecked settings...
[165] Fix | Delete
if ( ( 1 == $value || 'on' == $value ) && ! empty( $checked_setting ) ) {
[166] Fix | Delete
// ...if we do return checked setting
[167] Fix | Delete
return $checked_setting;
[168] Fix | Delete
} elseif ( 0 == $value && ! empty( $unchecked_setting ) ) {
[169] Fix | Delete
// ...else return unchecked setting.
[170] Fix | Delete
return $unchecked_setting;
[171] Fix | Delete
/*
[172] Fix | Delete
* These checks are for checkbox fields that were created before version 3.2.7.
[173] Fix | Delete
*/
[174] Fix | Delete
} elseif ( 1 == $value || 'on' == $value ) {
[175] Fix | Delete
return esc_html__( 'checked', 'ninja-forms' );
[176] Fix | Delete
} elseif ( 0 == $value ) {
[177] Fix | Delete
return esc_html__( 'unchecked', 'ninja-forms' );
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function