* referenced.
*
* The returned array has 'main', 'extended', and 'more_text' keys. Main has the text before
- * the <code><!--more--></code>. The 'extended' key has the content after the
- * <code><!--more--></code> comment. The 'more_text' key has the custom "Read More" text.
+ * the `<!--more-->`. The 'extended' key has the content after the
+ * `<!--more-->` comment. The 'more_text' key has the custom "Read More" text.
*
* @since 1.0.0
*
* @since 2.0.0
*
* @param int|WP_Post $ID Optional. Post ID or post object. Default empty.
- * @return string|bool The mime type on success, false on failure.
+ * @return string|false The mime type on success, false on failure.
*/
function get_post_mime_type( $ID = '' ) {
$post = get_post($ID);
* @since 2.0.0
*
* @param int|WP_Post $ID Optional. Post ID or post object. Default empty.
- * @return string|bool Post status on success, false on failure.
+ * @return string|false Post status on success, false on failure.
*/
function get_post_status( $ID = '' ) {
$post = get_post($ID);
}
/**
- * Get a list of all registered post status objects.
+ * Get a list of post statuses.
*
* @since 3.0.0
*
*
* @see register_post_status()
*
- * @param array|string $args Optional. Array or string of post status arguments. Default array.
- * @param string $output Optional. The type of output to return. Accepts post status 'names'
- * or 'objects'. Default 'names'.
+ * @param array|string $args Optional. Array or string of post status arguments to compare against
+ * properties of the global `$wp_post_statuses objects`. Default empty array.
+ * @param string $output Optional. The type of output to return, either 'names' or 'objects'. Default 'names'.
* @param string $operator Optional. The logical operation to perform. 'or' means only one element
* from the array needs to match; 'and' means all elements must match.
* Default 'and'.
* @since 2.1.0
*
* @param int|WP_Post $post Optional. Post ID or post object. Default is global $post.
- * @return string|bool Post type on success, false on failure.
+ * @return string|false Post type on success, false on failure.
*/
function get_post_type( $post = null ) {
if ( $post = get_post( $post ) )
*
* @global array $wp_post_types List of post types.
*
- * @see register_post_type()
+ * @see register_post_type() for accepted arguments.
*
* @param array|string $args Optional. An array of key => value arguments to match against
* the post type objects. Default empty array.
* @param string $output Optional. The type of output to return. Accepts post type 'names'
* or 'objects'. Default 'names'.
- * @param string $operator Optaionl. The logical operation to perform. 'or' means only one
+ * @param string $operator Optional. The logical operation to perform. 'or' means only one
* element from the array needs to match; 'and' means all elements
- * must match. Default 'and'.
+ * must match. Accepts 'or' or 'and'. Default 'and'.
* @return array A list of post type names or objects.
*/
function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) {
// If not set, default to the whether the full UI is shown.
if ( null === $args->show_in_admin_bar )
- $args->show_in_admin_bar = true === $args->show_in_menu;
+ $args->show_in_admin_bar = (bool) $args->show_in_menu;
// If not set, default to the setting for public.
if ( null === $args->show_in_nav_menus )
* - singular_name - name for one object of this post type. Default is Post/Page
* - add_new - Default is Add New for both hierarchical and non-hierarchical types.
* When internationalizing this string, please use a gettext context
- * {@see http://codex.wordpress.org/I18n_for_WordPress_Developers#Disambiguation_by_context}
- * matching your post type. Example: <code>_x('Add New', 'product');</code>.
+ * {@link http://codex.wordpress.org/I18n_for_WordPress_Developers#Disambiguation_by_context}
+ * matching your post type. Example: `_x( 'Add New', 'product' );`.
* - add_new_item - Default is Add New Post/Add New Page.
* - edit_item - Default is Edit Post/Edit Page.
* - new_item - Default is New Post/New Page.
* - parent_item_colon - This string isn't used on non-hierarchical types. In hierarchical
* ones the default is 'Parent Page:'.
* - all_items - String for the submenu. Default is All Posts/All Pages.
- * - menu_name - Default is the same as <code>name</code>.
+ * - menu_name - Default is the same as `name`.
*
* Above, the first default value is for non-hierarchical post types (like posts)
* and the second one is for hierarchical post types (like pages).
/**
* Filter the labels of a specific post type.
*
- * The dynamic portion of the hook name, $post_type, refers to
+ * The dynamic portion of the hook name, `$post_type`, refers to
* the post type slug.
*
* @since 3.5.0
*
* @since 2.5.0
*
- * @global wpdb $wpdb WordPress database access abstraction object.
+ * @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $post_id Optional. Post ID to change post type. Default 0.
* @param string $post_type Optional. Post type. Accepts 'post' or 'page' to
/**
* Filter the value of a specific post field to edit.
*
- * The dynamic portion of the hook name, $field, refers to the post
+ * The dynamic portion of the hook name, `$field`, refers to the post
* field name.
*
* @since 2.3.0
/**
* Filter the value of a specific post field to edit.
*
- * The dynamic portion of the hook name, $field_no_prefix, refers to
+ * The dynamic portion of the hook name, `$field_no_prefix`, refers to
* the post field name.
*
* @since 2.3.0
/**
* Filter the value of a specific post field before saving.
*
- * The dynamic portion of the hook name, $field, refers to the post
+ * The dynamic portion of the hook name, `$field`, refers to the post
* field name.
*
* @since 2.3.0
/**
* Filter the value of a specific field before saving.
*
- * The dynamic portion of the hook name, $field_no_prefix, refers
+ * The dynamic portion of the hook name, `$field_no_prefix`, refers
* to the post field name.
*
* @since 2.3.0
/**
* Filter the value of a specific post field before saving.
*
- * The dynamic portion of the hook name, $field, refers to the post
+ * The dynamic portion of the hook name, `$field`, refers to the post
* field name.
*
* @since 2.3.0
/**
* Filter the value of a specific post field for display.
*
- * The dynamic portion of the hook name, $field, refers to the post
+ * The dynamic portion of the hook name, `$field`, refers to the post
* field name.
*
* @since 2.3.0
*
* @since 1.0.0
*
- * @global wpdb $wpdb WordPress database access abstraction object.
+ * @global wpdb $wpdb WordPress database abstraction object.
* @see wp_delete_attachment()
* @see wp_trash_post()
*
*
* @since 2.9.0
*
- * @global wpdb $wpdb WordPress database access abstraction object.
+ * @global wpdb $wpdb WordPress database abstraction object.
*
* @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
* @return mixed False on failure.
* @since 2.9.0
*
* @param int|WP_Post $post Optional. Post ID or post object. Defaults to global $post.
- * @return mixed False on failure.
+ * @return null|bool Null on failure.
*/
function wp_untrash_post_comments( $post = null ) {
global $wpdb;
*
* @since 2.3.0
*
- * @uses wp_get_object_terms()
- *
* @param int $post_id Optional. The Post ID. Does not default to the ID of the
* global $post. Defualt 0.
* @param array $args Optional. Overwrite the defaults
*
* @since 2.8.0
*
- * @uses wp_get_object_terms()
- *
* @param int $post_id Optional. The Post ID. Does not default to the ID of the
* global $post. Default 0.
* @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
*
* @see get_posts()
*
- * @param string $deprecated Not used.
* @param array $args Optional. Arguments to retrieve posts. Default empty array.
* @param string $output Optional. Type of output. Accepts ARRAY_A or ''. Default ARRAY_A.
* @return array|bool Associative array if $output equals ARRAY_A, array or false if no results.
/**
* Fires once a post has been saved.
*
- * The dynamic portion of the hook name, $post->post_type, refers to
+ * The dynamic portion of the hook name, `$post->post_type`, refers to
* the post type slug.
*
* @since 3.7.0
if ( ! is_array( $feeds ) )
$feeds = array();
- $hierarchical_post_types = get_post_types( array('hierarchical' => true) );
if ( 'attachment' == $post_type ) {
// Attachment slugs must be unique across all types.
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
} while ( $post_name_check );
$slug = $alt_post_name;
}
- } elseif ( in_array( $post_type, $hierarchical_post_types ) ) {
+ } elseif ( is_post_type_hierarchical( $post_type ) ) {
if ( 'nav_menu_item' == $post_type )
return $slug;
* Page slugs must be unique within their own trees. Pages are in a separate
* namespace than posts so page slugs are allowed to overlap post slugs.
*/
- $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode( "', '", esc_sql( $hierarchical_post_types ) ) . "' ) AND ID != %d AND post_parent = %d LIMIT 1";
- $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID, $post_parent ) );
+ $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
+ $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) );
/**
* Filter whether the post slug would make a bad hierarchical post slug.
$suffix = 2;
do {
$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
- $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID, $post_parent ) );
+ $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID, $post_parent ) );
$suffix++;
} while ( $post_name_check );
$slug = $alt_post_name;
*
* @since 2.3.0
*
- * @param string $new_status Transition to this post status.
- * @param string $old_status Previous post status.
- * @param object $post Post data.
+ * @param string $new_status Transition to this post status.
+ * @param string $old_status Previous post status.
+ * @param WP_Post $post Post data.
*/
function wp_transition_post_status( $new_status, $old_status, $post ) {
/**
/**
* Fires when a post is transitioned from one status to another.
*
- * The dynamic portions of the hook name, $new_status and $old status,
+ * The dynamic portions of the hook name, `$new_status` and `$old status`,
* refer to the old and new post statuses, respectively.
*
* @since 2.3.0
/**
* Fires when a post is transitioned from one status to another.
*
- * The dynamic portions of the hook name, $new_status and $post->post_type,
+ * The dynamic portions of the hook name, `$new_status` and `$post->post_type`,
* refer to the new post status and post type, respectively.
*
* @since 2.3.0
*
* @since 1.5.1
*
- * @param int $page_id Page ID.
- * @param array $pages List of pages' objects.
+ * @param int $page_id Page ID.
+ * @param array $pages List of pages' objects.
* @return array List of page children.
*/
-function get_page_children($page_id, $pages) {
+function get_page_children( $page_id, $pages ) {
$page_list = array();
foreach ( (array) $pages as $page ) {
if ( $page->post_parent == $page_id ) {
$page_list[] = $page;
- if ( $children = get_page_children($page->ID, $pages) )
- $page_list = array_merge($page_list, $children);
+ if ( $children = get_page_children( $page->ID, $pages ) ) {
+ $page_list = array_merge( $page_list, $children );
+ }
}
}
+
return $page_list;
}
*
* @since 1.5.0
*
- * @param mixed $args {
- * Array or string of arguments. Optional.
- *
- * @type int 'child_of' Page ID to return child and grandchild pages of. Default 0, or no restriction.
- * @type string 'sort_order' How to sort retrieved pages.
- * Default 'ASC'. Accepts 'ASC', 'DESC'.
- * @type string 'sort_column' What columns to sort pages by, comma-separated.
- * Default 'post_title'. Accepts 'post_author', 'post_date', 'post_title', 'post_name',
- * 'post_modified', 'post_modified_gmt', 'menu_order', 'post_parent', 'ID', 'rand',
- * 'comment_count'. 'post_' can be omitted for any values that start with it.
- * @type bool 'hierarchical' Whether to return pages hierarchically. Default true.
- * @type array 'exclude' Array of page IDs to exclude.
- * @type array 'include' Array of page IDs to include. Cannot be used with 'child_of', 'parent', 'exclude',
- * 'meta_key', 'meta_value', or 'hierarchical'.
- * @type string 'meta_key' Only include pages with this meta key.
- * @type string 'meta_value' Only include pages with this meta value.
- * @type string 'authors' A comma-separated list of author IDs.
- * @type int 'parent' Page ID to return direct children of. 'hierarchical' must be false.
- * Default -1, or no restriction.
- * @type int 'exclude_tree' Remove all children of the given ID from returned pages.
- * @type int 'number' The number of pages to return. Default 0, or all pages.
- * @type int 'offset' The number of pages to skip before returning. Requires 'number'.
- * Default 0.
- * @type string 'post_type' The post type to query.
- * Default 'page'.
- * @type string 'post_status' A comma-separated list of post status types to include.
- * Default 'publish'.
+ * @param array|string $args {
+ * Optional. Array or string of arguments to retrieve pages.
+ *
+ * @type int $child_of Page ID to return child and grandchild pages of.
+ * Default 0, or no restriction.
+ * @type string $sort_order How to sort retrieved pages. Accepts 'ASC', 'DESC'. Default 'ASC'.
+ * @type string $sort_column What columns to sort pages by, comma-separated. Accepts 'post_author',
+ * 'post_date', 'post_title', 'post_name', 'post_modified', 'menu_order',
+ * 'post_modified_gmt', 'post_parent', 'ID', 'rand', 'comment_count'.
+ * 'post_' can be omitted for any values that start with it.
+ * Default 'post_title'.
+ * @type bool $hierarchical Whether to return pages hierarchically. Default true.
+ * @type array $exclude Array of page IDs to exclude. Default empty array.
+ * @type array $include Array of page IDs to include. Cannot be used with `$child_of`,
+ * `$parent`, `$exclude`, `$meta_key`, `$meta_value`, or `$hierarchical`.
+ * Default empty array.
+ * @type string $meta_key Only include pages with this meta key. Default empty.
+ * @type string $meta_value Only include pages with this meta value. Requires `$meta_key`.
+ * Default empty.
+ * @type string $authors A comma-separated list of author IDs. Default empty.
+ * @type int $parent Page ID to return direct children of. `$hierarchical` must be false.
+ * Default -1, or no restriction.
+ * @type string|array $exclude_tree Comma-separated string or array of page IDs to exclude.
+ * Default empty array.
+ * @type int $number The number of pages to return. Default 0, or all pages.
+ * @type int $offset The number of pages to skip before returning. Requires `$number`.
+ * Default 0.
+ * @type string $post_type The post type to query. Default 'page'.
+ * @type string $post_status A comma-separated list of post status types to include.
+ * Default 'publish'.
* }
- * @return array List of pages matching defaults or $args.
+ * @return array List of pages matching defaults or `$args`.
*/
function get_pages( $args = array() ) {
global $wpdb;
wp_cache_set( $cache_key, $page_structure, 'posts' );
- // Convert to WP_Post instances.
+ // Convert to WP_Post instances
$pages = array_map( 'get_post', $pages );
/**
function wp_insert_attachment( $args, $file = false, $parent = 0 ) {
$defaults = array(
'file' => $file,
- 'post_parent' => $parent
+ 'post_parent' => 0
);
+
$data = wp_parse_args( $args, $defaults );
+ if ( ! empty( $parent ) ) {
+ $data['post_parent'] = $parent;
+ }
+
$data['post_type'] = 'attachment';
return wp_insert_post( $data );
*
* @since 2.0.0
*
- * @global wpdb $wpdb WordPress database access abstraction object.
+ * @global wpdb $wpdb WordPress database abstraction object.
*
* @param int $post_id Attachment ID.
* @param bool $force_delete Optional. Whether to bypass trash and force deletion.
$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
$file = get_attached_file( $post_id );
- $intermediate_sizes = array();
- foreach ( get_intermediate_image_sizes() as $size ) {
- if ( $intermediate = image_get_intermediate_size( $post_id, $size ) )
- $intermediate_sizes[] = $intermediate;
- }
-
if ( is_multisite() )
delete_transient( 'dirsize_cache' );
}
// Remove intermediate and backup images if there are any.
- foreach ( $intermediate_sizes as $intermediate ) {
- /** This filter is documented in wp-admin/custom-header.php */
- $intermediate_file = apply_filters( 'wp_delete_file', $intermediate['path'] );
- @ unlink( path_join($uploadpath['basedir'], $intermediate_file) );
+ if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
+ foreach ( $meta['sizes'] as $size => $sizeinfo ) {
+ $intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file );
+ /** This filter is documented in wp-admin/custom-header.php */
+ $intermediate_file = apply_filters( 'wp_delete_file', $intermediate_file );
+ @ unlink( path_join( $uploadpath['basedir'], $intermediate_file ) );
+ }
}
if ( is_array($backup_sizes) ) {
}
/**
- * Retrieve last post modified date depending on timezone.
+ * Get the timestamp of the last time any post was modified.
*
* The server timezone is the default and is the difference between GMT and
* server time. The 'blog' value is just when the last post was modified. The
*
* @since 1.2.0
*
- * @param string $timezone The location to get the time. Accepts 'gmt', 'blog', or 'server'.
+ * @param string $timezone Optional. The timezone for the timestamp. Uses the server's internal timezone.
+ * Accepts 'server', 'blog', 'gmt'. or 'server'. 'server' uses the server's
+ * internal timezone. 'blog' uses the `post_modified` field, which proxies
+ * to the timezone set for the site. 'gmt' uses the `post_modified_gmt` field.
* Default 'server'.
- * @return string The date the post was last modified.
+ * @return string The timestamp.
*/
function get_lastpostmodified( $timezone = 'server' ) {
$lastpostmodified = _get_last_post_time( $timezone, 'modified' );
*
* @param string $lastpostmodified Date the last post was modified.
* @param string $timezone Location to use for getting the post modified date.
+ * See {@see get_lastpostmodified()} for accepted `$timezone` values.
*/
return apply_filters( 'get_lastpostmodified', $lastpostmodified, $timezone );
}
/**
- * Retrieve latest post date data based on timezone.
+ * Get the timestamp of the last time any post was modified or published.
*
- * @access private
* @since 3.1.0
+ * @access private
*
- * @param string $timezone The location to get the time. Accepts 'gmt', 'blog', or 'server'.
- * @param string $field Field to check. Can be 'date' or 'modified'.
- * @return string The date.
+ * @param string $timezone The timezone for the timestamp. See {@see get_lastpostmodified()}
+ * for information on accepted values.
+ * @param string $field Post field to check. Accepts 'date' or 'modified'.
+ * @return string The timestamp.
*/
function _get_last_post_time( $timezone, $field ) {
global $wpdb;
*
* @since 2.0.0
*
- * @global wpdb $wpdb WordPress database access abstraction object.
+ * @global wpdb $wpdb WordPress database abstraction object.
*
* @param int|WP_Post $post Post ID or post object to remove from the cache.
*/
* @access private
*
* @see wp_clear_scheduled_hook()
- * @global wpdb $wpdb WordPress database access abstraction object.
+ * @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $new_status New post status.
* @param string $old_status Previous post status.
*
* @since 3.1.0
*
- * @param int $post_id
+ * @param int $post_ID
*
* @return int|bool Post parent ID, otherwise false.
*/
*
* @since 3.4.0
*
- * @global wpdb $wpdb WordPress database access abstraction object.
+ * @global wpdb $wpdb WordPress database abstraction object.
*/
function wp_delete_auto_drafts() {
global $wpdb;
*
* @see update_post_caches()
*
- * @param array $post_ids ID list
+ * @param array $ids ID list
* @param bool $update_term_cache Optional. Whether to update the term cache. Default true.
* @param bool $update_meta_cache Optional. Whether to update the meta cache. Default true.
*/