Skip to content

Commit

Permalink
Fix header js and css for wordpress
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Mar 7, 2016
1 parent 657b584 commit 88d7c29
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/Wordpress/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use JBZoo\CrossCMS\AbstractHeader;
use JBZoo\CrossCMS\Cms;
use JBZoo\Utils\Str;

/**
* Class Header
Expand Down Expand Up @@ -78,16 +79,16 @@ public function noindex()
*/
public function jsFile($file)
{
$handle = uniqid('crosscms-js-', true);
wp_enqueue_script($handle, $file);
$handle = 'crosscms-js-' . md5($file);
\wp_enqueue_script($handle, $file);
}

/**
* {@inheritdoc}
*/
public function cssFile($file)
{
$handle = uniqid('crosscms-css-', true);
$handle = 'crosscms-css-' . md5($file);
\wp_enqueue_style($handle, $file);
}

Expand All @@ -96,24 +97,14 @@ public function cssFile($file)
*/
public function jsCode($code)
{
$code = sprintf('<script>%s</script>' . PHP_EOL, $code);
$filter = $this->_cms['env']->isAdmin() ? 'admin_print_scripts' : 'wp_print_scripts';

add_action($filter, function () use ($code) {
echo $code;
}, 30);
echo '<script type="text/javascript">' . PHP_EOL . $code . PHP_EOL . '</script>' . PHP_EOL;
}

/**
* {@inheritdoc}
*/
public function cssCode($code)
{
$code = sprintf('<style>%s</style>' . PHP_EOL, $code);
$filter = $this->_cms['env']->isAdmin() ? 'admin_print_styles' : 'wp_print_styles';

add_action($filter, function () use ($code) {
echo $code;
});
echo '<style type="text/css">' . $code . '</style>' . PHP_EOL;
}
}

0 comments on commit 88d7c29

Please sign in to comment.