Making WordPress.org

Ticket #1671: 1671.5.patch

File 1671.5.patch, 6.4 KB (added by keesiemeijer, 10 years ago)

Add handbook query vars to the current query

  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/extras.php

     
    9696 * @return string
    9797 */
    9898function wporg_filter_archive_excerpt( $excerpt ) {
    99         if ( ! is_single() && ! wporg_is_handbook() ) {
     99        if ( ! is_single() && ! get_query_var( 'is_handbook' ) ) {
    100100
    101101                $post_id = get_the_ID();
    102102                $type    = get_post_type_object( get_post_type( $post_id ) )->labels->singular_name;
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/handbooks.php

     
    3434         * @access public
    3535         */
    3636        public static function do_init() {
     37                add_filter( 'query_vars',  array( __CLASS__, 'add_query_vars' ) );
     38
     39                add_action( 'pre_get_posts',  array( __CLASS__, 'pre_get_posts' ), 9 );
     40
    3741                add_action( 'after_switch_theme', array( __CLASS__, 'add_roles' ) );
    3842
    3943                add_filter( 'user_has_cap', array( __CLASS__, 'adjust_handbook_editor_caps' ), 11 );
     
    5458        }
    5559
    5660        /**
     61         * Add public query vars for handbooks.
     62         *
     63         * @param array   $public_query_vars The array of whitelisted query variables.
     64         * @return array Array with public query vars.
     65         */
     66        public static function add_query_vars( $public_query_vars ) {
     67                $public_query_vars['is_handbook'] = false;
     68                $public_query_vars['current_handbook'] = false;
     69                $public_query_vars['current_handbook_home_url'] = false;
     70                $public_query_vars['current_handbook_name'] = '';
     71                return $public_query_vars;
     72        }
     73
     74        /**
     75         * Add handbook query vars to the current query.
     76         *
     77         * @param \WP_Query $query
     78         */
     79        public static function pre_get_posts( $query ) {
     80                $is_handbook = function_exists( 'wporg_is_handbook' ) ? wporg_is_handbook() : false;
     81                $query->set( 'is_handbook', $is_handbook );
     82
     83                $current_handbook = function_exists( 'wporg_get_current_handbook' ) ? wporg_get_current_handbook() : false;
     84                $query->set( 'current_handbook', $current_handbook );
     85
     86                $current_handbook_home_url = function_exists( 'wporg_get_current_handbook_home_url' ) ? wporg_get_current_handbook_home_url() : false;
     87                $query->set( 'current_handbook_home_url', $current_handbook_home_url );
     88
     89                $current_handbook_name = function_exists( 'wporg_get_current_handbook_name' ) ? wporg_get_current_handbook_name() : '';
     90                $query->set( 'current_handbook_name', $current_handbook_name );
     91        }
     92
     93        /**
    5794         * If a syntax highlighted code block exceeds a given number of lines, wrap the
    5895         * markup with other markup to trigger the code expansion/collapse JS handling
    5996         * already implemented for the code reference.
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/redirects.php

     
    3232         * Redirects a search query with only one result directly to that result.
    3333         */
    3434        public static function redirect_single_search_match() {
    35                 if ( is_search() && ! wporg_is_handbook() && 1 == $GLOBALS['wp_query']->found_posts ) {
     35                if ( is_search() && ! get_query_var( 'is_handbook' ) && 1 == $GLOBALS['wp_query']->found_posts ) {
    3636                        wp_redirect( get_permalink( get_post() ) );
    3737                        exit();
    3838                }
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/search.php

     
    4343
    4444                // Separates searches for handbook pages from non-handbook pages depending on
    4545                // whether the search was performed within context of a handbook page or not.
    46                 if ( wporg_is_handbook() ) {
     46                if ( get_query_var( 'is_handbook' ) ) {
    4747                        // Search only in current handbook post type.
    4848                        // Just to make sure. post type should already be set.
    4949                        $query->set( 'post_type', wporg_get_current_handbook() );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content.php

     
    6262         */
    6363        public static function scripts_and_styles() {
    6464                if ( is_singular() ) {
    65                         if ( '0' != get_comments_number() || \DevHub\post_type_has_source_code() || wporg_is_handbook_post_type() ) {
     65                        if ( '0' != get_comments_number() || \DevHub\post_type_has_source_code() || get_query_var( 'is_handbook' ) ) {
    6666                                wp_enqueue_script( 'wporg-developer-function-reference', get_template_directory_uri() . '/js/function-reference.js', array( 'jquery', 'syntaxhighlighter-core', 'syntaxhighlighter-brush-php' ), '20150319', true );
    6767                                wp_enqueue_style( 'syntaxhighlighter-core' );
    6868                                wp_enqueue_style( 'syntaxhighlighter-theme-default' );
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/searchform.php

     
    3434<?php } ?>
    3535
    3636        <?php
    37                 $is_handbook = wporg_is_handbook();
    38                 $search_url  = $is_handbook ? wporg_get_current_handbook_home_url() : home_url( '/' );
     37                $is_handbook = get_query_var( 'is_handbook' );
     38                $search_url  = get_query_var( 'current_handbook_home_url' );
     39                $search_url  = $search_url ? $search_url : home_url( '/' );
    3940                $form_class  = $is_handbook ? ' searchform-handbook' : '';
    4041        ?>
    4142