예제 #1
5
 public static function set_kiosk_location()
 {
     //Data
     if (!isset($_POST['latitude']) || !isset($_POST['longitude'])) {
         echo json_encode(array('json_result' => false));
         die;
     } else {
         $latitude = htmlspecialchars($_POST['latitude']);
         $longitude = htmlspecialchars($_POST['longitude']);
     }
     //Definitions
     $has_kiosk = false;
     //Get saved data
     $saved_kiosks = get_field('kiosk_repeater', 'option');
     //Look for kiosk
     if (!empty($saved_kiosks)) {
         foreach ($saved_kiosks as $saved_kiosk) {
             if ($saved_kiosk['kiosk_ip'] == self::$kiosk_id) {
                 $has_kiosk = true;
                 break;
             }
         }
     }
     //Not set, save  new
     if ($has_kiosk == false) {
         if (!is_array($saved_kiosks)) {
             $saved_kiosks = array();
         }
         //Add missing kiosk
         $saved_kiosks[] = array('kiosk_ip' => self::$kiosk_id, 'kiosk_lat' => $latitude, 'kiosk_long' => $longitude);
         //Update all
         foreach ($saved_kiosks as $kiosk_location_id => $kiosk_location) {
             foreach ($kiosk_location as $key => $value) {
                 update_sub_field(array('kiosk_repeater', $kiosk_location_id + 1, $key), $value);
             }
         }
         //Update count
         update_option('options_kiosk_repeater', count($saved_kiosks));
     }
     //Result
     echo json_encode(array('json_result' => true));
     die;
 }
예제 #2
0
function delete_sub_field($selector, $post_id = false)
{
    return update_sub_field($selector, null, $post_id);
}
예제 #3
0
 /**
  * Upon save, checks if data to save is ACF values and updates field values
  * @param  array $data data to save
  */
 public function acf_save($data)
 {
     foreach ($data as $this_data) {
         $field_type = $this_data['options']['field_type'];
         if (strpos($field_type, 'acf_') !== false) {
             $safe_content = wp_kses_stripslashes($this->unfilter_shortcodes($this_data['content']));
             $post_id = (int) $this_data['options']['post_id'];
             $acf_field_key = $this->extract_acf_field_key($field_type)['field_key'];
             $field_object = $this->wa_get_acf_field_object($field_type);
             switch ($field_object['field_object']['type']) {
                 case 'text':
                 case 'email':
                 case 'url':
                 case 'password':
                 case 'number':
                     $safe_content = trim(strip_tags($safe_content));
                 case 'textarea':
                     if ($field_object['field_object']['new_lines'] == 'wpautop' || $field_object['field_object']['new_lines'] == 'br') {
                         $safe_content = str_replace('</p>', '<br/>', str_replace(array('<p>', '<br/>', '<br />'), '', $safe_content));
                     } else {
                         $safe_content = strip_tags($safe_content);
                     }
                     $safe_content = trim($safe_content);
                 case 'wysiwyg':
                 case 'select':
                 case 'radio':
                     if ($field_object['sub_field']) {
                         update_sub_field($acf_field_key, $safe_content, $post_id);
                     } else {
                         update_field($acf_field_key, $safe_content, $post_id);
                     }
                     break;
                     // Saved for future use, handled by acf_form() right now
                     // case 'oembed':
                     // case 'image':
                     // case 'file':
                     // 	if($field_object['sub_field']){
                     // 		update_sub_field($acf_field_key, $safe_content, $post_id);
                     // 	}else{
                     // 		update_field($acf_field_key, $safe_content, $post_id);
                     // 	}
                     // 	break;
             }
         }
     }
 }
