Making WordPress.org


Ignore:
Timestamp:
07/30/2014 10:08:42 PM (12 years ago)
Author:
coffee2code
Message:

Code Reference: fixes for, and selective activation of, handbooks

  • Landing page:
    • Permit members of site to access the page
    • Set proper links to handbooks
    • Don't display the page content
  • Redirect naked '/handbook/' requests to home page
  • Remove 'Handbook' from handbook breadcrumbs
  • Base site section title for handbooks on is_post_type_archive()
File:
1 edited

Legend:

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

    r771 r773  
    4949        add_action( 'pre_get_posts', __NAMESPACE__ . '\\pre_get_posts' );
    5050        add_action( 'template_redirect', __NAMESPACE__ . '\\redirect_single_search_match' );
     51        add_action( 'template_redirect', __NAMESPACE__ . '\\redirect_handbook' );
    5152        add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\\theme_scripts_styles' );
    5253        add_filter( 'post_type_link', __NAMESPACE__ . '\\method_permalink', 10, 2 );
     
    6364
    6465        add_filter( 'breadcrumb_trail_items',  __NAMESPACE__ . '\\breadcrumb_trail_items', 10, 2 );
     66        add_filter( 'breadcrumb_trail_items',  __NAMESPACE__ . '\\breadcrumb_trail_remove_handbook', 10, 2 );
    6567
    6668        treat_comments_as_examples();
     
    9496        // Unset the last element since it shifted up in trail hierarchy
    9597        unset( $items[4] );
     98
     99        return $items;
     100}
     101
     102/**
     103 * Removes the 'Handbook' segment of the breakcrumb, when present.
     104 *
     105 * There is no handbook page or listing at present.
     106 *
     107 * @param  array $items The breadcrumb trail items
     108 * @param  array $args  Original arg
     109 * @return array
     110 */
     111function breadcrumb_trail_remove_handbook( $items, $args ) {
     112        if ( false !== strpos( $items[1], '>Handbook</a>' ) ) {
     113                array_splice( $items, 1, 1 );
     114        }
    96115
    97116        return $items;
     
    474493
    475494/**
     495 * Redirects a naked handbook request to home.
     496 */
     497function redirect_handbook() {
     498        if ( 'handbook' == get_query_var( 'name' ) && ! get_query_var( 'post_type ' ) ) {
     499                wp_redirect( home_url() );
     500                exit();
     501        }
     502}
     503
     504/**
    476505 * Makes phpDoc @link references clickable.
    477506 *
Note: See TracChangeset for help on using the changeset viewer.