Make WordPress Core

Ticket #17447: 17447.2.diff

File 17447.2.diff, 15.4 KB (added by MikeSchinkel, 10 years ago)

Patch to allow the 'register_post_type_args' hook to work on '_builtin' posts.

  • wp-includes/revision.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    667667
    668668        return true;
    669669}
     670
     671/**
     672 * Retrieve content from the specified post.
     673 *
     674 * wp_get_post_content() assumes setup_postdata() has previously been called.
     675 * In order to call get_the_content() without side-effects you must first
     676 * collect up the values of the global variables assigned in setup_postdata()
     677 * and afterwards restore those global variables.
     678 *
     679 * @since 4.4.0
     680 *
     681 * @uses save_postdata(), setup_postdata(), restore_postdata(), get_the_content()
     682 *
     683 * @param object|null|int $post Post data.
     684 * @param string $more_link_text Optional. Content for when there is more text.
     685 * @param bool $strip_teaser Optional. Teaser content before the more text.
     686 * @return string|null The Post's content
     687 */
     688function wp_get_post_content( $post = null, $more_link_text = null, $strip_teaser = false ) {
     689
     690        if ( ! is_object( $post = get_post( $post ) ) ) {
     691
     692                $the_content = null;
     693
     694        } else {
     695
     696                $save = wp_save_postdata();
     697                setup_postdata( $post );
     698                $the_content = get_the_content( $more_link_text, $stripteaser );
     699                wp_restore_postdata( $save );
     700
     701        }
     702
     703    return $the_content;
     704
     705}
     706
     707/**
     708 * Retrieve the excerpt from the specified post.
     709 *
     710 * wp_get_post_excerpt() assumes setup_postdata() has previously been called.
     711 * In order to call get_the_excerpt() without side-effects you must first
     712 * collect up the values of the global variables assigned in setup_postdata()
     713 * and afterwards restore those global variables.
     714 *
     715 * @since 4.4.0
     716 *
     717 * @uses save_postdata(), setup_postdata(), restore_postdata(), get_the_excerpt()
     718 *
     719 * @param object|null|int $post Post data.
     720 * @return string|null The Post's excerpt
     721 */
     722function get_post_excerpt( $post = null ) {
     723
     724        if ( ! is_object( $post = get_post( $post ) ) ) {
     725
     726                $the_excerpt = null;
     727
     728        } else {
     729
     730                $save = wp_save_postdata();
     731                setup_postdata( $post );
     732                $the_excerpt = get_the_excerpt();
     733                wp_restore_postdata( $save );
     734
     735        }
     736    return $the_excerpt;
     737
     738}
  • wp-includes/query.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    2323 * @return mixed
    2424 */
    2525function get_query_var( $var, $default = '' ) {
    26         global $wp_query;
     26                global $wp_query;
    2727        return $wp_query->get( $var, $default );
    2828}
    2929
     
    3838 * @return object
    3939 */
    4040function get_queried_object() {
    41         global $wp_query;
     41                global $wp_query;
    4242        return $wp_query->get_queried_object();
    4343}
    4444
     
    5353 * @return int
    5454 */
    5555function get_queried_object_id() {
    56         global $wp_query;
     56                global $wp_query;
    5757        return $wp_query->get_queried_object_id();
    5858}
    5959
     
    6868 * @param mixed  $value
    6969 */
    7070function set_query_var( $var, $value ) {
    71         global $wp_query;
     71                global $wp_query;
    7272        $wp_query->set( $var, $value );
    7373}
    7474
     
    116116 * @global WP_Query $wp_query
    117117 */
    118118function wp_reset_postdata() {
    119         global $wp_query;
     119                global $wp_query;
    120120
    121121        if ( isset( $wp_query ) ) {
    122122                $wp_query->reset_postdata();
     
    139139 * @return bool
    140140 */
    141141function is_archive() {
    142         global $wp_query;
     142                global $wp_query;
    143143
    144144        if ( ! isset( $wp_query ) ) {
    145145                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    160160 * @return bool
    161161 */
    162162function is_post_type_archive( $post_types = '' ) {
    163         global $wp_query;
     163                global $wp_query;
    164164
    165165        if ( ! isset( $wp_query ) ) {
    166166                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    181181 * @return bool
    182182 */
    183183function is_attachment( $attachment = '' ) {
    184         global $wp_query;
     184                global $wp_query;
    185185
    186186        if ( ! isset( $wp_query ) ) {
    187187                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    205205 * @return bool
    206206 */
    207207function is_author( $author = '' ) {
    208         global $wp_query;
     208                global $wp_query;
    209209
    210210        if ( ! isset( $wp_query ) ) {
    211211                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    229229 * @return bool
    230230 */
    231231function is_category( $category = '' ) {
    232         global $wp_query;
     232                global $wp_query;
    233233
    234234        if ( ! isset( $wp_query ) ) {
    235235                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    253253 * @return bool
    254254 */
    255255function is_tag( $tag = '' ) {
    256         global $wp_query;
     256                global $wp_query;
    257257
    258258        if ( ! isset( $wp_query ) ) {
    259259                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    282282 * @return bool
    283283 */
    284284function is_tax( $taxonomy = '', $term = '' ) {
    285         global $wp_query;
     285                global $wp_query;
    286286
    287287        if ( ! isset( $wp_query ) ) {
    288288                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    302302 * @return bool
    303303 */
    304304function is_comments_popup() {
    305         global $wp_query;
     305                global $wp_query;
    306306
    307307        if ( ! isset( $wp_query ) ) {
    308308                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    322322 * @return bool
    323323 */
    324324function is_date() {
    325         global $wp_query;
     325                global $wp_query;
    326326
    327327        if ( ! isset( $wp_query ) ) {
    328328                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    342342 * @return bool
    343343 */
    344344function is_day() {
    345         global $wp_query;
     345                global $wp_query;
    346346
    347347        if ( ! isset( $wp_query ) ) {
    348348                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    363363 * @return bool
    364364 */
    365365function is_feed( $feeds = '' ) {
    366         global $wp_query;
     366                global $wp_query;
    367367
    368368        if ( ! isset( $wp_query ) ) {
    369369                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    383383 * @return bool
    384384 */
    385385function is_comment_feed() {
    386         global $wp_query;
     386                global $wp_query;
    387387
    388388        if ( ! isset( $wp_query ) ) {
    389389                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    412412 * @return bool True, if front of site.
    413413 */
    414414function is_front_page() {
    415         global $wp_query;
     415                global $wp_query;
    416416
    417417        if ( ! isset( $wp_query ) ) {
    418418                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    441441 * @return bool True if blog view homepage.
    442442 */
    443443function is_home() {
    444         global $wp_query;
     444                global $wp_query;
    445445
    446446        if ( ! isset( $wp_query ) ) {
    447447                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    461461 * @return bool
    462462 */
    463463function is_month() {
    464         global $wp_query;
     464                global $wp_query;
    465465
    466466        if ( ! isset( $wp_query ) ) {
    467467                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    488488 * @return bool
    489489 */
    490490function is_page( $page = '' ) {
    491         global $wp_query;
     491                global $wp_query;
    492492
    493493        if ( ! isset( $wp_query ) ) {
    494494                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    508508 * @return bool
    509509 */
    510510function is_paged() {
    511         global $wp_query;
     511                global $wp_query;
    512512
    513513        if ( ! isset( $wp_query ) ) {
    514514                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    528528 * @return bool
    529529 */
    530530function is_preview() {
    531         global $wp_query;
     531                global $wp_query;
    532532
    533533        if ( ! isset( $wp_query ) ) {
    534534                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    548548 * @return bool
    549549 */
    550550function is_robots() {
    551         global $wp_query;
     551                global $wp_query;
    552552
    553553        if ( ! isset( $wp_query ) ) {
    554554                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    568568 * @return bool
    569569 */
    570570function is_search() {
    571         global $wp_query;
     571                global $wp_query;
    572572
    573573        if ( ! isset( $wp_query ) ) {
    574574                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    597597 * @return bool
    598598 */
    599599function is_single( $post = '' ) {
    600         global $wp_query;
     600                global $wp_query;
    601601
    602602        if ( ! isset( $wp_query ) ) {
    603603                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    624624 * @return bool
    625625 */
    626626function is_singular( $post_types = '' ) {
    627         global $wp_query;
     627                global $wp_query;
    628628
    629629        if ( ! isset( $wp_query ) ) {
    630630                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    644644 * @return bool
    645645 */
    646646function is_time() {
    647         global $wp_query;
     647                global $wp_query;
    648648
    649649        if ( ! isset( $wp_query ) ) {
    650650                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    664664 * @return bool
    665665 */
    666666function is_trackback() {
    667         global $wp_query;
     667                global $wp_query;
    668668
    669669        if ( ! isset( $wp_query ) ) {
    670670                _doing_it_wrong( __FUNCTION__, __( 'Conditional query tags do not work before the query is run. Before then, they always return false.' ), '3.1' );
     
    730730                _doing_it_wrong( __FUNCTION__, $message, '3.7' );
    731731        }
    732732
    733         global $wp_query;
     733                global $wp_query;
    734734        return $wp_query->is_main_query();
    735735}
    736736
     
    748748 * @return bool
    749749 */
    750750function have_posts() {
    751         global $wp_query;
     751                global $wp_query;
    752752        return $wp_query->have_posts();
    753753}
    754754
     
    762762 * @return bool True if caller is within loop, false if loop hasn't started or ended.
    763763 */
    764764function in_the_loop() {
    765         global $wp_query;
     765                global $wp_query;
    766766        return $wp_query->in_the_loop;
    767767}
    768768
     
    774774 * @global WP_Query $wp_query
    775775 */
    776776function rewind_posts() {
    777         global $wp_query;
     777                global $wp_query;
    778778        $wp_query->rewind_posts();
    779779}
    780780
     
    786786 * @global WP_Query $wp_query
    787787 */
    788788function the_post() {
    789         global $wp_query;
     789                global $wp_query;
    790790        $wp_query->the_post();
    791791}
    792792
     
    47174717 * @global wpdb     $wpdb     WordPress database abstraction object.
    47184718 */
    47194719function wp_old_slug_redirect() {
    4720         global $wp_query;
     4720                global $wp_query;
    47214721        if ( is_404() && '' != $wp_query->query_vars['name'] ) :
    47224722                global $wpdb;
    47234723
     
    47774777 * @return bool True when finished.
    47784778 */
    47794779function setup_postdata( $post ) {
    4780         global $wp_query;
     4780                global $wp_query;
    47814781
    47824782        if ( ! empty( $wp_query ) && $wp_query instanceof WP_Query ) {
    47834783                return $wp_query->setup_postdata( $post );
     
    47854785
    47864786        return false;
    47874787}
     4788
     4789/**
     4790 * Save global post data into an array for later restore.
     4791 *
     4792 * @since 4.4.0
     4793 *
     4794 * @return array Values of selected global variables to be restored by restore_postdata().
     4795 */
     4796function wp_save_postdata() {
     4797
     4798    global $id, $authordata, $day, $currentmonth, $page, $pages, $multipage, $more, $numpages;
     4799
     4800    $postdata = array( $id, $authordata, $day, $currentmonth, $page, $pages, $multipage, $more, $numpages );
     4801
     4802    return $postdata;
     4803}
     4804
     4805/**
     4806 * Save global post data into an array for later restore.
     4807 *
     4808 * @since 4.4.0
     4809 *
     4810 * @param array Values of selected global variables collected by save_postdata().
     4811 */
     4812function wp_restore_postdata( $postdata ) {
     4813
     4814    global $id, $day, $more, $post, $page, $pages, $numpages, $multipage, $authordata, $currentmonth;
     4815
     4816    list( $id, $authordata, $day, $currentmonth, $page, $pages, $multipage, $more, $numpages ) = $postdata;
     4817
     4818}
  • wp-includes/rewrite-functions.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    317317                if ( $id )
    318318                        return $id;
    319319        }
     320        /**
     321         * Check if we are working with an image file
     322         */
     323        if ( preg_match( '#^https?://.*?(?:png|jpg|jpeg|gif)$#ui', $url ) ) {
     324
     325                /**
     326                 * Okay, let's look to see if it's an attachment. Gotta get the upload dir's baseurl
     327                 * to strip off the protocal, domain and root paths because attachments are not stored
     328                 * as full urls but instead (typically) stored using yyy/mm/filename.ext" format.
     329                 */
     330                $upload_dir = wp_upload_dir();
     331
     332                /**
     333                 * Get the path or the original size image by slicing the base image url off the front
     334                 * and "-{$width}x{$height}" off the end, and adding the extension back.
     335                 */
     336                $regex = preg_quote( $upload_dir[ 'baseurl' ] ) . '/(.*?)\-\d+x\d+(\.(png|jpg|jpeg|gif))';
     337                $filepath = preg_replace( "#^{$regex}$#i", "$1$2", $url );
     338
     339                /**
     340                 * Look up the image in the metadata to see if it is attached
     341                 */
     342                global $wpdb;
     343
     344                if ( $id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_value='%s'", $filepath ) ) ) {
     345                        return $id;
     346                }
     347
     348                /**
     349                 * Hmmph. Didn't find anything. No clue what the ID is then.
     350                 */
     351                return 0;
     352
     353        }
    320354
    321355        // Check to see if we are using rewrite rules
    322356        $rewrite = $wp_rewrite->wp_rewrite_rules();
  • wp-includes/post-functions.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    991991        // Sanitize post type name
    992992        $post_type = sanitize_key( $post_type );
    993993
    994         if ( empty( $args['_builtin'] ) ) {
    995                 /**
    996                  * Filter the arguments for registering a post type.
    997                  *
    998                  * Not available for built-in post types.
    999                  *
    1000                  * @since 4.4.0
    1001                  *
    1002                  * @param array|string $args      Array or string of arguments for registering a post type.
    1003                  * @param string       $post_type Post type key.
    1004                  */
    1005                 $args = apply_filters( 'register_post_type_args', $args, $post_type );
    1006         }
     994        /**
     995         * Filter the arguments for registering a post type.
     996         *
     997         * Not available for built-in post types.
     998         *
     999         * @since 4.4.0
     1000         *
     1001         * @param array|string $args      Array or string of arguments for registering a post type.
     1002         * @param string       $post_type Post type key.
     1003         */
     1004        $args = apply_filters( 'register_post_type_args', $args, $post_type );
    10071005
    10081006        // Args prefixed with an underscore are reserved for internal use.
    10091007        $defaults = array(