MyBB Community Forums

Full Version: How to have plug-in add css to global.css on activation?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to figure out how to add css to global.css for all themes. I would rather add the css to the style sheet rather then inline. I also don't want to create my own css file because I don't want the page to have to make another request for a small css file. I am sure mybb has functions for this, but I am sure which ones to use and what the query should be to grab all themes global.css files.

I found the function insert_into_css($new_css, $selector="", $css="", $class_id=""), but I am not sure what $selector is used and what needs to be passed. The function is stored in admin/inc/functions_themes.php.
Anyone?
I'll try and explain the function as best I can in the circumstance...

$new_css is the the new code you want to add.
$selector can remain blank (I think it's used for the ajax CSS basic mode)
$css is the existing CSS to replace
$class_id is an existing CSS rule - leave this blank and the rule will be added to the file instead of replacing the existing rule.

So we can do this (where $new_css is CSS rules):

		$new_changes = insert_into_css($new_css, "", "global.css");
		$updated_stylesheet = array(
			"stylesheet" => $db->escape_string(unfix_css_urls($new_changes)),
			"lastmodified" => TIME_NOW
		);
		$db->update_query("themestylesheets", $updated_stylesheet, "sid='{$sid}'");

I think it works like that. I've just taken a look at the function and how it's used, I haven't actually tried to use it at all!
and how to edit global.css by some code in plugin?
example i want to replace ".apple{" whith ".apple{font-size:12px;"
LightbulbHeart