*/
function create_initial_post_types() {
register_post_type( 'post', array(
+ 'labels' => array(
+ 'name_admin_bar' => _x( 'Post', 'add new on admin bar' ),
+ ),
'public' => true,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
) );
register_post_type( 'page', array(
+ 'labels' => array(
+ 'name_admin_bar' => _x( 'Page', 'add new on admin bar' ),
+ ),
'public' => true,
+ 'publicly_queryable' => false,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'_edit_link' => 'post.php?post=%d', /* internal use only. don't use this when registering your own post type. */
'capability_type' => 'page',
register_post_type( 'attachment', array(
'labels' => array(
'name' => __( 'Media' ),
+ 'edit_item' => __( 'Edit Media' ),
),
'public' => true,
'show_ui' => false,
'rewrite' => false,
'query_var' => false,
'show_in_nav_menus' => false,
+ 'supports' => array( 'comments' ),
) );
register_post_type( 'revision', array(
_get_post_ancestors($post);
$_post = sanitize_post($post, 'raw');
wp_cache_add($post->ID, $_post, 'posts');
+ } elseif ( is_object($post) && 'raw' == $post->filter ) {
+ $_post = $post;
} else {
if ( is_object($post) )
$post_id = $post->ID;
/**
* Retrieve data from a post field based on Post ID.
*
- * Examples of the post field will be, 'post_type', 'post_status', 'content',
+ * Examples of the post field will be, 'post_type', 'post_status', 'post_content',
* etc and based off of the post object property or key names.
*
* The context values are based off of the taxonomy filter functions and
if ( !is_object($post) )
return false;
- // Unattached attachments are assumed to be published.
- if ( ('attachment' == $post->post_type) && ('inherit' == $post->post_status) && ( 0 == $post->post_parent) )
- return 'publish';
+ if ( 'attachment' == $post->post_type ) {
+ if ( 'private' == $post->post_status )
+ return 'private';
+
+ // Unattached attachments are assumed to be published
+ if ( ( 'inherit' == $post->post_status ) && ( 0 == $post->post_parent) )
+ return 'publish';
- if ( ('attachment' == $post->post_type) && $post->post_parent && ($post->ID != $post->post_parent) )
- return get_post_status($post->post_parent);
+ // Inherit status from the parent
+ if ( $post->post_parent && ( $post->ID != $post->post_parent ) )
+ return get_post_status($post->post_parent);
+ }
return $post->post_status;
}
*
* label - A descriptive name for the post status marked for translation. Defaults to $post_status.
* public - Whether posts of this status should be shown in the front end of the site. Defaults to true.
- * exclude_from_search - Whether to exclude posts with this post status from search results. Defaults to true.
+ * exclude_from_search - Whether to exclude posts with this post status from search results. Defaults to false.
* show_in_admin_all_list - Whether to include posts in the edit listing for their post type
* show_in_admin_status_list - Show in the list of statuses with post counts at the top of the edit
* listings, e.g. All (12) | Published (9) | My Custom Status (2) ...
'public' => false, 'rewrite' => true, 'has_archive' => false, 'query_var' => true,
'supports' => array(), 'register_meta_box_cb' => null,
'taxonomies' => array(), 'show_ui' => null, 'menu_position' => null, 'menu_icon' => null,
- 'permalink_epmask' => EP_PERMALINK, 'can_export' => true, 'show_in_nav_menus' => null, 'show_in_menu' => null,
+ 'permalink_epmask' => EP_PERMALINK, 'can_export' => true,
+ 'show_in_nav_menus' => null, 'show_in_menu' => null, 'show_in_admin_bar' => null,
);
$args = wp_parse_args($args, $defaults);
$args = (object) $args;
if ( null === $args->show_in_menu || ! $args->show_ui )
$args->show_in_menu = $args->show_ui;
+ // 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;
+
// Whether to show this type in nav-menus.php. Defaults to the setting for public.
if ( null === $args->show_in_nav_menus )
$args->show_in_nav_menus = $args->public;
$wp->add_query_var($args->query_var);
}
- if ( false !== $args->rewrite && '' != get_option('permalink_structure') ) {
+ if ( false !== $args->rewrite && ( is_admin() || '' != get_option('permalink_structure') ) ) {
if ( ! is_array( $args->rewrite ) )
$args->rewrite = array();
if ( empty( $args->rewrite['slug'] ) )
if ( $args->has_archive ) {
$archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive;
+ if ( $args->rewrite['with_front'] )
+ $archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug;
+ else
+ $archive_slug = $wp_rewrite->root . $archive_slug;
+
$wp_rewrite->add_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' );
if ( $args->rewrite['feeds'] && $wp_rewrite->feeds ) {
$feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
register_taxonomy_for_object_type( $taxonomy, $post_type );
}
+ do_action( 'registered_post_type', $post_type, $args );
+
return $args;
}
* can be deleted. If the post type does not support an author, then this will
* behave like delete_posts.
* - edit_private_posts - Controls whether private objects can be edited.
- * - edit_published_posts - Controls whether published objects can be deleted.
+ * - edit_published_posts - Controls whether published objects can be edited.
*
* These additional capabilities are only used in map_meta_cap(). Thus, they are
* only assigned by default if the post type is registered with the 'map_meta_cap'
* Builds an object with all post type labels out of a post type object
*
* Accepted keys of the label array in the post type object:
- * - name - general name for the post type, usually plural. The same and overriden by $post_type_object->label. Default is Posts/Pages
+ * - name - general name for the post type, usually plural. The same and overridden by $post_type_object->label. Default is Posts/Pages
* - 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 {@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>
* - add_new_item - Default is Add New Post/Add New Page
* - not_found - Default is No posts found/No pages found
* - not_found_in_trash - Default is No posts found in Trash/No pages found in Trash
* - 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>
*
* Above, the first default value is for non-hierarchical post types (like posts) and the second one is for hierarchical post types (like pages).
*
'not_found' => array( __('No posts found.'), __('No pages found.') ),
'not_found_in_trash' => array( __('No posts found in Trash.'), __('No pages found in Trash.') ),
'parent_item_colon' => array( null, __('Parent Page:') ),
+ 'all_items' => array( __( 'All Posts' ), __( 'All Pages' ) )
);
$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];
return _get_custom_object_labels( $post_type_object, $nohier_vs_hier_defaults );
if ( !isset( $object->labels['singular_name'] ) && isset( $object->labels['name'] ) )
$object->labels['singular_name'] = $object->labels['name'];
+ if ( ! isset( $object->labels['name_admin_bar'] ) )
+ $object->labels['name_admin_bar'] = isset( $object->labels['singular_name'] ) ? $object->labels['singular_name'] : $object->name;
+
if ( !isset( $object->labels['menu_name'] ) && isset( $object->labels['name'] ) )
$object->labels['menu_name'] = $object->labels['name'];
+ if ( !isset( $object->labels['all_items'] ) && isset( $object->labels['menu_name'] ) )
+ $object->labels['all_items'] = $object->labels['menu_name'];
+
foreach ( $nohier_vs_hier_defaults as $key => $value )
$defaults[$key] = $object->hierarchical ? $value[1] : $value[0];
// Submenus only.
if ( ! $ptype_obj->show_in_menu || $ptype_obj->show_in_menu === true )
continue;
- add_submenu_page( $ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->menu_name, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" );
+ add_submenu_page( $ptype_obj->show_in_menu, $ptype_obj->labels->name, $ptype_obj->labels->all_items, $ptype_obj->cap->edit_posts, "edit.php?post_type=$ptype" );
}
}
add_action( 'admin_menu', '_add_post_type_submenus' );
* 'excerpt', 'page-attributes', 'thumbnail', and 'custom-fields'.
*
* Additionally, the 'revisions' feature dictates whether the post type will store revisions,
- * and the 'comments' feature dicates whether the comments count will show on the edit screen.
+ * and the 'comments' feature dictates whether the comments count will show on the edit screen.
*
* @since 3.0.0
* @param string $post_type The post type for which to add the feature
* 'meta_value' - See {@link WP_Query::query()} for more.
* 'post_type' - Default is 'post'. Can be 'page', or 'attachment' to name a few.
* 'post_parent' - The parent of the post or post type.
- * 'post_status' - Default is 'published'. Post status to retrieve.
+ * 'post_status' - Default is 'publish'. Post status to retrieve.
*
* @since 1.2.0
* @uses $wpdb
/**
* Add meta data field to a post.
*
- * Post meta data is called "Custom Fields" on the Administration Panels.
+ * Post meta data is called "Custom Fields" on the Administration Screen.
*
* @since 1.5.0
* @uses $wpdb
* @return bool Whether the post meta key was deleted from the database
*/
function delete_post_meta_by_key($post_meta_key) {
- if ( !$post_meta_key )
- return false;
-
- global $wpdb;
- $post_ids = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key));
- if ( $post_ids ) {
- $postmetaids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key ) );
- $in = implode( ',', array_fill(1, count($postmetaids), '%d'));
- do_action( 'delete_postmeta', $postmetaids );
- $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN($in)", $postmetaids ));
- do_action( 'deleted_postmeta', $postmetaids );
- foreach ( $post_ids as $post_id )
- wp_cache_delete($post_id, 'post_meta');
- return true;
- }
- return false;
+ return delete_metadata( 'post', null, $post_meta_key, '', true );
}
/**
if ( $post->post_type == 'attachment' )
return wp_delete_attachment( $postid, $force_delete );
- do_action('delete_post', $postid);
+ do_action('before_delete_post', $postid);
delete_post_meta($postid,'_wp_trash_meta_status');
delete_post_meta($postid,'_wp_trash_meta_time');
wp_clear_scheduled_hook('publish_future_post', array( $postid ) );
- do_action('deleted_post', $postid);
+ do_action('after_delete_post', $postid);
return $post;
}
if ( $post['post_status'] == 'trash' )
return false;
- do_action('trash_post', $post_id);
+ do_action('wp_trash_post', $post_id);
add_post_meta($post_id,'_wp_trash_meta_status', $post['post_status']);
add_post_meta($post_id,'_wp_trash_meta_time', time());
'post_content' => '', 'post_title' => '');
$postarr = wp_parse_args($postarr, $defaults);
+
+ unset( $postarr[ 'filter' ] );
+
$postarr = sanitize_post($postarr, 'db');
// export array as variables
$previous_status = 'new';
}
- if ( ('' == $post_content) && ('' == $post_title) && ('' == $post_excerpt) && ('attachment' != $post_type) ) {
+ $maybe_empty = ! $post_content && ! $post_title && ! $post_excerpt && post_type_supports( $post_type, 'editor' )
+ && post_type_supports( $post_type, 'title' ) && post_type_supports( $post_type, 'excerpt' );
+ if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
if ( $wp_error )
- return new WP_Error('empty_content', __('Content, title, and excerpt are empty.'));
+ return new WP_Error( 'empty_content', __( 'Content, title, and excerpt are empty.' ) );
else
return 0;
}
$post_before = get_post($post_ID);
}
- // Don't allow contributors to set to set the post slug for pending review posts
+ // Don't allow contributors to set the post slug for pending review posts
if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) )
$post_name = '';
else
$post_name = '';
} else {
- $post_name = sanitize_title($post_name);
+ // On updates, we need to check to see if it's using the old, fixed sanitization context.
+ $check_name = sanitize_title( $post_name, '', 'old-save' );
+ if ( $update && strtolower( urlencode( $post_name ) ) == $check_name && get_post_field( 'post_name', $ID ) == $check_name )
+ $post_name = $check_name;
+ else // new post, or slug has changed.
+ $post_name = sanitize_title($post_name);
}
// If the post date is empty (due to having been new or a draft) and status is not 'draft' or 'pending', set date to now
$post->post_status = 'publish';
wp_transition_post_status('publish', $old_status, $post);
- // Update counts for the post's terms.
- foreach ( (array) get_object_taxonomies('post') as $taxonomy ) {
- $tt_ids = wp_get_object_terms($post_id, $taxonomy, array('fields' => 'tt_ids'));
- wp_update_term_count($tt_ids, $taxonomy);
- }
-
do_action('edit_post', $post_id, $post);
do_action('save_post', $post_id, $post);
do_action('wp_insert_post', $post_id, $post);
}
}
- return $slug;
+ return apply_filters( 'wp_unique_post_slug', $slug, $post_ID, $post_status, $post_type, $post_parent );
}
/**
*/
function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') {
global $wpdb;
- $null = null;
+
$page_path = rawurlencode(urldecode($page_path));
$page_path = str_replace('%2F', '/', $page_path);
$page_path = str_replace('%20', ' ', $page_path);
- $page_paths = '/' . trim($page_path, '/');
- $leaf_path = sanitize_title(basename($page_paths));
- $page_paths = explode('/', $page_paths);
- $full_path = '';
- foreach ( (array) $page_paths as $pathdir )
- $full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title($pathdir);
+ $parts = explode( '/', trim( $page_path, '/' ) );
+ $parts = array_map( 'esc_sql', $parts );
+ $parts = array_map( 'sanitize_title_for_query', $parts );
- $pages = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name = %s AND (post_type = %s OR post_type = 'attachment')", $leaf_path, $post_type ));
+ $in_string = "'". implode( "','", $parts ) . "'";
+ $post_type_sql = $post_type;
+ $wpdb->escape_by_ref( $post_type_sql );
+ $pages = $wpdb->get_results( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_name IN ($in_string) AND (post_type = '$post_type_sql' OR post_type = 'attachment')", OBJECT_K );
- if ( empty($pages) )
- return $null;
+ $revparts = array_reverse( $parts );
- foreach ( $pages as $page ) {
- $path = '/' . $leaf_path;
- $curpage = $page;
- while ( $curpage->post_parent != 0 ) {
- $post_parent = $curpage->post_parent;
- $curpage = wp_cache_get( $post_parent, 'posts' );
- if ( false === $curpage )
- $curpage = $wpdb->get_row( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE ID = %d and post_type = %s", $post_parent, $post_type ) );
- $path = '/' . $curpage->post_name . $path;
- }
+ $foundid = 0;
+ foreach ( (array) $pages as $page ) {
+ if ( $page->post_name == $revparts[0] ) {
+ $count = 0;
+ $p = $page;
+ while ( $p->post_parent != 0 && isset( $pages[ $p->post_parent ] ) ) {
+ $count++;
+ $parent = $pages[ $p->post_parent ];
+ if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] )
+ break;
+ $p = $parent;
+ }
- if ( $path == $full_path )
- return get_page($page->ID, $output, $post_type);
+ if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) {
+ $foundid = $page->ID;
+ break;
+ }
+ }
}
- return $null;
+ if ( $foundid )
+ return get_page( $foundid, $output );
+
+ return null;
}
/**
/**
* function to traverse and return all the nested children post names of a root page.
- * $children contains parent-chilren relations
+ * $children contains parent-children relations
*
* @since 2.9.0
*/
return false;
// Make sure we have a valid post status
- if ( !in_array($post_status, get_post_stati()) )
+ if ( !is_array( $post_status ) )
+ $post_status = explode( ',', $post_status );
+ if ( array_diff( $post_status, get_post_stati() ) )
return false;
$cache = array();
foreach ( $post_authors as $post_author ) {
//Do we have an author id or an author login?
if ( 0 == intval($post_author) ) {
- $post_author = get_userdatabylogin($post_author);
+ $post_author = get_user_by('login', $post_author);
if ( empty($post_author) )
continue;
if ( empty($post_author->ID) )
if ( $parent >= 0 )
$where .= $wpdb->prepare(' AND post_parent = %d ', $parent);
- $where_post_type = $wpdb->prepare( "post_type = '%s' AND post_status = '%s'", $post_type, $post_status );
+ if ( 1 == count( $post_status ) ) {
+ $where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $post_type, array_shift( $post_status ) );
+ } else {
+ $post_status = implode( "', '", $post_status );
+ $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $post_type );
+ }
+
+ $orderby_array = array();
+ $allowed_keys = array('author', 'post_author', 'date', 'post_date', 'title', 'post_title', 'name', 'post_name', 'modified',
+ 'post_modified', 'modified_gmt', 'post_modified_gmt', 'menu_order', 'parent', 'post_parent',
+ 'ID', 'rand', 'comment_count');
+ foreach ( explode( ',', $sort_column ) as $orderby ) {
+ $orderby = trim( $orderby );
+ if ( !in_array( $orderby, $allowed_keys ) )
+ continue;
+
+ switch ( $orderby ) {
+ case 'menu_order':
+ break;
+ case 'ID':
+ $orderby = "$wpdb->posts.ID";
+ break;
+ case 'rand':
+ $orderby = 'RAND()';
+ break;
+ case 'comment_count':
+ $orderby = "$wpdb->posts.comment_count";
+ break;
+ default:
+ if ( 0 === strpos( $orderby, 'post_' ) )
+ $orderby = "$wpdb->posts." . $orderby;
+ else
+ $orderby = "$wpdb->posts.post_" . $orderby;
+ }
+
+ $orderby_array[] = $orderby;
+
+ }
+ $sort_column = ! empty( $orderby_array ) ? implode( ',', $orderby_array ) : "$wpdb->posts.post_title";
+
+ $sort_order = strtoupper( $sort_order );
+ if ( '' !== $sort_order && !in_array( $sort_order, array( 'ASC', 'DESC' ) ) )
+ $sort_order = 'ASC';
$query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
$query .= $author_query;
function wp_insert_attachment($object, $file = false, $parent = 0) {
global $wpdb, $user_ID;
- $defaults = array('post_status' => 'draft', 'post_type' => 'post', 'post_author' => $user_ID,
+ $defaults = array('post_status' => 'inherit', 'post_type' => 'post', 'post_author' => $user_ID,
'ping_status' => get_option('default_ping_status'), 'post_parent' => 0,
'menu_order' => 0, 'to_ping' => '', 'pinged' => '', 'post_password' => '',
- 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0);
+ 'guid' => '', 'post_content_filtered' => '', 'post_excerpt' => '', 'import_id' => 0, 'context' => '');
$object = wp_parse_args($object, $defaults);
if ( !empty($parent) )
$object['post_parent'] = $parent;
+ unset( $object[ 'filter' ] );
+
$object = sanitize_post($object, 'db');
// export array as variables
$post_author = $user_ID;
$post_type = 'attachment';
- $post_status = 'inherit';
+
+ if ( ! in_array( $post_status, array( 'inherit', 'private' ) ) )
+ $post_status = 'inherit';
// Make sure we set a valid category.
if ( !isset($post_category) || 0 == count($post_category) || !is_array($post_category) ) {
clean_post_cache($post_ID);
- if ( isset($post_parent) && $post_parent < 0 )
- add_post_meta($post_ID, '_wp_attachment_temp_parent', $post_parent, true);
+ if ( ! empty( $context ) )
+ add_post_meta( $post_ID, '_wp_attachment_context', $context, true );
if ( $update) {
do_action('edit_attachment', $post_ID);
if ( !$post =& get_post( $post_id ) )
return false;
+ if ( 'attachment' != $post->post_type )
+ return false;
+
$url = '';
if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { //Get attached file
if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { //Get upload directory
}
}
- if ( empty($url) ) //If any of the above options failed, Fallback on the GUID as used pre-2.7, not recomended to rely upon this.
+ if ( empty($url) ) //If any of the above options failed, Fallback on the GUID as used pre-2.7, not recommended to rely upon this.
$url = get_the_guid( $post->ID );
$url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );
- if ( 'attachment' != $post->post_type || empty( $url ) )
+ if ( empty( $url ) )
return false;
return $url;
$dirs = apply_filters( 'icon_dirs', array($icon_dir => $icon_dir_uri) );
$icon_files = array();
while ( $dirs ) {
- $dir = array_shift($keys = array_keys($dirs));
+ $keys = array_keys( $dirs );
+ $dir = array_shift( $keys );
$uri = array_shift($dirs);
if ( $dh = opendir($dir) ) {
while ( false !== $file = readdir($dh) ) {
* Retrieve the private post SQL based on capability.
*
* This function provides a standardized way to appropriately select on the
- * post_status of posts/pages. The function will return a piece of SQL code that
- * can be added to a WHERE clause; this SQL is constructed to allow all
+ * post_status of a post type. The function will return a piece of SQL code
+ * that can be added to a WHERE clause; this SQL is constructed to allow all
* published posts, and all private posts to which the user has access.
*
- * It also allows plugins that define their own post type to control the cap by
- * using the hook 'pub_priv_sql_capability'. The plugin is expected to return
- * the capability the user must have to read the private post type.
- *
* @since 2.2.0
*
* @uses $user_ID
- * @uses apply_filters() Call 'pub_priv_sql_capability' filter for plugins with different post types.
*
* @param string $post_type currently only supports 'post' or 'page'.
* @return string SQL code that can be added to a where clause.
*/
-function get_private_posts_cap_sql($post_type) {
- return get_posts_by_author_sql($post_type, FALSE);
+function get_private_posts_cap_sql( $post_type ) {
+ return get_posts_by_author_sql( $post_type, false );
}
/**
* Retrieve the post SQL based on capability, author, and type.
*
- * See above for full description.
+ * @see get_private_posts_cap_sql() for full description.
*
* @since 3.0.0
- * @param string $post_type currently only supports 'post' or 'page'.
+ * @param string $post_type Post type.
* @param bool $full Optional. Returns a full WHERE statement instead of just an 'andalso' term.
* @param int $post_author Optional. Query posts having a single author ID.
* @return string SQL WHERE code that can be added to a query.
*/
-function get_posts_by_author_sql($post_type, $full = TRUE, $post_author = NULL) {
+function get_posts_by_author_sql( $post_type, $full = true, $post_author = null ) {
global $user_ID, $wpdb;
// Private posts
- if ($post_type == 'post') {
- $cap = 'read_private_posts';
- // Private pages
- } elseif ($post_type == 'page') {
- $cap = 'read_private_pages';
- // Dunno what it is, maybe plugins have their own post type?
- } else {
- $cap = '';
- $cap = apply_filters('pub_priv_sql_capability', $cap);
+ $post_type_obj = get_post_type_object( $post_type );
+ if ( ! $post_type_obj )
+ return $full ? 'WHERE 1 = 0' : ' 1 = 0 ';
- if (empty($cap)) {
- // We don't know what it is, filters don't change anything,
- // so set the SQL up to return nothing.
- return ' 1 = 0 ';
- }
- }
+ // This hook is deprecated. Why you'd want to use it, I dunno.
+ if ( ! $cap = apply_filters( 'pub_priv_sql_capability', '' ) )
+ $cap = $post_type_obj->cap->read_private_posts;
- if ($full) {
- if (is_null($post_author)) {
- $sql = $wpdb->prepare('WHERE post_type = %s AND ', $post_type);
+ if ( $full ) {
+ if ( null === $post_author ) {
+ $sql = $wpdb->prepare( 'WHERE post_type = %s AND ', $post_type );
} else {
- $sql = $wpdb->prepare('WHERE post_author = %d AND post_type = %s AND ', $post_author, $post_type);
+ $sql = $wpdb->prepare( 'WHERE post_author = %d AND post_type = %s AND ', $post_author, $post_type );
}
} else {
$sql = '';
$sql .= "(post_status = 'publish'";
- if (current_user_can($cap)) {
+ if ( current_user_can( $cap ) ) {
// Does the user have the capability to view private posts? Guess so.
$sql .= " OR post_status = 'private'";
- } elseif (is_user_logged_in()) {
+ } elseif ( is_user_logged_in() ) {
// Users can view their own private posts.
$id = (int) $user_ID;
- if (is_null($post_author) || !$full) {
+ if ( null === $post_author || ! $full ) {
$sql .= " OR post_status = 'private' AND post_author = $id";
- } elseif ($id == (int)$post_author) {
+ } elseif ( $id == (int) $post_author ) {
$sql .= " OR post_status = 'private'";
} // else none
} // else none
if ( !$date ) {
$add_seconds_server = date('Z');
- $post_types = get_post_types( array( 'publicly_queryable' => true ) );
+ $post_types = get_post_types( array( 'public' => true ) );
array_walk( $post_types, array( &$wpdb, 'escape_by_ref' ) );
$post_types = "'" . implode( "', '", $post_types ) . "'";
/**
* Will clean the attachment in the cache.
*
- * Cleaning means delete from the cache. Optionaly will clean the term
+ * Cleaning means delete from the cache. Optionally will clean the term
* object cache associated with the attachment ID.
*
* This function will not run if $_wp_suspend_cache_invalidation is not empty. See
* Determines which fields of posts are to be saved in revisions.
*
* Does two things. If passed a post *array*, it will return a post array ready
- * to be insterted into the posts table as a post revision. Otherwise, returns
+ * to be inserted into the posts table as a post revision. Otherwise, returns
* an array whose keys are the post fields to be saved for post revisions.
*
* @package WordPress
* @return array The array of post format slugs.
*/
function get_post_format_slugs() {
- // 3.2-early: use array_combine() and array_keys( get_post_format_strings() )
- $slugs = array(
- 'standard' => 'standard', // Special case. any value that evals to false will be considered standard
- 'aside' => 'aside',
- 'chat' => 'chat',
- 'gallery' => 'gallery',
- 'link' => 'link',
- 'image' => 'image',
- 'quote' => 'quote',
- 'status' => 'status',
- 'video' => 'video',
- 'audio' => 'audio',
- );
- return $slugs;
+ $slugs = array_keys( get_post_format_strings() );
+ return array_combine( $slugs, $slugs );
}
/**
return false;
}
+/**
+ * Removes a post thumbnail.
+ *
+ * @since 3.3.0
+ *
+ * @param int|object $post Post ID or object where thumbnail should be removed from.
+ * @return bool True on success, false on failure.
+ */
+function delete_post_thumbnail( $post ) {
+ $post = get_post( $post );
+ if ( $post )
+ return delete_post_meta( $post->ID, '_thumbnail_id' );
+ return false;
+}
+
/**
* Returns a link to a post format index.
*
* @since 3.1.0
*
- * @param $format string Post format
+ * @param string $format Post format
* @return string Link
*/
function get_post_format_link( $format ) {
if ( isset( $slugs[ $qvs['post_format'] ] ) )
$qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ];
$tax = get_taxonomy( 'post_format' );
- $qvs['post_type'] = $tax->object_type;
+ if ( ! is_admin() )
+ $qvs['post_type'] = $tax->object_type;
return $qvs;
}
add_filter( 'request', '_post_format_request' );
}
add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' );
-?>
\ No newline at end of file
+/**
+ * Update the custom taxonomies' term counts when a post's status is changed. For example, default posts term counts (for custom taxonomies) don't include private / draft posts.
+ *
+ * @access private
+ * @param string $new_status
+ * @param string $old_status
+ * @param object $post
+ * @since 3.3.0
+ */
+function _update_term_count_on_transition_post_status( $new_status, $old_status, $post ) {
+ // Update counts for the post's terms.
+ foreach ( (array) get_object_taxonomies( $post->post_type ) as $taxonomy ) {
+ $tt_ids = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'tt_ids' ) );
+ wp_update_term_count( $tt_ids, $taxonomy );
+ }
+}
+?>