Make WordPress Core

Ticket #1914: attachment-permalinks.diff

File attachment-permalinks.diff, 3.2 KB (added by MikeNGarrett, 12 years ago)

Attachment Permalinks diff

  • wp-includes/link-template.php

     
    321321                        $link = str_replace( '%postname%', $name, $link );
    322322        }
    323323
    324         if ( ! $link )
    325                 $link = home_url( '/?attachment_id=' . $post->ID );
     324        if ( ! $link ) {
     325                if($wp_rewrite->using_permalinks()) {
     326                        $link = home_url( '/attachment/' . $post->ID );
     327                } else {
     328                        $link = home_url( '/?attachment_id=' . $post->ID );
     329                }
     330        }
    326331
    327332        return apply_filters( 'attachment_link', $link, $post->ID );
    328333}
     
    14681473 *
    14691474 * @param int $pagenum Optional. Page ID.
    14701475 * @param bool $escape Optional. Whether to escape the URL for display, with esc_url(). Defaults to true.
    1471 *       Otherwise, prepares the URL with esc_url_raw().
     1476 * Otherwise, prepares the URL with esc_url_raw().
    14721477 * @return string
    14731478 */
    14741479function get_pagenum_link($pagenum = 1, $escape = true ) {
  • wp-includes/rewrite.php

     
    679679                '%post_id%',
    680680                '%author%',
    681681                '%pagename%',
    682                 '%search%'
     682                '%search%',
     683                '%attachment_id%'
    683684        );
    684685
    685686        /**
     
    722723                'p=',
    723724                'author_name=',
    724725                'pagename=',
    725                 's='
     726                's=',
     727                'attachment_id='
    726728        );
    727729
    728730        /**
     
    15511553                $post_rewrite = $this->generate_rewrite_rules( $this->permalink_structure, EP_PERMALINK );
    15521554                $post_rewrite = apply_filters('post_rewrite_rules', $post_rewrite);
    15531555
     1556                // Attachment
     1557                $attachment_rewrite = $this->generate_rewrite_rules( "/attachment/%attachment_id%", EP_NONE, false, false, false, false, false );
     1558                $attachment_rewrite = apply_filters('attachment_rewrite_rules', $attachment_rewrite);
     1559
    15541560                // Date
    15551561                $date_rewrite = $this->generate_rewrite_rules($this->get_date_permastruct(), EP_DATE);
    15561562                $date_rewrite = apply_filters('date_rewrite_rules', $date_rewrite);
     
    15961602
    15971603                // Put them together.
    15981604                if ( $this->use_verbose_page_rules )
    1599                         $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules);
     1605                        $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $attachment_rewrite, $page_rewrite, $post_rewrite, $this->extra_rules);
    16001606                else
    1601                         $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules);
     1607                        $this->rules = array_merge($this->extra_rules_top, $robots_rewrite, $deprecated_files, $registration_pages, $root_rewrite, $comments_rewrite, $search_rewrite,  $author_rewrite, $date_rewrite, $attachment_rewrite, $post_rewrite, $page_rewrite, $this->extra_rules);
    16021608
    16031609                do_action_ref_array('generate_rewrite_rules', array(&$this));
    16041610                $this->rules = apply_filters('rewrite_rules_array', $this->rules);