Making WordPress.org


Ignore:
Timestamp:
08/13/2020 11:43:14 PM (6 years ago)
Author:
coreymckrill
Message:

WordPress.org Learn: Sync with GitHub

https://github.com/WordPress/learn/compare/1accd3db38a60230689bdc157f9e82081d35d163...38e7793fd20434d72ca898988d017ba2009fb677

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2020/template-parts/component-breadcrumbs.php

    r10131 r10169  
    1010/**
    1111 * Returns list of workshops based on slug
    12  * 
     12 *
    1313 * @return array|bool
    1414 */
    1515function get_workshop_from_slug( $slug ) {
    16     $args = array(
    17         'name'        => $slug,
    18         'post_type'   => 'workshop',
    19         'post_status' => 'publish',
    20         'numberposts' => 1
    21       );
     16    $args = array(
     17        'name'        => $slug,
     18        'post_type'   => 'workshop',
     19        'post_status' => 'publish',
     20        'numberposts' => 1,
     21    );
    2222
    23     $workshop = get_posts( $args );
     23    $workshop = get_posts( $args );
    2424
    25     return isset( $workshop[ 0 ] ) ? $workshop[ 0 ] : false;
     25    return isset( $workshop[0] ) ? $workshop[0] : false;
    2626}
    2727
    2828/**
    2929 * Returns whether we are viewing a lesson from a workshop
    30  * 
     30 *
    3131 * @param string $referer
    3232 * @return bool
    3333 */
    3434function lesson_came_from_workshop( $referer ) {
    35     return wporg_post_type_is_lesson() && strrpos( $referer, 'workshop' );
     35    return wporg_post_type_is_lesson() && strrpos( $referer, 'workshop' );
    3636}
    3737
    38 $crumbs = [
    39     [
    40         'label' => __( 'Learn Home', 'wporg-learn' ),
    41         'url' => home_url()
    42     ]
    43 ];
     38$crumbs = array(
     39    array(
     40        'label' => __( 'Learn Home', 'wporg-learn' ),
     41        'url'   => home_url(),
     42    ),
     43);
    4444
    4545$referer = wp_get_referer();
    4646
    47 // If we came from a workshop, we want to modify the breadrumbs to bring us back to the workshop 
    48 if( lesson_came_from_workshop( $referer ) ) {
    49     $workshop = get_workshop_from_slug( basename( $referer ) );
     47// If we came from a workshop, we want to modify the breadrumbs to bring us back to the workshop.
     48if ( lesson_came_from_workshop( $referer ) ) {
     49    $workshop = get_workshop_from_slug( basename( $referer ) );
    5050
    51     if( $workshop ) {
    52         array_push( $crumbs, [
    53             'label' => __( 'Workshops', 'wporg-learn' ),
    54             'url' => get_post_type_archive_link( 'workshop' )
    55         ] );
     51    if ( $workshop ) {
     52        array_push( $crumbs, array(
     53            'label' => __( 'Workshops', 'wporg-learn' ),
     54            'url'   => get_post_type_archive_link( 'workshop' ),
     55        ) );
    5656
    57         array_push( $crumbs, [
    58             'label' => $workshop->post_title,
    59             'url' => get_post_permalink( $workshop->ID )
    60         ] );
    61     }
    62 
     57        array_push( $crumbs, array(
     58            'label' => $workshop->post_title,
     59            'url'   => get_post_permalink( $workshop->ID ),
     60        ) );
     61    }
    6362} else {
    6463
    65     // Get information about the post title.
    66     $post_type = get_post_type_object( get_post_type( get_queried_object() ) );
     64    // Get information about the post title.
     65    $cpt_object = get_post_type_object( get_post_type( get_queried_object() ) );
    6766
    68     if( wporg_post_type_is_lesson() ){
    69         array_push( $crumbs, [
    70             'label' => ucfirst( $post_type->labels->name ),
    71             'url' => home_url( $post_type->has_archive  )
    72         ] );
    73     }
     67    if ( wporg_post_type_is_lesson() ) {
     68        array_push( $crumbs, array(
     69            'label' => ucfirst( $cpt_object->labels->name ),
     70            'url'   => home_url( $cpt_object->has_archive ),
     71        ) );
     72    }
    7473}
    7574
    76 array_push( $crumbs, [
    77     'label' => get_the_title(),
    78     'url' => ''
    79 ] );
     75array_push( $crumbs, array(
     76    'label' => get_the_title(),
     77    'url'   => '',
     78) );
    8079?>
    8180
    8281<div class="clearfix">
    83     <div class="bbp-breadcrumb">       
    84     <?php
    85         $crumb_length = count($crumbs);
     82    <div class="bbp-breadcrumb">
     83    <?php
     84    $crumb_length = count( $crumbs );
    8685
    87         for( $x = 0; $x < $crumb_length; $x++ ) {
    88             if( empty( $crumbs[ $x ][ 'url' ] ) ) {
    89                 echo '<span class="bbp-breadcrumb-current">' . $crumbs[ $x ][ 'label' ] . '</span>';
    90             } else {
    91                 echo '<a href="' . $crumbs[ $x ][ 'url' ] .'" class="bbp-breadcrumb-home">';
    92                 echo $crumbs[ $x ][ 'label' ];
    93                 echo '</a>';
    94             }
     86    for ( $x = 0; $x < $crumb_length; $x++ ) {
     87        if ( empty( $crumbs[ $x ]['url'] ) ) {
     88            echo '<span class="bbp-breadcrumb-current">' . esc_html( $crumbs[ $x ]['label'] ) . '</span>';
     89        } else {
     90            echo '<a href="' . esc_url( $crumbs[ $x ]['url'] ) . '" class="bbp-breadcrumb-home">';
     91            echo esc_html( $crumbs[ $x ]['label'] );
     92            echo '</a>';
     93        }
    9594
    96             if( $x < $crumb_length - 1 ) {
    97                 echo ' <span class="bbp-breadcrumb-sep">»</span> ';
    98             }   
    99         }
    100     ?>
    101     </div>
     95        if ( $x < $crumb_length - 1 ) {
     96            echo ' <span class="bbp-breadcrumb-sep">»</span> ';
     97        }
     98    }
     99    ?>
     100    </div>
    102101</div>
Note: See TracChangeset for help on using the changeset viewer.