Ticket #10470: page_for_posts.patch
File page_for_posts.patch, 10.6 KB (added by , 15 years ago) |
---|
-
wp-includes/post.php
1158 1158 update_option('show_on_front', 'posts'); 1159 1159 delete_option('page_on_front'); 1160 1160 } 1161 if ( get_option('page_for_posts') == $postid ) { 1162 delete_option('page_for_posts'); 1163 } 1161 delete_post_from_page_for_posts($postid); 1164 1162 1165 1163 // Point children of this page to its parent, also clean the cache of affected children 1166 1164 $children_query = $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type='page'", $postid); -
wp-includes/functions.php
366 366 367 367 return apply_filters( 'option_' . $setting, maybe_unserialize( $value ) ); 368 368 } 369 /** 370 * Deletes the POST from pages for posts array 371 * 372 * @package WordPress 373 * @subpackage Option 374 * @uses get_option_page_for_posts() for checking whether the page is for posts and then for storing the value 375 * @uses update_option() Calls 'page_for_posts' to update the option with serialize(array) 376 * @uses delete_option() Calls 'page_for_posts' with the option name value. 377 * 378 * @param string $postid ID of post which is deleted 379 */ 380 function delete_post_from_page_for_posts($postid) { 381 $opt = get_option_page_for_posts(); 382 if (array_key_exists($postid, $opt)) { 383 unset ($opt[$postid]); 384 } 385 if (count($opt) > 0) { 386 update_option('page_for_posts', serialize($opt)); 387 } else { 388 delete_option('page_for_posts'); 389 } 390 } 391 /** 392 * returns whether the page is page for posts 393 * @package WordPress 394 * @subpackage Option 395 * @uses get_option_page_for_posts() to obtain the array map 396 * 397 * @param string $postid id of the post 398 * @return bool true if is page for posts 399 */ 400 function is_get_option_page_for_posts($postid) { 401 return array_key_exists($postid, get_option_page_for_posts()); 402 } 403 /** 404 * used for getting array mapping for pages for posts 405 * 406 * @package WordPress 407 * @subpackage Option 408 * @uses get_option() retrieves 'page_for_posts' option 409 * @return array filled with saved settings or empty array 410 */ 411 function get_option_page_for_posts() { 412 $opt = get_option('page_for_posts'); 413 if (is_array($opt)) { 414 return $opt; 415 } 416 $opt = unserialize($opt); 417 if (is_array($opt)) { 418 return $opt; 419 } 420 return array (); 421 } 422 /** 423 * returns category ID for desired post - if available 424 * @package WordPress 425 * @subpackage Option 426 * @uses get_option_page_for_posts() to get array map 427 * 428 * @param int $postid id of post 429 * @return mixed empty or id of category 430 */ 431 function get_option_page_for_posts_category($postid) { 432 $opts = get_option_page_for_posts(); 433 if (array_key_exists($postid, $opts)) 434 return $opts[$postid]; 435 return ''; 436 } 369 437 370 438 /** 371 439 * Protect WordPress special option from being modified. -
wp-includes/query.php
1078 1078 * @var bool 1079 1079 */ 1080 1080 var $is_posts_page = false; 1081 1082 1081 /** 1082 * Set to ID of posts page. 1083 * 1084 * Basically, the homepage if the option isn't set for the static homepage. 1085 * 1086 * @since 2.9.0 1087 * @access public 1088 * @var bool 1089 */ 1090 var $post_page_id = -1; 1091 /** 1083 1092 * Resets query flags to false. 1084 1093 * 1085 1094 * The query flags are what page info WordPress was able to figure out. … … 1112 1121 $this->is_singular = false; 1113 1122 $this->is_robots = false; 1114 1123 $this->is_posts_page = false; 1124 $this->post_page_id = -1; 1115 1125 } 1116 1126 1117 1127 /** … … 1471 1481 else 1472 1482 unset($this->queried_object); 1473 1483 1474 if ( 'page' == get_option('show_on_front') && isset($this->queried_object_id) && $this->queried_object_id == get_option('page_for_posts')) {1484 if ( 'page' == get_option('show_on_front') && isset($this->queried_object_id) && is_get_option_page_for_posts($this->queried_object_id)) { 1475 1485 $this->is_page = false; 1476 1486 $this->is_home = true; 1477 1487 $this->is_posts_page = true; 1488 $this->post_page_id = $this->queried_object_id; 1478 1489 } 1479 1490 } 1480 1491 1481 1492 if ( $qv['page_id'] ) { 1482 if ( 'page' == get_option('show_on_front') && $qv['page_id'] == get_option('page_for_posts')) {1493 if ( 'page' == get_option('show_on_front') && is_get_option_page_for_posts($qv['page_id'])) { 1483 1494 $this->is_page = false; 1484 1495 $this->is_home = true; 1485 1496 $this->is_posts_page = true; 1497 $this->post_page_id = $qv['page_id']; 1486 1498 } 1487 1499 } 1488 1500 … … 1686 1698 $reqpage = 0; 1687 1699 } 1688 1700 1689 $page_for_posts = get_option('page_for_posts'); 1690 if ( ('page' != get_option('show_on_front') ) || empty($page_for_posts) || ( $reqpage != $page_for_posts ) ) { 1701 if ( ('page' != get_option('show_on_front') ) || !is_get_option_page_for_posts($reqpage)) { 1691 1702 $q['pagename'] = str_replace('%2F', '/', urlencode(urldecode($q['pagename']))); 1692 1703 $page_paths = '/' . trim($q['pagename'], '/'); 1693 1704 $q['pagename'] = sanitize_title(basename($page_paths)); … … 1733 1744 $where .= $wpdb->prepare( " AND $wpdb->posts.post_parent = %d ", $q['post_parent'] ); 1734 1745 1735 1746 if ( $q['page_id'] ) { 1736 if ( ('page' != get_option('show_on_front') ) || ( $q['page_id'] != get_option('page_for_posts')) ) {1747 if ( ('page' != get_option('show_on_front') ) || ( !is_get_option_page_for_posts($q['page_id'])) ) { 1737 1748 $q['p'] = $q['page_id']; 1738 1749 $where = " AND {$wpdb->posts}.ID = " . $q['page_id']; 1739 1750 } … … 2011 2022 $q['author'] = $q['author']->ID; 2012 2023 $whichauthor .= " AND ($wpdb->posts.post_author = ".absint($q['author']).')'; 2013 2024 } 2014 2025 // category post page 2026 if($this->is_posts_page && $this->post_page_id >0){ 2027 $join.= " INNER JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id) INNER JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id) "; 2028 $whichcat.= " AND $wpdb->term_taxonomy.taxonomy = 'category' "; 2029 $whichcat.= "AND $wpdb->term_taxonomy.term_id = ".get_option_page_for_posts_category($this->post_page_id).""; 2030 $groupby = "{$wpdb->posts}.ID"; 2031 } 2015 2032 // MIME-Type stuff for attachment browsing 2016 2033 2017 2034 if ( isset($q['post_mime_type']) && '' != $q['post_mime_type'] ) … … 2533 2550 2534 2551 $this->queried_object = NULL; 2535 2552 $this->queried_object_id = 0; 2536 2537 2553 if ($this->is_category) { 2538 2554 $cat = $this->get('cat'); 2539 2555 $category = &get_category($cat); … … 2558 2574 $this->queried_object = $term; 2559 2575 $this->queried_object_id = $term->term_id; 2560 2576 } else if ($this->is_posts_page) { 2561 $this->queried_object = & get_page( get_option('page_for_posts'));2577 $this->queried_object = & get_page($this->post_page_id); 2562 2578 $this->queried_object_id = (int) $this->queried_object->ID; 2563 2579 } else if ($this->is_single) { 2564 2580 $this->queried_object = $this->post; -
wp-includes/classes.php
1181 1181 $css_class[] = 'current_page_item'; 1182 1182 elseif ( $_current_page && $page->ID == $_current_page->post_parent ) 1183 1183 $css_class[] = 'current_page_parent'; 1184 } elseif ( $page->ID == get_option('page_for_posts')) {1184 } elseif (is_get_option_page_for_posts($page->ID)) { 1185 1185 $css_class[] = 'current_page_parent'; 1186 1186 } 1187 1187 -
wp-admin/options.php
66 66 if ( !empty($_POST['time_format']) && isset($_POST['time_format_custom']) && '\c\u\s\t\o\m' == stripslashes( $_POST['time_format'] ) ) 67 67 $_POST['time_format'] = $_POST['time_format_custom']; 68 68 } 69 69 $modifiedpost = $_POST; 70 if('reading'==$option_page){ 71 $opts = array(); 72 //page_for_posts_cat_-1 73 foreach($_POST as $k=>$v){ 74 $pos = strpos($k,'page_for_posts_'); 75 if($pos===0){ 76 if(''==$v) continue; 77 $id = substr($k,strlen('page_for_posts_')); 78 $opts[$v] = $_POST['page_for_postscat_'.$id]; 79 } 80 } 81 $modifiedpost['page_for_posts'] = serialize($opts); 82 } 70 83 if ( $options ) { 71 84 foreach ( $options as $option ) { 72 85 $option = trim($option); 73 86 $value = null; 74 if ( isset($ _POST[$option]) )75 $value = $ _POST[$option];87 if ( isset($modifiedpost[$option]) ) 88 $value = $modifiedpost[$option]; 76 89 if ( !is_array($value) ) $value = trim($value); 77 90 $value = stripslashes_deep($value); 78 91 update_option($option, $value); 79 92 } 80 93 } 81 82 94 $goback = add_query_arg( 'updated', 'true', wp_get_referer() ); 83 95 wp_redirect( $goback ); 84 96 break; -
wp-admin/options-reading.php
39 39 </p> 40 40 <ul> 41 41 <li><?php printf("<label for='page_on_front'>".__('Front page: %s')."</label>", wp_dropdown_pages("name=page_on_front&echo=0&show_option_none=".__('- Select -')."&selected=" . get_option('page_on_front'))); ?></li> 42 <li><?php printf("<label for='page_for_posts'>".__('Posts page: %s')."</label>", wp_dropdown_pages("name=page_for_posts&echo=0&show_option_none=".__('- Select -')."&selected=" . get_option('page_for_posts'))); ?></li> 42 <? 43 $pages = get_option_page_for_posts(); 44 foreach($pages as $id=>$cat){ 45 $optcat=array('name'=>'page_for_postscat_'.$id,'echo'=>0,'hide_empty' => 0, 'orderby' => 'name', 'hierarchical' => 1 46 , 'selected'=>$cat); 47 $optpag = array('name'=>'page_for_posts_'.$id,'echo'=>0, 48 'show_option_none'=>__('- None -'),'selected'=>$id); 49 $sel = wp_dropdown_pages($optpag); 50 $catsel = wp_dropdown_categories($optcat); 51 printf("<li><label for='page_for_posts".$id."'>".__('Posts page: %s Category : %s')."</label></li>", $sel, $catsel); 52 } 53 $optcat=array('echo'=>0,'hide_empty' => 0, 'name'=>'page_for_postscat_-1', 'orderby' => 'name', 'hierarchical' => 1, 'selected'=>-1); 54 $optpag = array('name'=>'page_for_posts_-1','echo'=>0, 55 'show_option_none'=>__('- Add -'),'selected'=>-1); 56 $sel = wp_dropdown_pages($optpag); 57 $catsel = wp_dropdown_categories($optcat); 58 printf("<li><label for='page_for_posts%s'>".__('Posts page: %s Category : %s')."</label></li>", -1, $sel, $catsel); 59 ?> 43 60 </ul> 44 <?php if ( 'page' == get_option('show_on_front') && get_option('page_for_posts') == get_option('page_on_front')) : ?>61 <?php if ( 'page' == get_option('show_on_front') && is_get_option_page_for_posts(get_option('page_on_front') )) : ?> 45 62 <div id="front-page-warning" class="updated fade-ff0000"> 46 63 <p> 47 64 <?php _e('<strong>Warning:</strong> these pages should not be the same!'); ?>