5pn7ow
Last Updated: February 25, 2016
·
8.85K
· euantor
Irnhmv6

Add new stylesheets to MyBB via PluginLibrary

Frostschutz's PluginLibrary is an amazing resource for MyBB plugin developers of any skill level. It lets you do many common tasks supremely easily and makes sure you follow the best conventions for completing said tasks (such as adding new templates to template groups rather than just as global templates). Since Version 9 PluginLibrary has had a neat new method thanks to a pull request I submitted during the development of MyAlerts: (stylesheet).

The syntax is supremely simple and lets you add, disable and remove stylesheets via your plugin (something which should be supremely useful for those more feature filled plugins):

Global (top of your plugin):

if (!defined("PLUGINLIBRARY"))
{
    define("PLUGINLIBRARY", MYBB_ROOT."inc/plugins/pluginlibrary.php");
}

Activate:

if (!file_exists(PLUGINLIBRARY))
{
    flash_message($lang->myalerts_pluginlibrary_missing, "error");
    admin_redirect("index.php?module=config-plugins");
}

$PL or require_once PLUGINLIBRARY;

if ((int) $PL->version < 9)
{
    flash_message('This plugin requires PluginLibrary 9 or newer', 'error');
    admin_redirect('index.php?module=config-plugins');
}

$stylesheet = 'body { background: black; }
/* Some more CSS... */';

$PL->stylesheet('alerts.css', $stylesheet);

Deactivate:

if (!file_exists(PLUGINLIBRARY))
{
    flash_message($lang->myalerts_pluginlibrary_missing, "error");
    admin_redirect("index.php?module=config-plugins");
}

$PL or require_once PLUGINLIBRARY;

$PL->stylesheet_deactivate('alerts.css');

Uninstall:

if (!file_exists(PLUGINLIBRARY))
{
    flash_message($lang->myalerts_pluginlibrary_missing, "error");
    admin_redirect("index.php?module=config-plugins");
}

$PL or require_once PLUGINLIBRARY;

$PL->stylesheet_delete('alerts.css');

Obviously you can rename "alerts.css" to whatever you wish your stylesheet to be called.

This is by far the easiest way to add stylesheets via your plugins now though. It's completely painless and including PluginLibrary also gives you access to many more useful methods.

Say Thanks
Respond