本文整理汇总了PHP中get_post_format_slugs函数的典型用法代码示例。如果您正苦于以下问题:PHP get_post_format_slugs函数的具体用法?PHP get_post_format_slugs怎么用?PHP get_post_format_slugs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_post_format_slugs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: circleflip_get_post_format_media
function circleflip_get_post_format_media($post_id = null, $size = 'thumbnail', $ident = false)
{
$post = get_post($post_id);
if (!$post) {
return false;
}
$post_id = $post->ID;
$media_html = '';
$format = get_post_format($post_id);
$slugs = get_post_format_slugs();
$format_slug = $format ? $slugs[$format] : $slugs['standard'];
$meta = get_post_meta($post_id, '_circleflip_post_formats', true);
$meta = apply_filters('circleflip_post_format_meta', $meta, $format_slug, $post_id, $size, $ident);
$size_info = circleflip_get_size_dimensions($size);
$size_info = apply_filters('circleflip_post_format_media_size', $size_info, $format_slug, $post_id, $size, $ident);
$audiovideo = array('url' => '', 'args' => array('width' => $size_info['width'], 'height' => $size_info['height']), 'html5' => false);
switch ($format_slug) {
case 'audio':
if (!empty($meta['audio_embed'])) {
$audiovideo['url'] = $meta['audio_embed'];
} else {
if (!empty($meta['audio_id'])) {
$audiovideo['url'] = wp_get_attachment_url($meta['audio_id']);
$audiovideo['html5'] = true;
}
}
$media_html = circleflip_get_wp_media('audio', $audiovideo['url'], $audiovideo['args'], $audiovideo['html5']);
break;
case 'video':
if (!empty($meta['video_embed'])) {
$audiovideo['url'] = $meta['video_embed'];
unset($audiovideo['args']['height']);
} else {
if (!empty($meta['video_id'])) {
$audiovideo['url'] = wp_get_attachment_url($meta['video_id']);
$audiovideo['html5'] = true;
}
}
$media_html = circleflip_get_wp_media('video', $audiovideo['url'], $audiovideo['args'], $audiovideo['html5']);
break;
case 'gallery':
if (!empty($meta['gallery'])) {
$media_html = circleflip_get_gallery($meta['gallery'], $meta['gallery_layout']);
}
break;
case 'standard':
$media_html = '<a href="' . get_the_permalink($post_id) . '">' . get_the_post_thumbnail($post_id, $size) . '</a>';
}
$media_html = apply_filters("circleflip_post_format_{$format_slug}_html", $media_html, $post_id, $size, $ident, $audiovideo);
$media_html = apply_filters("circleflip_post_format_html", $media_html, $format_slug, $post_id, $size, $ident, $audiovideo);
return $media_html;
}
示例2: admin_enqueue_scripts
/**
* Enqueue necessary post format scripts
*
* @since 1.0
*/
public function admin_enqueue_scripts($hook)
{
if (in_array($hook, array('post.php', 'post-new.php'))) {
if ($post_formats_support = get_theme_support('post-formats')) {
/* Get supported post formats */
if (!isset($post_formats_support[0]) || !is_array($post_formats_support[0])) {
$post_formats_support = get_post_format_slugs();
} else {
$post_formats_support = $post_formats_support[0];
}
$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
wp_enqueue_script('youxi-post-formats', YOUXI_POST_FORMAT_URL . "/assets/js/youxi.post-formats{$suffix}.js", array('jquery'), YOUXI_POST_FORMAT_VERSION, true);
$metabox_id_map = array();
foreach ($this->metaboxes as $id => $metabox) {
$metabox_id_map[$id] = $metabox['id'];
}
wp_localize_script('youxi-post-formats', 'YouxiPostFormatsConfig', array('metaboxes' => $metabox_id_map));
}
}
}
示例3: _post_format_request
/**
* Filters the request to allow for the format prefix.
*
* @access private
* @since 3.1.0
*/
function _post_format_request($qvs)
{
if (!isset($qvs['post_format'])) {
return $qvs;
}
$slugs = get_post_format_slugs();
if (isset($slugs[$qvs['post_format']])) {
$qvs['post_format'] = 'post-format-' . $slugs[$qvs['post_format']];
}
$tax = get_taxonomy('post_format');
$qvs['post_type'] = $tax->object_type;
return $qvs;
}
示例4: tag_PostType
function tag_PostType(&$subject, $postmodifiers, $config)
{
$post_type = $config['post_type'];
$custom_post_type = $config['post_format'];
$separated_subject = array();
$separated_subject[0] = "";
$separated_subject[1] = $subject;
$custom_post_type_delim = "//";
if (strpos($subject, $custom_post_type_delim) !== FALSE) {
// Captures the custom post type in the subject before $custom_post_type_delim
$separated_subject = explode($custom_post_type_delim, $subject);
$custom_post_type = $separated_subject[0];
$custom_post_type = trim(strtolower($custom_post_type));
DebugEcho("post type: found possible type '{$custom_post_type}'");
}
$known_post_types = get_post_types();
if (in_array($custom_post_type, array_map('strtolower', $known_post_types))) {
DebugEcho("post type: found type '{$post_type}'");
$post_type = $custom_post_type;
$subject = trim($separated_subject[1]);
} elseif (in_array($custom_post_type, array_keys(get_post_format_slugs()))) {
DebugEcho("post type: found format '{$custom_post_type}'");
$postmodifiers->PostFormat = $custom_post_type;
$subject = trim($separated_subject[1]);
}
return $post_type;
}
示例5: add_theme_support
/**
* Allows a theme to register its support of a certain feature
*
* Must be called in the theme's functions.php file to work.
* If attached to a hook, it must be after_setup_theme.
* The init hook may be too late for some features.
*
* @since 2.9.0
* @param string $feature the feature being added
*/
function add_theme_support($feature)
{
global $_wp_theme_features;
if (func_num_args() == 1) {
$args = true;
} else {
$args = array_slice(func_get_args(), 1);
}
switch ($feature) {
case 'post-formats':
if (is_array($args[0])) {
$args[0] = array_intersect($args[0], array_keys(get_post_format_slugs()));
}
break;
case 'custom-header-uploads':
return add_theme_support('custom-header', array('uploads' => true));
break;
case 'custom-header':
if (!is_array($args)) {
$args = array(0 => array());
}
$defaults = array('default-image' => '', 'random-default' => false, 'width' => 0, 'height' => 0, 'flex-height' => false, 'flex-width' => false, 'default-text-color' => '', 'header-text' => true, 'uploads' => true, 'wp-head-callback' => '', 'admin-head-callback' => '', 'admin-preview-callback' => '');
$jit = isset($args[0]['__jit']);
unset($args[0]['__jit']);
// Merge in data from previous add_theme_support() calls.
// The first value registered wins. (A child theme is set up first.)
if (isset($_wp_theme_features['custom-header'])) {
$args[0] = wp_parse_args($_wp_theme_features['custom-header'][0], $args[0]);
}
// Load in the defaults at the end, as we need to insure first one wins.
// This will cause all constants to be defined, as each arg will then be set to the default.
if ($jit) {
$args[0] = wp_parse_args($args[0], $defaults);
}
// If a constant was defined, use that value. Otherwise, define the constant to ensure
// the constant is always accurate (and is not defined later, overriding our value).
// As stated above, the first value wins.
// Once we get to wp_loaded (just-in-time), define any constants we haven't already.
// Constants are lame. Don't reference them. This is just for backwards compatibility.
if (defined('NO_HEADER_TEXT')) {
$args[0]['header-text'] = !NO_HEADER_TEXT;
} elseif (isset($args[0]['header-text'])) {
define('NO_HEADER_TEXT', empty($args[0]['header-text']));
}
if (defined('HEADER_IMAGE_WIDTH')) {
$args[0]['width'] = (int) HEADER_IMAGE_WIDTH;
} elseif (isset($args[0]['width'])) {
define('HEADER_IMAGE_WIDTH', (int) $args[0]['width']);
}
if (defined('HEADER_IMAGE_HEIGHT')) {
$args[0]['height'] = (int) HEADER_IMAGE_HEIGHT;
} elseif (isset($args[0]['height'])) {
define('HEADER_IMAGE_HEIGHT', (int) $args[0]['height']);
}
if (defined('HEADER_TEXTCOLOR')) {
$args[0]['default-text-color'] = HEADER_TEXTCOLOR;
} elseif (isset($args[0]['default-text-color'])) {
define('HEADER_TEXTCOLOR', $args[0]['default-text-color']);
}
if (defined('HEADER_IMAGE')) {
$args[0]['default-image'] = HEADER_IMAGE;
} elseif (isset($args[0]['default-image'])) {
define('HEADER_IMAGE', $args[0]['default-image']);
}
if ($jit && !empty($args[0]['default-image'])) {
$args[0]['random-default'] = false;
}
// If headers are supported, and we still don't have a defined width or height,
// we have implicit flex sizes.
if ($jit) {
if (empty($args[0]['width']) && empty($args[0]['flex-width'])) {
$args[0]['flex-width'] = true;
}
if (empty($args[0]['height']) && empty($args[0]['flex-height'])) {
$args[0]['flex-height'] = true;
}
}
break;
case 'custom-background':
if (!is_array($args)) {
$args = array(0 => array());
}
$defaults = array('default-image' => '', 'default-color' => '', 'wp-head-callback' => '_custom_background_cb', 'admin-head-callback' => '', 'admin-preview-callback' => '');
$jit = isset($args[0]['__jit']);
unset($args[0]['__jit']);
// Merge in data from previous add_theme_support() calls. The first value registered wins.
if (isset($_wp_theme_features['custom-background'])) {
$args[0] = wp_parse_args($_wp_theme_features['custom-background'][0], $args[0]);
}
if ($jit) {
//.........这里部分代码省略.........
示例6: add_theme_support
/**
* Allows a theme to register its support of a certain feature
*
* Must be called in the theme's functions.php file to work.
* If attached to a hook, it must be after_setup_theme.
* The init hook may be too late for some features.
*
* @since 2.9.0
*
* @global array $_wp_theme_features
*
* @param string $feature The feature being added.
* @return void|bool False on failure, void otherwise.
*/
function add_theme_support($feature)
{
global $_wp_theme_features;
if (func_num_args() == 1) {
$args = true;
} else {
$args = array_slice(func_get_args(), 1);
}
switch ($feature) {
case 'post-formats':
if (is_array($args[0])) {
$post_formats = get_post_format_slugs();
unset($post_formats['standard']);
$args[0] = array_intersect($args[0], array_keys($post_formats));
}
break;
case 'html5':
// You can't just pass 'html5', you need to pass an array of types.
if (empty($args[0])) {
// Build an array of types for back-compat.
$args = array(0 => array('comment-list', 'comment-form', 'search-form'));
} elseif (!is_array($args[0])) {
_doing_it_wrong("add_theme_support( 'html5' )", __('You need to pass an array of types.'), '3.6.1');
return false;
}
// Calling 'html5' again merges, rather than overwrites.
if (isset($_wp_theme_features['html5'])) {
$args[0] = array_merge($_wp_theme_features['html5'][0], $args[0]);
}
break;
case 'custom-header-uploads':
return add_theme_support('custom-header', array('uploads' => true));
case 'custom-header':
if (!is_array($args)) {
$args = array(0 => array());
}
$defaults = array('default-image' => '', 'random-default' => false, 'width' => 0, 'height' => 0, 'flex-height' => false, 'flex-width' => false, 'default-text-color' => '', 'header-text' => true, 'uploads' => true, 'wp-head-callback' => '', 'admin-head-callback' => '', 'admin-preview-callback' => '');
$jit = isset($args[0]['__jit']);
unset($args[0]['__jit']);
// Merge in data from previous add_theme_support() calls.
// The first value registered wins. (A child theme is set up first.)
if (isset($_wp_theme_features['custom-header'])) {
$args[0] = wp_parse_args($_wp_theme_features['custom-header'][0], $args[0]);
}
// Load in the defaults at the end, as we need to insure first one wins.
// This will cause all constants to be defined, as each arg will then be set to the default.
if ($jit) {
$args[0] = wp_parse_args($args[0], $defaults);
}
// If a constant was defined, use that value. Otherwise, define the constant to ensure
// the constant is always accurate (and is not defined later, overriding our value).
// As stated above, the first value wins.
// Once we get to wp_loaded (just-in-time), define any constants we haven't already.
// Constants are lame. Don't reference them. This is just for backwards compatibility.
if (defined('NO_HEADER_TEXT')) {
$args[0]['header-text'] = !NO_HEADER_TEXT;
} elseif (isset($args[0]['header-text'])) {
define('NO_HEADER_TEXT', empty($args[0]['header-text']));
}
if (defined('HEADER_IMAGE_WIDTH')) {
$args[0]['width'] = (int) HEADER_IMAGE_WIDTH;
} elseif (isset($args[0]['width'])) {
define('HEADER_IMAGE_WIDTH', (int) $args[0]['width']);
}
if (defined('HEADER_IMAGE_HEIGHT')) {
$args[0]['height'] = (int) HEADER_IMAGE_HEIGHT;
} elseif (isset($args[0]['height'])) {
define('HEADER_IMAGE_HEIGHT', (int) $args[0]['height']);
}
if (defined('HEADER_TEXTCOLOR')) {
$args[0]['default-text-color'] = HEADER_TEXTCOLOR;
} elseif (isset($args[0]['default-text-color'])) {
define('HEADER_TEXTCOLOR', $args[0]['default-text-color']);
}
if (defined('HEADER_IMAGE')) {
$args[0]['default-image'] = HEADER_IMAGE;
} elseif (isset($args[0]['default-image'])) {
define('HEADER_IMAGE', $args[0]['default-image']);
}
if ($jit && !empty($args[0]['default-image'])) {
$args[0]['random-default'] = false;
}
// If headers are supported, and we still don't have a defined width or height,
// we have implicit flex sizes.
if ($jit) {
if (empty($args[0]['width']) && empty($args[0]['flex-width'])) {
//.........这里部分代码省略.........
示例7: raindrops_loop_class
function raindrops_loop_class($raindrops_loop_number, $raindrops_tile_post_id = '', $add_class = '')
{
if (is_front_page() || is_home()) {
$id = get_option('page_on_front');
$template_name = basename(get_page_template_slug($id), '.php');
} elseif (is_page()) {
global $template;
$template_name = basename($template, '.php');
} else {
$template_name = '';
}
$str_class = '';
$raindrops_background = '';
if (is_array($add_class)) {
foreach ($add_class as $class) {
$str_class = ' ' . $class;
}
} else {
$str_class = ' ' . $add_class;
}
$post_formats = get_post_format_slugs();
foreach ($post_formats as $key => $val) {
if (has_post_format($val)) {
$str_class .= ' loop-post-format-' . $val;
}
}
$raindrops_loop_five = $str_class;
if (12 == $raindrops_loop_number) {
$raindrops_loop_number = 0;
} elseif (0 == $raindrops_loop_number % 5) {
$raindrops_loop_five .= ' loop-five';
}
if (!empty($raindrops_tile_post_id)) {
$post_thumbnail_id = get_post_thumbnail_id($raindrops_tile_post_id);
$raindrops_background = wp_get_attachment_image_src($post_thumbnail_id, 'medium');
list($raindrops_background, $width, $height) = $raindrops_background;
} else {
$raindrops_background = false;
}
if (!$raindrops_background) {
$raindrops_loop_five .= ' loop-item-show-allways';
} else {
$raindrops_background = 'style="background:url( ' . $raindrops_background . ' );background-size:cover;"';
}
return array($raindrops_loop_number, $raindrops_loop_five, $raindrops_background);
}
示例8: get_screen_icon
/**
* Gets a screen icon.
*
* @since 3.2.0
*
* @global $post_ID
* @param string|WP_Screen $screen Optional. Accepts a screen object (and defaults to the current screen object)
* which it uses to determine an icon HTML ID. Or, if a string is provided, it is used to form the icon HTML ID.
* @return string HTML for the screen icon.
*/
function get_screen_icon($screen = '')
{
if (empty($screen)) {
$screen = get_current_screen();
} elseif (is_string($screen)) {
$icon_id = $screen;
}
$class = 'icon32';
if (empty($icon_id)) {
if (!empty($screen->parent_base)) {
$icon_id = $screen->parent_base;
} else {
$icon_id = $screen->base;
}
if ('page' == $screen->post_type) {
$icon_id = 'edit-pages';
}
if ($screen->post_type) {
$class .= ' ' . sanitize_html_class('icon32-posts-' . $screen->post_type);
}
if ('post' == $screen->id) {
$post_format = get_post_format();
if (!$post_format && !empty($_REQUEST['format']) && in_array($_REQUEST['format'], get_post_format_slugs())) {
$post_format = $_REQUEST['format'];
}
if ($post_format) {
$class .= ' wp-format-' . $post_format;
}
}
}
return '<div id="icon-' . esc_attr($icon_id) . '" class="' . $class . '"><br /></div>';
}
示例9: widget
/**
* Displaying the widget
*
* Handle the display of the widget
* @param array
* @param array
*/
function widget($args, $instance)
{
extract($args);
global $wp_query;
/* Before widget(defined by theme)*/
echo $before_widget;
$query = array();
if (!empty($instance['number_of_posts'])) {
$query['showposts'] = $instance['number_of_posts'];
} else {
$query['showposts'] = 1;
}
$formats = get_post_format_slugs();
foreach ((array) $formats as $i => $format) {
$formats[$i] = 'post-format-' . $format;
}
$query['tax_query'] = array(array('taxonomy' => 'post_format', 'field' => 'slug', 'terms' => $formats, 'operator' => 'NOT IN'));
/* START Widget body */
//if ( isset( $instance['title'] ) ) echo $before_title . $instance['title'] . $after_title;
if (!empty($instance['title'])) {
echo $before_title;
echo do_shortcode($instance['title']);
echo $after_title;
}
$i = 1;
$num_posts = sizeof(query_posts($query));
if (have_posts()) {
?>
<div class="postitems-wrapper">
<?php
while (have_posts()) {
the_post();
if (!empty($instance['excerpt_length'])) {
if (function_exists('iconv')) {
$text = iconv_substr(strip_tags(get_the_content()), 0, $instance['excerpt_length'], 'UTF-8');
} else {
$text = substr(strip_tags(get_the_content()), 0, $instance['excerpt_length']);
}
} else {
$text = get_the_excerpt();
}
$thumbnail_id = get_post_thumbnail_id(get_the_ID());
$thumbnail_args = wp_get_attachment_image_src($thumbnail_id, 'single-post-thumbnail');
switch ($instance['thumbnail_position']) {
case 'left':
$thumbnail_class = 'fl';
break;
case 'right':
$thumbnail_class = 'fr';
break;
default:
$thumbnail_class = '';
break;
}
$post_class = '';
// Is last post
if ($i == $num_posts) {
$post_class = ' last';
}
// Has thumbnail
if (has_post_thumbnail(get_the_ID()) && $instance['show_thumbnails']) {
$post_class .= ' with-thumbnail';
}
?>
<div class="postitem clearfix <?php
echo $post_class;
?>
">
<?php
if (has_post_thumbnail(get_the_ID()) && $instance['show_thumbnails']) {
?>
<div class="thumb-wrap <?php
echo $thumbnail_class;
?>
">
<a href="<?php
the_permalink();
?>
" class="greyscale">
<?php
if (TIMTHUMB_URL != '') {
?>
<img class="thumb" src="<?php
echo TIMTHUMB_URL;
?>
?src=<?php
echo getRealThumbnailUrl($thumbnail_args['0']);
?>
&w=<?php
echo $instance['thumbnail_width'];
//.........这里部分代码省略.........
示例10: insert_post
//.........这里部分代码省略.........
$post['post_name'] = $data['name'];
}
// Author
if (!empty($data['author'])) {
// Allow passing an author object
if (is_object($data['author'])) {
if (empty($data['author']->ID)) {
return new WP_Error('json_invalid_author', __('Invalid author object.'), array('status' => 400));
}
$data['author'] = (int) $data['author']->ID;
} else {
$data['author'] = (int) $data['author'];
}
// Only check edit others' posts if we are another user
if ($data['author'] !== get_current_user_id()) {
if (!json_check_post_permission($post, 'edit_others_posts')) {
return new WP_Error('json_cannot_edit_others', __('You are not allowed to edit posts as this user.'), array('status' => 401));
}
$author = get_userdata($data['author']);
if (!$author) {
return new WP_Error('json_invalid_author', __('Invalid author ID.'), array('status' => 400));
}
}
$post['post_author'] = $data['author'];
}
// Post password
if (!empty($data['password'])) {
$post['post_password'] = $data['password'];
if (!json_check_post_permission($post, 'publish_posts')) {
return new WP_Error('json_cannot_create_passworded', __('Sorry, you are not allowed to create password protected posts in this post type'), array('status' => 401));
}
}
// Content and excerpt
if (!empty($data['content_raw'])) {
$post['post_content'] = $data['content_raw'];
}
if (!empty($data['excerpt_raw'])) {
$post['post_excerpt'] = $data['excerpt_raw'];
}
// Parent
if (!empty($data['parent'])) {
$parent = get_post($data['parent']);
if (empty($parent)) {
return new WP_Error('json_post_invalid_id', __('Invalid post parent ID.'), array('status' => 400));
}
$post['post_parent'] = $parent->ID;
}
// Menu order
if (!empty($data['menu_order'])) {
$post['menu_order'] = $data['menu_order'];
}
// Comment status
if (!empty($data['comment_status'])) {
$post['comment_status'] = $data['comment_status'];
}
// Ping status
if (!empty($data['ping_status'])) {
$post['ping_status'] = $data['ping_status'];
}
// Post format
if (!empty($data['post_format'])) {
$formats = get_post_format_slugs();
if (!in_array($data['post_format'], $formats)) {
return new WP_Error('json_invalid_post_format', __('Invalid post format.'), array('status' => 400));
}
$post['post_format'] = $data['post_format'];
}
// Pre-insert hook
$can_insert = apply_filters('json_pre_insert_post', true, $post, $data, $update);
if (is_wp_error($can_insert)) {
return $can_insert;
}
// Post meta
// TODO: implement this
$post_ID = $update ? wp_update_post($post, true) : wp_insert_post($post, true);
if (is_wp_error($post_ID)) {
return $post_ID;
}
// If this is a new post, add the post ID to $post
if (!$update) {
$post['ID'] = $post_ID;
}
// Post meta
if (!empty($data['post_meta'])) {
$result = $this->handle_post_meta_action($post_ID, $data);
if (is_wp_error($result)) {
return $result;
}
}
// Sticky
if (isset($data['sticky'])) {
if ($data['sticky']) {
stick_post($post_ID);
} else {
unstick_post($post_ID);
}
}
do_action('json_insert_post', $post, $data, $update);
return $post_ID;
}
示例11: str_replace
}
if (is_admin_bar_showing()) {
$admin_body_class .= ' admin-bar';
}
if (is_rtl()) {
$admin_body_class .= ' rtl';
}
$admin_body_class .= ' branch-' . str_replace(array('.', ','), '-', floatval($wp_version));
$admin_body_class .= ' version-' . str_replace('.', '-', preg_replace('/^([.0-9]+).*/', '$1', $wp_version));
$admin_body_class .= ' admin-color-' . sanitize_html_class(get_user_option('admin_color'), 'fresh');
$admin_body_class .= ' locale-' . sanitize_html_class(strtolower(str_replace('_', '-', get_locale())));
if (isset($post) && is_a($post, 'WP_Post') && post_type_supports(get_post_type(), 'post-formats')) {
$post_format = get_post_format();
if (!$post_format) {
$post_format = 'standard';
if (!empty($_REQUEST['format']) && in_array($_REQUEST['format'], get_post_format_slugs())) {
$post_format = $_REQUEST['format'];
}
}
$admin_body_class .= ' wp-format-' . $post_format;
$show_post_format_ui = false;
if (apply_filters('enable_post_format_ui', true, $post)) {
// If the user has explicitly set a screen option, use it, otherwise the UI is shown
// when the theme supports formats, or if the site has formats assigned to posts.
$post_format_user_option = get_user_option('post_formats_' . $post->post_type);
if (false !== $post_format_user_option) {
$show_post_format_ui = (bool) $post_format_user_option;
} else {
$show_post_format_ui = current_theme_supports('post-formats') || (bool) get_terms('post_format', array('number' => 1));
}
}
示例12: get_item_schema
/**
* Get the Post's schema, conforming to JSON Schema.
*
* @return array
*/
public function get_item_schema()
{
$base = $this->get_post_type_base($this->post_type);
$schema = array('$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => $this->post_type, 'type' => 'object', 'properties' => array('date' => array('description' => "The date the object was published, in the site's timezone.", 'type' => 'string', 'format' => 'date-time', 'context' => array('view', 'edit', 'embed')), 'date_gmt' => array('description' => 'The date the object was published, as GMT.', 'type' => 'string', 'format' => 'date-time', 'context' => array('view', 'edit')), 'guid' => array('description' => 'The globally unique identifier for the object.', 'type' => 'object', 'context' => array('view', 'edit'), 'readonly' => true, 'properties' => array('raw' => array('description' => 'GUID for the object, as it exists in the database.', 'type' => 'string', 'context' => array('edit')), 'rendered' => array('description' => 'GUID for the object, transformed for display.', 'type' => 'string', 'context' => array('view', 'edit')))), 'id' => array('description' => 'Unique identifier for the object.', 'type' => 'integer', 'context' => array('view', 'edit', 'embed'), 'readonly' => true), 'link' => array('description' => 'URL to the object.', 'type' => 'string', 'format' => 'uri', 'context' => array('view', 'edit', 'embed'), 'readonly' => true), 'modified' => array('description' => "The date the object was last modified, in the site's timezone.", 'type' => 'string', 'format' => 'date-time', 'context' => array('view', 'edit')), 'modified_gmt' => array('description' => 'The date the object was last modified, as GMT.', 'type' => 'string', 'format' => 'date-time', 'context' => array('view', 'edit')), 'password' => array('description' => 'A password to protect access to the post.', 'type' => 'string', 'context' => array('edit')), 'slug' => array('description' => 'An alphanumeric identifier for the object unique to its type.', 'type' => 'string', 'context' => array('view', 'edit', 'embed'), 'arg_options' => array('sanitize_callback' => 'sanitize_title')), 'status' => array('description' => 'A named status for the object.', 'type' => 'string', 'enum' => array_keys(get_post_stati(array('internal' => false))), 'context' => array('edit')), 'type' => array('description' => 'Type of Post for the object.', 'type' => 'string', 'context' => array('view', 'edit', 'embed'), 'readonly' => true)));
$post_type_obj = get_post_type_object($this->post_type);
if ($post_type_obj->hierarchical) {
$schema['properties']['parent'] = array('description' => 'The id for the parent of the object.', 'type' => 'integer', 'context' => array('view', 'edit'));
}
$post_type_attributes = array('title', 'editor', 'author', 'excerpt', 'thumbnail', 'comments', 'revisions', 'page-attributes', 'post-formats');
$fixed_schemas = array('post' => array('title', 'editor', 'author', 'excerpt', 'thumbnail', 'comments', 'revisions', 'post-formats'), 'page' => array('title', 'editor', 'author', 'excerpt', 'thumbnail', 'comments', 'revisions', 'page-attributes'), 'attachment' => array('title', 'author', 'comments', 'revisions'));
foreach ($post_type_attributes as $attribute) {
if (isset($fixed_schemas[$this->post_type]) && !in_array($attribute, $fixed_schemas[$this->post_type])) {
continue;
} elseif (!in_array($this->post_type, array_keys($fixed_schemas)) && !post_type_supports($this->post_type, $attribute)) {
continue;
}
switch ($attribute) {
case 'title':
$schema['properties']['title'] = array('description' => 'The title for the object.', 'type' => 'object', 'context' => array('view', 'edit', 'embed'), 'properties' => array('raw' => array('description' => 'Title for the object, as it exists in the database.', 'type' => 'string', 'context' => array('edit')), 'rendered' => array('description' => 'Title for the object, transformed for display.', 'type' => 'string', 'context' => array('view', 'edit', 'embed'))));
break;
case 'editor':
$schema['properties']['content'] = array('description' => 'The content for the object.', 'type' => 'object', 'context' => array('view', 'edit'), 'properties' => array('raw' => array('description' => 'Content for the object, as it exists in the database.', 'type' => 'string', 'context' => array('edit')), 'rendered' => array('description' => 'Content for the object, transformed for display.', 'type' => 'string', 'context' => array('view', 'edit'))));
break;
case 'author':
$schema['properties']['author'] = array('description' => 'The id for the author of the object.', 'type' => 'integer', 'context' => array('view', 'edit', 'embed'));
break;
case 'excerpt':
$schema['properties']['excerpt'] = array('description' => 'The excerpt for the object.', 'type' => 'object', 'context' => array('view', 'edit', 'embed'), 'properties' => array('raw' => array('description' => 'Excerpt for the object, as it exists in the database.', 'type' => 'string', 'context' => array('edit')), 'rendered' => array('description' => 'Excerpt for the object, transformed for display.', 'type' => 'string', 'context' => array('view', 'edit', 'embed'))));
break;
case 'thumbnail':
$schema['properties']['featured_image'] = array('description' => 'The id of the featured image for the object.', 'type' => 'integer', 'context' => array('view', 'edit'));
break;
case 'comments':
$schema['properties']['comment_status'] = array('description' => 'Whether or not comments are open on the object.', 'type' => 'string', 'enum' => array('open', 'closed'), 'context' => array('view', 'edit'));
$schema['properties']['ping_status'] = array('description' => 'Whether or not the object can be pinged.', 'type' => 'string', 'enum' => array('open', 'closed'), 'context' => array('view', 'edit'));
break;
case 'page-attributes':
$schema['properties']['menu_order'] = array('description' => 'The order of the object in relation to other object of its type.', 'type' => 'integer', 'context' => array('view', 'edit'));
break;
case 'post-formats':
$schema['properties']['format'] = array('description' => 'The format for the object.', 'type' => 'string', 'enum' => array_values(get_post_format_slugs()), 'context' => array('view', 'edit'));
break;
}
}
if ('post' === $this->post_type) {
$schema['properties']['sticky'] = array('description' => 'Whether or not the object should be treated as sticky.', 'type' => 'boolean', 'context' => array('view', 'edit'));
}
if ('page' === $this->post_type) {
$schema['properties']['template'] = array('description' => 'The theme file to use to display the object.', 'type' => 'string', 'enum' => array_keys(wp_get_theme()->get_page_templates()), 'context' => array('view', 'edit'));
}
return $this->add_additional_fields_schema($schema);
}
示例13: add_theme_support
/**
* Allows a theme to register its support of a certain feature
*
* Must be called in the theme's functions.php file to work.
* If attached to a hook, it must be after_setup_theme.
* The init hook may be too late for some features.
*
* @since 2.9.0
* @param string $feature the feature being added
*/
function add_theme_support($feature)
{
global $_wp_theme_features;
if (func_num_args() == 1) {
$_wp_theme_features[$feature] = true;
} else {
$_wp_theme_features[$feature] = array_slice(func_get_args(), 1);
}
if ($feature == 'post-formats' && is_array($_wp_theme_features[$feature][0])) {
$_wp_theme_features[$feature][0] = array_intersect($_wp_theme_features[$feature][0], array_keys(get_post_format_slugs()));
}
}
示例14: _post_format_link
/**
* Filters the post format term link to remove the format prefix.
*
* @access private
* @since 3.1.0
*/
function _post_format_link($link, $term, $taxonomy)
{
global $wp_rewrite;
if ('post_format' != $taxonomy) {
return $link;
}
$slugs = get_post_format_slugs();
if ($wp_rewrite->get_extra_permastruct($taxonomy)) {
return str_replace("/{$term->slug}", '/' . $slugs[str_replace('post-format-', '', $term->slug)], $link);
} else {
$link = remove_query_arg('post_format', $link);
return add_query_arg('post_format', str_replace('post-format-', '', $term->slug), $link);
}
}
示例15: _post_formats_fix_empty_title
/**
* Fixes empty titles for aside and status formats.
*
* Passes a generated post title to the 'wp_insert_post_data' filter.
*
* @since 3.6.0
* @access private
*
* @uses _post_formats_generate_title()
*/
function _post_formats_fix_empty_title($data, $postarr)
{
if ('auto-draft' == $data['post_status'] || !post_type_supports($data['post_type'], 'post-formats')) {
return $data;
}
$post_id = isset($postarr['ID']) ? absint($postarr['ID']) : 0;
$post_format = '';
if ($post_id) {
$post_format = get_post_format($post_id);
}
if (isset($postarr['post_format'])) {
$post_format = in_array($postarr['post_format'], get_post_format_slugs()) ? $postarr['post_format'] : '';
}
if (!in_array($post_format, array('aside', 'status'))) {
return $data;
}
if ($data['post_title'] == _post_formats_generate_title($data['post_content'], $post_format)) {
return $data;
}
// If updating an existing post, check whether the title was auto-generated.
if ($post_id && ($post = get_post($post_id))) {
if ($post->post_title == $data['post_title'] && $post->post_title == _post_formats_generate_title($post->post_content, get_post_format($post->ID))) {
$data['post_title'] = '';
}
}
if (empty($data['post_title'])) {
$data['post_title'] = _post_formats_generate_title($data['post_content'], $post_format);
}
return $data;
}