當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WPCOM_JSON_API::is_truthy方法代碼示例

本文整理匯總了PHP中WPCOM_JSON_API::is_truthy方法的典型用法代碼示例。如果您正苦於以下問題:PHP WPCOM_JSON_API::is_truthy方法的具體用法?PHP WPCOM_JSON_API::is_truthy怎麽用?PHP WPCOM_JSON_API::is_truthy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WPCOM_JSON_API的用法示例。


在下文中一共展示了WPCOM_JSON_API::is_truthy方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: write_post


//.........這裏部分代碼省略.........
         foreach ($terms as $term) {
             if (!ctype_digit($term)) {
                 // skip anything that doesn't look like an ID
                 continue;
             }
             $term = (int) $term;
             $term_info = get_term_by('id', $term, $taxonomy, ARRAY_A);
             if ($term_info && !is_wp_error($term_info)) {
                 if ($is_hierarchical) {
                     // Categories must be added by ID
                     $tax_input[$taxonomy][] = $term;
                 } else {
                     // Tags must be added by name
                     $tax_input[$taxonomy][] = $term_info['name'];
                 }
             }
         }
     }
     if ((isset($input['categories']) || isset($input['categories_by_id'])) && empty($tax_input['category']) && 'revision' !== $post_type->name) {
         $tax_input['category'][] = get_option('default_category');
     }
     unset($input['tags'], $input['categories'], $input['tags_by_id'], $input['categories_by_id']);
     $insert = array();
     if (!empty($input['slug'])) {
         $insert['post_name'] = $input['slug'];
         unset($input['slug']);
     }
     if (isset($input['discussion'])) {
         $discussion = (array) $input['discussion'];
         foreach (array('comment', 'ping') as $discussion_type) {
             $discussion_open = sprintf('%ss_open', $discussion_type);
             $discussion_status = sprintf('%s_status', $discussion_type);
             if (isset($discussion[$discussion_open])) {
                 $is_open = WPCOM_JSON_API::is_truthy($discussion[$discussion_open]);
                 $discussion[$discussion_status] = $is_open ? 'open' : 'closed';
             }
             if (in_array($discussion[$discussion_status], array('open', 'closed'))) {
                 $insert[$discussion_status] = $discussion[$discussion_status];
             }
         }
     }
     unset($input['discussion']);
     if (isset($input['menu_order'])) {
         $insert['menu_order'] = $input['menu_order'];
         unset($input['menu_order']);
     }
     if (isset($input['publicize'])) {
         $publicize = $input['publicize'];
         unset($input['publicize']);
     }
     if (isset($input['publicize_message'])) {
         $publicize_custom_message = $input['publicize_message'];
         unset($input['publicize_message']);
     }
     if (isset($input['featured_image'])) {
         $featured_image = trim($input['featured_image']);
         $delete_featured_image = empty($featured_image);
         unset($input['featured_image']);
     }
     if (isset($input['metadata'])) {
         $metadata = $input['metadata'];
         unset($input['metadata']);
     }
     if (isset($input['likes_enabled'])) {
         $likes = $input['likes_enabled'];
         unset($input['likes_enabled']);
開發者ID:brooklyntri,項目名稱:btc-plugins,代碼行數:67,代碼來源:class.wpcom-json-api-update-post-v1-2-endpoint.php

示例2: cast_and_filter_item


//.........這裏部分代碼省略.........
             // nobreak
         // nobreak
         case 'array':
             // Fallback array -> string
             if (is_string($value)) {
                 if (!empty($types[0])) {
                     $next_type = array_shift($types);
                     return $this->cast_and_filter_item($return, $next_type, $key, $value, $types, $for_output);
                 }
             }
             if (isset($type['children'])) {
                 $children = array();
                 foreach ((array) $value as $k => $child) {
                     $this->cast_and_filter_item($children, $type['children'], $k, $child, array(), $for_output);
                 }
                 $return[$key] = (array) $children;
                 break;
             }
             $return[$key] = (array) $value;
             break;
         case 'iso 8601 datetime':
         case 'datetime':
             // (string)s
             $dates = $this->parse_date((string) $value);
             if ($for_output) {
                 $return[$key] = $this->format_date($dates[1], $dates[0]);
             } else {
                 list($return[$key], $return["{$key}_gmt"]) = $dates;
             }
             break;
         case 'float':
             $return[$key] = (double) $value;
             break;
         case 'int':
         case 'integer':
             $return[$key] = (int) $value;
             break;
         case 'bool':
         case 'boolean':
             $return[$key] = (bool) WPCOM_JSON_API::is_truthy($value);
             break;
         case 'object':
             // Fallback object -> false
             if (is_scalar($value) || is_null($value)) {
                 if (!empty($types[0]) && 'false' === $types[0]['type']) {
                     return $this->cast_and_filter_item($return, 'false', $key, $value, $types, $for_output);
                 }
             }
             if (isset($type['children'])) {
                 $children = array();
                 foreach ((array) $value as $k => $child) {
                     $this->cast_and_filter_item($children, $type['children'], $k, $child, array(), $for_output);
                 }
                 $return[$key] = (object) $children;
                 break;
             }
             if (isset($type['subtype'])) {
                 return $this->cast_and_filter_item($return, $type['subtype'], $key, $value, $types, $for_output);
             }
             $return[$key] = (object) $value;
             break;
         case 'post':
             $return[$key] = (object) $this->cast_and_filter($value, $this->post_object_format, false, $for_output);
             break;
         case 'comment':
             $return[$key] = (object) $this->cast_and_filter($value, $this->comment_object_format, false, $for_output);
             break;
         case 'tag':
         case 'category':
             $docs = array('name' => '(string)', 'slug' => '(string)', 'description' => '(HTML)', 'post_count' => '(int)', 'meta' => '(object)');
             if ('category' === $type) {
                 $docs['parent'] = '(int)';
             }
             $return[$key] = (object) $this->cast_and_filter($value, $docs, false, $for_output);
             break;
         case 'post_reference':
         case 'comment_reference':
             $docs = array('ID' => '(int)', 'type' => '(string)', 'link' => '(URL)');
             $return[$key] = (object) $this->cast_and_filter($value, $docs, false, $for_output);
             break;
         case 'geo':
             $docs = array('latitude' => '(float)', 'longitude' => '(float)', 'address' => '(string)');
             $return[$key] = (object) $this->cast_and_filter($value, $docs, false, $for_output);
             break;
         case 'author':
             $docs = array('ID' => '(int)', 'email' => '(string|false)', 'name' => '(string)', 'URL' => '(URL)', 'avatar_URL' => '(URL)', 'profile_URL' => '(URL)');
             $return[$key] = (object) $this->cast_and_filter($value, $docs, false, $for_output);
             break;
         case 'attachment':
             $docs = array('ID' => '(int)', 'URL' => '(URL)', 'guid' => '(string)', 'mime_type' => '(string)', 'width' => '(int)', 'height' => '(int)', 'duration' => '(int)');
             $return[$key] = (object) $this->cast_and_filter($value, apply_filters('wpcom_json_api_attachment_cast_and_filter', $docs), false, $for_output);
             break;
         case 'metadata':
             $docs = array('id' => '(int)', 'key' => '(string)', 'value' => '(string|false|float|int|array|object)', 'previous_value' => '(string)', 'operation' => '(string)');
             $return[$key] = (object) $this->cast_and_filter($value, apply_filters('wpcom_json_api_attachment_cast_and_filter', $docs), false, $for_output);
             break;
         default:
             trigger_error("Unknown API casting type {$type['type']}", E_USER_WARNING);
     }
 }
