From cb5e46d7d86d9e5e6e91c87d946a5180f9790dca Mon Sep 17 00:00:00 2001 From: Kiran Prajapati Date: Wed, 4 Sep 2024 18:45:41 +0530 Subject: [PATCH] Fix deprecated notice in class-geodir-settings-cpt-cf.php file --- .../settings/class-geodir-settings-cpt-cf.php | 133 +++++++++--------- 1 file changed, 68 insertions(+), 65 deletions(-) diff --git a/includes/admin/settings/class-geodir-settings-cpt-cf.php b/includes/admin/settings/class-geodir-settings-cpt-cf.php index 5d7551e5..d94bd363 100644 --- a/includes/admin/settings/class-geodir-settings-cpt-cf.php +++ b/includes/admin/settings/class-geodir-settings-cpt-cf.php @@ -1425,46 +1425,54 @@ public function right_panel_content() { * * @return string */ - public static function loop_fields_output($tabs,$tab_id = ''){ + public static function loop_fields_output( $tabs, $tab_id = '' ) { ob_start(); - if(!empty($tabs)){ - foreach($tabs as $key => $tab){ + if ( ! empty( $tabs ) ) { + foreach ( $tabs as $key => $tab ) { + if ( $tab_id && $tab->id != $tab_id ) { + continue; + } elseif ( $tab_id && $tab->id == $tab_id && $tab->tab_level > 0 ) { + echo self::output_custom_field_setting_item( $tab->id, $tab ); + break; + } - if($tab_id && $tab->id!=$tab_id){ + if ( $tab->tab_level == '1' ) { continue; - }elseif($tab_id && $tab->id==$tab_id && $tab->tab_level > 0){ - echo self::output_custom_field_setting_item($tab->id,$tab); break; } - if($tab->tab_level=='1' ){continue;} + $tab_content = self::output_custom_field_setting_item( $tab->id, $tab ); + $tab_content = $tab_content ? str_replace( "", "", $tab_content ) : ''; + $child_tabs = ''; + foreach ( $tabs as $child_tab ) { + if ( $child_tab->tab_parent == $tab->id ) { + $child_tab_content = self::output_custom_field_setting_item( $child_tab->id, $child_tab ); - $tab_rendered = self::output_custom_field_setting_item($tab->id,$tab); - $tab_rendered = str_replace("","",$tab_rendered); - $child_tabs = ''; - foreach($tabs as $child_tab){ - if($child_tab->tab_parent==$tab->id){ - $child_tabs .= self::output_custom_field_setting_item($child_tab->id,$child_tab); + if ( $child_tab_content ) { + $child_tabs .= $child_tab_content; + } } } - if($child_tabs){ - $tab_rendered .= ""; + if ( $child_tabs ) { + $tab_content .= ""; } - echo $tab_rendered; + echo $tab_content; echo ""; - unset($tabs[$key]); - + unset( $tabs[ $key ] ); } } - return ob_get_clean(); - } + $content = ob_get_clean(); + $content = trim( $content ); + + return $content; + } /** * GeoDir get all fields by posttype. @@ -1482,7 +1490,6 @@ public static function get_all_fields($post_type){ return $cf_arr1 + $cf_arr2 + $cf_arr3; // this way defaults can't be overwritten } - /** * Adds admin html for custom fields. * @@ -1494,81 +1501,74 @@ public static function get_all_fields($post_type){ * @param string $field_ins_upd When set to "submit" displays form. * @param string $field_type_key The key of the custom field. */ - public static function output_custom_field_setting_item($field_id = '',$field = '',$cf = array()) - { - + public static function output_custom_field_setting_item( $field_id = '', $field = '', $cf = array() ) { ob_start(); - // if field not provided get it - if (!is_object($field) && $field_id) { - global $wpdb; - $field = $wpdb->get_row($wpdb->prepare("select * from " . GEODIR_CUSTOM_FIELDS_TABLE . " where id= %d", array($field_id))); - } - // if field template not provided get it - if(empty($cf)){ - $cf_arr = self::get_all_fields($field->post_type); - $cf = (isset($cf_arr[$field->field_type_key])) ? $cf_arr[$field->field_type_key] : ''; // the field type + // If field not provided get it. + if ( ! is_object( $field ) && $field_id ) { + $field = self::get_item( $field_id ); } - //print_r($cf); + // If field template not provided get it. + if ( empty( $cf ) ) { + $cf_arr = self::get_all_fields( $field->post_type ); - // set defaults - if(isset($cf['defaults'])){ - foreach($cf['defaults'] as $key => $val ){ - if(!isset($field->{$key})){ + $cf = isset( $cf_arr[ $field->field_type_key ] ) ? $cf_arr[ $field->field_type_key ] : ''; + } + + // Set defaults + if ( isset( $cf['defaults'] ) ) { + foreach ( $cf['defaults'] as $key => $val ) { + if ( ! isset( $field->{$key} ) ) { $field->{$key} = $val; } } } - if(!isset( $field->is_default ))$field->is_default = 0; - - // Setup some variables - + if ( ! isset( $field->is_default ) ) { + $field->is_default = 0; + } - // Strip slashes but not from json extra_fields + // Strip slashes but not from json extra_fields. if ( isset( $field->extra_fields ) ) { $extra_fields = $field->extra_fields; } - $validation_pattern = isset($field->validation_pattern) ? $field->validation_pattern : ''; - $field = wp_unslash( $field ); // strip slashes from labels - $field->validation_pattern = str_replace('\\\\', '\\', $validation_pattern);// we need the validation pattern without slashes stripped. + + $validation_pattern = isset( $field->validation_pattern ) ? $field->validation_pattern : ''; + $field = wp_unslash( $field ); // Strip slashes from labels. + $field->validation_pattern = str_replace( '\\\\', '\\', $validation_pattern ); // We need the validation pattern without slashes stripped. + if ( isset( $field->extra_fields ) ) { $field->extra_fields = $extra_fields; } - //print_r($field); - // Set nonce + // Set nonce. $nonce = wp_create_nonce( 'custom_fields_' . $field->id ); - // Set if this is a default field + // Set if this is a default field. $default = isset( $field->is_admin ) ? $field->is_admin : ''; - // Remove Send Enquiry from listings page + // Remove Send Enquiry from listings page. $display_on_listing = true; $htmlvar_name = isset( $field->htmlvar_name ) && $field->htmlvar_name != '' ? $field->htmlvar_name : ''; + if ( $htmlvar_name == 'geodir_email' ) { $display_on_listing = false; } - // Hide the field from custom fields (i.e. address field from location less CPT) + // Hide the field from custom fields (i.e. address field from location less CPT). if ( has_filter( "geodir_cfa_skip_item_output_{$field->field_type}" ) ) { if ( apply_filters( "geodir_cfa_skip_item_output_{$field->field_type}", false, $field_id, $field, $cf ) === true ) { - return; + $content = ob_get_clean(); + $content = trim( $content ); + + return $content; } } - - // @todo do we need this? - $field_display = $field->field_type == 'address' && $field->htmlvar_name == 'post' ? 'style="display:none"' : ''; - - // set a unique id for radio fields - $radio_id = ( isset( $field->htmlvar_name ) && $field->htmlvar_name ) ? $field->htmlvar_name : rand( 5, 500 ); - - // field icon $icon = isset( $cf['icon'] ) ? $cf['icon'] : ( isset( $field->field_icon ) ? $field->field_icon : '' ); - // Set the field icon + // Set the field icon. if ( geodir_is_fa_icon( $icon ) ) { $field_icon = ''; } elseif ( geodir_is_icon_url( $icon ) ) { @@ -1577,7 +1577,7 @@ public static function output_custom_field_setting_item($field_id = '',$field = $field_icon = ''; } - // if field type name is missing set it from main settings + // If field type name is missing set it from main settings. if ( isset( $cf['name'] ) && $cf['name'] ) { $field->field_type_name = $cf['name']; } else { @@ -1595,8 +1595,11 @@ public static function output_custom_field_setting_item($field_id = '',$field = * @since 2.0.0 */ include( dirname( __FILE__ ) . '/../views/html-admin-settings-cpt-cf-setting-item.php' ); - return ob_get_clean(); + $content = ob_get_clean(); + $content = trim( $content ); + + return $content; } /**