WordPress.org

Making WordPress.org

Changeset 4608


Ignore:
Timestamp:
01/05/2017 11:10:51 PM (4 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Add class to REST API handbook reference sub-pages.

Targeted CSS rules are needed for special formatting of reference pages in the REST API handbook.

See #2347.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/handbooks.php

    r4341 r4608  
    4646
    4747        add_filter( 'the_content', array( __CLASS__, 'autolink_credits' ) );
     48
     49        // Add class to REST API handbook reference pages.
     50        add_filter( 'body_class', array( __CLASS__, 'add_rest_api_handbook_reference_class' ) );
    4851
    4952        // Add the handbook's 'Watch' action link.
     
    229232    }
    230233
     234    /**
     235     * Adds class to REST API handbook reference sub-pages.
     236     *
     237     * Due to special formatting of particular pages in the REST API handbook, a
     238     * class is needed to target CSS rules.
     239     *
     240     * @param array $classes Body classes.
     241     * @return array
     242     */
     243    public static function add_rest_api_handbook_reference_class( $classes ) {
     244        if (
     245            is_single()
     246            &&
     247            'rest-api-handbook' === get_query_var( 'current_handbook' )
     248            &&
     249            ( ( $parent = wp_get_post_parent_id( get_the_ID() ) ) && ( 'reference' === get_post( $parent )->post_name ) )
     250        ) {
     251            $classes[] = 'rest-api-handbook-reference';
     252        }
     253
     254        return $classes;
     255    }
     256
    231257} // Devhub_Handbooks
    232258
Note: See TracChangeset for help on using the changeset viewer.