本文整理汇总了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']);
示例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);
}
}
示例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)';
示例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)';