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: Terms.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* Class NF_Fields_Terms
[3] Fix | Delete
*/
[4] Fix | Delete
class NF_Fields_Terms extends NF_Fields_ListCheckbox
[5] Fix | Delete
{
[6] Fix | Delete
protected $_name = 'terms';
[7] Fix | Delete
protected $_type = 'terms';
[8] Fix | Delete
[9] Fix | Delete
protected $_nicename = 'Terms List';
[10] Fix | Delete
[11] Fix | Delete
protected $_section = '';
[12] Fix | Delete
[13] Fix | Delete
protected $_icon = 'tags';
[14] Fix | Delete
[15] Fix | Delete
protected $_templates = array( 'terms', 'listcheckbox' );
[16] Fix | Delete
[17] Fix | Delete
protected $_settings = array( 'taxonomy', 'add_new_terms' );
[18] Fix | Delete
[19] Fix | Delete
protected $_settings_exclude = array( 'required' );
[20] Fix | Delete
[21] Fix | Delete
protected $_excluded_taxonomies = array(
[22] Fix | Delete
'post_format'
[23] Fix | Delete
);
[24] Fix | Delete
[25] Fix | Delete
public function __construct()
[26] Fix | Delete
{
[27] Fix | Delete
parent::__construct();
[28] Fix | Delete
[29] Fix | Delete
$this->_nicename = esc_html__( 'Terms List', 'ninja-forms' );
[30] Fix | Delete
[31] Fix | Delete
// If we are on the ninja-forms page...
[32] Fix | Delete
// OR we're looking at nf_sub post types...
[33] Fix | Delete
// OR we're editing a single post...
[34] Fix | Delete
if ( ( ! empty( $_GET[ 'page' ] ) && 'ninja-forms' == $_GET[ 'page' ] ) ||
[35] Fix | Delete
( ! empty( $_GET[ 'post_type' ] ) && 'nf_sub' == $_GET[ 'post_type' ] ) ||
[36] Fix | Delete
isset( $_GET[ 'post' ] ) ) {
[37] Fix | Delete
// Initiate the termslist.
[38] Fix | Delete
add_action( 'admin_init', array( $this, 'init_settings' ) );
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
add_filter( 'ninja_forms_display_field', array( $this, 'active_taxonomy_field_check' ) );
[42] Fix | Delete
add_filter( 'ninja_forms_localize_field_' . $this->_type, array( $this, 'add_term_options' ) );
[43] Fix | Delete
add_filter( 'ninja_forms_localize_field_' . $this->_type . '_preview', array( $this, 'add_term_options' ) );
[44] Fix | Delete
[45] Fix | Delete
add_filter( 'ninja_forms_merge_tag_value_' . $this->_type, array( $this, 'merge_tag_value' ), 10, 2 );
[46] Fix | Delete
[47] Fix | Delete
$this->_settings[ 'options' ][ 'group' ] = '';
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
public function process( $field, $data )
[51] Fix | Delete
{
[52] Fix | Delete
return $data;
[53] Fix | Delete
}
[54] Fix | Delete
[55] Fix | Delete
public function init_settings()
[56] Fix | Delete
{
[57] Fix | Delete
$term_settings = array();
[58] Fix | Delete
$taxonomies = get_taxonomies( array( 'public' => true ), 'objects' );
[59] Fix | Delete
foreach( $taxonomies as $name => $taxonomy ){
[60] Fix | Delete
[61] Fix | Delete
$tax_term_settings = array();
[62] Fix | Delete
[63] Fix | Delete
if( in_array( $name, $this->_excluded_taxonomies ) ) continue;
[64] Fix | Delete
[65] Fix | Delete
$this->_settings[ 'taxonomy' ][ 'options' ][] = array(
[66] Fix | Delete
'label' => $taxonomy->labels->name,
[67] Fix | Delete
'value' => $name
[68] Fix | Delete
);
[69] Fix | Delete
[70] Fix | Delete
$terms = get_terms( $name, array( 'hide_empty' => false ) );
[71] Fix | Delete
[72] Fix | Delete
foreach( $terms as $term ){
[73] Fix | Delete
[74] Fix | Delete
// Check the slug instead of term_id to ensure we ONLY remove 'uncategorized'.
[75] Fix | Delete
if( 'uncategorized' == $term->slug ) continue;
[76] Fix | Delete
[77] Fix | Delete
$tax_term_settings[] = array(
[78] Fix | Delete
'name' => 'taxonomy_term_' . $term->term_id,
[79] Fix | Delete
'type' => 'toggle',
[80] Fix | Delete
'label' => $term->name . ' (' . $term->count .')',
[81] Fix | Delete
'width' => 'one-third',
[82] Fix | Delete
'deps' => array(
[83] Fix | Delete
'taxonomy' => $name
[84] Fix | Delete
),
[85] Fix | Delete
);
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
if( empty( $tax_term_settings ) ){
[89] Fix | Delete
$tax_term_settings[] = array(
[90] Fix | Delete
'name' => $name . '_no_terms',
[91] Fix | Delete
'type' => 'html',
[92] Fix | Delete
'width' => 'full',
[93] Fix | Delete
'value' => sprintf( esc_html__( 'No available terms for this taxonomy. %sAdd a term%s', 'ninja-forms' ), '<a href="' . admin_url( "edit-tags.php?taxonomy=$name" ) . '">', '</a>' ),
[94] Fix | Delete
'deps' => array(
[95] Fix | Delete
'taxonomy' => $name
[96] Fix | Delete
)
[97] Fix | Delete
);
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
$term_settings = array_merge( $term_settings, $tax_term_settings );
[101] Fix | Delete
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
$term_settings[] = array(
[105] Fix | Delete
'name' => '_no_taxonomy',
[106] Fix | Delete
'type' => 'html',
[107] Fix | Delete
'width' => 'full',
[108] Fix | Delete
'value' => esc_html__( 'No taxonomy selected.', 'ninja-forms' ),
[109] Fix | Delete
'deps' => array(
[110] Fix | Delete
'taxonomy' => ''
[111] Fix | Delete
)
[112] Fix | Delete
);
[113] Fix | Delete
[114] Fix | Delete
$this->_settings[ 'taxonomy_terms' ] = array(
[115] Fix | Delete
'name' => 'taxonomy_terms',
[116] Fix | Delete
'type' => 'fieldset',
[117] Fix | Delete
'label' => esc_html__( 'Available Terms', 'ninja-forms' ),
[118] Fix | Delete
'width' => 'full',
[119] Fix | Delete
'group' => 'primary',
[120] Fix | Delete
'settings' => $term_settings
[121] Fix | Delete
);
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
public function active_taxonomy_field_check( $field )
[125] Fix | Delete
{
[126] Fix | Delete
if( $this->_type != $field->get_setting( 'type' ) ) return $field;
[127] Fix | Delete
[128] Fix | Delete
$taxonomy = $field->get_setting( 'taxonomy' );
[129] Fix | Delete
[130] Fix | Delete
if( ! taxonomy_exists( $taxonomy ) ) return FALSE;
[131] Fix | Delete
[132] Fix | Delete
return $field;
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
public function add_term_options( $field )
[136] Fix | Delete
{
[137] Fix | Delete
$settings = ( is_object( $field ) ) ? $field->get_settings() : $field[ 'settings' ];
[138] Fix | Delete
[139] Fix | Delete
$settings[ 'options' ] = array();
[140] Fix | Delete
[141] Fix | Delete
if( isset( $settings[ 'taxonomy' ] ) && $settings[ 'taxonomy' ] ){
[142] Fix | Delete
[143] Fix | Delete
$terms = get_terms( $settings[ 'taxonomy' ], array( 'hide_empty' => false ) );
[144] Fix | Delete
[145] Fix | Delete
if( ! is_wp_error( $terms ) ){
[146] Fix | Delete
foreach( $terms as $term ) {
[147] Fix | Delete
[148] Fix | Delete
if( ! isset( $settings[ 'taxonomy_term_' . $term->term_id ] ) ) continue;
[149] Fix | Delete
if( ! $settings[ 'taxonomy_term_' . $term->term_id ] ) continue;
[150] Fix | Delete
[151] Fix | Delete
$settings['options'][] = array(
[152] Fix | Delete
'label' => $term->name,
[153] Fix | Delete
'value' => $term->term_id,
[154] Fix | Delete
'calc' => '',
[155] Fix | Delete
'selected' => 0,
[156] Fix | Delete
'order' => 0
[157] Fix | Delete
);
[158] Fix | Delete
}
[159] Fix | Delete
}
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
if( is_object( $field ) ) {
[163] Fix | Delete
$field->update_settings( $settings );
[164] Fix | Delete
} else {
[165] Fix | Delete
$field[ 'settings' ] = $settings;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
return $field;
[169] Fix | Delete
}
[170] Fix | Delete
[171] Fix | Delete
public function merge_tag_value( $value, $field )
[172] Fix | Delete
{
[173] Fix | Delete
$terms = explode( ',', $value );
[174] Fix | Delete
if( ! is_array( $terms ) ) {
[175] Fix | Delete
$term = get_term_by( 'id', $value, $field[ 'taxonomy' ] );
[176] Fix | Delete
if( $term ) {
[177] Fix | Delete
return $term->name;
[178] Fix | Delete
} else {
[179] Fix | Delete
return $value;
[180] Fix | Delete
}
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
$term_names = array();
[184] Fix | Delete
foreach( $terms as $term_id ){
[185] Fix | Delete
$term = get_term_by( 'id', $term_id, $field[ 'taxonomy' ] );
[186] Fix | Delete
$term_names[] = ( $term ) ? $term->name : $term_id; // If the term is `false`, fallback to the term_id.
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
return implode( ',', $term_names );
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
public function get_parent_type()
[193] Fix | Delete
{
[194] Fix | Delete
return 'listcheckbox';
[195] Fix | Delete
}
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function