Making WordPress.org


Ignore:
Timestamp:
05/31/2016 08:10:44 PM (10 years ago)
Author:
coffee2code
Message:

developer.wordpress.org: Set handbook-related flags and data once via query variables rather than assuming (or always checking for) the presence of handbook plugin template tags.

Specifically sets 'is_handbook', 'current_handbook', 'current_handbook_home_url', 'current_handbook_name'.

Props keesiemeijer.
Fixes #1671.

File:
1 edited

Legend:

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

    r3239 r3281  
    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
     
    5256                        add_filter( 'syntaxhighlighter_htmlresult', array( __CLASS__, 'syntaxhighlighter_htmlresult' ) );
    5357                }
     58        }
     59
     60        /**
     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
     72                return $public_query_vars;
     73        }
     74
     75        /**
     76         * Add handbook query vars to the current query.
     77         *
     78         * @param \WP_Query $query
     79         */
     80        public static function pre_get_posts( $query ) {
     81                $is_handbook = function_exists( 'wporg_is_handbook' ) ? wporg_is_handbook() : false;
     82                $query->set( 'is_handbook', $is_handbook );
     83
     84                $current_handbook = function_exists( 'wporg_get_current_handbook' ) ? wporg_get_current_handbook() : false;
     85                $query->set( 'current_handbook', $current_handbook );
     86
     87                $current_handbook_home_url = function_exists( 'wporg_get_current_handbook_home_url' ) ? wporg_get_current_handbook_home_url() : false;
     88                $query->set( 'current_handbook_home_url', $current_handbook_home_url );
     89
     90                $current_handbook_name = function_exists( 'wporg_get_current_handbook_name' ) ? wporg_get_current_handbook_name() : '';
     91                $query->set( 'current_handbook_name', $current_handbook_name );
    5492        }
    5593
Note: See TracChangeset for help on using the changeset viewer.