Making WordPress.org


Ignore:
Timestamp:
10/14/2021 12:08:48 AM (5 years ago)
Author:
coreymckrill
Message:

WordPress.org Learn: Sync with GitHub

https://github.com/WordPress/learn/compare/bf713ca73b711629febd561298510997ffc2cece...44cf2973a5a7e457cf3ad7e1a093003899a5d081

File:
1 edited

Legend:

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

    r11275 r11278  
    412412                'duration' => 'duration',
    413413                'level'    => 'level',
    414                 'series'   => 'wporg_workshop_series',
    415414                'topic'    => 'topic',
    416415                'type'     => 'instruction_type',
    417416        );
     417
     418        $series_slug = wporg_learn_get_series_taxonomy_slug( $query->get( 'post_type' ) );
     419        if ( $series_slug ) {
     420                $entity_map['series'] = $series_slug;
     421        }
    418422
    419423        $meta_query = array();
     
    771775
    772776/**
    773  * Get the series taxonomy term object for a workshop post.
    774  *
    775  * @param int|WP_Post|null $workshop
     777 * Get the slug for the series taxonomy for a given post type.
     778 *
     779 * @param string $post_type
     780 *
     781 * @return false|string
     782 */
     783function wporg_learn_get_series_taxonomy_slug( $post_type ) {
     784        $tax_slug = false;
     785
     786        switch ( $post_type ) {
     787                case 'lesson-plan':
     788                        $tax_slug = 'wporg_lesson_plan_series';
     789                        break;
     790                case 'wporg_workshop':
     791                        $tax_slug = 'wporg_workshop_series';
     792                        break;
     793        }
     794
     795        return $tax_slug;
     796}
     797
     798/**
     799 * Get the series taxonomy term object for a post.
     800 *
     801 * @param int|WP_Post|null $post
    776802 *
    777803 * @return WP_Term|bool
    778804 */
    779 function wporg_workshop_series_get_term( $workshop = null ) {
    780         $workshop = get_post( $workshop );
    781 
    782         if ( ! $workshop instanceof WP_Post ) {
     805function wporg_learn_series_get_term( $post = null ) {
     806        $post = get_post( $post );
     807
     808        if ( ! $post instanceof WP_Post ) {
    783809                return false;
    784810        }
    785811
    786         $terms = wp_get_post_terms( $workshop->ID, 'wporg_workshop_series' );
     812        $tax_slug = wporg_learn_get_series_taxonomy_slug( get_post_type( $post ) );
     813        $terms = wp_get_post_terms( $post->ID, $tax_slug );
    787814
    788815        if ( empty( $terms ) ) {
     
    794821
    795822/**
    796  * Given a workshop post in a series, get all the workshop posts in the series.
    797  *
    798  * @param int|WP_Post|null $workshop
     823 * Given a post in a series, get all the posts in the series.
     824 *
     825 * @param int|WP_Post|null $post
    799826 *
    800827 * @return WP_Post[]
    801828 */
    802 function wporg_workshop_series_get_siblings( $workshop = null ) {
    803         $term = wporg_workshop_series_get_term( $workshop );
     829function wporg_learn_series_get_siblings( $post = null ) {
     830        $post_type = get_post_type( $post );
     831        $term = wporg_learn_series_get_term( $post );
    804832
    805833        if ( ! $term ) {
     
    808836
    809837        $args = array(
    810                 'post_type'      => 'wporg_workshop',
     838                'post_type'      => $post_type,
    811839                'post_status'    => 'publish',
    812840                'posts_per_page' => 999,
     
    814842                'tax_query'      => array(
    815843                        array(
    816                                 'taxonomy' => 'wporg_workshop_series',
     844                                'taxonomy' => wporg_learn_get_series_taxonomy_slug( $post_type ),
    817845                                'terms'    => $term->term_id,
    818846                        ),
     
    824852
    825853/**
    826  * Given a workshop post in a series, get an adjacent workshop post in the series.
     854 * Given a post in a series, get an adjacent post in that series.
    827855 *
    828856 * @param string           $which    Which adjacent post to retrieve. 'previous' or 'next'.
    829  * @param int|WP_Post|null $workshop
     857 * @param int|WP_Post|null $post
    830858 *
    831859 * @return WP_Post|bool
    832860 */
    833 function wporg_workshop_series_get_adjacent( $which, $workshop = null ) {
    834         if ( ! $workshop instanceof WP_Post ) {
    835                 $workshop = get_post( $workshop );
    836         }
    837 
    838         $siblings    = wporg_workshop_series_get_siblings( $workshop );
     861function wporg_learn_series_get_adjacent( $which, $post = null ) {
     862        if ( ! $post instanceof WP_Post ) {
     863                $post = get_post( $post );
     864        }
     865
     866        $siblings    = wporg_learn_series_get_siblings( $post );
    839867        $sibling_ids = wp_list_pluck( $siblings, 'ID' );
    840         $index       = array_search( $workshop->ID, $sibling_ids, true );
     868        $index       = array_search( $post->ID, $sibling_ids, true );
    841869
    842870        if ( false === $index ) {
Note: See TracChangeset for help on using the changeset viewer.