/var/www/wordpress/wp-admin/includes/admin.php
/var/www/wordpress/wp-admin/includes/bookmark.php
/var/www/wordpress/wp-admin/includes/class-ftp-pure.php
/var/www/wordpress/wp-admin/includes/class-ftp-sockets.php
/var/www/wordpress/wp-admin/includes/class-ftp.php
/var/www/wordpress/wp-admin/includes/class-pclzip.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-base.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-direct.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ftpext.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ftpsockets.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ssh2.php
/var/www/wordpress/wp-admin/includes/class-wp-importer.php
/var/www/wordpress/wp-admin/includes/class-wp-upgrader.php
/var/www/wordpress/wp-admin/includes/comment.php
/var/www/wordpress/wp-admin/includes/continents-cities.php
/var/www/wordpress/wp-admin/includes/dashboard.php
/var/www/wordpress/wp-admin/includes/deprecated.php
/var/www/wordpress/wp-admin/includes/export.php
/var/www/wordpress/wp-admin/includes/file.php
/var/www/wordpress/wp-admin/includes/image-edit.php
/var/www/wordpress/wp-admin/includes/image.php
/var/www/wordpress/wp-admin/includes/import.php
/var/www/wordpress/wp-admin/includes/manifest.php
/var/www/wordpress/wp-admin/includes/media.php
/var/www/wordpress/wp-admin/includes/meta-boxes.php
/var/www/wordpress/wp-admin/includes/misc.php
/var/www/wordpress/wp-admin/includes/ms-deprecated.php
/var/www/wordpress/wp-admin/includes/ms.php
/var/www/wordpress/wp-admin/includes/nav-menu.php
/var/www/wordpress/wp-admin/includes/plugin-install.php
/var/www/wordpress/wp-admin/includes/plugin.php
/var/www/wordpress/wp-admin/includes/post.php
/var/www/wordpress/wp-admin/includes/schema.php
/var/www/wordpress/wp-admin/includes/taxonomy.php
/var/www/wordpress/wp-admin/includes/template.php
/var/www/wordpress/wp-admin/includes/theme-install.php
/var/www/wordpress/wp-admin/includes/theme.php
/var/www/wordpress/wp-admin/includes/update-core.php
/var/www/wordpress/wp-admin/includes/update.php
/var/www/wordpress/wp-admin/includes/upgrade.php
/var/www/wordpress/wp-admin/includes/user.php
/var/www/wordpress/wp-admin/includes/widgets.php
/var/www/wordpress/wp-admin/js/revisions-js.php
/var/www/wordpress/wp-admin/maint/repair.php
/var/www/wordpress/wp-admin/admin-ajax.php
/var/www/wordpress/wp-admin/admin-footer.php
/var/www/wordpress/wp-admin/admin-functions.php
/var/www/wordpress/wp-admin/admin-header.php
/var/www/wordpress/wp-admin/admin-post.php
/var/www/wordpress/wp-admin/admin.php
/var/www/wordpress/wp-admin/async-upload.php
/var/www/wordpress/wp-admin/comment.php
/var/www/wordpress/wp-admin/custom-background.php
/var/www/wordpress/wp-admin/custom-header.php
/var/www/wordpress/wp-admin/edit-attachment-rows.php
/var/www/wordpress/wp-admin/edit-comments.php
/var/www/wordpress/wp-admin/edit-form-advanced.php
/var/www/wordpress/wp-admin/edit-form-comment.php
/var/www/wordpress/wp-admin/edit-link-categories.php
/var/www/wordpress/wp-admin/edit-link-category-form.php
/var/www/wordpress/wp-admin/edit-link-form.php
/var/www/wordpress/wp-admin/edit-post-rows.php
/var/www/wordpress/wp-admin/edit-tag-form.php
/var/www/wordpress/wp-admin/edit-tags.php
/var/www/wordpress/wp-admin/edit.php
/var/www/wordpress/wp-admin/export.php
/var/www/wordpress/wp-admin/gears-manifest.php
/var/www/wordpress/wp-admin/import.php
/var/www/wordpress/wp-admin/index-extra.php
/var/www/wordpress/wp-admin/index.php
/var/www/wordpress/wp-admin/install-helper.php
/var/www/wordpress/wp-admin/install.php
/var/www/wordpress/wp-admin/link-add.php
/var/www/wordpress/wp-admin/link-category.php
/var/www/wordpress/wp-admin/link-manager.php
/var/www/wordpress/wp-admin/link-parse-opml.php
/var/www/wordpress/wp-admin/link.php
/var/www/wordpress/wp-admin/load-scripts.php
/var/www/wordpress/wp-admin/load-styles.php
/var/www/wordpress/wp-admin/media-new.php
/var/www/wordpress/wp-admin/media-upload.php
/var/www/wordpress/wp-admin/media.php
/var/www/wordpress/wp-admin/menu-header.php
/var/www/wordpress/wp-admin/menu.php
/var/www/wordpress/wp-admin/moderation.php
/var/www/wordpress/wp-admin/ms-admin.php
/var/www/wordpress/wp-admin/ms-delete-site.php
/var/www/wordpress/wp-admin/ms-edit.php
/var/www/wordpress/wp-admin/ms-options.php
/var/www/wordpress/wp-admin/ms-sites.php
/var/www/wordpress/wp-admin/ms-themes.php
/var/www/wordpress/wp-admin/ms-upgrade-network.php
/var/www/wordpress/wp-admin/ms-users.php
/var/www/wordpress/wp-admin/my-sites.php
/var/www/wordpress/wp-admin/nav-menus.php
/var/www/wordpress/wp-admin/network.php
/var/www/wordpress/wp-admin/options-discussion.php
/var/www/wordpress/wp-admin/options-general.php
/var/www/wordpress/wp-admin/options-head.php
/var/www/wordpress/wp-admin/options-media.php
/var/www/wordpress/wp-admin/options-permalink.php
/var/www/wordpress/wp-admin/options-privacy.php
/var/www/wordpress/wp-admin/options-reading.php
/var/www/wordpress/wp-admin/options-writing.php
/var/www/wordpress/wp-admin/options.php
/var/www/wordpress/wp-admin/plugin-editor.php
/var/www/wordpress/wp-admin/plugin-install.php
/var/www/wordpress/wp-admin/plugins.php
/var/www/wordpress/wp-admin/post-new.php
/var/www/wordpress/wp-admin/post.php
/var/www/wordpress/wp-admin/press-this.php
/var/www/wordpress/wp-admin/profile.php
/var/www/wordpress/wp-admin/revision.php
/var/www/wordpress/wp-admin/setup-config.php
/var/www/wordpress/wp-admin/sidebar.php
/var/www/wordpress/wp-admin/theme-editor.php
/var/www/wordpress/wp-admin/theme-install.php
/var/www/wordpress/wp-admin/themes.php
/var/www/wordpress/wp-admin/tools.php
/var/www/wordpress/wp-admin/update-core.php
/var/www/wordpress/wp-admin/update.php
/var/www/wordpress/wp-admin/upgrade-functions.php
/var/www/wordpress/wp-admin/upgrade.php
/var/www/wordpress/wp-admin/upload.php
/var/www/wordpress/wp-admin/user-edit.php
/var/www/wordpress/wp-admin/user-new.php
/var/www/wordpress/wp-admin/users.php
/var/www/wordpress/wp-admin/widgets.php
/var/www/wordpress/wp-content/languages/ru_RU.php
/var/www/wordpress/wp-content/plugins/akismet/akismet.php
/var/www/wordpress/wp-content/plugins/rh/rh.php
/var/www/wordpress/wp-content/plugins/hello.php
/var/www/wordpress/wp-content/plugins/index.php
/var/www/wordpress/wp-content/themes/twentyten/404.php
/var/www/wordpress/wp-content/themes/twentyten/archive.php
/var/www/wordpress/wp-content/themes/twentyten/attachment.php
/var/www/wordpress/wp-content/themes/twentyten/author.php
/var/www/wordpress/wp-content/themes/twentyten/category.php
/var/www/wordpress/wp-content/themes/twentyten/comments.php
/var/www/wordpress/wp-content/themes/twentyten/footer.php
/var/www/wordpress/wp-content/themes/twentyten/functions.php
/var/www/wordpress/wp-content/themes/twentyten/header.php
/var/www/wordpress/wp-content/themes/twentyten/index.php
/var/www/wordpress/wp-content/themes/twentyten/loop.php
/var/www/wordpress/wp-content/themes/twentyten/onecolumn-page.php
/var/www/wordpress/wp-content/themes/twentyten/page.php
/var/www/wordpress/wp-content/themes/twentyten/search.php
/var/www/wordpress/wp-content/themes/twentyten/sidebar-footer.php
/var/www/wordpress/wp-content/themes/twentyten/sidebar.php
/var/www/wordpress/wp-content/themes/twentyten/single.php
/var/www/wordpress/wp-content/themes/twentyten/tag.php
/var/www/wordpress/wp-content/themes/index.php
/var/www/wordpress/wp-content/index.php
/var/www/wordpress/wp-includes/js/tinymce/langs/wp-langs.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/Logger.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/EnchantSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/GoogleSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpellShell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/SpellChecker.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/includes/general.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/config.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/rpc.php
/var/www/wordpress/wp-includes/js/tinymce/wp-mce-help.php
/var/www/wordpress/wp-includes/js/tinymce/wp-tinymce.php
/var/www/wordpress/wp-includes/pomo/entry.php
/var/www/wordpress/wp-includes/pomo/mo.php
/var/www/wordpress/wp-includes/pomo/po.php
/var/www/wordpress/wp-includes/pomo/streams.php
/var/www/wordpress/wp-includes/pomo/translations.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/native.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/shell.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/string.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/xdiff.php
/var/www/wordpress/wp-includes/Text/Diff/Renderer/inline.php
/var/www/wordpress/wp-includes/Text/Diff/Renderer.php
/var/www/wordpress/wp-includes/Text/Diff.php
/var/www/wordpress/wp-includes/theme-compat/comments-popup.php
/var/www/wordpress/wp-includes/theme-compat/comments.php
/var/www/wordpress/wp-includes/theme-compat/footer.php
/var/www/wordpress/wp-includes/theme-compat/header.php
/var/www/wordpress/wp-includes/theme-compat/sidebar.php
/var/www/wordpress/wp-includes/atomlib.php
/var/www/wordpress/wp-includes/author-template.php
/var/www/wordpress/wp-includes/bookmark-template.php
/var/www/wordpress/wp-includes/bookmark.php
/var/www/wordpress/wp-includes/cache.php
/var/www/wordpress/wp-includes/canonical.php
/var/www/wordpress/wp-includes/capabilities.php
/var/www/wordpress/wp-includes/category-template.php
/var/www/wordpress/wp-includes/category.php
/var/www/wordpress/wp-includes/class-feed.php
/var/www/wordpress/wp-includes/class-http.php
/var/www/wordpress/wp-includes/class-IXR.php
/var/www/wordpress/wp-includes/class-json.php
/var/www/wordpress/wp-includes/class-oembed.php
/var/www/wordpress/wp-includes/class-phpass.php
/var/www/wordpress/wp-includes/class-phpmailer.php
/var/www/wordpress/wp-includes/class-pop3.php
/var/www/wordpress/wp-includes/class-simplepie.php
/var/www/wordpress/wp-includes/class-smtp.php
/var/www/wordpress/wp-includes/class-snoopy.php
/var/www/wordpress/wp-includes/class.wp-dependencies.php
/var/www/wordpress/wp-includes/class.wp-scripts.php
/var/www/wordpress/wp-includes/class.wp-styles.php
/var/www/wordpress/wp-includes/classes.php
/var/www/wordpress/wp-includes/comment-template.php
/var/www/wordpress/wp-includes/comment.php
/var/www/wordpress/wp-includes/compat.php
/var/www/wordpress/wp-includes/cron.php
/var/www/wordpress/wp-includes/default-constants.php
/var/www/wordpress/wp-includes/default-embeds.php
/var/www/wordpress/wp-includes/default-filters.php
/var/www/wordpress/wp-includes/default-widgets.php
/var/www/wordpress/wp-includes/deprecated.php
/var/www/wordpress/wp-includes/feed-atom-comments.php
/var/www/wordpress/wp-includes/feed-atom.php
/var/www/wordpress/wp-includes/feed-rdf.php
/var/www/wordpress/wp-includes/feed-rss.php
/var/www/wordpress/wp-includes/feed-rss2-comments.php
/var/www/wordpress/wp-includes/feed-rss2.php
/var/www/wordpress/wp-includes/feed.php
/var/www/wordpress/wp-includes/formatting.php
/var/www/wordpress/wp-includes/functions.php
/var/www/wordpress/wp-includes/functions.wp-scripts.php
/var/www/wordpress/wp-includes/functions.wp-styles.php
/var/www/wordpress/wp-includes/general-template.php
/var/www/wordpress/wp-includes/http.php
/var/www/wordpress/wp-includes/kses.php
/var/www/wordpress/wp-includes/l10n.php
/var/www/wordpress/wp-includes/link-template.php
/var/www/wordpress/wp-includes/load.php
/var/www/wordpress/wp-includes/locale.php
/var/www/wordpress/wp-includes/media.php
/var/www/wordpress/wp-includes/meta.php
/var/www/wordpress/wp-includes/ms-blogs.php
/var/www/wordpress/wp-includes/ms-default-constants.php
/var/www/wordpress/wp-includes/ms-default-filters.php
/var/www/wordpress/wp-includes/ms-deprecated.php
/var/www/wordpress/wp-includes/ms-files.php
/var/www/wordpress/wp-includes/ms-functions.php
/var/www/wordpress/wp-includes/ms-load.php
/var/www/wordpress/wp-includes/ms-settings.php
/var/www/wordpress/wp-includes/nav-menu-template.php
/var/www/wordpress/wp-includes/nav-menu.php
/var/www/wordpress/wp-includes/pluggable-deprecated.php
/var/www/wordpress/wp-includes/pluggable.php
/var/www/wordpress/wp-includes/plugin.php
/var/www/wordpress/wp-includes/post-template.php
/var/www/wordpress/wp-includes/post-thumbnail-template.php
/var/www/wordpress/wp-includes/post.php
#CodeDescriptions
1<?php
2/**
3 * Post functions and post utility function.
4 *
5 * @package WordPress
6 * @subpackage Post
7 * @since 1.5.0
8 */
9
10//
11// Post Type Registration
12//
13
14/**
15 * Creates the initial post types when 'init' action is fired.
16 */
17function create_initial_post_types() {
18 register_post_type( 'post', array(
19 'public' => true,
20 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
21 '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
22 'capability_type' => 'post',
23 'hierarchical' => false,
24 'rewrite' => false,
25 'query_var' => false,
26 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions' ),
27 ) );
28
29 register_post_type( 'page', array(
30 'public' => true,
31 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
32 '_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
33 'capability_type' => 'page',
34 'hierarchical' => true,
35 'rewrite' => false,
36 'query_var' => false,
37 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes', 'custom-fields', 'comments', 'revisions' ),
38 ) );
39
40 register_post_type( 'attachment', array(
41 'labels' => array(
42 'name' => __( 'Media' ),
43 ),
44 'public' => true,
45 'show_ui' => false,
46 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
47 '_edit_link' => 'media.php?attachment_id=%d', /* internal use only. don't use this when registering your own post type. */
48 'capability_type' => 'post',
49 'hierarchical' => false,
50 'rewrite' => false,
51 'query_var' => false,
52 'can_export' => false,
53 'show_in_nav_menus' => false,
54 ) );
55
56 register_post_type( 'revision', array(
57 'labels' => array(
58 'name' => __( 'Revisions' ),
59 'singular_name' => __( 'Revision' ),
60 ),
61 'public' => false,
62 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
63 '_edit_link' => 'revision.php?revision=%d', /* internal use only. don't use this when registering your own post type. */
64 'capability_type' => 'post',
65 'hierarchical' => false,
66 'rewrite' => false,
67 'query_var' => false,
68 ) );
69
70 register_post_type( 'nav_menu_item', array(
71 'labels' => array(
72 'name' => __( 'Navigation Menu Items' ),
73 'singular_name' => __( 'Navigation Menu Item' ),
74 ),
75 'public' => false,
76 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */
77 'capability_type' => 'post',
78 'hierarchical' => false,
79 'rewrite' => false,
80 'query_var' => false,
81 ) );
82
83 register_post_status( 'publish', array(
84 'label' => _x( 'Published', 'post' ),
85 'public' => true,
86 '_builtin' => true, /* internal use only. */
87 'label_count' => _n_noop( 'Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>' ),
88 ) );
89
90 register_post_status( 'future', array(
91 'label' => _x( 'Scheduled', 'post' ),
92 'protected' => true,
93 '_builtin' => true, /* internal use only. */
94 'label_count' => _n_noop('Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>' ),
95 ) );
96
97 register_post_status( 'draft', array(
98 'label' => _x( 'Draft', 'post' ),
99 'protected' => true,
100 '_builtin' => true, /* internal use only. */
101 'label_count' => _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' ),
102 ) );
103
104 register_post_status( 'pending', array(
105 'label' => _x( 'Pending', 'post' ),
106 'protected' => true,
107 '_builtin' => true, /* internal use only. */
108 'label_count' => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>' ),
109 ) );
110
111 register_post_status( 'private', array(
112 'label' => _x( 'Private', 'post' ),
113 'private' => true,
114 '_builtin' => true, /* internal use only. */
115 'label_count' => _n_noop( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>' ),
116 ) );
117
118 register_post_status( 'trash', array(
119 'label' => _x( 'Trash', 'post' ),
120 'internal' => true,
121 '_builtin' => true, /* internal use only. */
122 'label_count' => _n_noop( 'Trash <span class="count">(%s)</span>', 'Trash <span class="count">(%s)</span>' ),
123 'show_in_admin_status_list' => true,
124 ) );
125
126 register_post_status( 'auto-draft', array(
127 'label' => 'auto-draft',
128 'internal' => true,
129 '_builtin' => true, /* internal use only. */
130 ) );
131
132 register_post_status( 'inherit', array(
133 'label' => 'inherit',
134 'internal' => true,
135 '_builtin' => true, /* internal use only. */
136 'exclude_from_search' => false,
137 ) );
138}
139add_action( 'init', 'create_initial_post_types', 0 ); // highest priority
140
141/**
142 * Retrieve attached file path based on attachment ID.
143 *
144 * You can optionally send it through the 'get_attached_file' filter, but by
145 * default it will just return the file path unfiltered.
146 *
147 * The function works by getting the single post meta name, named
148 * '_wp_attached_file' and returning it. This is a convenience function to
149 * prevent looking up the meta name and provide a mechanism for sending the
150 * attached filename through a filter.
151 *
152 * @since 2.0.0
153 * @uses apply_filters() Calls 'get_attached_file' on file path and attachment ID.
154 *
155 * @param int $attachment_id Attachment ID.
156 * @param bool $unfiltered Whether to apply filters.
157 * @return string The file path to the attached file.
158 */
159function get_attached_file( $attachment_id, $unfiltered = false ) {
160 $file = get_post_meta( $attachment_id, '_wp_attached_file', true );
161 // If the file is relative, prepend upload dir
162 if ( 0 !== strpos($file, '/') && !preg_match('|^.:\\\|', $file) && ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) )
163 $file = $uploads['basedir'] . "/$file";//Arbitrary file disclosing
164 if ( $unfiltered )
165 return $file;
166 return apply_filters( 'get_attached_file', $file, $attachment_id );//Arbitrary file disclosing
167}
168
169/**
170 * Update attachment file path based on attachment ID.
171 *
172 * Used to update the file path of the attachment, which uses post meta name
173 * '_wp_attached_file' to store the path of the attachment.
174 *
175 * @since 2.1.0
176 * @uses apply_filters() Calls 'update_attached_file' on file path and attachment ID.
177 *
178 * @param int $attachment_id Attachment ID
179 * @param string $file File path for the attachment
180 * @return bool False on failure, true on success.
181 */
182function update_attached_file( $attachment_id, $file ) {
183 if ( !get_post( $attachment_id ) )
184 return false;
185
186 $file = apply_filters( 'update_attached_file', $file, $attachment_id );//Arbitrary file disclosing
187 $file = _wp_relative_upload_path($file);
188
189 return update_post_meta( $attachment_id, '_wp_attached_file', $file );//Arbitrary file disclosing
190}
191
192/**
193 * Return relative path to an uploaded file.
194 *
195 * The path is relative to the current upload dir.
196 *
197 * @since 2.9.0
198 * @uses apply_filters() Calls '_wp_relative_upload_path' on file path.
199 *
200 * @param string $path Full path to the file
201 * @return string relative path on success, unchanged path on failure.
202 */
203function _wp_relative_upload_path( $path ) {
204 $new_path = $path;
205
206 if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) {
207 if ( 0 === strpos($new_path, $uploads['basedir']) ) {
208 $new_path = str_replace($uploads['basedir'], '', $new_path);
209 $new_path = ltrim($new_path, '/');
210 }
211 }
212
213 return apply_filters( '_wp_relative_upload_path', $new_path, $path );
214}
215
216/**
217 * Retrieve all children of the post parent ID.
218 *
219 * Normally, without any enhancements, the children would apply to pages. In the
220 * context of the inner workings of WordPress, pages, posts, and attachments
221 * share the same table, so therefore the functionality could apply to any one
222 * of them. It is then noted that while this function does not work on posts, it
223 * does not mean that it won't work on posts. It is recommended that you know
224 * what context you wish to retrieve the children of.
225 *
226 * Attachments may also be made the child of a post, so if that is an accurate
227 * statement (which needs to be verified), it would then be possible to get
228 * all of the attachments for a post. Attachments have since changed since
229 * version 2.5, so this is most likely unaccurate, but serves generally as an
230 * example of what is possible.
231 *
232 * The arguments listed as defaults are for this function and also of the
233 * {@link get_posts()} function. The arguments are combined with the
234 * get_children defaults and are then passed to the {@link get_posts()}
235 * function, which accepts additional arguments. You can replace the defaults in
236 * this function, listed below and the additional arguments listed in the
237 * {@link get_posts()} function.
238 *
239 * The 'post_parent' is the most important argument and important attention
240 * needs to be paid to the $args parameter. If you pass either an object or an
241 * integer (number), then just the 'post_parent' is grabbed and everything else
242 * is lost. If you don't specify any arguments, then it is assumed that you are
243 * in The Loop and the post parent will be grabbed for from the current post.
244 *
245 * The 'post_parent' argument is the ID to get the children. The 'numberposts'
246 * is the amount of posts to retrieve that has a default of '-1', which is
247 * used to get all of the posts. Giving a number higher than 0 will only
248 * retrieve that amount of posts.
249 *
250 * The 'post_type' and 'post_status' arguments can be used to choose what
251 * criteria of posts to retrieve. The 'post_type' can be anything, but WordPress
252 * post types are 'post', 'pages', and 'attachments'. The 'post_status'
253 * argument will accept any post status within the write administration panels.
254 *
255 * @see get_posts() Has additional arguments that can be replaced.
256 * @internal Claims made in the long description might be inaccurate.
257 *
258 * @since 2.0.0
259 *
260 * @param mixed $args Optional. User defined arguments for replacing the defaults.
261 * @param string $output Optional. Constant for return type, either OBJECT (default), ARRAY_A, ARRAY_N.
262 * @return array|bool False on failure and the type will be determined by $output parameter.
263 */
264function &get_children($args = '', $output = OBJECT) {
265 $kids = array();
266 if ( empty( $args ) ) {
267 if ( isset( $GLOBALS['post'] ) ) {
268 $args = array('post_parent' => (int) $GLOBALS['post']->post_parent );
269 } else {
270 return $kids;
271 }
272 } elseif ( is_object( $args ) ) {
273 $args = array('post_parent' => (int) $args->post_parent );
274 } elseif ( is_numeric( $args ) ) {
275 $args = array('post_parent' => (int) $args);
276 }
277
278 $defaults = array(
279 'numberposts' => -1, 'post_type' => 'any',
280 'post_status' => 'any', 'post_parent' => 0,
281 );
282
283 $r = wp_parse_args( $args, $defaults );
284
285 $children = get_posts( $r );
286
287 if ( !$children )
288 return $kids;
289
290 update_post_cache($children);
291
292 foreach ( $children as $key => $child )
293 $kids[$child->ID] =& $children[$key];
294
295 if ( $output == OBJECT ) {
296 return $kids;
297 } elseif ( $output == ARRAY_A ) {
298 foreach ( (array) $kids as $kid )
299 $weeuns[$kid->ID] = get_object_vars($kids[$kid->ID]);
300 return $weeuns;
301 } elseif ( $output == ARRAY_N ) {
302 foreach ( (array) $kids as $kid )
303 $babes[$kid->ID] = array_values(get_object_vars($kids[$kid->ID]));
304 return $babes;
305 } else {
306 return $kids;
307 }
308}
309
310/**
311 * Get extended entry info (<!--more-->).
312 *
313 * There should not be any space after the second dash and before the word
314 * 'more'. There can be text or space(s) after the word 'more', but won't be
315 * referenced.
316 *
317 * The returned array has 'main' and 'extended' keys. Main has the text before
318 * the <code><!--more--></code>. The 'extended' key has the content after the
319 * <code><!--more--></code> comment.
320 *
321 * @since 1.0.0
322 *
323 * @param string $post Post content.
324 * @return array Post before ('main') and after ('extended').
325 */
326function get_extended($post) {
327 //Match the new style more links
328 if ( preg_match('/<!--more(.*?)?-->/', $post, $matches) ) {
329 list($main, $extended) = explode($matches[0], $post, 2);
330 } else {
331 $main = $post;
332 $extended = '';
333 }
334
335 // Strip leading and trailing whitespace
336 $main = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $main);
337 $extended = preg_replace('/^[\s]*(.*)[\s]*$/', '\\1', $extended);
338
339 return array('main' => $main, 'extended' => $extended);
340}
341
342/**
343 * Retrieves post data given a post ID or post object.
344 *
345 * See {@link sanitize_post()} for optional $filter values. Also, the parameter
346 * $post, must be given as a variable, since it is passed by reference.
347 *
348 * @since 1.5.1
349 * @uses $wpdb
350 * @link http://codex.wordpress.org/Function_Reference/get_post
351 *
352 * @param int|object $post Post ID or post object.
353 * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N.
354 * @param string $filter Optional, default is raw.
355 * @return mixed Post data
356 */
357function &get_post(&$post, $output = OBJECT, $filter = 'raw') {
358 global $wpdb;
359 $null = null;
360
361 if ( empty($post) ) {
362 if ( isset($GLOBALS['post']) )
363 $_post = & $GLOBALS['post'];
364 else
365 return $null;
366 } elseif ( is_object($post) && empty($post->filter) ) {
367 _get_post_ancestors($post);
368 $_post = sanitize_post($post, 'raw');
369 wp_cache_add($post->ID, $_post, 'posts');
370 } else {
371 if ( is_object($post) )
372 $post_id = $post->ID;
373 else
374 $post_id = $post;
375
376 $post_id = (int) $post_id;
377 if ( ! $_post = wp_cache_get($post_id, 'posts') ) {
378 $_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id));
379 if ( ! $_post )
380 return $null;
381 _get_post_ancestors($_post);
382 $_post = sanitize_post($_post, 'raw');
383 wp_cache_add($_post->ID, $_post, 'posts');
384 }
385 }
386
387 if ($filter != 'raw')
388 $_post = sanitize_post($_post, $filter);
389
390 if ( $output == OBJECT ) {
391 return $_post;
392 } elseif ( $output == ARRAY_A ) {
393 $__post = get_object_vars($_post);
394 return $__post;
395 } elseif ( $output == ARRAY_N ) {
396 $__post = array_values(get_object_vars($_post));
397 return $__post;
398 } else {
399 return $_post;
400 }
401}
402
403/**
404 * Retrieve ancestors of a post.
405 *
406 * @since 2.5.0
407 *
408 * @param int|object $post Post ID or post object
409 * @return array Ancestor IDs or empty array if none are found.
410 */
411function get_post_ancestors($post) {
412 $post = get_post($post);
413
414 if ( !empty($post->ancestors) )
415 return $post->ancestors;
416
417 return array();
418}
419
420/**
421 * Retrieve data from a post field based on Post ID.
422 *
423 * Examples of the post field will be, 'post_type', 'post_status', 'content',
424 * etc and based off of the post object property or key names.
425 *
426 * The context values are based off of the taxonomy filter functions and
427 * supported values are found within those functions.
428 *
429 * @since 2.3.0
430 * @uses sanitize_post_field() See for possible $context values.
431 *
432 * @param string $field Post field name
433 * @param id $post Post ID
434 * @param string $context Optional. How to filter the field. Default is display.
435 * @return WP_Error|string Value in post field or WP_Error on failure
436 */
437function get_post_field( $field, $post, $context = 'display' ) {
438 $post = (int) $post;
439 $post = get_post( $post );
440
441 if ( is_wp_error($post) )
442 return $post;
443
444 if ( !is_object($post) )
445 return '';
446
447 if ( !isset($post->$field) )
448 return '';
449
450 return sanitize_post_field($field, $post->$field, $post->ID, $context);
451}
452
453/**
454 * Retrieve the mime type of an attachment based on the ID.
455 *
456 * This function can be used with any post type, but it makes more sense with
457 * attachments.
458 *
459 * @since 2.0.0
460 *
461 * @param int $ID Optional. Post ID.
462 * @return bool|string False on failure or returns the mime type
463 */
464function get_post_mime_type($ID = '') {
465 $post = & get_post($ID);
466
467 if ( is_object($post) )
468 return $post->post_mime_type;
469
470 return false;
471}
472
473/**
474 * Retrieve the post status based on the Post ID.
475 *
476 * If the post ID is of an attachment, then the parent post status will be given
477 * instead.
478 *
479 * @since 2.0.0
480 *
481 * @param int $ID Post ID
482 * @return string|bool Post status or false on failure.
483 */
484function get_post_status($ID = '') {
485 $post = get_post($ID);
486
487 if ( !is_object($post) )
488 return false;
489
490 // Unattached attachments are assumed to be published.
491 if ( ('attachment' == $post->post_type) && ('inherit' == $post->post_status) && ( 0 == $post->post_parent) )
492 return 'publish';
493
494 if ( ('attachment' == $post->post_type) && $post->post_parent && ($post->ID != $post->post_parent) )
495 return get_post_status($post->post_parent);
496
497 return $post->post_status;
498}
499
500/**
501 * Retrieve all of the WordPress supported post statuses.
502 *
503 * Posts have a limited set of valid status values, this provides the
504 * post_status values and descriptions.
505 *
506 * @since 2.5.0
507 *
508 * @return array List of post statuses.
509 */
510function get_post_statuses( ) {
511 $status = array(
512 'draft' => __('Draft'),
513 'pending' => __('Pending Review'),
514 'private' => __('Private'),
515 'publish' => __('Published')
516 );
517
518 return $status;
519}
520
521/**
522 * Retrieve all of the WordPress support page statuses.
523 *
524 * Pages have a limited set of valid status values, this provides the
525 * post_status values and descriptions.
526 *
527 * @since 2.5.0
528 *
529 * @return array List of page statuses.
530 */
531function get_page_statuses( ) {
532 $status = array(
533 'draft' => __('Draft'),
534 'private' => __('Private'),
535 'publish' => __('Published')
536 );
537
538 return $status;
539}
540
541/**
542 * Register a post type. Do not use before init.
543 *
544 * A simple function for creating or modifying a post status based on the
545 * parameters given. The function will accept an array (second optional
546 * parameter), along with a string for the post status name.
547 *
548 *
549 * Optional $args contents:
550 *
551 * label - A descriptive name for the post status marked for translation. Defaults to $post_status.
552 * public - Whether posts of this status should be shown in the admin UI. Defaults to true.
553 * exclude_from_search - Whether to exclude posts with this post status from search results. Defaults to true.
554 *
555 * @package WordPress
556 * @subpackage Post
557 * @since 3.0.0
558 * @uses $wp_post_statuses Inserts new post status object into the list
559 *
560 * @param string $post_status Name of the post status.
561 * @param array|string $args See above description.
562 */
563function register_post_status($post_status, $args = array()) {
564 global $wp_post_statuses;
565
566 if (!is_array($wp_post_statuses))
567 $wp_post_statuses = array();
568
569 // Args prefixed with an underscore are reserved for internal use.
570 $defaults = array('label' => false, 'label_count' => false, 'exclude_from_search' => null, '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'hierarchical' => false, 'public' => null, 'internal' => null, 'protected' => null, 'private' => null, 'show_in_admin_all' => null, 'publicly_queryable' => null, 'show_in_admin_status_list' => null, 'show_in_admin_all_list' => null, 'single_view_cap' => null);
571 $args = wp_parse_args($args, $defaults);
572 $args = (object) $args;
573
574 $post_status = sanitize_user($post_status, true);
575 $args->name = $post_status;
576
577 if ( null === $args->public && null === $args->internal && null === $args->protected && null === $args->private )
578 $args->internal = true;
579
580 if ( null === $args->public )
581 $args->public = false;
582
583 if ( null === $args->private )
584 $args->private = false;
585
586 if ( null === $args->protected )
587 $args->protected = false;
588
589 if ( null === $args->internal )
590 $args->internal = false;
591
592 if ( null === $args->publicly_queryable )
593 $args->publicly_queryable = $args->public;
594
595 if ( null === $args->exclude_from_search )
596 $args->exclude_from_search = $args->internal;
597
598 if ( null === $args->show_in_admin_all_list )
599 $args->show_in_admin_all_list = !$args->internal;
600
601 if ( null === $args->show_in_admin_status_list )
602 $args->show_in_admin_status_list = !$args->internal;
603
604 if ( null === $args->single_view_cap )
605 $args->single_view_cap = $args->public ? '' : 'edit';
606
607 if ( false === $args->label )
608 $args->label = $post_status;
609
610 if ( false === $args->label_count )
611 $args->label_count = array( $args->label, $args->label );
612
613 $wp_post_statuses[$post_status] = $args;
614
615 return $args;
616}
617
618/**
619 * Retrieve a post status object by name
620 *
621 * @package WordPress
622 * @subpackage Post
623 * @since 3.0.0
624 * @uses $wp_post_statuses
625 * @see register_post_status
626 * @see get_post_statuses
627 *
628 * @param string $post_type The name of a registered post status
629 * @return object A post status object
630 */
631function get_post_status_object( $post_status ) {
632 global $wp_post_statuses;
633
634 if ( empty($wp_post_statuses[$post_status]) )
635 return null;
636
637 return $wp_post_statuses[$post_status];
638}
639
640/**
641 * Get a list of all registered post status objects.
642 *
643 * @package WordPress
644 * @subpackage Post
645 * @since 3.0.0
646 * @uses $wp_post_statuses
647 * @see register_post_status
648 * @see get_post_status_object
649 *
650 * @param array|string $args An array of key => value arguments to match against the post status objects.
651 * @param string $output The type of output to return, either post status 'names' or 'objects'. 'names' is the default.
652 * @param string $operator The logical operation to perform. 'or' means only one element
653 * from the array needs to match; 'and' means all elements must match. The default is 'and'.
654 * @return array A list of post type names or objects
655 */
656function get_post_stati( $args = array(), $output = 'names', $operator = 'and' ) {
657 global $wp_post_statuses;
658
659 $field = ('names' == $output) ? 'name' : false;
660
661 return wp_filter_object_list($wp_post_statuses, $args, $operator, $field);
662}
663
664/**
665 * Whether the post type is hierarchical.
666 *
667 * A false return value might also mean that the post type does not exist.
668 *
669 * @since 3.0.0
670 * @see get_post_type_object
671 *
672 * @param string $post Post type name
673 * @return bool Whether post type is hierarchical.
674 */
675function is_post_type_hierarchical( $post_type ) {
676 if ( ! post_type_exists( $post_type ) )
677 return false;
678
679 $post_type = get_post_type_object( $post_type );
680 return $post_type->hierarchical;
681}
682
683/**
684 * Checks if a post type is registered.
685 *
686 * @since 3.0.0
687 * @uses get_post_type_object()
688 *
689 * @param string Post type name
690 * @return bool Whether post type is registered.
691 */
692function post_type_exists( $post_type ) {
693 return (bool) get_post_type_object( $post_type );
694}
695
696/**
697 * Retrieve the post type of the current post or of a given post.
698 *
699 * @since 2.1.0
700 *
701 * @uses $post The Loop current post global
702 *
703 * @param mixed $the_post Optional. Post object or post ID.
704 * @return bool|string post type or false on failure.
705 */
706function get_post_type( $the_post = false ) {
707 global $post;
708
709 if ( false === $the_post )
710 $the_post = $post;
711 elseif ( is_numeric($the_post) )
712 $the_post = get_post($the_post);
713
714 if ( is_object($the_post) )
715 return $the_post->post_type;
716
717 return false;
718}
719
720/**
721 * Retrieve a post type object by name
722 *
723 * @package WordPress
724 * @subpackage Post
725 * @since 3.0.0
726 * @uses $wp_post_types
727 * @see register_post_type
728 * @see get_post_types
729 *
730 * @param string $post_type The name of a registered post type
731 * @return object A post type object
732 */
733function get_post_type_object( $post_type ) {
734 global $wp_post_types;
735
736 if ( empty($wp_post_types[$post_type]) )
737 return null;
738
739 return $wp_post_types[$post_type];
740}
741
742/**
743 * Get a list of all registered post type objects.
744 *
745 * @package WordPress
746 * @subpackage Post
747 * @since 2.9.0
748 * @uses $wp_post_types
749 * @see register_post_type
750 *
751 * @param array|string $args An array of key => value arguments to match against the post type objects.
752 * @param string $output The type of output to return, either post type 'names' or 'objects'. 'names' is the default.
753 * @param string $operator The logical operation to perform. 'or' means only one element
754 * from the array needs to match; 'and' means all elements must match. The default is 'and'.
755 * @return array A list of post type names or objects
756 */
757function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) {
758 global $wp_post_types;
759
760 $field = ('names' == $output) ? 'name' : false;
761
762 return wp_filter_object_list($wp_post_types, $args, $operator, $field);
763}
764
765/**
766 * Register a post type. Do not use before init.
767 *
768 * A simple function for creating or modifying a post type based on the
769 * parameters given. The function will accept an array (second optional
770 * parameter), along with a string for the post type name.
771 *
772 *
773 * Optional $args contents:
774 *
775 * - label - Name of the post type shown in the menu. Usually plural. If not set, labels['name'] will be used.
776 * - description - A short descriptive summary of what the post type is. Defaults to blank.
777 * - public - Whether posts of this type should be shown in the admin UI. Defaults to false.
778 * - exclude_from_search - Whether to exclude posts with this post type from search results. Defaults to true if the type is not public, false if the type is public.
779 * - publicly_queryable - Whether post_type queries can be performed from the front page. Defaults to whatever public is set as.
780 * - show_ui - Whether to generate a default UI for managing this post type. Defaults to true if the type is public, false if the type is not public.
781 * - menu_position - The position in the menu order the post type should appear. Defaults to the bottom.
782 * - menu_icon - The url to the icon to be used for this menu. Defaults to use the posts icon.
783 * - capability_type - The post type to use for checking read, edit, and delete capabilities. Defaults to "post".
784 * - capabilities - Array of capabilities for this post type. You can see accepted values in {@link get_post_type_capabilities()}. By default the capability_type is used to construct capabilities.
785 * - hierarchical - Whether the post type is hierarchical. Defaults to false.
786 * - supports - An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none.
787 * - register_meta_box_cb - Provide a callback function that will be called when setting up the meta boxes for the edit form. Do remove_meta_box() and add_meta_box() calls in the callback.
788 * - taxonomies - An array of taxonomy identifiers that will be registered for the post type. Default is no taxonomies. Taxonomies can be registered later with register_taxonomy() or register_taxonomy_for_object_type().
789 * - labels - An array of labels for this post type. You can see accepted values in {@link get_post_type_labels()}. By default post labels are used for non-hierarchical types and page labels for hierarchical ones.
790 * - permalink_epmask - The default rewrite endpoint bitmasks.
791 * - rewrite - false to prevent rewrite, or array('slug'=>$slug) to customize permastruct; default will use $post_type as slug.
792 * - query_var - false to prevent queries, or string to value of the query var to use for this post type
793 * - can_export - true allows this post type to be exported.
794 * - show_in_nav_menus - true makes this post type available for selection in navigation menus.
795 * - _builtin - true if this post type is a native or "built-in" post_type. THIS IS FOR INTERNAL USE ONLY!
796 * - _edit_link - URL segement to use for edit link of this post type. Set to 'post.php?post=%d'. THIS IS FOR INTERNAL USE ONLY!
797 *
798 * @since 2.9.0
799 * @uses $wp_post_types Inserts new post type object into the list
800 *
801 * @param string $post_type Name of the post type.
802 * @param array|string $args See above description.
803 * @return object the registered post type object
804 */
805function register_post_type($post_type, $args = array()) {
806 global $wp_post_types, $wp_rewrite, $wp;
807
808 if ( !is_array($wp_post_types) )
809 $wp_post_types = array();
810
811 // Args prefixed with an underscore are reserved for internal use.
812 $defaults = array(
813 'labels' => array(), 'description' => '', 'publicly_queryable' => null, 'exclude_from_search' => null,
814 '_builtin' => false, '_edit_link' => 'post.php?post=%d', 'capability_type' => 'post', 'capabilities' => array(), 'hierarchical' => false,
815 'public' => false, 'rewrite' => true, 'query_var' => true, 'supports' => array(), 'register_meta_box_cb' => null,
816 'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,
817 'permalink_epmask' => EP_PERMALINK, 'can_export' => true, 'show_in_nav_menus' => null
818 );
819 $args = wp_parse_args($args, $defaults);
820 $args = (object) $args;
821
822 $post_type = sanitize_user($post_type, true);
823 $args->name = $post_type;
824
825 // If not set, default to the setting for public.
826 if ( null === $args->publicly_queryable )
827 $args->publicly_queryable = $args->public;
828
829 // If not set, default to the setting for public.
830 if ( null === $args->show_ui )
831 $args->show_ui = $args->public;
832
833 // Whether to show this type in nav-menus.php. Defaults to the setting for public.
834 if ( null === $args->show_in_nav_menus )
835 $args->show_in_nav_menus = $args->public;
836
837 // If not set, default to true if not public, false if public.
838 if ( null === $args->exclude_from_search )
839 $args->exclude_from_search = !$args->public;
840
841 if ( empty($args->capability_type) )
842 $args->capability_type = 'post';
843
844 $args->cap = get_post_type_capabilities( $args );
845 unset($args->capabilities);
846
847 if ( ! empty($args->supports) ) {
848 add_post_type_support($post_type, $args->supports);
849 unset($args->supports);
850 } else {
851 // Add default features
852 add_post_type_support($post_type, array('title', 'editor'));
853 }
854
855 if ( false !== $args->query_var && !empty($wp) ) {
856 if ( true === $args->query_var )
857 $args->query_var = $post_type;
858 $args->query_var = sanitize_title_with_dashes($args->query_var);
859 $wp->add_query_var($args->query_var);
860 }
861
862 if ( false !== $args->rewrite && '' != get_option('permalink_structure') ) {
863 if ( !is_array($args->rewrite) )
864 $args->rewrite = array();
865 if ( !isset($args->rewrite['slug']) )
866 $args->rewrite['slug'] = $post_type;
867 if ( !isset($args->rewrite['with_front']) )
868 $args->rewrite['with_front'] = true;
869 if ( $args->hierarchical )
870 $wp_rewrite->add_rewrite_tag("%$post_type%", '(.+?)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");
871 else
872 $wp_rewrite->add_rewrite_tag("%$post_type%", '([^/]+)', $args->query_var ? "{$args->query_var}=" : "post_type=$post_type&name=");
873 $wp_rewrite->add_permastruct($post_type, "{$args->rewrite['slug']}/%$post_type%", $args->rewrite['with_front'], $args->permalink_epmask);
874 }
875
876 if ( $args->register_meta_box_cb )
877 add_action('add_meta_boxes_' . $post_type, $args->register_meta_box_cb, 10, 1);
878
879 $args->labels = get_post_type_labels( $args );
880 $args->label = $args->labels->name;
881
882 $wp_post_types[$post_type] = $args;
883
884 add_action( 'future_' . $post_type, '_future_post_hook', 5, 2 );
885
886 foreach ( $args->taxonomies as $taxonomy ) {
887 register_taxonomy_for_object_type( $taxonomy, $post_type );
888 }
889
890 return $args;
891}
892
893/**
894 * Builds an object with all post type capabilities out of a post type object
895 *
896 * Accepted keys of the capabilities array in the post type object:
897 * - edit_post - The meta capability that controls editing a particular object of this post type. Defaults to "edit_ . $capability_type" (edit_post).
898 * - edit_posts - The capability that controls editing objects of this post type as a class. Defaults to "edit_ . $capability_type . s" (edit_posts).
899 * - edit_others_posts - The capability that controls editing objects of this post type that are owned by other users. Defaults to "edit_others_ . $capability_type . s" (edit_others_posts).
900 * - publish_posts - The capability that controls publishing objects of this post type. Defaults to "publish_ . $capability_type . s" (publish_posts).
901 * - read_post - The meta capability that controls reading a particular object of this post type. Defaults to "read_ . $capability_type" (read_post).
902 * - read_private_posts - The capability that controls reading private posts. Defaults to "read_private . $capability_type . s" (read_private_posts).
903 * - delete_post - The meta capability that controls deleting a particular object of this post type. Defaults to "delete_ . $capability_type" (delete_post).
904 *
905 * @since 3.0.0
906 * @param object $args
907 * @return object object with all the capabilities as member variables
908 */
909function get_post_type_capabilities( $args ) {
910 $defaults = array(
911 'edit_post' => 'edit_' . $args->capability_type,
912 'edit_posts' => 'edit_' . $args->capability_type . 's',
913 'edit_others_posts' => 'edit_others_' . $args->capability_type . 's',
914 'publish_posts' => 'publish_' . $args->capability_type . 's',
915 'read_post' => 'read_' . $args->capability_type,
916 'read_private_posts' => 'read_private_' . $args->capability_type . 's',
917 'delete_post' => 'delete_' . $args->capability_type,
918 );
919 $labels = array_merge( $defaults, $args->capabilities );
920 return (object) $labels;
921}
922
923/**
924 * Builds an object with all post type labels out of a post type object
925 *
926 * Accepted keys of the label array in the post type object:
927 * - name - general name for the post type, usually plural. The same and overriden by $post_type_object->label. Default is Posts/Pages
928 * - singular_name - name for one object of this post type. Default is Post/Page
929 * - add_new - Default is Add New for both hierarchical and non-hierarchical types. When internationalizing this string, please use a {@link http://codex.wordpress.org/I18n_for_WordPress_Developers#Disambiguation_by_context gettext context} matching your post type. Example: <code>_x('Add New', 'product');</code>
930 * - add_new_item - Default is Add New Post/Add New Page
931 * - edit_item - Default is Edit Post/Edit Page
932 * - new_item - Default is New Post/New Page
933 * - view_item - Default is View Post/View Page
934 * - search_items - Default is Search Posts/Search Pages
935 * - not_found - Default is No posts found/No pages found
936 * - not_found_in_trash - Default is No posts found in Trash/No pages found in Trash
937 * - parent_item_colon - This string isn't used on non-hierarchical types. In hierarchical ones the default is Parent Page:
938 *
939 * Above, the first default value is for non-hierarchical post types (like posts) and the second one is for hierarchical post types (like pages.)
940 *
941 * @since 3.0.0
942 * @param object $post_type_object
943 * @return object object with all the labels as member variables
944 */
945function get_post_type_labels( $post_type_object ) {
946 $nohier_vs_hier_defaults = array(
947 'name' => array( _x('Posts', 'post type general name'), _x('Pages', 'post type general name') ),
948 'singular_name' => array( _x('Post', 'post type singular name'), _x('Page', 'post type singular name') ),
949 'add_new' => array( _x('Add New', 'post'), _x('Add New', 'page') ),
950 'add_new_item' => array( __('Add New Post'), __('Add New Page') ),
951 'edit_item' => array( __('Edit Post'), __('Edit Page') ),
952 'new_item' => array( __('New Post'), __('New Page') ),
953 'view_item' => array( __('View Post'), __('View Page') ),
954 'search_items' => array( __('Search Posts'), __('Search Pages') ),
955 'not_found' => array( __('No posts found'), __('No pages found') ),
956 'not_found_in_trash' => array( __('No posts found in Trash'), __('No pages found in Trash') ),
957 'parent_item_colon' => array( null, __('Parent Page:') )
958 );
959 return _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults );
960}
961
962/**
963 * Builds an object with custom-something object (post type, taxonomy) labels out of a custom-something object
964 *
965 * @access private
966 */
967function _get_custom_object_labels( $object, $nohier_vs_hier_defaults ) {
968
969 if ( isset( $object->label ) && empty( $object->labels['name'] ) )
970 $object->labels['name'] = $object->label;
971
972 if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) )
973 $object->labels['singular_name'] = $object->labels['name'];
974
975 $defaults = array_map( create_function( '$x', $object->hierarchical? 'return $x[1];' : 'return $x[0];' ), $nohier_vs_hier_defaults );
976 $labels = array_merge( $defaults, $object->labels );
977 return (object)$labels;
978}
979
980/**
981 * Register support of certain features for a post type.
982 *
983 * All features are directly associated with a functional area of the edit screen, such as the
984 * editor or a meta box: 'title', 'editor', 'comments', 'revisions', 'trackbacks', 'author',
985 * 'excerpt', 'page-attributes', 'thumbnail', and 'custom-fields'.
986 *
987 * Additionally, the 'revisions' feature dictates whether the post type will store revisions,
988 * and the 'comments' feature dicates whether the comments count will show on the edit screen.
989 *
990 * @since 3.0.0
991 * @param string $post_type The post type for which to add the feature
992 * @param string|array $feature the feature being added, can be an array of feature strings or a single string
993 */
994function add_post_type_support( $post_type, $feature ) {
995 global $_wp_post_type_features;
996
997 $features = (array) $feature;
998 foreach ($features as $feature) {
999 if ( func_num_args() == 2 )
1000 $_wp_post_type_features[$post_type][$feature] = true;
/var/www/wordpress/wp-includes/query.php
/var/www/wordpress/wp-includes/registration-functions.php
/var/www/wordpress/wp-includes/registration.php
/var/www/wordpress/wp-includes/rewrite.php
/var/www/wordpress/wp-includes/rss-functions.php
/var/www/wordpress/wp-includes/rss.php
/var/www/wordpress/wp-includes/script-loader.php
/var/www/wordpress/wp-includes/shortcodes.php
/var/www/wordpress/wp-includes/taxonomy.php
/var/www/wordpress/wp-includes/template-loader.php
/var/www/wordpress/wp-includes/theme.php
/var/www/wordpress/wp-includes/update.php
/var/www/wordpress/wp-includes/user.php
/var/www/wordpress/wp-includes/vars.php
/var/www/wordpress/wp-includes/version.php
/var/www/wordpress/wp-includes/widgets.php
/var/www/wordpress/wp-includes/wp-db.php
/var/www/wordpress/wp-includes/wp-diff.php
/var/www/wordpress/index.php
/var/www/wordpress/wp-activate.php
/var/www/wordpress/wp-app.php
/var/www/wordpress/wp-atom.php
/var/www/wordpress/wp-blog-header.php
/var/www/wordpress/wp-comments-post.php
/var/www/wordpress/wp-commentsrss2.php
/var/www/wordpress/wp-config-sample.php
/var/www/wordpress/wp-cron.php
/var/www/wordpress/wp-feed.php
/var/www/wordpress/wp-links-opml.php
/var/www/wordpress/wp-load.php
/var/www/wordpress/wp-login.php
/var/www/wordpress/wp-mail.php
/var/www/wordpress/wp-pass.php
/var/www/wordpress/wp-rdf.php
/var/www/wordpress/wp-register.php
/var/www/wordpress/wp-rss.php
/var/www/wordpress/wp-rss2.php
/var/www/wordpress/wp-settings.php
/var/www/wordpress/wp-signup.php
/var/www/wordpress/wp-trackback.php
/var/www/wordpress/xmlrpc.php