Ticket #11631: 11631-code-improvements.2.patch
| File 11631-code-improvements.2.patch, 5.7 KB (added by , 17 years ago) |
|---|
-
wp-includes/post-template.php
### Eclipse Workspace Patch 1.0 #P wordpress-trunk
94 94 /** 95 95 * Retrieve post title. 96 96 * 97 * If the post is protected and the visitor is not an admin, then "Protected" 98 * will be displayed before the post title. If the post is private, then 99 * "Private" will be located before the post title. 97 * Get title of a post. Reflects visibility like public, password protected 98 * or private. 100 99 * 101 100 * @since 0.71 102 101 * 103 * @param int $id Optional. Post ID.104 * @return string 102 * @param int $id (optional) id of post 103 * @return string title 105 104 */ 106 105 function get_the_title( $id = 0 ) { 107 $post = &get_post($id); 106 $title = ''; 107 $format = ''; 108 $post = &get_post($id); 109 110 if ( isset($post->ID) ) 111 $id = $post->ID; 108 112 109 $title = $post->post_title; 113 if ( isset($post->post_title) ) 114 $title = $post->post_title; 110 115 111 if ( !is_admin() ) { 112 if ( !empty($post->post_password) ) { 113 $protected_title_format = apply_filters('protected_title_format', __('Protected: %s')); 114 $title = sprintf($protected_title_format, $title); 115 } else if ( isset($post->post_status) && 'private' == $post->post_status ) { 116 $private_title_format = apply_filters('private_title_format', __('Private: %s')); 117 $title = sprintf($private_title_format, $title); 118 } 116 if ( !is_admin() && !empty($post->post_password)) { 117 $format = apply_filters('protected_title_format', __('Protected: %s')); 118 } else if ( !is_admin() && isset($post->post_status) && 'private' == $post->post_status ) { 119 $format = apply_filters('private_title_format', __('Private: %s')); 119 120 } 120 return apply_filters( 'the_title', $title, $post->ID ); 121 122 if ($format) $title = sprintf($format, $title); 123 124 return apply_filters('the_title', $title, $id); 121 125 } 122 126 123 127 /** -
wp-includes/post.php
230 230 * $post, must be given as a variable, since it is passed by reference. 231 231 * 232 232 * @since 1.5.1 233 * @uses $wpdb234 233 * @link http://codex.wordpress.org/Function_Reference/get_post 235 234 * 236 * @param int|object $post Post ID or post object. 237 * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N. 238 * @param string $filter Optional, default is raw. 239 * @return mixed Post data 235 * @param int|object $post Post ID or post object or set to 0 to get current post 236 * @param string $output (optional) default is OBJECT, can be ARRAY_A or ARRAY_N. 237 * @param string $filter (optional) default is 'raw'. 238 * @return object|array Post data based on $output parameter: OBJECT, ARRAY_A or 239 * ARRAY_N. NULL if no post available. 240 240 */ 241 241 function &get_post(&$post, $output = OBJECT, $filter = 'raw') { 242 global $wpdb; 243 $null = null; 242 $_post = null; // init return value 244 243 245 if ( empty($post) ) { 246 if ( isset($GLOBALS['post']) ) 247 $_post = & $GLOBALS['post']; 248 else 249 return $null; 250 } elseif ( is_object($post) && empty($post->filter) ) { 251 _get_post_ancestors($post); 252 $_post = sanitize_post($post, 'raw'); 253 wp_cache_add($post->ID, $_post, 'posts'); 244 if ( empty($post) && ! isset($GLOBALS['post']) ) { 245 return $_post; 246 } else if ( empty($post) && isset($GLOBALS['post']) ) { 247 $_post = & $GLOBALS['post']; 248 } else if ( is_object($post) && empty($post->filter) ) { 249 $_post = wp_get_post($post); 254 250 } else { 255 if ( is_object($post) ) 256 $post = $post->ID; 257 $post = (int) $post; 258 if ( ! $_post = wp_cache_get($post, 'posts') ) { 259 $_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post)); 260 if ( ! $_post ) 261 return $null; 262 _get_post_ancestors($_post); 263 $_post = sanitize_post($_post, 'raw'); 264 wp_cache_add($_post->ID, $_post, 'posts'); 251 // retrieve post by numerical ID (incl. cache roundtrip) 252 $post = (int) ( is_object($post) ? $post->ID : $post ); 253 if ( ! ( $_post = wp_cache_get($post, 'posts') ) 254 && null === ( $_post = wp_get_post($post) ) ) { 255 return $_post; 265 256 } 266 257 } 267 258 268 259 if ($filter != 'raw') 269 260 $_post = sanitize_post($_post, $filter); 261 262 // convert into parametrized output datatype 263 264 if ( ARRAY_N == $ouput || ARRAY_A == $ouput ) 265 $_post = get_object_vars($_post); 266 267 if ( ARRAY_N == $ouput ) 268 $_post = array_values($_post); 269 270 return $_post; 271 } 270 272 271 if ( $output == OBJECT ) { 272 return $_post; 273 } elseif ( $output == ARRAY_A ) { 274 $__post = get_object_vars($_post); 275 return $__post; 276 } elseif ( $output == ARRAY_N ) { 277 $__post = array_values(get_object_vars($_post)); 278 return $__post; 273 /** 274 * get post object by id 275 * 276 * retrieves the data from the database, retrieves the posts 277 * ancestors, sanitizes it with RAW context and stores it in 278 * the cache. 279 * 280 * @since 3.0 281 * @see get_post() 282 * 283 * @param int|onject $inpost id of post to get or post object 284 * @return object post, NULL if post of id does not exists 285 * @global WPDB 286 */ 287 function &wp_get_post( &$inpost ) 288 { 289 /* @var $wpdb WPDB */ 290 global $wpdb; 291 292 if ( is_object($inpost) ) { 293 $post =& $inpost; 279 294 } else { 280 return $_post; 295 $post_id = intval($inpost); 296 $post = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->posts} WHERE ID = %d LIMIT 1", $post_id)); 281 297 } 298 299 if ( ! $post ) 300 { 301 $post = null; 302 } else { 303 _get_post_ancestors($post); 304 $post = sanitize_post($post, 'raw'); 305 wp_cache_add($post->ID, $post, 'posts'); 306 } 307 308 return $post; 282 309 } 283 310 284 311 /** … … 859 886 return $post; 860 887 } 861 888 889 862 890 /** 863 891 * Sanitize post field based on context. 864 892 *