/** * List post type support values given a list of values to support. * * Typically needed for 'post' and 'page'. * * @param string[] $to_remove */ static function remove_post_type_support($to_remove) { if (!is_array($to_remove)) { $to_remove = array($to_remove); } $supports = array_diff(array_keys(get_all_post_type_supports(static::POST_TYPE)), $to_remove); foreach ($supports as $support) { remove_post_type_support(static::POST_TYPE, $support); } }
public function test_add_supports_custom() { $post_type = rand_str(); $post_type_object = new WP_Post_Type($post_type, array('supports' => array('editor', 'comments', 'revisions'))); $post_type_object->add_supports(); $post_type_supports = get_all_post_type_supports($post_type); $post_type_object->remove_supports(); $post_type_supports_after = get_all_post_type_supports($post_type); $this->assertEqualSets(array('editor' => true, 'comments' => true, 'revisions' => true), $post_type_supports); $this->assertEqualSets(array(), $post_type_supports_after); }
/** * Does the post type support this byline type? */ public function post_type_supports_byline($post_type, $type) { if (current_theme_supports('bylines')) { $byline_types = get_theme_support('bylines'); if (in_array($type, reset($byline_types))) { $post_type_supports = get_all_post_type_supports($post_type); if (in_array($type, array_keys($post_type_supports))) { return true; } } } return false; }
function callback($path = '', $blog_id = 0) { $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id)); if (is_wp_error($blog_id)) { return $blog_id; } if (defined('IS_WPCOM') && IS_WPCOM) { $this->load_theme_functions(); } $args = $this->query_args(); /** * Whether API responses should be returned in a custom locale. False * for Jetpack; may be true for WP.com requests. * * @since 3.9.2 */ if (apply_filters('rest_api_localize_response', false)) { // API localization occurs after the initial post types have been // registered, so re-register if localizing response create_initial_post_types(); } $queryable_only = isset($args['api_queryable']) && $args['api_queryable']; // Get a list of available post types $post_types = get_post_types(array('public' => true)); $formatted_post_type_objects = array(); // Retrieve post type object for each post type foreach ($post_types as $post_type) { // Skip non-queryable if filtering on queryable only $is_queryable = $this->is_post_type_allowed($post_type); if ($queryable_only && !$is_queryable) { continue; } $post_type_object = get_post_type_object($post_type); $formatted_post_type_object = array(); // Include only the desired keys in the response foreach (self::$post_type_keys_to_include as $key => $value) { $formatted_post_type_object[$value] = $post_type_object->{$key}; } $formatted_post_type_object['api_queryable'] = $is_queryable; $formatted_post_type_object['supports'] = get_all_post_type_supports($post_type); if ($this->post_type_supports_tags($post_type)) { $formatted_post_type_object['supports']['tags'] = true; } $formatted_post_type_objects[] = $formatted_post_type_object; } return array('found' => count($formatted_post_type_objects), 'post_types' => $formatted_post_type_objects); }
/** * Prepares post data for return in an XML-RPC object. * * @access protected * * @param object $post_type Post type object * @param array $fields The subset of post fields to return * @return array The prepared post type data */ protected function _prepare_post_type($post_type, $fields) { $_post_type = array('name' => $post_type->name, 'label' => $post_type->label, 'hierarchical' => (bool) $post_type->hierarchical, 'public' => (bool) $post_type->public, 'show_ui' => (bool) $post_type->show_ui, '_builtin' => (bool) $post_type->_builtin, 'has_archive' => (bool) $post_type->has_archive, 'supports' => get_all_post_type_supports($post_type->name)); if (in_array('labels', $fields)) { $_post_type['labels'] = (array) $post_type->labels; } if (in_array('cap', $fields)) { $_post_type['cap'] = (array) $post_type->cap; $_post_type['map_meta_cap'] = (bool) $post_type->map_meta_cap; } if (in_array('menu', $fields)) { $_post_type['menu_position'] = (int) $post_type->menu_position; $_post_type['menu_icon'] = $post_type->menu_icon; $_post_type['show_in_menu'] = (bool) $post_type->show_in_menu; } if (in_array('taxonomies', $fields)) { $_post_type['taxonomies'] = get_object_taxonomies($post_type->name, 'names'); } /** * Filter XML-RPC-prepared date for the given post type. * * @since 3.4.0 * * @param array $_post_type An array of post type data. * @param object $post_type Post type object. */ return apply_filters('xmlrpc_prepare_post_type', $_post_type, $post_type); }
/** * Prepares post data for return in an XML-RPC object. * * @access protected * * @param object $post_type Post type object * @param array $fields The subset of post fields to return * @return array The prepared post type data */ protected function _prepare_post_type($post_type, $fields) { $_post_type = array('name' => $post_type->name, 'label' => $post_type->label, 'hierarchical' => (bool) $post_type->hierarchical, 'public' => (bool) $post_type->public, 'show_ui' => (bool) $post_type->show_ui, '_builtin' => (bool) $post_type->_builtin, 'has_archive' => (bool) $post_type->has_archive, 'supports' => get_all_post_type_supports($post_type->name)); if (in_array('labels', $fields)) { $_post_type['labels'] = (array) $post_type->labels; } if (in_array('cap', $fields)) { $_post_type['cap'] = (array) $post_type->cap; $_post_type['map_meta_cap'] = (bool) $post_type->map_meta_cap; } if (in_array('menu', $fields)) { $_post_type['menu_position'] = (int) $post_type->menu_position; $_post_type['menu_icon'] = $post_type->menu_icon; $_post_type['show_in_menu'] = (bool) $post_type->show_in_menu; } if (in_array('taxonomies', $fields)) { $_post_type['taxonomies'] = get_object_taxonomies($post_type->name, 'names'); } return apply_filters('xmlrpc_prepare_post_type', $_post_type, $post_type); }
function callback($path = '', $blog_id = 0) { $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id)); if (is_wp_error($blog_id)) { return $blog_id; } if (defined('IS_WPCOM') && IS_WPCOM) { $this->load_theme_functions(); } $args = $this->query_args(); $queryable_only = isset($args['api_queryable']) && $args['api_queryable']; // Get a list of available post types $post_types = get_post_types(array('public' => true)); $formatted_post_type_objects = array(); // Retrieve post type object for each post type foreach ($post_types as $post_type) { // Skip non-queryable if filtering on queryable only $is_queryable = $this->is_post_type_allowed($post_type); if ($queryable_only && !$is_queryable) { continue; } $post_type_object = get_post_type_object($post_type); $formatted_post_type_object = array(); // Include only the desired keys in the response foreach (self::$post_type_keys_to_include as $key => $value) { $formatted_post_type_object[$value] = $post_type_object->{$key}; } $formatted_post_type_object['api_queryable'] = $is_queryable; $formatted_post_type_object['supports'] = get_all_post_type_supports($post_type); $formatted_post_type_objects[] = $formatted_post_type_object; } return array('found' => count($formatted_post_type_objects), 'post_types' => $formatted_post_type_objects); }
public function set_page_builder() { if (current_theme_supports('bon-page-builder') && class_exists('BON_Main')) { $bon_toolkit_options = get_option($this->option_name); $builder_options = isset($bon_toolkit_options['page_builder_post_type']) ? $bon_toolkit_options['page_builder_post_type'] : ''; $builder_support = get_theme_support('bon-page-builder'); if (is_array($builder_options) && !empty($builder_options)) { $this->builder_post_types = $builder_options; } else { if (!empty($builder_support[0])) { $this->builder_post_types = array_merge($this->builder_post_types, $builder_support[0]); } $post_types = get_post_types(array('public' => true)); foreach ($post_types as $type) { $post_type_supports = get_all_post_type_supports($type); if (!empty($post_type_supports) && array_key_exists('bon-page-builder', $post_type_supports) && !in_array($type, $this->builder_post_types)) { $this->builder_post_types[] = $type; } } } include_once 'includes/builder/builder-options.php'; include_once 'includes/builder/builder.php'; include_once 'includes/builder/builder-interface.php'; } }
/** * Prepares post data for return in an XML-RPC object. * * @access protected * * @param array|object $post_type The unprepared post type data * @param array $fields The subset of post fields to return * @return array The prepared post type data */ protected function _prepare_post_type($post_type, $fields) { $post_type = (array) $post_type; $_post_type = array('name' => $post_type['name'], 'label' => $post_type['label'], 'description' => $post_type['description'], 'hierarchical' => $post_type['hierarchical'], 'public' => $post_type['public'], '_builtin' => $post_type['_builtin'], 'supports' => get_all_post_type_supports($post_type['name'])); if (in_array('labels', $fields)) { $_post_type['labels'] = (array) $post_type['labels']; } if (in_array('capabilities', $fields)) { $_post_type['cap'] = (array) $post_type['cap']; $_post_type['capability_type'] = $post_type['capability_type']; $_post_type['map_meta_cap'] = $post_type['map_meta_cap']; } if (in_array('admin', $fields)) { $_post_type['publicly_queryable'] = $post_type['publicly_queryable']; $_post_type['exclude_from_search'] = $post_type['exclude_from_search']; $_post_type['_edit_link'] = $post_type['_edit_link']; $_post_type['rewrite'] = $post_type['rewrite']; $_post_type['has_archive'] = $post_type['has_archive']; $_post_type['query_var'] = $post_type['query_var']; } if (in_array('menu', $fields)) { $_post_type['show_ui'] = $post_type['show_ui']; $_post_type['menu_position'] = $post_type['menu_position']; $_post_type['menu_icon'] = $post_type['menu_icon']; $_post_type['show_in_nav_menus'] = $post_type['show_in_nav_menus']; $_post_type['show_in_menu'] = $post_type['show_in_menu']; $_post_type['show_in_admin_bar'] = $post_type['show_in_admin_bar']; } if (in_array('taxonomies', $fields)) { $_post_type['taxonomies'] = get_object_taxonomies($_post_type['name']); } return apply_filters('xmlrpc_prepare_post_type', $_post_type, $post_type); }
function map_to_dropdown() { global $wpdb; $dont_allow = array('_wp_attachment_image_alt', '_wp_attachment_metadata', '_wp_attached_file', '_edit_lock', '_edit_last', '_wp_page_template'); $html = ' <li data-post-type="all" class="live_filter"> <input type="text" class="live_filter" placeholder="' . esc_attr($this->__('Search... ')) . '" /> </li>'; $field_groups = array(); $supports_custom = array(); $yoast_field_type_array = array('text', 'textarea', 'select', 'upload', 'radio', 'multiselect'); $yoast = false; if (function_exists('wpseo_admin_init')) { $this->_initialize_yoast(); $yoast = true; } $yoast_prefix = '_yoast_wpseo_'; $yoast_fields = array(); foreach ($this->post_types as $name => $title) { $supports = get_all_post_type_supports($name); if (isset($supports['custom-fields'])) { $supports_custom[] = $name; } if ($name == 'attachment') { $html .= ' <li data-post-type="|attachment|" data-search="' . esc_attr($this->__('Title')) . '"> <a href="#" data-value="post_title">' . $this->__('Title') . '</a> </li> <li data-post-type="|attachment|" data-search="' . esc_attr($this->__('Caption')) . '"> <a href="#" data-value="post_excerpt">' . $this->__('Caption') . '</a> </li> <li data-post-type="|attachment|" data-search="' . esc_attr($this->__('Description')) . '"> <a href="#" data-value="post_content">' . $this->__('Description') . '</a> </li> <li data-post-type="|attachment|" data-search="' . esc_attr($this->__('Alt Text')) . '"> <a href="#" data-value="_wp_attachment_image_alt">' . $this->__('Alt Text') . '</a> </li>'; } else { $labels = array('title' => sprintf($this->__('%s Title'), $title), 'editor' => sprintf($this->__('%s Content'), $title), 'excerpt' => sprintf($this->__('%s Excerpt'), $title), 'thumbnail' => $this->__('Featured Image'), 'tags' => $this->__('Tags'), 'cats' => $this->__('Category'), 'author' => $this->__('Author')); $fields = array('editor' => 'post_content', 'title' => 'post_title', 'excerpt' => 'post_excerpt', 'thumbnail' => 'gc_featured_image_', 'author' => 'post_author'); foreach ($fields as $type => $fieldname) { if (isset($supports[$type])) { $html .= ' <li data-post-type="|' . $name . '|" data-search="' . esc_attr($labels[$type]) . '"> <a href="#" data-value="' . $fieldname . '">' . esc_html($labels[$type]) . '</a> </li>'; } } if (count($this->taxonomies[$name]) > 0) { $html .= ' <li data-post-type="|' . $name . '|" data-search="' . esc_attr($labels['cats']) . '"> <a href="#" data-value="gc_post_cat_">' . esc_html($labels['cats']) . '</a> </li>'; } if (isset($this->allows_tags[$name])) { $html .= ' <li data-post-type="|' . $name . '|" data-search="' . esc_attr($labels['tags']) . '"> <a href="#" data-value="gc_post_tags_">' . esc_html($labels['tags']) . '</a> </li>'; } } if ($this->has_acf) { $acf = $this->_acf_get_field_groups(array('post_type' => $name)); foreach ($acf as $post_id) { if (!isset($field_groups[$post_id])) { $field_groups[$post_id] = array('types' => array(), 'posts' => array()); } $field_groups[$post_id]['types'][] = $name; $field_groups[$post_id]['posts'][] = 0; } foreach ($this->page_ids[$name] as $page_id) { $acf = $this->_acf_get_field_groups(array('post_id' => $page_id)); foreach ($acf as $post_id) { if (!isset($field_groups[$post_id])) { $field_groups[$post_id] = array('posts' => array()); } elseif (!isset($field_groups[$post_id]['posts'])) { $field_groups[$post_id]['posts'] = array(); } $field_groups[$post_id]['posts'][] = $page_id; } } } if ($yoast) { $meta_boxes = array_merge(WPSEO_Meta::get_meta_field_defs('general', $name), WPSEO_Meta::get_meta_field_defs('advanced'), apply_filters('wpseo_save_metaboxes', array())); foreach ($meta_boxes as $field_name => $meta_box) { if (in_array($meta_box['type'], $yoast_field_type_array)) { $yoast_fields[$yoast_prefix . $field_name] = true; $html .= ' <li data-post-type="|' . $name . '|" data-search="' . esc_attr($meta_box['title']) . '"> <a href="#" data-value="' . $yoast_prefix . esc_attr($field_name) . '">' . esc_html($meta_box['title']) . '</a> </li>'; } } } } foreach ($field_groups as $id => $options) { $options['posts'] = array_unique($options['posts']); if ($this->acf_pro) { $fields = acf_get_fields($id); } else { $fields = apply_filters('acf/field_group/get_fields', array(), $id); } foreach ($fields as $field) { $dont_allow[] = $field['key']; $text = $field['label']; if (strlen($text) > 30) { $text = substr($text, 0, 30) . '...'; } $ext = ''; if (isset($options['types']) && count($options['types']) > 0) { $ext .= ' data-acf-post-types="|' . implode('|', $options['types']) . '|"'; } if (isset($options['posts']) && count($options['posts']) > 0) { $ext .= ' data-acf-post-ids="|' . implode('|', $options['posts']) . '|"'; } $html .= ' <li data-post-type="all" class="acf-row" data-search="' . esc_attr($field['label']) . '"' . $ext . '> <a href="#" data-value="' . esc_attr($field['name']) . '" data-acf-post="' . esc_attr($id) . '" data-acf-field="' . esc_attr($field['key']) . '" title="' . esc_attr($field['label']) . '" class="acf-field">' . esc_html($text) . '</a> </li>'; } } if ($yoast) { $yoast_fields[$yoast_prefix . 'linkdex'] = true; $dont_allow = array_merge($dont_allow, array_keys($yoast_fields)); } $dont_allow = "'" . implode("','", $dont_allow) . "'"; $keys = $wpdb->get_col("SELECT meta_key FROM {$wpdb->postmeta} WHERE meta_key NOT IN({$dont_allow}) GROUP BY meta_key ORDER BY meta_key"); $supports_custom = '|' . implode('|', $supports_custom) . '|'; if ($keys) { natcasesort($keys); foreach ($keys as $key) { $text = $key; if (strlen($key) > 30) { $text = substr($key, 0, 30) . '...'; } $html .= ' <li data-post-type="' . $supports_custom . '" class="custom-field" data-search="' . esc_attr($key) . '"> <a href="#" data-value="' . esc_attr($key) . '" title="' . esc_attr($key) . '">' . esc_html($text) . '</a> </li>'; } } $html .= ' <li data-post-type="' . $supports_custom . '" data-search="' . $this->__('New Custom Field') . '"> <a href="#" data-value="_new_custom_field_">' . $this->__('New Custom Field') . '</a> </li> <li class="divider" data-post-type="all"></li> <li data-post-type="all" data-search="' . $this->__('Do Not Import') . '"> <a href="#" data-value="_dont_import_">' . $this->__('Do Not Import') . '</a> </li>'; $this->data['map_to_select'] = $html; }
function appthemes_page_attributes_meta_box($post) { $post_type_object = get_post_type_object($post->post_type); $post_type_supports = get_all_post_type_supports($post->post_type); if ($post_type_object->hierarchical && !$post_type_supports['appthemes_page_attributes'][0]['hide_page_parent']) { $dropdown_args = array('post_type' => $post->post_type, 'exclude_tree' => $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)', APP_TD), 'sort_column' => 'menu_order, post_title', 'echo' => 0); $dropdown_args = apply_filters('page_attributes_dropdown_pages_args', $dropdown_args, $post); $pages = wp_dropdown_pages($dropdown_args); if (!empty($pages)) { ?> <p><strong><?php _e('Parent', APP_TD); ?> </strong></p> <label class="screen-reader-text" for="parent_id"><?php _e('Parent', APP_TD); ?> </label> <?php echo $pages; ?> <?php } // end empty pages check } // end hierarchical check. if ('page' == $post->post_type && 0 != count(get_page_templates())) { $current_template = !empty($post->page_template) ? $post->page_template : false; if ($post_type_supports['appthemes_page_attributes'][0]['internal_use_only']) { // This is an internal use page, need to keep the page template locked and don't even offer dropdown appthemes_fixed_page_template($post); } else { ?> <p><strong><?php _e('Template', APP_TD); ?> </strong></p> <label class="screen-reader-text" for="page_template"><?php _e('Page Template', APP_TD); ?> </label> <select name="page_template" id="page_template"> <option value='default'><?php _e('Default Template', APP_TD); ?> </option> <?php $templates = get_page_templates(); ksort($templates); // Take out appthemes internal use templates foreach ($templates as $name => $template) { if (in_array($template, $post_type_supports['appthemes_internal_use_page_templates'][0])) { unset($templates[$name]); } } foreach (array_keys($templates) as $template) { if ($current_template == $templates[$template]) { $selected = " selected='selected'"; } else { $selected = ''; } echo "\n\t<option value='" . $templates[$template] . "' {$selected}>{$template}</option>"; } ?> </select> <?php } } if (!$post_type_supports['appthemes_page_attributes'][0]['hide_page_order']) { ?> <p><strong><?php _e('Order', APP_TD); ?> </strong></p> <p><label class="screen-reader-text" for="menu_order"><?php _e('Order', APP_TD); ?> </label><input name="menu_order" type="text" size="4" id="menu_order" value="<?php echo esc_attr($post->menu_order); ?> " /></p> <p><?php if ('page' == $post->post_type) { _e('Need help? Use the Help tab in the upper right of your screen.', APP_TD); } ?> </p> <?php } }