• Hi

    I was debugging a site for a customer of ours who also uses the WP-CRM plugin when I found a problem in how your plugin handles the admin_body_class filter.

    In this file: ~/wp-content/plugins/wp-crm/core/class_core.php

    This line:

    add_filter( "admin_body_class", create_function( '', "return WP_CRM_Core::admin_body_class(); " ) );

    Should be changed to:

    add_filter( "admin_body_class", array( 'WP_CRM_Core', 'admin_body_class' ) );

    And your admin_body_class() method should return $classes regardless if it’s empty or not. It should not do a conditional return. Also, the admin_body_class() method should accept $classes as an argument.

    This code:

    static function admin_body_class() {
        global $current_screen, $wp_crm_user, $current_user;
    
        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 );
        }
    
      }

    Should be changed to this:

    static function admin_body_class( $classes ) {
    	global $current_screen, $wp_crm_user, $current_user;
    
    	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;
    
    	}
    
    	return $classes;
    
    }

    I hope this helps!

    Thanks,
    Eric

    https://wordpress.org/plugins/wp-crm/

Viewing 1 replies (of 1 total)
  • THANK YOU datafeedr! This makes the wordpress “users” page work again as it had been broken by the latest upgrade of the plugin.

    Before your code fix, if you searched for a user in “users” and then clicked on “edit” you would be thrown out to the outside world of the site. Now it works as expected.

    Respect.

Viewing 1 replies (of 1 total)
  • The topic ‘Improper use of admin_body_class filter’ is closed to new replies.