예제 #4
0
function delete_row($selector, $row = 1, $post_id = false)
{
    // filter post_id
    $post_id = acf_get_valid_post_id($post_id);
    // get field
    $field = acf_maybe_get_field($selector, $post_id);
    // bail early if no field
    if (!$field) {
        return false;
    }
    // get value
    $rows = acf_get_value($post_id, $field);
    // bail early if no value
    if (empty($rows)) {
        return false;
    }
    // deincrement
    if ($row == count($rows)) {
        acf_update_metadata($post_id, $field['name'], $row - 1);
    }
    // update sub field values
    foreach ($rows[0] as $k => $v) {
        update_sub_field(array($field['key'], $row, $k), null, $post_id);
    }
    // return
    return true;
}
        the_row();
        ?>
    <?php 
        // Determine whether user provided lat/lng for this location. If not, attempt to geocode
        $lat = get_sub_field("latitude");
        $lng = get_sub_field("longitude");
        if (empty($lat) || empty($lng)) {
            // Geocode
            $safe_address = str_replace("\n", "", json_encode(strip_tags(get_sub_field('address'))));
            $address_info = geocode_address($safe_address);
            if (!empty($address_info)) {
                $lat = $address_info['latitude'];
                $lng = $address_info['longitude'];
                // update DB so we don't need to geocode on every page refresh
                update_sub_field('latitude', $lat);
                update_sub_field('longitude', $lng);
            } else {
                $geocode_error = true;
            }
        }
        ?>
      <div class="loc-box-wrapper">
            <h4><?php 
        echo get_sub_field('title');
        ?>
</h4>
            <?php 
        if (@$geocode_error) {
            ?>
            <strong>Could not create map. Admin, please check the address in the system.</strong>
            <?php 
예제 #6
0
 /**
  * Update a graph data upgrade node (X/Y coordinates and link IDs)
  * @param Object $node An object containing the new `x`, `y` and `links` properties of a node `id`
  * @param array $links The IDs of the nodes linked to this skill
  */
 public function update_upgrade_graph_data($node, $links)
 {
     $acfLinks = array();
     foreach ($links as $link) {
         $acfLinks[] = array('id' => $link);
     }
     $idFragments = explode('-', $node['id']);
     // Update coordinates
     update_sub_field(array($this->_fields['upgrades']['key'], $idFragments[1], 'graph_data', 1, 'x'), $node['x'], $idFragments[0]);
     update_sub_field(array($this->_fields['upgrades']['key'], $idFragments[1], 'graph_data', 1, 'y'), $node['y'], $idFragments[0]);
     // Update links
     update_sub_field(array($this->_fields['upgrades']['key'], $idFragments[1], 'graph_data', 1, 'links'), $acfLinks, $idFragments[0]);
 }
 /**
  * Update a graph data node (X/Y coordinates and link IDs). At this point,
  * all nodes entering here should already exist in DB
  * @param Object $node An object containing the new `x`, `y`, `start` and `links` properties of a node `id`
  * @param array $links The IDs of the nodes linked to this skill
  */
 public function update_graph_data($node, $links)
 {
     $acfLinks = array();
     foreach ($links as $link) {
         $acfLinks[] = array('id' => $link);
     }
     // Update point node values
     update_field($this->_fields['node_type']['key'], $node['type'], $node['id']);
     update_field($this->_fields['value']['key'], $node['value'], $node['id']);
     // Update coordinates
     update_sub_field(array($this->_fields['graph_data']['key'], 1, 'x'), $node['x'], $node['id']);
     update_sub_field(array($this->_fields['graph_data']['key'], 1, 'y'), $node['y'], $node['id']);
     // Update links
     update_sub_field(array($this->_fields['graph_data']['key'], 1, 'links'), $acfLinks, $node['id']);
     // Update start node status
     update_sub_field(array($this->_fields['graph_data']['key'], 1, 'start'), $node['start'] === 'true', $node['id']);
 }
예제 #8
0
function update_row($selector, $row = 1, $value = false, $post_id = false)
{
    // bail early if no value
    if (empty($value)) {
        return false;
    }
    // filter post_id
    $post_id = acf_get_valid_post_id($post_id);
    // get field
    $field = acf_maybe_get_field($selector, $post_id);
    // bail early if no field
    if (!$field) {
        return false;
    }
    // update sub fields
    foreach ($value as $k => $v) {
        update_sub_field(array($field['key'], $row, $k), $v, $post_id);
    }
    // return
    return true;
}