Make WordPress Core

Ticket #12702: Enable sticky for custom post type 15659.patch

File Enable sticky for custom post type 15659.patch, 6.1 KB (added by azizur, 13 years ago)

Enable sticky for custom post type r15659

  • wp-admin/includes/default-list-tables.php

     
    920920                                        </select>
    921921                                </label>
    922922
    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 ) ) : ?>
    924924
    925         <?php   if ( $bulk ) : ?>
     925        <?php   if ( $bulk && post_type_supports( $screen->post_type, 'sticky' ) ) : ?>
    926926
    927927                                <label class="alignright">
    928928                                        <span class="title"><?php _e( 'Sticky' ); ?></span>
     
    933933                                        </select>
    934934                                </label>
    935935
    936         <?php   else : // $bulk ?>
     936        <?php   elseif(post_type_supports( $screen->post_type, 'sticky' )) : // $bulk ?>
    937937
    938938                                <label class="alignleft">
    939939                                        <input type="checkbox" name="sticky" value="sticky" />
    940                                         <span class="checkbox-title"><?php _e( 'Make this post sticky' ); ?></span>
     940                                        <span class="checkbox-title"><?php _e( 'Make this sticky' ); ?></span>
    941941                                </label>
    942942
    943943        <?php   endif; // $bulk ?>
  • wp-admin/includes/meta-boxes.php

     
    116116} elseif ( !empty( $post->post_password ) ) {
    117117        $visibility = 'password';
    118118        $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 ) ) {
    120120        $visibility = 'public';
    121121        $visibility_trans = __('Public, Sticky');
    122122} else {
     
    130130
    131131<div id="post-visibility-select" class="hide-if-js">
    132132<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' )): ?>
    134134<input type="checkbox" style="display:none" name="hidden_post_sticky" id="hidden-post-sticky" value="sticky" <?php checked(is_sticky($post->ID)); ?> />
    135135<?php endif; ?>
    136136<input type="hidden" name="hidden_post_visibility" id="hidden-post-visibility" value="<?php echo esc_attr( $visibility ); ?>" />
    137137
    138138
    139139<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 post to 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>
    142142<?php endif; ?>
    143143<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 />
    144144<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

     
    2323                'hierarchical' => false,
    2424                'rewrite' => false,
    2525                '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' ),
    2727        ) );
    2828
    2929        register_post_type( 'page', array(
     
    13341334 * @return bool Whether post is sticky.
    13351335 */
    13361336function is_sticky( $post_id = 0 ) {
     1337    global $post;
     1338    $post_type = $post->post_type;
     1339   
    13371340        $post_id = absint( $post_id );
    13381341
    13391342        if ( ! $post_id )
     
    13411344
    13421345        $stickies = get_option( 'sticky_posts' );
    13431346
    1344         if ( ! is_array( $stickies ) )
     1347        if ( ! is_array( $stickies ) || ! isset($stickies[$post_type]) )
    13451348                return false;
    13461349
    1347         if ( in_array( $post_id, $stickies ) )
     1350        if ( in_array( $post_id, $stickies ) || in_array( $post_id, $stickies[$post_type] ))
    13481351                return true;
    13491352
    13501353        return false;
     
    14861489 * @param int $post_id Post ID.
    14871490 */
    14881491function stick_post($post_id) {
     1492    global $post;
     1493    $post_type = $post['post_type'];
     1494   
    14891495        $stickies = get_option('sticky_posts');
    14901496
    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);
    14931499
    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;
    14961502
    14971503        update_option('sticky_posts', $stickies);
    14981504}
     
    15071513 * @param int $post_id Post ID.
    15081514 */
    15091515function unstick_post($post_id) {
     1516    global $post;
     1517    $post_type = $post['post_type'];
     1518   
    15101519        $stickies = get_option('sticky_posts');
    15111520
    1512         if ( !is_array($stickies) )
     1521        if ( !is_array($stickies) || !isset($stickies[$post_type]) )
    15131522                return;
    15141523
    1515         if ( ! in_array($post_id, $stickies) )
     1524        if ( ! in_array($post_id, $stickies[$post_type]) )
    15161525                return;
    15171526
    1518         $offset = array_search($post_id, $stickies);
     1527        $offset = array_search($post_id, $stickies[$post_type]);
    15191528        if ( false === $offset )
    15201529                return;
    15211530
    1522         array_splice($stickies, $offset, 1);
     1531        array_splice($stickies[$post_type], $offset, 1);
    15231532
    15241533        update_option('sticky_posts', $stickies);
    15251534}