WordPress.org

Make WordPress Core

Ticket #17185: optimize-verbose-page.diff

File optimize-verbose-page.diff, 3.7 KB (added by duck_, 10 years ago)
  • wp-includes/rewrite.php

     
    782782                foreach ( $posts as $id => $post ) {
    783783                        // URL => page name
    784784                        $uri = get_page_uri($id);
    785                         $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id ));
     785                        $attachments = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $id ) );
    786786                        if ( !empty($attachments) ) {
    787787                                foreach ( $attachments as $attachment ) {
    788788                                        $attach_uri = get_page_uri($attachment->ID);
     
    826826                if ( is_array( $attachment_uris ) ) {
    827827                        foreach ( $attachment_uris as $uri => $pagename ) {
    828828                                $this->add_rewrite_tag('%pagename%', "($uri)", 'attachment=');
    829                                 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));
     829                                $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES, false));
    830830                        }
    831831                }
    832832                if ( is_array( $uris ) ) {
    833833                        foreach ( $uris as $uri => $pagename ) {
    834834                                $this->add_rewrite_tag('%pagename%', "($uri)", 'pagename=');
    835                                 $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES));
     835                                $rewrite_rules = array_merge($rewrite_rules, $this->generate_rewrite_rules($page_structure, EP_PAGES, false));
    836836                        }
    837837                }
    838838
     839                // page attachments catch-all
     840                $rewrite_rules = array_merge( $rewrite_rules, array( '.+?/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]' ) );
     841
    839842                return $rewrite_rules;
    840843        }
    841844
     
    13891392                                        $sub1feed = $sub1 . $feedregex; //and <permalink>/feed/(atom|...)
    13901393                                        $sub1feed2 = $sub1 . $feedregex2; //and <permalink>/(feed|atom...)
    13911394                                        $sub1comment = $sub1 . $commentregex; //and <permalink>/comment-page-xx
    1392                                         //add an ? as we don't have to match that last slash, and finally a $ so we
    1393                                         //match to the end of the URL
    13941395
    1395                                         //add another rule to match attachments in the explicit form:
    1396                                         //<permalink>/attachment/some-text
     1396                                        //add another rule to match attachments in the explicit form: <permalink>/attachment/some-text
    13971397                                        $sub2 = $submatchbase . '/attachment/([^/]+)/';
    13981398                                        $sub2tb = $sub2 . $trackbackregex; //and add trackbacks <permalink>/attachment/trackback
    13991399                                        $sub2feed = $sub2 . $feedregex;    //feeds, <permalink>/attachment/feed/(atom|...)
     
    14171417                                        }
    14181418
    14191419                                        //now we've finished with endpoints, finish off the $sub1 and $sub2 matches
     1420                                        //add a ? as we don't have to match that last slash, and finally a $ so we match to the end of the URL
    14201421                                        $sub1 .= '?$';
    14211422                                        $sub2 .= '?$';
    14221423
     
    14421443                                        //add regexes/queries for attachments, attachment trackbacks and so on
    14431444                                        if ( ! $page ) //require <permalink>/attachment/stuff form for pages because of confusion with subpages
    14441445                                                $rewrite = array_merge($rewrite, array($sub1 => $subquery, $sub1tb => $subtbquery, $sub1feed => $subfeedquery, $sub1feed2 => $subfeedquery, $sub1comment => $subcommentquery));
    1445                                         $rewrite = array_merge(array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery, $sub2comment => $subcommentquery), $rewrite);
     1446                                        if ( ! $page || ! $this->use_verbose_page_rules ) //individual <permalink>/attachment/stuff only for non-verbose page or non-page rewrites
     1447                                                $rewrite = array_merge(array($sub2 => $subquery, $sub2tb => $subtbquery, $sub2feed => $subfeedquery, $sub2feed2 => $subfeedquery, $sub2comment => $subcommentquery), $rewrite);
    14461448                                }
    14471449                        } //if($num_toks)
    14481450                        //add the rules for this dir to the accumulating $post_rewrite