diff --git a/csshelper.php b/csshelper.php index 609eb92818a2812abbc62dd127b053fc016ede71..6030ea3ea191084d0cac61d8d5dbc86258316fae 100644 --- a/csshelper.php +++ b/csshelper.php @@ -139,7 +139,45 @@ function csshelper_civicrm_preProcess($formName, &$form) { */ +/*Enqueue default CiviCRM CSS in admin. Create a filter to allow themes and other plugins to overrride */ +function csshelper_deregister_civicrm_admin_styles() { + //Bail if not in Admin + if ( ! is_admin() ) return; + + // Bail if admin css is disabled by CAU + if ( csshelper_cau_has_disabled_admin_css() ) return; + + // Disable natively. + $url = CRM_Core_Resources::singleton()->getUrl( 'civicrm', 'css/civicrm.css', true ); + $registration = CRM_Core_Region::instance( 'html-header' )->get( $url ); + if ( ! empty( $registration ) ) { + CRM_Core_Region::instance( 'html-header' )->update( $url, array( 'disabled' => true ) ); + + } +} + +if ( function_exists( 'civi_wp' ) ) { + add_action( 'admin_head', 'csshelper_deregister_civicrm_admin_styles', 9 ); +} + + +function csshelper_register_admin_civicrm_styles() { + if ( ! function_exists( 'civi_wp' ) ) { + return; + } + // Bail if admin css is disabled by CAU + if ( csshelper_cau_has_disabled_admin_css() ) { + return; + } + $tc_civi_css_admin = ( plugin_dir_url( 'civicrm' ) . 'civicrm/civicrm/css/civicrm.css' ); + $tc_civi_css_admin = apply_filters( 'tc_civicss_override_admin', $tc_civi_css_admin ); + wp_enqueue_style( 'tad_admin_civicrm', $tc_civi_css_admin ); +} + +if ( function_exists( 'civi_wp' ) ) { + add_action( 'admin_enqueue_scripts', 'csshelper_register_admin_civicrm_styles' ); +} /** * Disable CiviCRM's default CSS on front end. @@ -197,7 +235,21 @@ function csshelper_cau_has_disabled_css() { if ( ! function_exists('civicrm_au') ) return false; // Get setting and return as boolean. - $disabled = civicrm_au()->single->setting_get( 'css_admin', '0' ); + $disabled = civicrm_au()->single->setting_get( 'css_default', '0' ); return ($disabled == '1') ? true : false; +} + +/** + * Check if CAU has disabled Default CSS in admnin. + */ +function csshelper_cau_has_disabled_admin_css() { + + // If there's no CAU, it can't have done so. + if ( ! function_exists('civicrm_au') ) return false; + + // Get setting and return as boolean. + $disabled = civicrm_au()->single->setting_get( 'css_admin', '0' ); + return ($disabled == '1') ? true : false; + } \ No newline at end of file