Making WordPress.org

Changeset 6085


Ignore:
Timestamp:
11/07/2017 10:35:12 PM (7 years ago)
Author:
coffee2code
Message:

Handbook plugin: Add compatibility with o2 to override its default post navigation handling.

Fixes #2871.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/navigation.php

    r6084 r6085  
    3131            self::$using_pages_widget = true;
    3232        }
     33
     34        // Override o2 navigation defaults.
     35        add_filter( 'o2_post_fragment', array( __CLASS__, 'o2_post_fragment' ), 10, 2 );
     36    }
     37
     38    /**
     39     * Overrides the o2 post fragment data to use data pertaining to the post
     40     * navigation handled by this plugin rather than o2's default post
     41     * navigation presumptions.
     42     *
     43     * @param array $fragment The post fragments used by o2's templates.
     44     * @param int   $post_id  The post ID.
     45     * @return array
     46     */
     47    public static function o2_post_fragment( $fragment, $post_id ) {
     48        $prev = $next = false;
     49
     50        if ( self::$using_pages_widget ) {
     51            $adjacent = self::get_adjacent_posts_via_handbook_pages_widget( $post_id );
     52        } else {
     53            $adjacent = self::get_adjacent_posts_via_menu( $menu_name, $post_id );
     54        }
     55
     56        // If an array wasn't returned, then handbook navigation does not apply.
     57        if ( ! is_array( $adjacent ) ) {
     58            return $fragment;
     59        }
     60
     61        list( $prev, $next ) = $adjacent;
     62
     63        $fragment['hasPrevPost']   = ! empty( $prev );
     64        $fragment['prevPostTitle'] = $prev ? $prev->title : '';
     65        $fragment['prevPostURL']   = $prev ? $prev->url   : '';
     66        $fragment['hasNextPost']   = ! empty( $next );
     67        $fragment['nextPostTitle'] = $next ? $next->title : '';
     68        $fragment['nextPostURL']   = $next ? $next->url   : '';
     69
     70        return $fragment;
    3371    }
    3472
Note: See TracChangeset for help on using the changeset viewer.