strickdj / acf-field-address

address field addon for Advanced Custom Fields (ACF)
Other
47 stars 18 forks source link

Support for PHP versions older than 5.4 #6

Closed indianabenny closed 9 years ago

indianabenny commented 9 years ago

Replace:

if ( is_array( $field['address_layout'] ) ) {
  $field['address_layout'] = json_encode( $field['address_layout'], JSON_UNESCAPED_UNICODE );
 }
 if ( is_object( $field['address_options'] ) ) {
  $field['address_options'] = json_encode( $field['address_options'], JSON_UNESCAPED_UNICODE );
}

with

if (version_compare(phpversion(), '5.4.0', '>')) {
 if ( is_array( $field['address_layout'] ) ) {
    $field['address_layout'] = json_encode( $field['address_layout'], JSON_UNESCAPED_UNICODE );
 }
 if ( is_object( $field['address_options'] ) ) {
   $field['address_options'] = json_encode( $field['address_options'], JSON_UNESCAPED_UNICODE );
}
} else {
  if ( is_array( $field['address_layout'] ) ) {
    $field['address_layout'] = json_encode( $field['address_layout']);
  }
  if ( is_object( $field['address_options'] ) ) {
    $field['address_options'] = json_encode( $field['address_options']);
  }
}