WordPress.org

Make WordPress Core

Ticket #16747: 16747.diff

File 16747.diff, 3.9 KB (added by kawauso, 4 years ago)

Introduce 'rss_enclosures' and 'atom_enclosures' filters, pass $enclosure to singular filters, general code cleanup

  • wp-includes/feed.php

     
    369369 * the user has the password for the post. If not then it will return before 
    370370 * displaying. 
    371371 * 
    372  * Also uses the function get_post_custom() to get the post's 'enclosure' 
     372 * Also uses the function get_post_meta() to get the post's 'enclosure' 
    373373 * metadata field and parses the value to display the enclosure(s). The 
    374374 * enclosure(s) consist of enclosure HTML tag(s) with a URI and other 
    375375 * attributes. 
     
    377377 * @package WordPress 
    378378 * @subpackage Template 
    379379 * @since 1.5.0 
    380  * @uses apply_filters() Calls 'rss_enclosure' hook on rss enclosure. 
    381  * @uses get_post_custom() To get the current post enclosure metadata. 
     380 * @uses apply_filters() Calls 'rss_enclosure' hook on rss enclosure and 'rss_enclosures' hook on all rss enclosures. 
     381 * @uses get_post_meta() To get the current post enclosure metadata. 
    382382 */ 
    383383function rss_enclosure() { 
    384384        if ( post_password_required() ) 
    385385                return; 
    386386 
    387         foreach ( (array) get_post_custom() as $key => $val) { 
    388                 if ($key == 'enclosure') { 
    389                         foreach ( (array) $val as $enc ) { 
    390                                 $enclosure = explode("\n", $enc); 
     387        $output = ''; 
     388        $post_id = get_the_ID(); 
     389        $encs = get_post_meta( $post_id, 'enclosure' ); 
    391390 
    392                                 //only get the the first element eg, audio/mpeg from 'audio/mpeg mpga mp2 mp3' 
    393                                 $t = preg_split('/[ \t]/', trim($enclosure[2]) ); 
    394                                 $type = $t[0]; 
     391        if ( !$encs ) 
     392                return; 
    395393 
    396                                 echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($enclosure[0])) . '" length="' . trim($enclosure[1]) . '" type="' . $type . '" />' . "\n"); 
    397                         } 
    398                 } 
     394        foreach ( $encs as $enc ) { 
     395                $enclosure = array_map( 'trim', explode( "\n", $enc ) ); 
     396 
     397                //only get the the first element eg, audio/mpeg from 'audio/mpeg mpga mp2 mp3' 
     398                list( $type ) = preg_split( '/[ \t]/', $enclosure[2] ); 
     399 
     400                $output .= apply_filters( 'rss_enclosure', "\t\t" . '<enclosure url="' . htmlspecialchars( $enclosure[0] ) . '" length="' . $enclosure[1] . '" type="' . $type . '" />' . "\n", $enclosure ); 
    399401        } 
     402 
     403        echo apply_filters( 'rss_enclosures', $output ); 
    400404} 
    401405 
    402406/** 
     
    406410 * the user has the password for the post. If not then it will return before 
    407411 * displaying. 
    408412 * 
    409  * Also uses the function get_post_custom() to get the post's 'enclosure' 
     413 * Also uses the function get_post_meta() to get the post's 'enclosure' 
    410414 * metadata field and parses the value to display the enclosure(s). The 
    411415 * enclosure(s) consist of link HTML tag(s) with a URI and other attributes. 
    412416 * 
    413417 * @package WordPress 
    414418 * @subpackage Template 
    415419 * @since 2.2.0 
    416  * @uses apply_filters() Calls 'atom_enclosure' hook on atom enclosure. 
    417  * @uses get_post_custom() To get the current post enclosure metadata. 
     420 * @uses apply_filters() Calls 'atom_enclosure' hook on atom enclosure and 'atom_enclosures' hook on all atom enclosures. 
     421 * @uses get_post_meta() To get the current post enclosure metadata. 
    418422 */ 
    419423function atom_enclosure() { 
    420424        if ( post_password_required() ) 
    421425                return; 
    422426 
    423         foreach ( (array) get_post_custom() as $key => $val ) { 
    424                 if ($key == 'enclosure') { 
    425                         foreach ( (array) $val as $enc ) { 
    426                                 $enclosure = split("\n", $enc); 
    427                                 echo apply_filters('atom_enclosure', '<link href="' . trim(htmlspecialchars($enclosure[0])) . '" rel="enclosure" length="' . trim($enclosure[1]) . '" type="' . trim($enclosure[2]) . '" />' . "\n"); 
    428                         } 
    429                 } 
     427        $output = ''; 
     428        $post_id = get_the_ID(); 
     429        $encs = get_post_meta( $post_id, 'enclosure' ); 
     430 
     431        if ( !$encs ) 
     432                return; 
     433 
     434        foreach ( $encs as $enc ) { 
     435                $enclosure = array_map( 'trim', explode( "\n", $enc ) ); 
     436                $output .= apply_filters( 'atom_enclosure', "\t\t" . '<link href="' . htmlspecialchars( $enclosure[0] ) . '" rel="enclosure" length="' . $enclosure[1] . '" type="' . $enclosure[2] . '" />' . "\n", $enclosure ); 
    430437        } 
     438 
     439        echo apply_filters( 'atom_enclosures', $output ); 
    431440} 
    432441 
    433442/**