Ticket #12702: Enable sticky post checkbox for custom post type - patch-2.patch
File Enable sticky post checkbox for custom post type - patch-2.patch, 12.1 KB (added by , 14 years ago) |
---|
-
wp-admin/includes/meta-boxes.php
116 116 } elseif ( !empty( $post->post_password ) ) { 117 117 $visibility = 'password'; 118 118 $visibility_trans = __('Password protected'); 119 } elseif ( $post_type == 'post'&& is_sticky( $post->ID ) ) {119 } elseif ( post_type_supports( $post_type, 'sticky') && is_sticky( $post->ID ) ) { 120 120 $visibility = 'public'; 121 121 $visibility_trans = __('Public, Sticky'); 122 122 } else { … … 130 130 131 131 <div id="post-visibility-select" class="hide-if-js"> 132 132 <input type="hidden" name="hidden_post_password" id="hidden-post-password" value="<?php echo esc_attr($post->post_password); ?>" /> 133 <?php if ( $post_type == 'post'): ?>133 <?php if ( post_type_supports( $post_type, 'sticky') ): ?> 134 134 <input type="checkbox" style="display:none" name="hidden_post_sticky" id="hidden-post-sticky" value="sticky" <?php checked(is_sticky($post->ID)); ?> /> 135 135 <?php endif; ?> 136 136 <input type="hidden" name="hidden_post_visibility" id="hidden-post-visibility" value="<?php echo esc_attr( $visibility ); ?>" /> 137 137 138 138 139 139 <input type="radio" name="visibility" id="visibility-radio-public" value="public" <?php checked( $visibility, 'public' ); ?> /> <label for="visibility-radio-public" class="selectit"><?php _e('Public'); ?></label><br /> 140 <?php if ( $post_type == 'post'): ?>141 <span id="sticky-span"><input id="sticky" name="sticky" type="checkbox" value="sticky" <?php checked(is_sticky($post->ID)); ?> tabindex="4" /> <label for="sticky" class="selectit"><?php _e('Stick this postto the front page') ?></label><br /></span>140 <?php if ( post_type_supports( $post_type, 'sticky') ): ?> 141 <span id="sticky-span"><input id="sticky" name="sticky" type="checkbox" value="sticky" <?php checked(is_sticky($post->ID)); ?> tabindex="4" /> <label for="sticky" class="selectit"><?php _e('Stick this to the front page') ?></label><br /></span> 142 142 <?php endif; ?> 143 143 <input type="radio" name="visibility" id="visibility-radio-password" value="password" <?php checked( $visibility, 'password' ); ?> /> <label for="visibility-radio-password" class="selectit"><?php _e('Password protected'); ?></label><br /> 144 144 <span id="password-span"><label for="post_password"><?php _e('Password:'); ?></label> <input type="text" name="post_password" id="post_password" value="<?php echo esc_attr($post->post_password); ?>" /><br /></span> -
wp-admin/includes/template.php
1111 1111 </select> 1112 1112 </label> 1113 1113 1114 <?php if ( 'post' == $screen->post_type&& $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>1114 <?php if ( post_type_supports($screen->post_type, 'sticky') && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?> 1115 1115 1116 1116 <?php if ( $bulk ) : ?> 1117 1117 … … 1128 1128 1129 1129 <label class="alignleft"> 1130 1130 <input type="checkbox" name="sticky" value="sticky" /> 1131 <span class="checkbox-title"><?php _e( 'Make this poststicky' ); ?></span>1131 <span class="checkbox-title"><?php _e( 'Make this sticky' ); ?></span> 1132 1132 </label> 1133 1133 1134 1134 <?php endif; // $bulk ?> -
wp-includes/post.php
23 23 'hierarchical' => false, 24 24 'rewrite' => false, 25 25 'query_var' => false, 26 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions' ),26 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'sticky' ), 27 27 ) ); 28 28 29 29 register_post_type( 'page', array( … … 1338 1338 global $id; 1339 1339 1340 1340 $post_id = absint($post_id); 1341 $sticky_post_type = get_post_type($post_id); 1341 1342 1342 1343 if ( !$post_id ) 1343 1344 $post_id = absint($id); 1344 1345 1345 $stickies = get_option('sticky_posts'); 1346 if('post' == $sticky_post_type) { 1347 $stickies = get_option('sticky_posts'); 1348 } else { 1349 $stickies = get_option('sticky_' . $sticky_post_type); 1350 } 1346 1351 1347 1352 if ( !is_array($stickies) ) 1348 1353 return false; … … 1489 1494 * @param int $post_id Post ID. 1490 1495 */ 1491 1496 function stick_post($post_id) { 1497 $sticky_post_type = get_post_type($post_id); 1498 1499 if('post' == $sticky_post_type){ 1492 1500 $stickies = get_option('sticky_posts'); 1501 } else { 1502 $stickies = get_option('sticky_' . $sticky_post_type); 1503 } 1493 1504 1494 1505 if ( !is_array($stickies) ) 1495 1506 $stickies = array($post_id); … … 1497 1508 if ( ! in_array($post_id, $stickies) ) 1498 1509 $stickies[] = $post_id; 1499 1510 1511 1512 if('post' == $sticky_post_type){ 1500 1513 update_option('sticky_posts', $stickies); 1514 } else { 1515 update_option('sticky_'. $sticky_post_type, $stickies); 1516 } 1501 1517 } 1502 1518 1503 1519 /** … … 1510 1526 * @param int $post_id Post ID. 1511 1527 */ 1512 1528 function unstick_post($post_id) { 1529 $sticky_post_type = get_post_type($post_id); 1530 if('post' == get_post_type($post_id)) { 1513 1531 $stickies = get_option('sticky_posts'); 1532 } else { 1533 $stickies = get_option('sticky_' . $sticky_post_type); 1534 } 1514 1535 1515 1536 if ( !is_array($stickies) ) 1516 1537 return; … … 1523 1544 return; 1524 1545 1525 1546 array_splice($stickies, $offset, 1); 1526 1547 if('post' == $sticky_post_type){ 1527 1548 update_option('sticky_posts', $stickies); 1549 } else { 1550 update_option('sticky_'. $sticky_post_type, $stickies); 1551 } 1528 1552 } 1529 1553 1530 1554 /** -
wp-includes/query.php
2471 2471 } 2472 2472 2473 2473 // Put sticky posts at the top of the posts array 2474 $sticky_posts = get_option('sticky_posts'); 2475 if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['caller_get_posts'] ) { 2476 $num_posts = count($this->posts); 2477 $sticky_offset = 0; 2478 // Loop over posts and relocate stickies to the front. 2479 for ( $i = 0; $i < $num_posts; $i++ ) { 2480 if ( in_array($this->posts[$i]->ID, $sticky_posts) ) { 2481 $sticky_post = $this->posts[$i]; 2482 // Remove sticky from current position 2483 array_splice($this->posts, $i, 1); 2484 // Move to front, after other stickies 2485 array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); 2486 // Increment the sticky offset. The next sticky will be placed at this offset. 2487 $sticky_offset++; 2488 // Remove post from sticky posts array 2489 $offset = array_search($sticky_post->ID, $sticky_posts); 2490 unset( $sticky_posts[$offset] ); 2491 } 2492 } 2474 foreach(get_post_types() as $sticky_post_type) { 2475 if( !post_type_supports( $sticky_post_type, 'sticky') ) { 2476 continue; 2477 } 2478 2479 if( 'post' == $sticky_post_type) { 2480 // get the core post stickies 2481 $sticky_posts = get_option('sticky_posts'); 2482 } else { // TODO: Need a conditional here to see if stickies to be combined? 2483 continue; 2484 // get the custom_post_type stickies 2485 // $sticky_posts = get_option('sticky_'.$sticky_post_type); 2486 } 2487 if ( $this->is_home && $page <= 1 && is_array($sticky_posts) && !empty($sticky_posts) && !$q['caller_get_posts'] ) { 2488 $num_posts = count($this->posts); 2489 $sticky_offset = 0; 2490 // Loop over posts and relocate stickies to the front. 2491 for ( $i = 0; $i < $num_posts; $i++ ) { 2492 if ( in_array($this->posts[$i]->ID, $sticky_posts) ) { 2493 $sticky_post = $this->posts[$i]; 2494 // Remove sticky from current position 2495 array_splice($this->posts, $i, 1); 2496 // Move to front, after other stickies 2497 array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); 2498 // Increment the sticky offset. The next sticky will be placed at this offset. 2499 $sticky_offset++; 2500 // Remove post from sticky posts array 2501 $offset = array_search($sticky_post->ID, $sticky_posts); 2502 unset( $sticky_posts[$offset] ); 2503 } 2504 } 2493 2505 2494 2495 2496 2506 // If any posts have been excluded specifically, Ignore those that are sticky. 2507 if ( !empty($sticky_posts) && !empty($q['post__not_in']) ) 2508 $sticky_posts = array_diff($sticky_posts, $q['post__not_in']); 2497 2509 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2510 // Fetch sticky posts that weren't in the query results 2511 if ( !empty($sticky_posts) ) { 2512 $stickies__in = implode(',', array_map( 'absint', $sticky_posts )); 2513 // honor post type(s) if not set to any 2514 $stickies_where = ''; 2515 if ( 'any' != $post_type && '' != $post_type ) { 2516 if ( is_array( $post_type ) ) { 2517 $post_types = join( "', '", $post_type ); 2518 } else { 2519 $post_types = $post_type; 2520 } 2521 $stickies_where = "AND $wpdb->posts.post_type IN ('" . $post_types . "')"; 2522 } 2511 2523 2512 $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in) $stickies_where" ); 2513 foreach ( $stickies as $sticky_post ) { 2514 // Ignore sticky posts the current user cannot read or are not published. 2515 if ( 'publish' != $sticky_post->post_status ) 2516 continue; 2517 array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); 2518 $sticky_offset++; 2519 } 2520 } 2521 } 2524 $stickies = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE $wpdb->posts.ID IN ($stickies__in) $stickies_where" ); 2525 foreach ( $stickies as $sticky_post ) { 2526 // Ignore sticky posts the current user cannot read or are not published. 2527 if ( 'publish' != $sticky_post->post_status ) 2528 continue; 2529 array_splice($this->posts, $sticky_offset, 0, array($sticky_post)); 2530 $sticky_offset++; 2531 } 2532 } 2533 } 2534 } 2522 2535 2523 2536 if ( !$q['suppress_filters'] ) 2524 2537 $this->posts = apply_filters_ref_array('the_posts', array( $this->posts, &$this ) );