Making WordPress.org

Changeset 4690


Ignore:
Timestamp:
01/16/2017 02:37:42 AM (10 years ago)
Author:
pento
Message:

Handbook: A handful of tweaks to make the handbook play nicer with o2.

File:
1 edited

Legend:

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

    r4626 r4690  
    132132                add_filter( 'post_class',                         array( $this, 'add_post_class' ) );
    133133                add_filter( 'o2_process_the_content',             array( $this, 'disable_o2_processing' ) );
     134                add_filter( 'o2_application_container',           array( $this, 'o2_application_container' ) );
     135                add_filter( 'o2_view_type',                       array( $this, 'o2_view_type' ) );
     136                add_filter( 'o2_post_fragment',                   array( $this, 'o2_post_fragment' ) );
     137                add_filter( 'comments_open',                      array( $this, 'comments_open', 10, 2 ) );
    134138        }
    135139
     
    354358                        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    355359                        'after_widget'  => '</aside>',
    356                         'before_title'  => '<h2 class="widget-title">',
    357                         'after_title'   => '</h2>',
     360                        'before_title'  => '<h1 class="widget-title">',
     361                        'after_title'   => '</h1>',
    358362                );
    359363
     
    394398        }
    395399
     400        /**
     401         * Use the correct ID for the content container element.
     402         *
     403         * @param string $container The container element ID.
     404         * @return string
     405         */
     406        function o2_application_container( $container ) {
     407                return ( $this->post_type === get_post_type() ) ? '#primary' : $container;
     408        }
     409
     410        /**
     411         * Tell o2 to use the 'single' view type for handbook pages. This removes a lot of the meta
     412         * cruft around the content.
     413         *
     414         * @param string $view_type The o2 view type.
     415         * @return string
     416         */
     417        function o2_view_type( $view_type ) {
     418                return ( $this->post_type === get_post_type() ) ? 'single' : $view_type;
     419        }
     420
     421        /**
     422         * Tell o2 to treat the handbook page the same as it would a normal page.
     423         *
     424         * @param array $post_fragment The o2 post fragment
     425         * @return array
     426         */
     427        function o2_post_fragment( $post_fragment ) {
     428                $post = get_post( $post_fragment['id'] );
     429                if ( ! $post ) {
     430                        return $post_fragment;
     431                }
     432
     433                if ( $post->post_type === $this->post_type ) {
     434                        $post_fragment['isPage'] = true;
     435                }
     436
     437                return $post_fragment;
     438        }
     439
     440        /**
     441         * Don't show the comment form on handbook pages.
     442         *
     443         * @param bool $open Whether the comments are open or not.
     444         * @param WP_Post|int $post_id The current post.
     445         * @return bool
     446         */
     447        function comments_open( $open, $post_id ) {
     448                $post = get_post( $post_id );
     449                if ( ! $post ) {
     450                        return $open;
     451                }
     452
     453                if ( $post->post_type === $this->post_type ) {
     454                        return false;
     455                }
     456
     457                return $open;
     458        }
    396459}
Note: See TracChangeset for help on using the changeset viewer.