X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/b137f4ce021b4022c56f452c2eafa7abfcef0a7c..bf5c68485ef07868ad0a91168ecd0092af7661ae:/wp-includes/post.php diff --git a/wp-includes/post.php b/wp-includes/post.php index b28a415c..f875f2f8 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -18,6 +18,9 @@ */ 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. */ @@ -30,7 +33,11 @@ function create_initial_post_types() { ) ); 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', @@ -44,6 +51,7 @@ function create_initial_post_types() { register_post_type( 'attachment', array( 'labels' => array( 'name' => __( 'Media' ), + 'edit_item' => __( 'Edit Media' ), ), 'public' => true, 'show_ui' => false, @@ -55,6 +63,7 @@ function create_initial_post_types() { 'rewrite' => false, 'query_var' => false, 'show_in_nav_menus' => false, + 'supports' => array( 'comments' ), ) ); register_post_type( 'revision', array( @@ -372,6 +381,8 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') { _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; @@ -425,7 +436,7 @@ function get_post_ancestors($post) { /** * 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 @@ -626,7 +637,7 @@ function get_page_statuses( ) { * * 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) ... @@ -913,7 +924,8 @@ function register_post_type($post_type, $args = array()) { '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; @@ -936,6 +948,10 @@ function register_post_type($post_type, $args = array()) { 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; @@ -972,7 +988,7 @@ function register_post_type($post_type, $args = array()) { $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'] ) ) @@ -1023,6 +1039,8 @@ function register_post_type($post_type, $args = array()) { register_taxonomy_for_object_type( $taxonomy, $post_type ); } + do_action( 'registered_post_type', $post_type, $args ); + return $args; } @@ -1067,7 +1085,7 @@ function register_post_type($post_type, $args = array()) { * 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' @@ -1141,7 +1159,7 @@ function _post_type_meta_capabilities( $capabilities = null ) { * 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: _x('Add New', 'product'); * - add_new_item - Default is Add New Post/Add New Page @@ -1152,6 +1170,8 @@ function _post_type_meta_capabilities( $capabilities = null ) { * - 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 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). * @@ -1172,6 +1192,7 @@ function get_post_type_labels( $post_type_object ) { '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 ); @@ -1191,9 +1212,15 @@ function _get_custom_object_labels( $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]; @@ -1213,7 +1240,7 @@ function _add_post_type_submenus() { // 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' ); @@ -1226,7 +1253,7 @@ 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 @@ -1329,7 +1356,7 @@ function set_post_type( $post_id = 0, $post_type = 'post' ) { * '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 @@ -1378,7 +1405,7 @@ function get_posts($args = null) { /** * 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 @@ -1475,22 +1502,7 @@ function update_post_meta($post_id, $meta_key, $meta_value, $prev_value = '') { * @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 ); } /** @@ -1963,7 +1975,7 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { 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'); @@ -2035,7 +2047,7 @@ function wp_delete_post( $postid = 0, $force_delete = false ) { wp_clear_scheduled_hook('publish_future_post', array( $postid ) ); - do_action('deleted_post', $postid); + do_action('after_delete_post', $postid); return $post; } @@ -2063,7 +2075,7 @@ function wp_trash_post($post_id = 0) { 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()); @@ -2427,9 +2439,11 @@ function wp_insert_post($postarr, $wp_error = false) { $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; } @@ -2464,7 +2478,7 @@ function wp_insert_post($postarr, $wp_error = false) { $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 = ''; @@ -2476,7 +2490,12 @@ function wp_insert_post($postarr, $wp_error = false) { 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 @@ -2719,12 +2738,6 @@ function wp_publish_post($post_id) { $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); @@ -2833,7 +2846,7 @@ function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_p } } - return $slug; + return apply_filters( 'wp_unique_post_slug', $slug, $post_ID, $post_status, $post_type, $post_parent ); } /** @@ -3139,38 +3152,45 @@ function &get_page(&$page, $output = OBJECT, $filter = 'raw') { */ 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; } /** @@ -3250,7 +3270,7 @@ function &get_page_hierarchy( &$pages, $page_id = 0 ) { /** * 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 */ @@ -3327,7 +3347,9 @@ function &get_pages($args = '') { 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(); @@ -3386,7 +3408,7 @@ function &get_pages($args = '') { 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) ) @@ -3422,10 +3444,15 @@ function &get_pages($args = '') { 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', 'modified', + $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 ) { @@ -3700,9 +3727,6 @@ function wp_insert_attachment($object, $file = false, $parent = 0) { 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 ); @@ -3873,6 +3897,9 @@ function wp_get_attachment_url( $post_id = 0 ) { 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 @@ -3885,12 +3912,12 @@ function wp_get_attachment_url( $post_id = 0 ) { } } - 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; @@ -4010,7 +4037,8 @@ function wp_mime_type_icon( $mime = 0 ) { $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) ) { @@ -4100,63 +4128,49 @@ function wp_check_for_changed_slugs($post_id, $post, $post_before) { * 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 = ''; @@ -4164,15 +4178,15 @@ function get_posts_by_author_sql($post_type, $full = TRUE, $post_author = NULL) $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 @@ -4248,7 +4262,7 @@ function _get_last_post_time( $timezone, $field ) { 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 ) . "'"; @@ -4454,7 +4468,7 @@ function update_postmeta_cache($post_ids) { /** * 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 @@ -4652,7 +4666,7 @@ function _get_post_ancestors(&$_post) { * 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 @@ -5134,20 +5148,8 @@ function get_post_format_strings() { * @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 ); } /** @@ -5188,12 +5190,27 @@ function set_post_thumbnail( $post, $thumbnail_id ) { 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 ) { @@ -5216,7 +5233,8 @@ function _post_format_request( $qvs ) { 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' ); @@ -5294,4 +5312,20 @@ function _post_format_wp_get_object_terms( $terms ) { } add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' ); +/** + * 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 ); + } +} ?>