当前位置: 首页>>代码示例>>PHP>>正文


PHP PodsForm::text_field_types方法代码示例

本文整理汇总了PHP中PodsForm::text_field_types方法的典型用法代码示例。如果您正苦于以下问题:PHP PodsForm::text_field_types方法的具体用法?PHP PodsForm::text_field_types怎么用?PHP PodsForm::text_field_types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PodsForm的用法示例。


在下文中一共展示了PodsForm::text_field_types方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: add_to

 /**
  * Add an item to the values of a relationship field, add a value to a number field (field+1), add time to a date field, or add text to a text field
  *
  * @see PodsAPI::save_pod_item
  *
  * @param string $field Field name
  * @param mixed $value ID(s) to add, int|float to add to number field, string for dates (+1 week), or string for text
  * @param int $id (optional) ID of the pod item to update
  *
  * @return int The item ID
  *
  * @since 2.3
  */
 public function add_to($field, $value, $id = null)
 {
     $pod =& $this;
     $fetch = false;
     if (null === $id) {
         $fetch = true;
         $id = $this->id();
     } elseif ($id != $this->id()) {
         $pod = pods($this->pod, $id);
     }
     $this->do_hook('add_to', $field, $value, $id);
     if (!isset($this->fields[$field])) {
         return $id;
     }
     // Tableless fields
     if (in_array($this->fields[$field]['type'], PodsForm::tableless_field_types())) {
         if (!is_array($value)) {
             $value = explode(',', $value);
         }
         if ('pick' == $this->fields[$field]['type'] && in_array($this->fields[$field]['pick_object'], PodsForm::field_method('pick', 'simple_objects'))) {
             $current_value = $pod->raw($field);
             if (!empty($current_value) || !is_array($current_value) && 0 < strlen($current_value)) {
                 $current_value = (array) $current_value;
             } else {
                 $current_value = array();
             }
             $value = array_merge($current_value, $value);
         } else {
             $related_ids = $this->api->lookup_related_items($this->fields[$field]['id'], $this->pod_data['id'], $id, $this->fields[$field], $this->pod_data);
             foreach ($value as $k => $v) {
                 if (!preg_match('/[^0-9]/', $v)) {
                     $value[$k] = (int) $v;
                 }
             }
             $value = array_merge($related_ids, $value);
         }
         if (!empty($value)) {
             $value = array_filter(array_unique($value));
         } else {
             $value = array();
         }
         if (empty($value)) {
             return $id;
         }
     } elseif (in_array($this->fields[$field]['type'], PodsForm::number_field_types())) {
         $current_value = (double) $pod->raw($field);
         $value = $current_value + (double) $value;
     } elseif (in_array($this->fields[$field]['type'], PodsForm::date_field_types())) {
         $current_value = $pod->raw($field);
         if (0 < strlen($current_value)) {
             $value = strtotime($value, strtotime($current_value));
         } else {
             $value = strtotime($value);
         }
     } elseif (in_array($this->fields[$field]['type'], PodsForm::text_field_types())) {
         $current_value = $pod->raw($field);
         if (0 < strlen($current_value)) {
             $value = $current_value . $value;
         }
     }
     // @todo handle object fields and taxonomies
     $params = array('pod' => $this->pod, 'id' => $id, 'data' => array($field => $value));
     $id = $this->api->save_pod_item($params);
     if (0 < $id && $fetch) {
         $pod->fetch($id, false);
     }
     return $id;
 }
开发者ID:erkmen,项目名称:wpstartersetup,代码行数:81,代码来源:Pods.php


注:本文中的PodsForm::text_field_types方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。