Make WordPress Core

Changeset 11956


Ignore:
Timestamp:
09/21/2009 09:33:00 PM (17 years ago)
Author:
ryan
Message:

get_delete_post_link()

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/template.php

    r11954 r11956  
    14511451                                }
    14521452                                if ( current_user_can('delete_post', $post->ID) ) {
    1453                                         $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this post to the Trash')) . "' href='" . wp_nonce_url("post.php?action=trash&amp;post=$post->ID", 'trash-post_' . $post->ID) . "'>" . __('Trash') . "</a>";
     1453                                        $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this post to the Trash')) . "' href='" . get_delete_post_link($post->ID) . "'>" . __('Trash') . "</a>";
    14541454                                }
    14551455                                if ( in_array($post->post_status, array('pending', 'draft')) ) {
     
    16711671                        }
    16721672                        if ( current_user_can('delete_page', $page->ID) ) {
    1673                                 $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this page to the Trash')) . "' href='" . wp_nonce_url("page.php?action=trash&amp;post=$page->ID", 'trash-page_' . $page->ID) . "'>" . __('Trash') . "</a>";
     1673                                $actions['trash'] = "<a class='submitdelete' title='" . esc_attr(__('Move this page to the Trash')) . "' href='" . get_delete_post_link($page->ID) . "'>" . __('Trash') . "</a>";
    16741674                        }
    16751675                        if ( in_array($post->post_status, array('pending', 'draft')) ) {
  • trunk/wp-includes/link-template.php

    r11930 r11956  
    733733
    734734/**
     735 * Retrieve delete posts link for post.
     736 *
     737 * Can be used within the WordPress loop or outside of it. Can be used with
     738 * pages, posts, attachments, and revisions.
     739 *
     740 * @since 2.9.0
     741 *
     742 * @param int $id Optional. Post ID.
     743 * @param string $context Optional, default to display. How to write the '&', defaults to '&amp;'.
     744 * @return string
     745 */
     746function get_delete_post_link($id = 0, $context = 'display') {
     747        if ( !$post = &get_post( $id ) )
     748                return;
     749
     750        if ( 'display' == $context )
     751                $action = 'action=trash&amp;';
     752        else
     753                $action = 'action=trash&';
     754
     755        switch ( $post->post_type ) :
     756        case 'page' :
     757                if ( !current_user_can( 'delete_page', $post->ID ) )
     758                        return;
     759                $file = 'page';
     760                $var  = 'post';
     761                break;
     762        case 'attachment' :
     763                if ( !current_user_can( 'delete_post', $post->ID ) )
     764                        return;
     765                $file = 'media';
     766                $var  = 'attachment_id';
     767                break;
     768        case 'revision' :
     769                if ( !current_user_can( 'delete_post', $post->ID ) )
     770                        return;
     771                $file = 'revision';
     772                $var  = 'revision';
     773                $action = '';
     774                break;
     775        default :
     776                if ( !current_user_can( 'edit_post', $post->ID ) )
     777                        return apply_filters( 'get_delete_post_link', '', $post->ID, $context );;
     778                $file = 'post';
     779                $var  = 'post';
     780                break;
     781        endswitch;
     782
     783        return apply_filters( 'get_delete_post_link', wp_nonce_url( admin_url("$file.php?{$action}$var=$post->ID"), "trash-{$file}_" . $post->ID ), $context );
     784}
     785
     786/**
    735787 * Retrieve edit comment link.
    736788 *
Note: See TracChangeset for help on using the changeset viewer.