I would like to load a css file in my Wordpress plugin by php. First I tried file_get_contents:
$stylesheet = file_get_contents(plugins_url('assets/css/fonts.css', __FILE__ ));
But than I get this error:
failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
I noticed that one has to enable Allow_url_fopen in php.ini (but I also read about this being a security risk).
Is there a WordPress function to load e.g. a txt file and store its content in a variable?
EDIT: I would like to parse a CSS file and get all its font-families.
<?php
function my_fonts() {
$stylesheet = file_get_contents('../assets/css/fonts.css');
$rows = explode("\n", $stylesheet);
array_shift($rows);
$fonts = array();
foreach($rows as $row => $data)
{
// Find all available font-families
$regex = '#font\-family:(.*)#';
preg_match($regex, $data, $output);
if($output){
$font = str_replace(array('font-family:', '\'', ';'), '', $output[0]);
$fonts[] = $font;
}
}
// Remove dublicates
$fonts = array_unique($fonts);
print_r($fonts);
}
?>