WP-CRM removes admin body classes, breaking other plugins
-
WP-CRM is removing admin body classes added by other plugins using the filter ‘admin_body_class’. This breaks any other plugins which rely on these classes.
The problem is in two places. The first is in /lib/class_core.php, line 151:
add_filter( "admin_body_class", create_function( '', "return WP_CRM_Core::admin_body_class(); " ) );
This does not allow $classes to be passed in. It should be:
add_filter( "admin_body_class", array( 'WP_CRM_Core', 'admin_body_class' ) );
The second place is in the same file, stating at line 909. You have:
static function admin_body_class() { global $current_screen, $wp_crm_user, $current_user; $classes = array(); switch ( $current_screen->id ) { case 'toplevel_page_wp_crm': case 'crm_page_wp_crm_settings': $classes[ ] = 'wp_crm'; break; case 'crm_page_wp_crm_add_new': $classes[ ] = 'wp_crm'; if ( $wp_crm_user ) { if ( $current_user->data->ID == $wp_crm_user[ 'ID' ][ 'default' ][ 0 ] ) { $classes[ ] = 'wp_crm_my_profile'; } $classes[ ] = 'wp_crm_existing_user'; } else { $classes[ ] = 'wp_crm_new_user'; } break; } if ( !empty( $classes ) && is_array( $classes ) ) { return implode( ' ', $classes ); } }
But this does not pass in $classes. Instead you define $classes as an empty array, fill in the classes you want, and return only this. This overwrites any classes that already existed prior to your filter, removing them. What you should have is something like this:
static function admin_body_class( $classes ) { global $current_screen, $wp_crm_user, $current_user; $new_classes = array(); switch ( $current_screen->id ) { case 'toplevel_page_wp_crm': case 'crm_page_wp_crm_settings': $new_classes[ ] = 'wp_crm'; break; case 'crm_page_wp_crm_add_new': $new_classes[ ] = 'wp_crm'; if ( $wp_crm_user ) { if ( $current_user->data->ID == $wp_crm_user[ 'ID' ][ 'default' ][ 0 ] ) { $new_classes[ ] = 'wp_crm_my_profile'; } $new_classes[ ] = 'wp_crm_existing_user'; } else { $new_classes[ ] = 'wp_crm_new_user'; } break; } if ( !empty( $new_classes ) && is_array( $new_classes ) ) { $classes = $classes . ' ' . implode( ' ', $new_classes ); } return $classes; }
It’s very important that you accept $classes as input. Then you can append what you need without breaking other plugins.
- The topic ‘WP-CRM removes admin body classes, breaking other plugins’ is closed to new replies.