開發者ID:vsalx,項目名稱:rattieinfo,代碼行數:101,代碼來源:class.json-api-endpoints.php

示例3: cast_and_filter_item


//.........這裏部分代碼省略.........
                     $next_type = array_shift($types);
                     return $this->cast_and_filter_item($return, $next_type, $key, $value, $types, $for_output);
                 }
             }
             if (isset($type['children'])) {
                 $children = array();
                 foreach ((array) $value as $k => $child) {
                     $this->cast_and_filter_item($children, $type['children'], $k, $child, array(), $for_output);
                 }
                 $return[$key] = (array) $children;
                 break;
             }
             $return[$key] = (array) $value;
             break;
         case 'iso 8601 datetime':
         case 'datetime':
             // (string)s
             $dates = $this->parse_date((string) $value);
             if ($for_output) {
                 $return[$key] = $this->format_date($dates[1], $dates[0]);
             } else {
                 list($return[$key], $return["{$key}_gmt"]) = $dates;
             }
             break;
         case 'float':
             $return[$key] = (double) $value;
             break;
         case 'int':
         case 'integer':
             $return[$key] = (int) $value;
             break;
         case 'bool':
         case 'boolean':
             $return[$key] = (bool) WPCOM_JSON_API::is_truthy($value);
             break;
         case 'object':
             // Fallback object -> false
             if (is_scalar($value) || is_null($value)) {
                 if (!empty($types[0]) && 'false' === $types[0]['type']) {
                     return $this->cast_and_filter_item($return, 'false', $key, $value, $types, $for_output);
                 }
             }
             if (isset($type['children'])) {
                 $children = array();
                 foreach ((array) $value as $k => $child) {
                     $this->cast_and_filter_item($children, $type['children'], $k, $child, array(), $for_output);
                 }
                 $return[$key] = (object) $children;
                 break;
             }
             if (isset($type['subtype'])) {
                 return $this->cast_and_filter_item($return, $type['subtype'], $key, $value, $types, $for_output);
             }
             $return[$key] = (object) $value;
             break;
         case 'post':
             $return[$key] = (object) $this->cast_and_filter($value, $this->post_object_format, false, $for_output);
             break;
         case 'comment':
             $return[$key] = (object) $this->cast_and_filter($value, $this->comment_object_format, false, $for_output);
             break;
         case 'tag':
         case 'category':
             $docs = array('ID' => '(int)', 'name' => '(string)', 'slug' => '(string)', 'description' => '(HTML)', 'post_count' => '(int)', 'meta' => '(object)');
             if ('category' === $type['type']) {
                 $docs['parent'] = '(int)';
開發者ID:frontend-labs,項目名稱:post-template,代碼行數:67,代碼來源:class.json-api-endpoints.php

示例4: cast_and_filter_item


//.........這裏部分代碼省略.........
                     $next_type = array_shift($types);
                     return $this->cast_and_filter_item($return, $next_type, $key, $value, $types, $for_output);
                 }
             }
             if (isset($type['children'])) {
                 $children = array();
                 foreach ((array) $value as $k => $child) {
                     $this->cast_and_filter_item($children, $type['children'], $k, $child, array(), $for_output);
                 }
                 $return[$key] = (array) $children;
                 break;
             }
             $return[$key] = (array) $value;
             break;
         case 'iso 8601 datetime':
         case 'datetime':
             // (string)s
             $dates = $this->parse_date((string) $value);
             if ($for_output) {
                 $return[$key] = $this->format_date($dates[1], $dates[0]);
             } else {
                 list($return[$key], $return["{$key}_gmt"]) = $dates;
             }
             break;
         case 'float':
             $return[$key] = (double) $value;
             break;
         case 'int':
         case 'integer':
             $return[$key] = (int) $value;
             break;
         case 'bool':
         case 'boolean':
             $return[$key] = (bool) WPCOM_JSON_API::is_truthy($value);
             break;
         case 'object':
             // Fallback object -> false
             if (is_scalar($value) || is_null($value)) {
                 if (!empty($types[0]) && 'false' === $types[0]['type']) {
                     return $this->cast_and_filter_item($return, 'false', $key, $value, $types, $for_output);
                 }
             }
             if (isset($type['children'])) {
                 $children = array();
                 foreach ((array) $value as $k => $child) {
                     $this->cast_and_filter_item($children, $type['children'], $k, $child, array(), $for_output);
                 }
                 $return[$key] = (object) $children;
                 break;
             }
             if (isset($type['subtype'])) {
                 return $this->cast_and_filter_item($return, $type['subtype'], $key, $value, $types, $for_output);
             }
             $return[$key] = (object) $value;
             break;
         case 'post':
             $return[$key] = (object) $this->cast_and_filter($value, $this->post_object_format, false, $for_output);
             break;
         case 'comment':
             $return[$key] = (object) $this->cast_and_filter($value, $this->comment_object_format, false, $for_output);
             break;
         case 'tag':
         case 'category':
             $docs = array('ID' => '(int)', 'name' => '(string)', 'slug' => '(string)', 'description' => '(HTML)', 'post_count' => '(int)', 'meta' => '(object)');
             if ('category' === $type['type']) {
                 $docs['parent'] = '(int)';
開發者ID:spielhoelle,項目名稱:amnesty,代碼行數:67,代碼來源:class.json-api-endpoints.php


注:本文中的WPCOM_JSON_API::is_truthy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。