Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/ninja-fo.../includes/Fields
File: ListCountry.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Class NF_Fields_CountryList
[3] Fix | Delete
*/
[4] Fix | Delete
class NF_Fields_ListCountry extends NF_Abstracts_List
[5] Fix | Delete
{
[6] Fix | Delete
protected $_name = 'listcountry';
[7] Fix | Delete
[8] Fix | Delete
protected $_type = 'listcountry';
[9] Fix | Delete
[10] Fix | Delete
protected $_nicename = 'Country';
[11] Fix | Delete
[12] Fix | Delete
protected $_section = 'userinfo';
[13] Fix | Delete
[14] Fix | Delete
protected $_templates = array( 'listcountry', 'listselect' );
[15] Fix | Delete
[16] Fix | Delete
public function __construct()
[17] Fix | Delete
{
[18] Fix | Delete
parent::__construct();
[19] Fix | Delete
[20] Fix | Delete
$this->_nicename = esc_html__( 'Country', 'ninja-forms' );
[21] Fix | Delete
[22] Fix | Delete
$this->_settings[ 'options' ][ 'group' ] = '';
[23] Fix | Delete
// $this->_settings[ 'options' ][ 'value' ] = $this->get_options();
[24] Fix | Delete
[25] Fix | Delete
$this->_settings[ 'default' ] = array(
[26] Fix | Delete
'name' => 'default',
[27] Fix | Delete
'type' => 'select',
[28] Fix | Delete
'label' => esc_html__( 'Default Value', 'ninja-forms' ),
[29] Fix | Delete
'options' => $this->get_default_value_options(),
[30] Fix | Delete
'width' => 'one-half',
[31] Fix | Delete
'group' => 'primary',
[32] Fix | Delete
'value' => 'US',
[33] Fix | Delete
);
[34] Fix | Delete
[35] Fix | Delete
add_filter( 'ninja_forms_custom_columns', array( $this, 'custom_columns' ), 10, 2 );
[36] Fix | Delete
add_filter( 'ninja_forms_render_options_' . $this->_type, array( $this, 'filter_options' ), 10, 2 );
[37] Fix | Delete
add_filter( 'ninja_forms_subs_export_field_value_' . $this->_name, array( $this, 'filter_csv_value' ), 10, 2 );
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
public function custom_columns( $value, $field )
[41] Fix | Delete
{
[42] Fix | Delete
if( $this->_name != $field->get_setting( 'type' ) ) return $value;
[43] Fix | Delete
[44] Fix | Delete
foreach( Ninja_Forms()->config( 'CountryList' ) as $country => $abbr ){
[45] Fix | Delete
if( $value == $abbr ) return $country;
[46] Fix | Delete
}
[47] Fix | Delete
[48] Fix | Delete
return $value;
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
public function filter_options( $options, $settings )
[52] Fix | Delete
{
[53] Fix | Delete
$default_value = ( isset( $settings[ 'default' ] ) ) ? $settings[ 'default' ] : '';
[54] Fix | Delete
[55] Fix | Delete
$options = $this->get_options(); // Overwrite the default list options.
[56] Fix | Delete
foreach( $options as $key => $option ){
[57] Fix | Delete
if( $default_value != $option[ 'value' ] ) continue;
[58] Fix | Delete
$options[ $key ][ 'selected' ] = 1;
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
usort( $options, array($this,'sort_options_by_label') );
[62] Fix | Delete
[63] Fix | Delete
return $options;
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
private function sort_options_by_label( $option_a, $option_b )
[67] Fix | Delete
{
[68] Fix | Delete
return strcasecmp( $option_a['label'], $option_b['label'] );
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
public function filter_options_preview( $field_settings )
[72] Fix | Delete
{
[73] Fix | Delete
$field_settings[ 'settings' ][ 'options' ] = $this->get_options();
[74] Fix | Delete
[75] Fix | Delete
foreach( $field_settings[ 'settings' ][ 'options' ] as $key => $option ){
[76] Fix | Delete
if( $field_settings[ 'settings' ][ 'default' ] != $option[ 'value' ] ) continue;
[77] Fix | Delete
$field_settings[ 'settings' ][ 'options' ][ $key ][ 'selected' ] = 1;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
return $field_settings;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
public function admin_form_element( $id, $value )
[84] Fix | Delete
{
[85] Fix | Delete
$field = Ninja_Forms()->form()->get_field( $id );
[86] Fix | Delete
[87] Fix | Delete
$options = $this->get_options();
[88] Fix | Delete
$options = apply_filters( 'ninja_forms_render_options', $options, $field->get_settings() );
[89] Fix | Delete
$options = apply_filters( 'ninja_forms_render_options_' . $this->_type, $options, $field->get_settings() );
[90] Fix | Delete
[91] Fix | Delete
ob_start();
[92] Fix | Delete
echo "<select name='fields[$id]'>";
[93] Fix | Delete
foreach( $options as $option ){
[94] Fix | Delete
$selected = ( $option['value'] == $value ) ? ' selected' : '';
[95] Fix | Delete
echo "<option value='" . $option['value'] . "'" . $selected . ">" . $option['label'] . "</option>";
[96] Fix | Delete
}
[97] Fix | Delete
echo "</select>";
[98] Fix | Delete
return ob_get_clean();
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
private function get_default_value_options()
[102] Fix | Delete
{
[103] Fix | Delete
$options = array();
[104] Fix | Delete
// Option to have no default country
[105] Fix | Delete
$options[] = array(
[106] Fix | Delete
'label' => '- ' . esc_html__( 'Select Country', 'ninja-forms' ) . ' -',
[107] Fix | Delete
'value' => ''
[108] Fix | Delete
);
[109] Fix | Delete
foreach( Ninja_Forms()->config( 'CountryList' ) as $label => $value ){
[110] Fix | Delete
$options[] = array(
[111] Fix | Delete
'label' => $label,
[112] Fix | Delete
'value' => $value,
[113] Fix | Delete
);
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
return $options;
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
private function get_options()
[120] Fix | Delete
{
[121] Fix | Delete
$order = 0;
[122] Fix | Delete
$options = array();
[123] Fix | Delete
// option to have no default country selected
[124] Fix | Delete
$options[] = array(
[125] Fix | Delete
'label' => '- ' . esc_html__( 'Select Country', 'ninja-forms' ) . ' -',
[126] Fix | Delete
'value' => '',
[127] Fix | Delete
'calc' => '',
[128] Fix | Delete
'selected' => 0,
[129] Fix | Delete
'order' => $order,
[130] Fix | Delete
);
[131] Fix | Delete
$order++;
[132] Fix | Delete
foreach( Ninja_Forms()->config( 'CountryList' ) as $label => $value ){
[133] Fix | Delete
$options[] = array(
[134] Fix | Delete
'label' => $label,
[135] Fix | Delete
'value' => $value,
[136] Fix | Delete
'calc' => '',
[137] Fix | Delete
'selected' => 0,
[138] Fix | Delete
'order' => $order
[139] Fix | Delete
);
[140] Fix | Delete
[141] Fix | Delete
$order++;
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
return $options;
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
public function filter_csv_value( $field_value, $field )
[148] Fix | Delete
{
[149] Fix | Delete
$lookup = array_flip( Ninja_Forms()->config( 'CountryList' ) );
[150] Fix | Delete
if( isset( $lookup[ $field_value ] ) ) $field_value = $lookup[ $field_value ];
[151] Fix | Delete
return $field_value;
[152] Fix | Delete
}
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function