Making WordPress.org

Changeset 3482


Ignore:
Timestamp:
06/19/2016 09:55:15 PM (9 years ago)
Author:
coffee2code
Message:

Handbook plugin: Hook 'body_class' and 'post_class' to add generic 'handbook' versions of classes so designs need not target post type specific classes.

File:
1 edited

Legend:

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

    r3481 r3482  
    126126        add_action( 'p2_action_links',                    array( $this, 'disable_p2_resolved_posts_action_links' ) );
    127127        add_action( 'admin_init',                         array( $this, 'add_name_setting' ) );
     128        add_filter( 'body_class',                         array( $this, 'add_body_class' ) );
     129        add_filter( 'post_class',                         array( $this, 'add_post_class' ) );
     130    }
     131
     132    /**
     133     * Adds 'post-type-archive-handbook' or 'single-handbook' class to body tag
     134     * when appropriate.
     135     *
     136     * @param array $classes Array of body classes.
     137     * @return array
     138     */
     139    function add_body_class( $classes ) {
     140        if ( is_post_type_archive( $this->post_type )  ) {
     141            $classes[] = 'post-type-archive-handbook';
     142        } elseif ( is_singular( $this->post_type ) ) {
     143            $classes[] = 'single-handbook';
     144        }
     145
     146        return $classes;
     147    }
     148
     149    /**
     150     * Adds 'type-handbook' class to the list of post classes to a handbook post
     151     * when appropriate.
     152     *
     153     * @param array $classes Array of post classes.
     154     * @return array
     155     */
     156    function add_post_class( $classes ) {
     157        if ( $this->post_type === get_post_type() ) {
     158            $classes[] = 'type-handbook';
     159        }
     160
     161        return $classes;
    128162    }
    129163
Note: See TracChangeset for help on using the changeset viewer.