Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20225 Add classes to body element when on basepage #111

Merged
merged 1 commit into from
Mar 8, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions includes/civicrm.basepage.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ public function basepage_handler( $wp ) {
// tweak admin bar
add_action( 'wp_before_admin_bar_render', array( $this->civi, 'clear_edit_post_menu_item' ) );

// add body classes for easier styling
add_filter( 'body_class', array( $this, 'add_body_classes' ) );

// flag that we have parsed the base page
$this->basepage_parsed = TRUE;

Expand Down Expand Up @@ -327,6 +330,49 @@ public function basepage_template( $template ) {
}


/**
* Add classes to body element when on basepage.
*
* This allows selectors to be written for particular CiviCRM "pages" despite
* them all being rendered on the one WordPress basepage.
*
* @param array $classes The existing body classes
* @return array $classes The modified body classes
*/
public function add_body_classes( $classes ) {

$args = $this->civi->get_request_args();

// bail if we don't have any
if ( is_null( $args['argString'] ) ) {
return $classes;
}

// check for top level - it can be assumed this always 'civicrm'
if ( isset( $args['args'][0] ) AND ! empty( $args['args'][0] ) ) {
$classes[] = $args['args'][0];
}

// check for second level - the component
if ( isset( $args['args'][1] ) AND ! empty( $args['args'][1] ) ) {
$classes[] = $args['args'][0] . '-' . $args['args'][1];
}

// check for third level - the component's configuration
if ( isset( $args['args'][2] ) AND ! empty( $args['args'][2] ) ) {
$classes[] = $args['args'][0] . '-' . $args['args'][1] . '-' . $args['args'][2];
}

// check for fourth level - because well, why not?
if ( isset( $args['args'][3] ) AND ! empty( $args['args'][3] ) ) {
$classes[] = $args['args'][0] . '-' . $args['args'][1] . '-' . $args['args'][2] . '-' . $args['args'][3];
}

return $classes;

}


} // class CiviCRM_For_WordPress_Basepage ends