Make WordPress Core


Ignore:
Timestamp:
09/14/2015 02:58:40 AM (10 years ago)
Author:
wonderboymusic
Message:

Move Walker_Page and Walker_PageDropdown into their own files via svn cp. Remove them from post-template.php. Load them in post.php.

post-template.php loads after post.php in wp-settings.php. It could probably also be loaded in post.php, but avoiding that for the moment.

See #33413.

File:
1 edited

Legend:

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

    r34108 r34109  
    13221322}
    13231323
    1324 /**
    1325  * Create HTML list of pages.
    1326  *
    1327  * @since 2.1.0
    1328  * @uses Walker
    1329  */
    1330 class Walker_Page extends Walker {
    1331     /**
    1332      * @see Walker::$tree_type
    1333      * @since 2.1.0
    1334      * @var string
    1335      */
    1336     public $tree_type = 'page';
    1337 
    1338     /**
    1339      * @see Walker::$db_fields
    1340      * @since 2.1.0
    1341      * @todo Decouple this.
    1342      * @var array
    1343      */
    1344     public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
    1345 
    1346     /**
    1347      * @see Walker::start_lvl()
    1348      * @since 2.1.0
    1349      *
    1350      * @param string $output Passed by reference. Used to append additional content.
    1351      * @param int    $depth  Depth of page. Used for padding.
    1352      * @param array  $args
    1353      */
    1354     public function start_lvl( &$output, $depth = 0, $args = array() ) {
    1355         $indent = str_repeat("\t", $depth);
    1356         $output .= "\n$indent<ul class='children'>\n";
    1357     }
    1358 
    1359     /**
    1360      * @see Walker::end_lvl()
    1361      * @since 2.1.0
    1362      *
    1363      * @param string $output Passed by reference. Used to append additional content.
    1364      * @param int    $depth  Depth of page. Used for padding.
    1365      * @param array  $args
    1366      */
    1367     public function end_lvl( &$output, $depth = 0, $args = array() ) {
    1368         $indent = str_repeat("\t", $depth);
    1369         $output .= "$indent</ul>\n";
    1370     }
    1371 
    1372     /**
    1373      * @see Walker::start_el()
    1374      * @since 2.1.0
    1375      *
    1376      * @param string $output       Passed by reference. Used to append additional content.
    1377      * @param object $page         Page data object.
    1378      * @param int    $depth        Depth of page. Used for padding.
    1379      * @param int    $current_page Page ID.
    1380      * @param array  $args
    1381      */
    1382     public function start_el( &$output, $page, $depth = 0, $args = array(), $current_page = 0 ) {
    1383         if ( $depth ) {
    1384             $indent = str_repeat( "\t", $depth );
    1385         } else {
    1386             $indent = '';
    1387         }
    1388 
    1389         $css_class = array( 'page_item', 'page-item-' . $page->ID );
    1390 
    1391         if ( isset( $args['pages_with_children'][ $page->ID ] ) ) {
    1392             $css_class[] = 'page_item_has_children';
    1393         }
    1394 
    1395         if ( ! empty( $current_page ) ) {
    1396             $_current_page = get_post( $current_page );
    1397             if ( $_current_page && in_array( $page->ID, $_current_page->ancestors ) ) {
    1398                 $css_class[] = 'current_page_ancestor';
    1399             }
    1400             if ( $page->ID == $current_page ) {
    1401                 $css_class[] = 'current_page_item';
    1402             } elseif ( $_current_page && $page->ID == $_current_page->post_parent ) {
    1403                 $css_class[] = 'current_page_parent';
    1404             }
    1405         } elseif ( $page->ID == get_option('page_for_posts') ) {
    1406             $css_class[] = 'current_page_parent';
    1407         }
    1408 
    1409         /**
    1410          * Filter the list of CSS classes to include with each page item in the list.
    1411          *
    1412          * @since 2.8.0
    1413          *
    1414          * @see wp_list_pages()
    1415          *
    1416          * @param array   $css_class    An array of CSS classes to be applied
    1417          *                             to each list item.
    1418          * @param WP_Post $page         Page data object.
    1419          * @param int     $depth        Depth of page, used for padding.
    1420          * @param array   $args         An array of arguments.
    1421          * @param int     $current_page ID of the current page.
    1422          */
    1423         $css_classes = implode( ' ', apply_filters( 'page_css_class', $css_class, $page, $depth, $args, $current_page ) );
    1424 
    1425         if ( '' === $page->post_title ) {
    1426             /* translators: %d: ID of a post */
    1427             $page->post_title = sprintf( __( '#%d (no title)' ), $page->ID );
    1428         }
    1429 
    1430         $args['link_before'] = empty( $args['link_before'] ) ? '' : $args['link_before'];
    1431         $args['link_after'] = empty( $args['link_after'] ) ? '' : $args['link_after'];
    1432 
    1433         /** This filter is documented in wp-includes/post-template.php */
    1434         $output .= $indent . sprintf(
    1435             '<li class="%s"><a href="%s">%s%s%s</a>',
    1436             $css_classes,
    1437             get_permalink( $page->ID ),
    1438             $args['link_before'],
    1439             apply_filters( 'the_title', $page->post_title, $page->ID ),
    1440             $args['link_after']
    1441         );
    1442 
    1443         if ( ! empty( $args['show_date'] ) ) {
    1444             if ( 'modified' == $args['show_date'] ) {
    1445                 $time = $page->post_modified;
    1446             } else {
    1447                 $time = $page->post_date;
    1448             }
    1449 
    1450             $date_format = empty( $args['date_format'] ) ? '' : $args['date_format'];
    1451             $output .= " " . mysql2date( $date_format, $time );
    1452         }
    1453     }
    1454 
    1455     /**
    1456      * @see Walker::end_el()
    1457      * @since 2.1.0
    1458      *
    1459      * @param string $output Passed by reference. Used to append additional content.
    1460      * @param object $page Page data object. Not used.
    1461      * @param int    $depth Depth of page. Not Used.
    1462      * @param array  $args
    1463      */
    1464     public function end_el( &$output, $page, $depth = 0, $args = array() ) {
    1465         $output .= "</li>\n";
    1466     }
    1467 
    1468 }
    1469 
    1470 /**
    1471  * Create HTML dropdown list of pages.
    1472  *
    1473  * @since 2.1.0
    1474  * @uses Walker
    1475  */
    1476 class Walker_PageDropdown extends Walker {
    1477     /**
    1478      * @see Walker::$tree_type
    1479      * @since 2.1.0
    1480      * @var string
    1481      */
    1482     public $tree_type = 'page';
    1483 
    1484     /**
    1485      * @see Walker::$db_fields
    1486      * @since 2.1.0
    1487      * @todo Decouple this
    1488      * @var array
    1489      */
    1490     public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
    1491 
    1492     /**
    1493      * @see Walker::start_el()
    1494      * @since 2.1.0
    1495      *
    1496      * @param string $output Passed by reference. Used to append additional content.
    1497      * @param object $page   Page data object.
    1498      * @param int    $depth  Depth of page in reference to parent pages. Used for padding.
    1499      * @param array  $args   Uses 'selected' argument for selected page to set selected HTML attribute for option
    1500      *                       element. Uses 'value_field' argument to fill "value" attribute. See {@see wp_dropdown_pages()}.
    1501      * @param int    $id
    1502      */
    1503     public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) {
    1504         $pad = str_repeat('&nbsp;', $depth * 3);
    1505 
    1506         if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
    1507             $args['value_field'] = 'ID';
    1508         }
    1509 
    1510         $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\"";
    1511         if ( $page->ID == $args['selected'] )
    1512             $output .= ' selected="selected"';
    1513         $output .= '>';
    1514 
    1515         $title = $page->post_title;
    1516         if ( '' === $title ) {
    1517             /* translators: %d: ID of a post */
    1518             $title = sprintf( __( '#%d (no title)' ), $page->ID );
    1519         }
    1520 
    1521         /**
    1522          * Filter the page title when creating an HTML drop-down list of pages.
    1523          *
    1524          * @since 3.1.0
    1525          *
    1526          * @param string $title Page title.
    1527          * @param object $page  Page data object.
    1528          */
    1529         $title = apply_filters( 'list_pages', $title, $page );
    1530         $output .= $pad . esc_html( $title );
    1531         $output .= "</option>\n";
    1532     }
    1533 }
    1534 
    15351324//
    15361325// Attachments
Note: See TracChangeset for help on using the changeset viewer.