Function Reference: geodir_cf_address

Summary

Get the html output for the custom field: address

Parameters

$html
(string) (required) The html to be filtered.

Default: None
$location
(string) (required) The location to output the html.

Default: None
$cf
(array) (required) The custom field array details.

Default: None

Return Values

(string)
  • The html to output for the custom field.

Change Log

Since: 1.6.6

1.6.21 New hook added to filter address fields being displayed.

Filters

‘geodir_custom_field_output_address_loc_{$location}’ [Line: 1695]

‘geodir_custom_field_output_address_var_{$html_var}’ [Line: 1708]

‘geodir_custom_field_output_address_key_{$cf[field_type_key]}’ [Line: 1721]

‘geodir_show_city_in_address’ [Line: 1747]

‘geodir_show_region_in_address’ [Line: 1759]

‘geodir_show_country_in_address’ [Line: 1770]

‘geodir_show_zip_in_address’ [Line: 1781]

‘geodir_custom_field_output_address_fields’ [Line: 1834]

Source File

geodir_cf_address() is located in geodirectory-functions/custom_fields_output_functions.php [Line: 1673]

Source Code

function geodir_cf_address($html,$location,$cf,$p=''){

    // check we have the post value
    if(is_int($p)){$post = geodir_get_post_info($p);}
    else{ global $post;}

    if(!is_array($cf) && $cf!=''){
        $cf = geodir_get_field_infoby('htmlvar_name', $cf, $post->post_type);
        if(!$cf){return NULL;}
    }

    $html_var = $cf['htmlvar_name'];

    // Check if there is a location specific filter.
    if(has_filter("geodir_custom_field_output_address_loc_{$location}")){
        /**
         * Filter the address html by location.
         *
         * @param string $html The html to filter.
         * @param array $cf The custom field array.
         * @since 1.6.6
         */
        $html = apply_filters("geodir_custom_field_output_address_loc_{$location}",$html,$cf);
    }

    // Check if there is a custom field specific filter.
    if(has_filter("geodir_custom_field_output_address_var_{$html_var}")){
        /**
         * Filter the address html by individual custom field.
         *
         * @param string $html The html to filter.
         * @param string $location The location to output the html.
         * @param array $cf The custom field array.
         * @since 1.6.6
         */
        $html = apply_filters("geodir_custom_field_output_address_var_{$html_var}",$html,$location,$cf);
    }

    // Check if there is a custom field key specific filter.
    if(has_filter("geodir_custom_field_output_address_key_{$cf['field_type_key']}")){
        /**
         * Filter the address html by field type key.
         *
         * @param string $html The html to filter.
         * @param string $location The location to output the html.
         * @param array $cf The custom field array.
         * @since 1.6.6
         */
        $html = apply_filters("geodir_custom_field_output_address_key_{$cf['field_type_key']}",$html,$location,$cf);
    }

    // If not html then we run the standard output.
    if(empty($html)){

        global $preview;
        $html_var = $cf['htmlvar_name'] . '_address';

        if ($cf['extra_fields']) {

            $extra_fields = stripslashes_deep(unserialize($cf['extra_fields']));

            $addition_fields = '';

            if (!empty($extra_fields)) {

                $show_city_in_address = false;
                if (isset($extra_fields['show_city']) && $extra_fields['show_city']) {
                    $show_city_in_address = true;
                }
                /**
                 * Filter "show city in address" value.
                 *
                 * @since 1.0.0
                 */
                $show_city_in_address = apply_filters('geodir_show_city_in_address', $show_city_in_address);


                $show_region_in_address = false;
                if (isset($extra_fields['show_region']) && $extra_fields['show_region']) {
                    $show_region_in_address = true;
                }
                /**
                 * Filter "show region in address" value.
                 *
                 * @since 1.6.6
                 */
                $show_region_in_address = apply_filters('geodir_show_region_in_address', $show_region_in_address);

                $show_country_in_address = false;
                if (isset($extra_fields['show_country']) && $extra_fields['show_country']) {
                    $show_country_in_address = true;
                }
                /**
                 * Filter "show country in address" value.
                 *
                 * @since 1.6.6
                 */
                $show_country_in_address = apply_filters('geodir_show_country_in_address', $show_country_in_address);

                $show_zip_in_address = false;
                if (isset($extra_fields['show_zip']) && $extra_fields['show_zip']) {
                    $show_zip_in_address = true;
                }
                /**
                 * Filter "show zip in address" value.
                 *
                 * @since 1.6.6
                 */
                $show_zip_in_address = apply_filters('geodir_show_zip_in_address', $show_zip_in_address);


            }

        }


        if ($post->{$html_var}) {

            $field_icon = geodir_field_icon_proccess( $cf );
            if ( strpos( $field_icon, 'http' ) !== false ) {
                $field_icon_af = '';
            } elseif ( $field_icon == '' ) {
                $field_icon_af = '';
            } else {
                $field_icon_af = $field_icon;
                $field_icon    = '';
            }
            
            $html = '
'; $html .= '' . $field_icon_af; $html .= ( trim( $cf['site_title'] ) ) ? __( $cf['site_title'], 'geodirectory' ) . ': ' : ' '; $html .= ''; $address_fields = array(); if ( isset($post->post_address) ) { $address_fields['post_address'] = '' . $post->post_address . ''; } if ($show_city_in_address && isset( $post->post_city ) && $post->post_city ) { $address_fields['post_city'] = '' . $post->post_city . ''; } if ($show_region_in_address && isset( $post->post_region ) && $post->post_region ) { $address_fields['post_region'] = '' . $post->post_region . ''; } if ($show_zip_in_address && isset( $post->post_zip ) && $post->post_zip ) { $address_fields['post_zip'] = '' . $post->post_zip . ''; } if ($show_country_in_address && isset( $post->post_country ) && $post->post_country ) { $address_fields['post_country'] = '' . __( $post->post_country, 'geodirectory' ) . ''; } /** * Filter the address fields array being displayed. * * @param array $address_fields The array of address fields. * @param object $post The current post object. * @param array $cf The custom field array details. * @param string $location The location to output the html. * * @since 1.6.21 */ $address_fields = apply_filters('geodir_custom_field_output_address_fields', $address_fields, $post, $cf, $location); if (!empty($address_fields) && is_array($address_fields)) { $address_fields = array_values($address_fields); $html .= implode('
', $address_fields); } $html .= '
'; } } return $html; }