Move all domain folders from src/AKSRT/{Domain} to src/{Domain}; remap
Composer PSR-4 "AKSRT\\": "src/"; update audit script + README + ADR
paths; remove dead tools/build-psr4-map.php (scanned deleted inc/classes).
59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* @package AKSRT
|
|
*/
|
|
|
|
namespace AKSRT\Frontend;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
class CustomCodeRenderer {
|
|
|
|
public function output_header(): void {
|
|
$custom_css = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::custom_css()
|
|
: aksrt_get_setting('custom_css', '');
|
|
$head_code = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::custom_head_code()
|
|
: aksrt_get_setting('custom_head_code', get_option('aksrt_custom_head_code', ''));
|
|
$trackcode = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::trackcode()
|
|
: '';
|
|
|
|
echo $this->format((string) $custom_css, 'css', 'aksrt-custom-css');
|
|
if ($head_code) {
|
|
echo $this->format((string) $head_code, 'js', 'aksrt-custom-js-header');
|
|
}
|
|
if ($trackcode) {
|
|
echo $this->format((string) $trackcode, 'js', 'aksrt-trackcode');
|
|
}
|
|
}
|
|
|
|
public function output_footer(): void {
|
|
$footer_code = class_exists('\AKSRT\Settings\Settings')
|
|
? \AKSRT\Settings\Settings::custom_footer_code()
|
|
: aksrt_get_setting('custom_footer_code', get_option('aksrt_custom_footer_code', ''));
|
|
|
|
if ($footer_code) {
|
|
echo $this->format((string) $footer_code, 'js', 'aksrt-custom-js-footer');
|
|
}
|
|
}
|
|
|
|
private function format(string $code, string $type, string $id): string {
|
|
$code = trim($code);
|
|
if ($code === '') {
|
|
return '';
|
|
}
|
|
|
|
if (preg_match('/<\s*(script|style|meta|link|noscript)\b/i', $code)) {
|
|
return $code . "\n";
|
|
}
|
|
|
|
if ($type === 'css') {
|
|
return '<style id="' . esc_attr($id) . '">' . "\n" . $code . "\n</style>\n";
|
|
}
|
|
|
|
return '<script id="' . esc_attr($id) . '">' . "\n" . $code . "\n</script>\n";
|
|
}
|
|
}
|