Proper way to reference assets from CSS files in plugins.
Posted: 28 Sep 2015, 14:24
With the advent of mantis 1.3 and increased security, it is a little bit more involved to have access to client assets such as images, declared in CSS files included in plugins. The plugin file handling functions offer plugin_file() a function that takes files from the plugin directory and streams them securely through the mantis layer. However this is not available in client-only files such as CSS. I know that the result of plugin_file() is a path to the following php page: plugin_file.php?file=PluginName/path_to_file.
My question is: Is it OK to directly reference plugin_file.php? For example:
PluginName/files/mystyle.css
Or is the only way to have to create a php file with a text/css header in order to call the actual function:
PluginName/pages/mystyle_css.php
My concern lies on whether plugin_file.php is OK to call directly.
Thanks for your help.
My question is: Is it OK to directly reference plugin_file.php? For example:
PluginName/files/mystyle.css
Code: Select all
.myclass {
background-image: url("plugin_file.php?file=PluginName/mybackground.png");
}PluginName/pages/mystyle_css.php
Code: Select all
<?php header("Content-type: text/css", true); ?>
.myclass {
background-image: url("<?php echo plugin_file('mybackground.png') ?>");
}Thanks for your help.