Ticket #12702: Enable sticky for custom post type 15659.patch
File Enable sticky for custom post type 15659.patch, 6.1 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/default-list-tables.php
920 920 </select> 921 921 </label> 922 922 923 <?php if ( 'post' == $screen->post_type&& $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?>923 <?php if ( post_type_supports( $screen->post_type, 'sticky' ) && $can_publish && current_user_can( $post_type_object->cap->edit_others_posts ) ) : ?> 924 924 925 <?php if ( $bulk ) : ?>925 <?php if ( $bulk && post_type_supports( $screen->post_type, 'sticky' ) ) : ?> 926 926 927 927 <label class="alignright"> 928 928 <span class="title"><?php _e( 'Sticky' ); ?></span> … … 933 933 </select> 934 934 </label> 935 935 936 <?php else : // $bulk ?>936 <?php elseif(post_type_supports( $screen->post_type, 'sticky' )) : // $bulk ?> 937 937 938 938 <label class="alignleft"> 939 939 <input type="checkbox" name="sticky" value="sticky" /> 940 <span class="checkbox-title"><?php _e( 'Make this poststicky' ); ?></span>940 <span class="checkbox-title"><?php _e( 'Make this sticky' ); ?></span> 941 941 </label> 942 942 943 943 <?php endif; // $bulk ?> -
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->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->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->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-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', 'sticky', 'trackbacks', 'custom-fields', 'comments', 'revisions' ), 27 27 ) ); 28 28 29 29 register_post_type( 'page', array( … … 1334 1334 * @return bool Whether post is sticky. 1335 1335 */ 1336 1336 function is_sticky( $post_id = 0 ) { 1337 global $post; 1338 $post_type = $post->post_type; 1339 1337 1340 $post_id = absint( $post_id ); 1338 1341 1339 1342 if ( ! $post_id ) … … 1341 1344 1342 1345 $stickies = get_option( 'sticky_posts' ); 1343 1346 1344 if ( ! is_array( $stickies ) )1347 if ( ! is_array( $stickies ) || ! isset($stickies[$post_type]) ) 1345 1348 return false; 1346 1349 1347 if ( in_array( $post_id, $stickies ) )1350 if ( in_array( $post_id, $stickies ) || in_array( $post_id, $stickies[$post_type] )) 1348 1351 return true; 1349 1352 1350 1353 return false; … … 1486 1489 * @param int $post_id Post ID. 1487 1490 */ 1488 1491 function stick_post($post_id) { 1492 global $post; 1493 $post_type = $post['post_type']; 1494 1489 1495 $stickies = get_option('sticky_posts'); 1490 1496 1491 if ( !is_array($stickies) )1492 $stickies = array($post_id);1497 if ( !is_array($stickies) || !isset($stickies[$post_type]) ) 1498 $stickies[$post_type] = array($post_id); 1493 1499 1494 if ( ! in_array($post_id, $stickies ) )1495 $stickies[ ] = $post_id;1500 if ( ! in_array($post_id, $stickies[$post_type]) ) 1501 $stickies[$post_type][] = $post_id; 1496 1502 1497 1503 update_option('sticky_posts', $stickies); 1498 1504 } … … 1507 1513 * @param int $post_id Post ID. 1508 1514 */ 1509 1515 function unstick_post($post_id) { 1516 global $post; 1517 $post_type = $post['post_type']; 1518 1510 1519 $stickies = get_option('sticky_posts'); 1511 1520 1512 if ( !is_array($stickies) )1521 if ( !is_array($stickies) || !isset($stickies[$post_type]) ) 1513 1522 return; 1514 1523 1515 if ( ! in_array($post_id, $stickies ) )1524 if ( ! in_array($post_id, $stickies[$post_type]) ) 1516 1525 return; 1517 1526 1518 $offset = array_search($post_id, $stickies );1527 $offset = array_search($post_id, $stickies[$post_type]); 1519 1528 if ( false === $offset ) 1520 1529 return; 1521 1530 1522 array_splice($stickies , $offset, 1);1531 array_splice($stickies[$post_type], $offset, 1); 1523 1532 1524 1533 update_option('sticky_posts', $stickies); 1525 1534 }