Support » Plugin: bbp style pack » Missing dependency (bbp-default)

  • Resolved Bart Kuijper



    There’s an issue I’ve run into that’s due to the theme I’m using (evolve).

    The theme deregisters the bbp-default style in wp-content/themes/evolve/inc/bbpress-support.php on line 11. If I comment this line out, then obviously bbp-default gets loaded, but this also clashes with the theme’s styling, resulting in a jumbled mess.

    But the bbp style pack plugin requires the bbp-default style as a dependency in wp-content/plugins/bbp-style-pack/includes/generate_css.php on lines 50 and 52. With bbp-default deregistered by my theme, bbp’s CSS never gets loaded. The code on line 52 is the code that is run in my case:

    else wp_register_style('bsp', plugins_url('css/bspstyle.css',dirname(__FILE__) ), array( 'bbp-default' ), $bsp_ver, 'screen');

    If I remove the dependency like so:

    else wp_register_style('bsp', plugins_url('css/bspstyle.css',dirname(__FILE__) ), array(), $bsp_ver, 'screen');

    Then bbp’s CSS works as intended.

    My question is what would be the best way to solve this?

    I can’t re-register the bbp-default style, because that messes up the layout. But editing the bbp plugin files to remove the dependency will break on the next plugin update. Could I maybe load a dummy bbp-default style just to satisfy bbp’s dependncy?

    Or is there perhaps a bbp setting I overlooked that allows for disabling this dependency?

    Thanks for your time, kind regards,

    Bart Kuijper

    • This topic was modified 1 year, 1 month ago by Bart Kuijper. Reason: typo's
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Robin W


    hmm. I’d try this in your child theme functions file, untested, but in theory removes my the ‘bsp’ style and then adds a new one that is not bbpress dependant

    add_action ('plugins_loaded' , 'rew_redo' ) ;
    function rew_redo () {
    wp_dequeue_style( 'bsp' )
    add_action('wp_enqueue_scripts', 'rew_enqueue_css');
    function rew_enqueue_css() {
    	global $bsp_css_location ;
    	$bsp_ver = get_option('bsp_version') ;
    	//register style so that it runs after bbpress (bbp-default)
    	if (!empty ($bsp_css_location ['activate css location']) && !empty($bsp_css_location ['location'])) {
    		$location = $bsp_css_location ['location'] ;
    			// if it starts with '/' -  remove
    		if (0 === strpos($location, '/')) {
    			$location = substr( $location, 1, strlen($location) ) ;
    		// if it doesn't end with a '/' add one
    		if (substr( $location, strlen($location)-1, strlen($location) ) !== '/') {
    			$location = $location.'/' ;
    		$location = home_url().'/'.$location ;
    		wp_register_style('bsp', $location.'bspstyle.css', array( 'bbp-default' ), $bsp_ver, 'screen');
    	//***NOTE YOU MAY NEED TO AMEND THE URL HERE TO YOURS **** as plugins_url won't work or use the location but above
    	else wp_register_style('bsp', plugins_url('css/bspstyle.css',dirname(__FILE__) ), array( '' ), $bsp_ver, 'screen');
    	wp_enqueue_style( 'bsp');
    • This reply was modified 1 year, 1 month ago by Robin W.
    Thread Starter Bart Kuijper


    Thank you very much for your reply, your code, your effort, and your time!

    I couldn’t get bbp-default to register, not even when giving my wp_enqueue_scripts hook a priority of PHP_INT_MAX to make sure it goes last.

    So then I had another look at when my theme deregisters bbp-default. Turns out the evolve theme deregisters the style using the wp_print_styles hook that fires later than wp_enqueue_scripts. Note: since WP 3.3 the wp_print_styles hook isn’t supposed to be used for enqueueing scripts and styles for the frontend. (source)

    Since I’m not using a child theme currently, I decided to create a small Must-Use plugin that fixes the issue by registering the bbp-default style with its source set to false. This way the bbp-default style doesn’t actually get loaded and so doesn’t interfere with my theme, but it does satisfy this plugin’s bsp style dependency.

    There’s of course some fluff in the mu-plugin (file header, comments) which I won’t all paste here. The actual magic happens in just these few lines of code anyway. Again I’m using a priority of PHP_INT_MAX, since the evolve theme uses this same hook to deregister the style and I want to make sure my hook fires last.

    add_action( 'wp_print_styles', 'fix_bbp_dependency', PHP_INT_MAX, 0 );
    function fix_bbp_dependency() {
    	wp_register_style( 'bbp-default', false );
    • This reply was modified 1 year, 1 month ago by Bart Kuijper. Reason: typo's & marked as resolved
    • This reply was modified 1 year, 1 month ago by Bart Kuijper. Reason: corrected an ambiguous sentence
    Plugin Author Robin W


    great – love the ingenuity !!

    Thread Starter Bart Kuijper


    Thanks for the compliment!

    I have one more thing to add to the code I posted. In order to make sure the BBP Style Pack can overrule my theme’s CSS, I’ve added some of my theme’s styles as a dependency to my bbp-default dummy style, in order to ensure that the bsp style gets loaded after my theme’s CSS.

    wp_register_style( 'bbp-default', false, array( 'evolve-style', 'evolve-bootstrap' ) );

    Just wanted to add that for completeness, in case anyone with a similar issue comes across this topic.

    Plugin Author Robin W


    great – thanks for posting – I’ve bookmarked in case this comes up again

    Thread Starter Bart Kuijper


    Alright one more addition, this time an alternative method. I created this because the previously posted method only worked to an extent. Certain bbp-style-pack options still didn’t work, probably because they rely on overruling parts of the bbpress.css which isn’t being loaded.

    The code is again specific to the evolve theme, but it should be easy enough to adapt to a different theme.

    How it works: the evolve theme hooks into wp_print_styles to deregister the bbp-default style. So we hook into that same action with a lower priority (PHP_INT_MIN) and unhook evolve’s function before it gets a chance to run. An important note about removing hooks: you don’t get an error message if removing the hook failed, and in order to succesfully remove a hook you need to specify the exact priority that was used to add the hook in the first place. Also in this case the theme’s hooked function is luckily not inside a class, so all I need is the function’s name.

    My code then searches through the enqueued styles and injects some dependencies to make the bbp-default style load after the theme’s CSS.

    add_action( 'wp_print_styles', 'style_dependency_fix', PHP_INT_MIN, 0 );
    function style_dependency_fix() {
    	remove_action( 'wp_print_styles', 'evolve_deregister_bbpress_styles', 15 );
    	global $wp_styles;
    	foreach ( $wp_styles->queue as $style ) :
    		if ( 'bbp-default' === $wp_styles->registered[ $style ]->handle ) {
    			$wp_styles->registered[ $style ]->deps = array_merge( $wp_styles->registered[ $style ]->deps, array( 'evolve-style', 'evolve-bootstrap' ) );
    • This reply was modified 1 year, 1 month ago by Bart Kuijper. Reason: typo
    Plugin Author Robin W



Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Missing dependency (bbp-default)’ is closed to new replies.