public function default_set_method_input() { $set_method_array = hm_time_timezone_options(); $set_method = ''; // only need to display set method if there is more than one option if (1 < count($set_method_array)) { $set_method_input = '<p><label><input type="radio" name="%1$s" value="%2$s" %3$s/> %4$s</label></p>'; $global_default_method = hm_time_options('default_set_method'); $stored_default_method = 'manual'; if (!empty($global_default_method)) { $stored_default_method = $global_default_method; } foreach ($set_method_array as $sm_value => $sm_label) { $sm_saved = $stored_default_method === $sm_value ? 'checked=checked' : ''; $set_method .= sprintf($set_method_input, 'hm_time_options[default_set_method]', $sm_value, $sm_saved, $sm_label); } $set_method .= '<span class="description">Please select how you want your timezone to be updated</span>'; } else { $set_method = '<p>Only method currently is <strong>Manual</strong>. Please insert Foursqaure app or GeoIP api details to have more options.</p>'; } echo $set_method; }
function hm_time_save_profile_fields($user_id, $timezone = null, $location = null, $workhours = null) { $hm_time_new_set_method = ''; $hm_time_new_timezone = ''; $hm_time_new_location = ''; $hm_time_new_workhours = array(); // data coming from foursqaure push api $set_method = get_user_meta(1, 'hm_time_set_method', true); if ('foursquare' == $set_method && !isset($_POST['hm_time_set_method'])) { if (!empty($timezone)) { $hm_time_new_timezone = $timezone; } if (!empty($location)) { $hm_time_new_location = $location; } if (!empty($workshours)) { $hm_time_new_workhours = $workhours; } } else { $hm_time_new_set_method = $_POST['hm_time_set_method']; $hm_time_new_timezone = $_POST['hm_time_timezone']; $hm_time_new_location = $_POST['hm_time_location']; $hm_time_new_workhours = $_POST['hm_time_workhours']; } // Validate and Sanitize //Set method validation $valid_set_methods = hm_time_timezone_options(); if (!empty($hm_time_new_set_method) && array_key_exists($hm_time_new_set_method, $valid_set_methods)) { update_user_meta($user_id, 'hm_time_set_method', $hm_time_new_set_method); } // Timezone validation $valid_timezones = timezone_identifiers_list(); if (!empty($hm_time_new_timezone) && in_array($hm_time_new_timezone, $valid_timezones)) { $hm_time_new_timezone = apply_filters('hm_time_timezone_filter', $hm_time_new_timezone, $_POST); update_user_meta($user_id, 'hm_time_timezone', $hm_time_new_timezone); } // Location validation if (!empty($hm_time_new_location)) { $hm_time_new_location = sanitize_text_field($hm_time_new_location); $hm_time_new_location = apply_filters('hm_time_location_filter', $hm_time_new_location, $_POST); update_user_meta($user_id, 'hm_time_location', $hm_time_new_location); } // Work hours validation if (!empty($hm_time_new_workhours)) { $valid_workhours = array_walk_recursive($hm_time_new_workhours, 'validate_workhours'); if ($valid_workhours) { $hm_time_new_workhours = apply_filters('hm_time_workhours_filter', $hm_time_new_workhours, $_POST); update_user_meta($user_id, 'hm_time_workhours', $hm_time_new_workhours); } } }