Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 282523fb9c | |||
| 71db3f5ff2 | |||
| 03253bed9b | |||
| 59fcc487bf | |||
| 04d6ba2079 | |||
| 7c21552f05 | |||
| 98039df80e | |||
| db32925598 | |||
| 74e4b59a31 | |||
| 0a2bbcbef8 | |||
| 61da5b15e5 | |||
| ca7101489a | |||
| eda333d17a | |||
| 1ee3574d03 | |||
| b51ce9ab3f | |||
| 3150f4da51 | |||
| 1020442c06 | |||
| 81ed7efa1a |
@@ -0,0 +1,173 @@
|
||||
/**
|
||||
* Code block styles
|
||||
*
|
||||
* Frontend and editor preview styles for the Zeitfresser code block feature.
|
||||
* The selectors are scoped to avoid leaking into unrelated blocks or plugins.
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Code block wrapper
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Code block wrapper
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
.ztfr-code {
|
||||
position: relative;
|
||||
|
||||
background-color: var(--footer-color);
|
||||
color: var(--light-color);
|
||||
|
||||
padding: 1rem 1.2rem;
|
||||
margin: 1rem 0;
|
||||
|
||||
border-radius: 0;
|
||||
border: 1px solid rgba(248, 248, 242, 0.08);
|
||||
border-left: 4px solid var(--hover-color);
|
||||
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
|
||||
font-family: var(--secondary-font);
|
||||
font-size: 0.85rem;
|
||||
line-height: 1.6;
|
||||
font-weight: 400;
|
||||
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Prism overrides
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
.ztfr-code pre,
|
||||
.ztfr-code code {
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.ztfr-code pre[class*="language-"],
|
||||
.ztfr-code code[class*="language-"] {
|
||||
background: transparent !important;
|
||||
padding: 0 !important;
|
||||
margin: 0 !important;
|
||||
white-space: pre-wrap !important;
|
||||
word-break: break-word !important;
|
||||
overflow-wrap: break-word !important;
|
||||
}
|
||||
|
||||
.ztfr-code pre[class*="language-"] {
|
||||
overflow-x: visible !important;
|
||||
}
|
||||
|
||||
.ztfr-code pre code {
|
||||
display: block;
|
||||
padding: 1rem;
|
||||
overflow-x: auto;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Copy button
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
.ztfr-code__copy {
|
||||
position: absolute;
|
||||
top: 0.75rem;
|
||||
right: 0.75rem;
|
||||
background-color: var(--footer-color);
|
||||
color: var(--light-color);
|
||||
border: 1px solid rgba(248, 248, 242, 0.12);
|
||||
border-radius: 4px;
|
||||
font-size: 0.72rem;
|
||||
line-height: 1;
|
||||
padding: 0.45rem 0.65rem;
|
||||
cursor: pointer;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition:
|
||||
opacity 0.2s ease,
|
||||
background-color 0.2s ease,
|
||||
color 0.2s ease,
|
||||
border-color 0.2s ease;
|
||||
}
|
||||
|
||||
.ztfr-code:hover .ztfr-code__copy {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.ztfr-code__copy:hover {
|
||||
background-color: var(--hover-color);
|
||||
color: #f8f8f2;
|
||||
}
|
||||
|
||||
.ztfr-code__copy:focus {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
|
||||
outline: 2px solid #bd93f9;
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Dracula token colors
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
.ztfr-code .token.comment,
|
||||
.ztfr-code .token.prolog,
|
||||
.ztfr-code .token.doctype,
|
||||
.ztfr-code .token.cdata {
|
||||
color: #6272a4;
|
||||
}
|
||||
|
||||
.ztfr-code .token.punctuation {
|
||||
color: #f8f8f2;
|
||||
}
|
||||
|
||||
.ztfr-code .token.tag,
|
||||
.ztfr-code .token.constant,
|
||||
.ztfr-code .token.symbol,
|
||||
.ztfr-code .token.deleted {
|
||||
color: #ff79c6;
|
||||
}
|
||||
|
||||
.ztfr-code .token.attr-name,
|
||||
.ztfr-code .token.property,
|
||||
.ztfr-code .token.selector,
|
||||
.ztfr-code .token.important,
|
||||
.ztfr-code .token.atrule {
|
||||
color: #8be9fd;
|
||||
}
|
||||
|
||||
.ztfr-code .token.attr-value,
|
||||
.ztfr-code .token.string,
|
||||
.ztfr-code .token.char,
|
||||
.ztfr-code .token.inserted {
|
||||
color: #f1fa8c;
|
||||
}
|
||||
|
||||
.ztfr-code .token.keyword,
|
||||
.ztfr-code .token.boolean,
|
||||
.ztfr-code .token.number {
|
||||
color: #bd93f9;
|
||||
}
|
||||
|
||||
.ztfr-code .token.operator,
|
||||
.ztfr-code .token.entity,
|
||||
.ztfr-code .token.url {
|
||||
color: #f8f8f2;
|
||||
}
|
||||
|
||||
.ztfr-code .token.function,
|
||||
.ztfr-code .token.class-name {
|
||||
color: #50fa7b;
|
||||
}
|
||||
|
||||
.block-editor-block-list__layout .ztfr-code,
|
||||
.editor-styles-wrapper .ztfr-code {
|
||||
margin: 0;
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* Editor styles
|
||||
*
|
||||
* Scoped styles for Gutenberg and Classic Editor.
|
||||
*/
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Editor base
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
.editor-styles-wrapper,
|
||||
.mce-content-body {
|
||||
font-family: var(--secondary-font);
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Shared code block preview
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
.editor-styles-wrapper .ztfr-code,
|
||||
.editor-styles-wrapper pre.language-yaml,
|
||||
.mce-content-body pre.language-yaml {
|
||||
position: relative;
|
||||
background-color: #282a36;
|
||||
color: #f8f8f2;
|
||||
border: 1px solid rgba(248, 248, 242, 0.08);
|
||||
border-radius: 6px;
|
||||
padding: 1rem 1.2rem;
|
||||
margin: 1rem 0;
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
font-family: var(--secondary-font);
|
||||
font-size: 0.95rem;
|
||||
line-height: 1.7;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Gutenberg preview
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
.editor-styles-wrapper .ztfr-code pre,
|
||||
.editor-styles-wrapper .ztfr-code code {
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.editor-styles-wrapper .ztfr-code pre.language-yaml,
|
||||
.editor-styles-wrapper .ztfr-code code.language-yaml {
|
||||
background: transparent !important;
|
||||
padding: 0 !important;
|
||||
margin: 0 !important;
|
||||
white-space: pre-wrap !important;
|
||||
word-break: break-word !important;
|
||||
overflow-wrap: break-word !important;
|
||||
}
|
||||
|
||||
.editor-styles-wrapper .ztfr-code pre code {
|
||||
display: block;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Classic Editor preview
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
.mce-content-body pre.language-yaml {
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
.mce-content-body pre.language-yaml code.language-yaml {
|
||||
display: block;
|
||||
background: transparent;
|
||||
color: inherit;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Editor label
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
.editor-styles-wrapper .ztfr-code.is-editor-preview::before,
|
||||
.mce-content-body pre.language-yaml::before {
|
||||
content: "YAML";
|
||||
display: inline-block;
|
||||
margin-bottom: 0.75rem;
|
||||
padding: 0.2rem 0.45rem;
|
||||
border-radius: 4px;
|
||||
background: #44475a;
|
||||
color: #f8f8f2;
|
||||
font-size: 0.72rem;
|
||||
line-height: 1;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------
|
||||
Lists
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
.editor-styles-wrapper ul,
|
||||
.editor-styles-wrapper ol,
|
||||
.mce-content-body ul,
|
||||
.mce-content-body ol {
|
||||
margin-left: 0;
|
||||
padding-left: 1.25em;
|
||||
list-style-position: outside;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Code Block UI Enhancements
|
||||
*
|
||||
* Handles:
|
||||
* - Copy button
|
||||
* - Prism highlight trigger
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
function copyText(text, onSuccess, onError) {
|
||||
if (!text) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
navigator.clipboard.writeText(text).then(onSuccess).catch(onError);
|
||||
return;
|
||||
}
|
||||
|
||||
const textarea = document.createElement('textarea');
|
||||
textarea.value = text;
|
||||
textarea.setAttribute('readonly', 'readonly');
|
||||
textarea.style.position = 'fixed';
|
||||
textarea.style.opacity = '0';
|
||||
textarea.style.pointerEvents = 'none';
|
||||
|
||||
document.body.appendChild(textarea);
|
||||
textarea.focus();
|
||||
textarea.select();
|
||||
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
onSuccess();
|
||||
} catch (error) {
|
||||
onError();
|
||||
}
|
||||
|
||||
document.body.removeChild(textarea);
|
||||
}
|
||||
|
||||
function initCodeUI() {
|
||||
const wrappers = document.querySelectorAll('.ztfr-code');
|
||||
|
||||
if (!wrappers.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
wrappers.forEach(function (wrapper) {
|
||||
const code = wrapper.querySelector('code');
|
||||
|
||||
if (!code) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!wrapper.querySelector('.ztfr-code__copy')) {
|
||||
const button = document.createElement('button');
|
||||
button.className = 'ztfr-code__copy';
|
||||
button.type = 'button';
|
||||
button.setAttribute('aria-label', 'Copy code');
|
||||
button.textContent = 'Copy';
|
||||
|
||||
button.addEventListener('click', function () {
|
||||
const text = code.textContent;
|
||||
|
||||
copyText(
|
||||
text,
|
||||
function () {
|
||||
button.textContent = 'Copied';
|
||||
window.setTimeout(function () {
|
||||
button.textContent = 'Copy';
|
||||
}, 2000);
|
||||
},
|
||||
function () {
|
||||
button.textContent = 'Error';
|
||||
window.setTimeout(function () {
|
||||
button.textContent = 'Copy';
|
||||
}, 2000);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
wrapper.appendChild(button);
|
||||
}
|
||||
});
|
||||
|
||||
if (typeof Prism !== 'undefined') {
|
||||
Prism.highlightAll();
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', initCodeUI);
|
||||
})();
|
||||
@@ -0,0 +1,219 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Escape HTML before saving it into the code block markup.
|
||||
*
|
||||
* @param {string} text Raw code.
|
||||
* @returns {string} Escaped code.
|
||||
*/
|
||||
function escapeHtml(text) {
|
||||
return String(text)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gutenberg block
|
||||
*/
|
||||
if (
|
||||
window.wp &&
|
||||
window.wp.blocks &&
|
||||
window.wp.element &&
|
||||
window.wp.i18n &&
|
||||
window.wp.components &&
|
||||
window.wp.blockEditor
|
||||
) {
|
||||
const blocks = window.wp.blocks;
|
||||
const element = window.wp.element;
|
||||
const i18n = window.wp.i18n;
|
||||
const blockEditor = window.wp.blockEditor;
|
||||
const components = window.wp.components;
|
||||
|
||||
const el = element.createElement;
|
||||
const __ = i18n.__;
|
||||
const PlainText = blockEditor.PlainText;
|
||||
const Button = components.Button;
|
||||
const Modal = components.Modal;
|
||||
const TextareaControl = components.TextareaControl;
|
||||
const useState = element.useState;
|
||||
const useEffect = element.useEffect;
|
||||
const Fragment = element.Fragment;
|
||||
|
||||
function EditCodeBlock(props) {
|
||||
const content = props.attributes.content || '';
|
||||
const setAttributes = props.setAttributes;
|
||||
const state = useState(false);
|
||||
const isDialogOpen = state[0];
|
||||
const setDialogOpen = state[1];
|
||||
|
||||
function updateCode(value) {
|
||||
setAttributes({ content: value });
|
||||
}
|
||||
|
||||
useEffect(function () {
|
||||
if (!isDialogOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.setTimeout(function () {
|
||||
const textarea = document.querySelector('.ztfr-code__modal-textarea textarea');
|
||||
|
||||
if (textarea) {
|
||||
textarea.focus();
|
||||
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
|
||||
}
|
||||
}, 50);
|
||||
}, [isDialogOpen]);
|
||||
|
||||
return el(
|
||||
Fragment,
|
||||
null,
|
||||
el(
|
||||
'div',
|
||||
{
|
||||
className: 'ztfr-code is-editor-preview',
|
||||
'data-language': 'yaml'
|
||||
},
|
||||
el(
|
||||
'div',
|
||||
{ className: 'ztfr-code__editor-actions' },
|
||||
el(
|
||||
Button,
|
||||
{
|
||||
variant: 'secondary',
|
||||
onClick: function () {
|
||||
setDialogOpen(true);
|
||||
}
|
||||
},
|
||||
__('Edit code', 'zeitfresser')
|
||||
)
|
||||
),
|
||||
el(
|
||||
'pre',
|
||||
{ className: 'language-yaml' },
|
||||
el(PlainText, {
|
||||
tagName: 'code',
|
||||
className: 'language-yaml',
|
||||
value: content,
|
||||
placeholder: __('Write or paste YAML code here…', 'zeitfresser'),
|
||||
onChange: updateCode
|
||||
})
|
||||
)
|
||||
),
|
||||
isDialogOpen &&
|
||||
el(
|
||||
Modal,
|
||||
{
|
||||
title: __('Edit code block', 'zeitfresser'),
|
||||
onRequestClose: function () {
|
||||
setDialogOpen(false);
|
||||
},
|
||||
className: 'ztfr-code__modal'
|
||||
},
|
||||
el(TextareaControl, {
|
||||
label: __('Code', 'zeitfresser'),
|
||||
value: content,
|
||||
onChange: updateCode,
|
||||
help: __('Paste your YAML code here. Indentation and line breaks are preserved.', 'zeitfresser'),
|
||||
rows: 18,
|
||||
className: 'ztfr-code__modal-textarea'
|
||||
}),
|
||||
el(
|
||||
'div',
|
||||
{ className: 'ztfr-code__modal-actions' },
|
||||
el(
|
||||
Button,
|
||||
{
|
||||
variant: 'primary',
|
||||
onClick: function () {
|
||||
setDialogOpen(false);
|
||||
}
|
||||
},
|
||||
__('Done', 'zeitfresser')
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
blocks.registerBlockType('ztfr/code-block', {
|
||||
title: __('Code', 'zeitfresser'),
|
||||
icon: 'editor-code',
|
||||
category: 'formatting',
|
||||
description: __('Insert a styled YAML code block.', 'zeitfresser'),
|
||||
supports: {
|
||||
html: false
|
||||
},
|
||||
attributes: {
|
||||
content: {
|
||||
type: 'string',
|
||||
default: ''
|
||||
}
|
||||
},
|
||||
|
||||
edit: EditCodeBlock,
|
||||
|
||||
save: function (props) {
|
||||
const content = props.attributes.content || '';
|
||||
|
||||
return el(
|
||||
'pre',
|
||||
{ className: 'language-yaml' },
|
||||
el(
|
||||
'code',
|
||||
{ className: 'language-yaml' },
|
||||
content
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Classic Editor TinyMCE button
|
||||
*/
|
||||
if (window.tinymce && window.tinymce.PluginManager) {
|
||||
window.tinymce.PluginManager.add('ztfr_code_block', function (editor) {
|
||||
function insertCodeBlockFromDialog() {
|
||||
editor.windowManager.open({
|
||||
title: 'Insert code block',
|
||||
body: [
|
||||
{
|
||||
type: 'textbox',
|
||||
name: 'code',
|
||||
label: 'Code',
|
||||
multiline: true,
|
||||
minWidth: 700,
|
||||
minHeight: 350,
|
||||
value: ''
|
||||
}
|
||||
],
|
||||
onsubmit: function (event) {
|
||||
const code = event.data.code || 'your_key: your_value';
|
||||
const safeCode = escapeHtml(code);
|
||||
|
||||
editor.insertContent(
|
||||
'<pre class="language-yaml"><code class="language-yaml">' +
|
||||
safeCode +
|
||||
'</code></pre><p></p>'
|
||||
);
|
||||
|
||||
editor.focus();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
editor.addButton('ztfr_code_block', {
|
||||
text: 'Code',
|
||||
icon: false,
|
||||
onclick: insertCodeBlockFromDialog
|
||||
});
|
||||
});
|
||||
}
|
||||
})();
|
||||
File diff suppressed because one or more lines are too long
@@ -1,7 +0,0 @@
|
||||
/* Align lists in the Classic Editor */
|
||||
ul, ol {
|
||||
margin-left: 0 !important;
|
||||
padding-left: 1.0em !important;
|
||||
list-style-position: inside !important;
|
||||
}
|
||||
|
||||
+115
-607
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -15,98 +15,50 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
if ( ! defined( 'ZEITFRESSER_VERSION' ) ) {
|
||||
define( 'ZEITFRESSER_VERSION', '2.3.6' );
|
||||
define( 'ZEITFRESSER_VERSION', '2.3.6' );
|
||||
}
|
||||
|
||||
if ( ! defined( 'ZEITFRESSER_IMAGE_OPTIMIZATION_VERSION' ) ) {
|
||||
define( 'ZEITFRESSER_IMAGE_OPTIMIZATION_VERSION', '1.0' );
|
||||
define( 'ZEITFRESSER_IMAGE_OPTIMIZATION_VERSION', '1.0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Core Modules
|
||||
* Customizer
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Helpers (foundation)
|
||||
require get_template_directory() . '/inc/helpers/zeitfresser-helpers.php';
|
||||
|
||||
// Theme logic
|
||||
require get_template_directory() . '/inc/zeitfresser-toc.php';
|
||||
|
||||
// Performance layer
|
||||
require get_template_directory() . '/inc/performance/performance-tools.php';
|
||||
require_once get_template_directory() . '/inc/customizer/core-settings.php';
|
||||
require_once get_template_directory() . '/inc/customizer/general-settings.php';
|
||||
require_once get_template_directory() . '/inc/customizer/layout-settings.php';
|
||||
require_once get_template_directory() . '/inc/customizer/toc-settings.php';
|
||||
require_once get_template_directory() . '/inc/customizer/social-settings.php';
|
||||
require_once get_template_directory() . '/inc/customizer/image-optimizer-settings.php';
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Customizer (modular)
|
||||
* Utilities
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
require get_template_directory() . '/inc/customizer/core.php';
|
||||
require get_template_directory() . '/inc/customizer/general.php';
|
||||
require get_template_directory() . '/inc/customizer/layout.php';
|
||||
require get_template_directory() . '/inc/customizer/toc.php';
|
||||
require get_template_directory() . '/inc/customizer/social.php';
|
||||
require_once get_template_directory() . '/inc/utilities/helpers.php';
|
||||
require_once get_template_directory() . '/inc/utilities/template-tags.php';
|
||||
require_once get_template_directory() . '/inc/utilities/template-functions.php';
|
||||
require_once get_template_directory() . '/inc/utilities/pagination.php';
|
||||
require_once get_template_directory() . '/inc/utilities/toc.php';
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Theme Utilities
|
||||
* Tools
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
require get_template_directory() . '/inc/template-tags.php';
|
||||
require get_template_directory() . '/inc/template-functions.php';
|
||||
require get_template_directory() . '/inc/pagination.php';
|
||||
require_once get_template_directory() . '/inc/tools/image-optimizer.php';
|
||||
require_once get_template_directory() . '/inc/tools/code-block.php';
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Upload Handling (Original File Tracking)
|
||||
* Performance
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
function zeitfresser_capture_original_upload( $upload, $context ) {
|
||||
|
||||
if ( empty( $upload['file'] ) ) {
|
||||
return $upload;
|
||||
}
|
||||
|
||||
// Store temporarily (request-scoped)
|
||||
$GLOBALS['zeitfresser_last_uploaded_file'] = $upload['file'];
|
||||
|
||||
return $upload;
|
||||
}
|
||||
add_filter( 'wp_handle_upload', 'zeitfresser_capture_original_upload', 10, 2 );
|
||||
|
||||
/**
|
||||
* Persist original file path to attachment meta
|
||||
*/
|
||||
function zeitfresser_store_original_file( $attachment_id ) {
|
||||
|
||||
if ( ! wp_attachment_is_image( $attachment_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( empty( $GLOBALS['zeitfresser_last_uploaded_file'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$file = $GLOBALS['zeitfresser_last_uploaded_file'];
|
||||
|
||||
// Safety: ensure file still exists
|
||||
if ( ! file_exists( $file ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent overwrite if already set
|
||||
if ( get_post_meta( $attachment_id, '_zeitfresser_original_file', true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
update_post_meta(
|
||||
$attachment_id,
|
||||
'_zeitfresser_original_file',
|
||||
$file
|
||||
);
|
||||
}
|
||||
add_action( 'add_attachment', 'zeitfresser_store_original_file' );
|
||||
require_once get_template_directory() . '/inc/performance/performance.php';
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
@@ -115,40 +67,42 @@ add_action( 'add_attachment', 'zeitfresser_store_original_file' );
|
||||
*/
|
||||
function zeitfresser_setup() {
|
||||
|
||||
load_theme_textdomain( 'zeitfresser', get_template_directory() . '/languages' );
|
||||
load_theme_textdomain( 'zeitfresser', get_template_directory() . '/languages' );
|
||||
|
||||
add_theme_support( 'automatic-feed-links' );
|
||||
add_theme_support( 'title-tag' );
|
||||
add_theme_support( 'post-thumbnails' );
|
||||
add_theme_support( 'automatic-feed-links' );
|
||||
add_theme_support( 'title-tag' );
|
||||
add_theme_support( 'post-thumbnails' );
|
||||
|
||||
add_theme_support( 'html5', array(
|
||||
'search-form',
|
||||
'comment-form',
|
||||
'comment-list',
|
||||
'gallery',
|
||||
'caption',
|
||||
'style',
|
||||
'script',
|
||||
));
|
||||
// Editor Styles
|
||||
add_theme_support( 'editor-styles' );
|
||||
add_editor_style( 'assets/css/editor.css' );
|
||||
|
||||
add_theme_support( 'customize-selective-refresh-widgets' );
|
||||
add_theme_support( 'html5', array(
|
||||
'search-form',
|
||||
'comment-form',
|
||||
'comment-list',
|
||||
'gallery',
|
||||
'caption',
|
||||
'style',
|
||||
'script',
|
||||
));
|
||||
|
||||
add_theme_support( 'custom-logo', array(
|
||||
'height' => 250,
|
||||
'width' => 250,
|
||||
'flex-width' => true,
|
||||
'flex-height' => true,
|
||||
));
|
||||
add_theme_support( 'customize-selective-refresh-widgets' );
|
||||
|
||||
add_theme_support( 'align-wide' );
|
||||
add_theme_support( 'wp-block-styles' );
|
||||
add_theme_support( 'responsive-embeds' );
|
||||
add_theme_support( 'custom-logo', array(
|
||||
'height' => 250,
|
||||
'width' => 250,
|
||||
'flex-width' => true,
|
||||
'flex-height' => true,
|
||||
));
|
||||
|
||||
register_nav_menus( array(
|
||||
'menu-1' => esc_html__( 'Primary', 'zeitfresser' ),
|
||||
));
|
||||
add_theme_support( 'align-wide' );
|
||||
add_theme_support( 'wp-block-styles' );
|
||||
add_theme_support( 'responsive-embeds' );
|
||||
|
||||
add_editor_style( 'editor-style.css' );
|
||||
register_nav_menus( array(
|
||||
'menu-1' => esc_html__( 'Primary', 'zeitfresser' ),
|
||||
));
|
||||
}
|
||||
add_action( 'after_setup_theme', 'zeitfresser_setup' );
|
||||
|
||||
@@ -158,8 +112,8 @@ add_action( 'after_setup_theme', 'zeitfresser_setup' );
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
function zeitfresser_custom_image_sizes() {
|
||||
add_image_size( 'zeitfresser-content', 720, 0, false );
|
||||
add_image_size( 'zeitfresser-card', 480, 0, false );
|
||||
add_image_size( 'zeitfresser-content', 720, 0, false );
|
||||
add_image_size( 'zeitfresser-card', 480, 0, false );
|
||||
}
|
||||
add_action( 'after_setup_theme', 'zeitfresser_custom_image_sizes' );
|
||||
|
||||
@@ -169,7 +123,7 @@ add_action( 'after_setup_theme', 'zeitfresser_custom_image_sizes' );
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
function zeitfresser_content_width() {
|
||||
$GLOBALS['content_width'] = apply_filters( 'zeitfresser_content_width', 640 );
|
||||
$GLOBALS['content_width'] = apply_filters( 'zeitfresser_content_width', 640 );
|
||||
}
|
||||
add_action( 'after_setup_theme', 'zeitfresser_content_width', 0 );
|
||||
|
||||
@@ -179,15 +133,15 @@ add_action( 'after_setup_theme', 'zeitfresser_content_width', 0 );
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
function zeitfresser_widgets_init() {
|
||||
register_sidebar( array(
|
||||
'name' => esc_html__( 'Sidebar', 'zeitfresser' ),
|
||||
'id' => 'sidebar-1',
|
||||
'description' => esc_html__( 'Add widgets here.', 'zeitfresser' ),
|
||||
'before_widget' => '<section id="%1$s" class="widget %2$s">',
|
||||
'after_widget' => '</section>',
|
||||
'before_title' => '<h4 class="widget-title">',
|
||||
'after_title' => '</h4>',
|
||||
));
|
||||
register_sidebar( array(
|
||||
'name' => esc_html__( 'Sidebar', 'zeitfresser' ),
|
||||
'id' => 'sidebar-1',
|
||||
'description' => esc_html__( 'Add widgets here.', 'zeitfresser' ),
|
||||
'before_widget' => '<section id="%1$s" class="widget %2$s">',
|
||||
'after_widget' => '</section>',
|
||||
'before_title' => '<h4 class="widget-title">',
|
||||
'after_title' => '</h4>',
|
||||
));
|
||||
}
|
||||
add_action( 'widgets_init', 'zeitfresser_widgets_init' );
|
||||
|
||||
@@ -198,511 +152,65 @@ add_action( 'widgets_init', 'zeitfresser_widgets_init' );
|
||||
*/
|
||||
function zeitfresser_scripts() {
|
||||
|
||||
// Base stylesheet (theme root)
|
||||
wp_enqueue_style(
|
||||
'zeitfresser',
|
||||
get_template_directory_uri() . '/style.css',
|
||||
[],
|
||||
file_exists( get_template_directory() . '/style.css' )
|
||||
? filemtime( get_template_directory() . '/style.css' )
|
||||
: ZEITFRESSER_VERSION
|
||||
);
|
||||
/**
|
||||
* Base stylesheet
|
||||
*/
|
||||
wp_enqueue_style(
|
||||
'zeitfresser',
|
||||
get_template_directory_uri() . '/style.css',
|
||||
[],
|
||||
file_exists( get_template_directory() . '/style.css' )
|
||||
? filemtime( get_template_directory() . '/style.css' )
|
||||
: ZEITFRESSER_VERSION
|
||||
);
|
||||
|
||||
// Styles
|
||||
$fonts = zeitfresser_asset_versioned('/css/fonts.css');
|
||||
$colors = zeitfresser_asset_versioned('/css/colors.css');
|
||||
/**
|
||||
* Additional styles (versioned helper)
|
||||
*/
|
||||
$fonts = zeitfresser_asset_versioned('/css/fonts.css');
|
||||
$colors = zeitfresser_asset_versioned('/css/colors.css');
|
||||
|
||||
wp_enqueue_style(
|
||||
'zeitfresser-fonts',
|
||||
$fonts['url'],
|
||||
[],
|
||||
$fonts['version']
|
||||
);
|
||||
wp_enqueue_style(
|
||||
'zeitfresser-fonts',
|
||||
$fonts['url'],
|
||||
['zeitfresser'],
|
||||
$fonts['version']
|
||||
);
|
||||
|
||||
wp_enqueue_style(
|
||||
'zeitfresser-colors',
|
||||
$colors['url'],
|
||||
['zeitfresser'],
|
||||
$colors['version']
|
||||
);
|
||||
wp_enqueue_style(
|
||||
'zeitfresser-colors',
|
||||
$colors['url'],
|
||||
['zeitfresser'],
|
||||
$colors['version']
|
||||
);
|
||||
|
||||
// Scripts
|
||||
$nav = zeitfresser_asset_versioned('/js/navigation.js');
|
||||
$scripts = zeitfresser_asset_versioned('/js/scripts.js');
|
||||
/**
|
||||
* Scripts
|
||||
*/
|
||||
$nav = zeitfresser_asset_versioned('/js/navigation.js');
|
||||
$scripts = zeitfresser_asset_versioned('/js/scripts.js');
|
||||
|
||||
wp_enqueue_script(
|
||||
'zeitfresser-navigation',
|
||||
$nav['url'],
|
||||
[],
|
||||
$nav['version'],
|
||||
true
|
||||
);
|
||||
wp_enqueue_script(
|
||||
'zeitfresser-navigation',
|
||||
$nav['url'],
|
||||
[],
|
||||
$nav['version'],
|
||||
true
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'zeitfresser-scripts',
|
||||
$scripts['url'],
|
||||
[],
|
||||
$scripts['version'],
|
||||
true
|
||||
);
|
||||
wp_enqueue_script(
|
||||
'zeitfresser-scripts',
|
||||
$scripts['url'],
|
||||
['zeitfresser-navigation'],
|
||||
$scripts['version'],
|
||||
true
|
||||
);
|
||||
|
||||
// WordPress native threaded comments
|
||||
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
|
||||
wp_enqueue_script( 'comment-reply' );
|
||||
}
|
||||
/**
|
||||
* WordPress native threaded comments
|
||||
*/
|
||||
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
|
||||
wp_enqueue_script( 'comment-reply' );
|
||||
}
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'zeitfresser_scripts', 10 );
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Performance Tweaks
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Defer non-critical JavaScript
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* Prevents JS from blocking page rendering.
|
||||
*/
|
||||
function zeitfresser_defer_scripts( $tag, $handle, $src ) {
|
||||
|
||||
$defer_scripts = array(
|
||||
'zeitfresser-navigation',
|
||||
'zeitfresser-scripts',
|
||||
);
|
||||
|
||||
if ( in_array( $handle, $defer_scripts, true ) ) {
|
||||
return str_replace( ' src=', ' defer src=', $tag );
|
||||
}
|
||||
|
||||
return $tag;
|
||||
}
|
||||
add_filter( 'script_loader_tag', 'zeitfresser_defer_scripts', 10, 3 );
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Image Loading Optimization (LCP + Lazy Loading)
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* Ensures the first visible image loads immediately (LCP),
|
||||
* while all other images are lazy-loaded for performance.
|
||||
*/
|
||||
function zeitfresser_optimize_image_attributes( $attr, $attachment, $size ) {
|
||||
|
||||
static $is_first = true;
|
||||
|
||||
if ( ! is_admin() ) {
|
||||
|
||||
if ( $is_first ) {
|
||||
// First image (critical for LCP)
|
||||
$attr['loading'] = 'eager';
|
||||
$is_first = false;
|
||||
} else {
|
||||
// All other images
|
||||
$attr['loading'] = 'lazy';
|
||||
}
|
||||
|
||||
// Improve decoding performance
|
||||
$attr['decoding'] = 'async';
|
||||
}
|
||||
|
||||
return $attr;
|
||||
}
|
||||
add_filter( 'wp_get_attachment_image_attributes', 'zeitfresser_optimize_image_attributes', 10, 3 );
|
||||
|
||||
/**
|
||||
* Lower the threshold for WordPress scaled originals when auto optimization is enabled.
|
||||
*
|
||||
* When automatic optimization is disabled, original uploads should remain untouched.
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
function zeitfresser_big_image_size_threshold() {
|
||||
|
||||
$auto_enabled = get_theme_mod( 'ztfr_auto_optimize', true );
|
||||
$force_enabled = ! empty( $GLOBALS['zeitfresser_force_image_optimization'] );
|
||||
|
||||
if ( ! $auto_enabled && ! $force_enabled ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1800;
|
||||
}
|
||||
add_filter( 'big_image_size_threshold', 'zeitfresser_big_image_size_threshold' );
|
||||
|
||||
/**
|
||||
* Skip generating oversized core intermediate sizes we do not use.
|
||||
*
|
||||
* @param array $sizes Registered intermediate sizes.
|
||||
* @return array
|
||||
*/
|
||||
function zeitfresser_filter_intermediate_image_sizes( $sizes ) {
|
||||
|
||||
$auto_enabled = get_theme_mod( 'ztfr_auto_optimize', true );
|
||||
$force_enabled = ! empty( $GLOBALS['zeitfresser_force_image_optimization'] );
|
||||
|
||||
if ( ! $auto_enabled && ! $force_enabled ) {
|
||||
return $sizes;
|
||||
}
|
||||
|
||||
unset(
|
||||
$sizes['1536x1536'],
|
||||
$sizes['2048x2048']
|
||||
);
|
||||
|
||||
return $sizes;
|
||||
}
|
||||
add_filter( 'intermediate_image_sizes_advanced', 'zeitfresser_filter_intermediate_image_sizes' );
|
||||
|
||||
/**
|
||||
* Improve attachment image attributes for layout stability and fetch priority.
|
||||
*
|
||||
* @param array $attr Image markup attributes.
|
||||
* @param WP_Post $attachment Attachment post object.
|
||||
* @param string|array $size Requested image size.
|
||||
* @return array
|
||||
*/
|
||||
function zeitfresser_improve_attachment_dimensions( $attr, $attachment, $size ) {
|
||||
|
||||
if ( empty( $attr['width'] ) || empty( $attr['height'] ) ) {
|
||||
$metadata = wp_get_attachment_metadata( $attachment->ID );
|
||||
|
||||
if ( is_array( $metadata ) && ! empty( $metadata['width'] ) && ! empty( $metadata['height'] ) ) {
|
||||
if ( empty( $attr['width'] ) ) {
|
||||
$attr['width'] = (int) $metadata['width'];
|
||||
}
|
||||
|
||||
if ( empty( $attr['height'] ) ) {
|
||||
$attr['height'] = (int) $metadata['height'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $attr['fetchpriority'] ) && ! is_admin() && ! is_feed() ) {
|
||||
static $did_set_high_priority = false;
|
||||
|
||||
if ( ! $did_set_high_priority && is_singular() ) {
|
||||
$attr['fetchpriority'] = 'high';
|
||||
$did_set_high_priority = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $attr;
|
||||
}
|
||||
add_filter( 'wp_get_attachment_image_attributes', 'zeitfresser_improve_attachment_dimensions', 11, 3 );
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Preload critical fonts
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* Preloads only the fonts that are needed for initial rendering
|
||||
* (headings + body text). This improves LCP and avoids render delays.
|
||||
*/
|
||||
function zeitfresser_preload_fonts() {
|
||||
?>
|
||||
<!-- Critical Fonts Only -->
|
||||
<link rel="preload" href="<?php echo zeitfresser_asset('/fonts/oswald-400.woff2'); ?>" as="font" type="font/woff2" crossorigin>
|
||||
<link rel="preload" href="<?php echo zeitfresser_asset('/fonts/oswald-700.woff2'); ?>" as="font" type="font/woff2" crossorigin>
|
||||
<link rel="preload" href="<?php echo zeitfresser_asset('/fonts/roboto-400.woff2'); ?>" as="font" type="font/woff2" crossorigin>
|
||||
<link rel="preload" href="<?php echo zeitfresser_asset('/fonts/roboto-500.woff2'); ?>" as="font" type="font/woff2" crossorigin>
|
||||
<?php
|
||||
}
|
||||
add_action('wp_head', 'zeitfresser_preload_fonts', 0);
|
||||
|
||||
/**
|
||||
* Optimize font loading with preconnect
|
||||
*/
|
||||
add_filter( 'wp_resource_hints', function( $urls, $relation_type ) {
|
||||
|
||||
if ( 'preconnect' === $relation_type ) {
|
||||
$urls[] = [
|
||||
'href' => get_template_directory_uri(),
|
||||
'crossorigin' => 'anonymous',
|
||||
];
|
||||
}
|
||||
|
||||
return $urls;
|
||||
|
||||
}, 10, 2 );
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Critical CSS (inline for faster first render)
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* We inline only the minimal CSS required for initial layout.
|
||||
* This ensures the page structure renders immediately without
|
||||
* waiting for the full stylesheet.
|
||||
*/
|
||||
function zeitfresser_inline_critical_css() {
|
||||
?>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
background: #1e1f29;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: var(--container-width, 1140px);
|
||||
margin: 0 auto;
|
||||
padding: 0 70px;
|
||||
}
|
||||
|
||||
@media (max-width: 800px) {
|
||||
.container {
|
||||
padding: 0 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.custom-grid-view {
|
||||
display: grid;
|
||||
}
|
||||
|
||||
header.site-header {
|
||||
background: var(--light-color);
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
add_action('wp_head', 'zeitfresser_inline_critical_css', 1);
|
||||
|
||||
function zeitfresser_performance_setup() {
|
||||
if ( ! is_admin() ) {
|
||||
wp_deregister_script( 'wp-embed' );
|
||||
}
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'zeitfresser_performance_setup', 100 );
|
||||
|
||||
function zeitfresser_cleanup_wp_head() {
|
||||
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
|
||||
remove_action( 'wp_print_styles', 'print_emoji_styles' );
|
||||
remove_action( 'wp_head', 'rsd_link' );
|
||||
remove_action( 'wp_head', 'wlwmanifest_link' );
|
||||
remove_action( 'wp_head', 'wp_generator' );
|
||||
}
|
||||
add_action( 'init', 'zeitfresser_cleanup_wp_head' );
|
||||
|
||||
/**
|
||||
* Convert generated JPEG and PNG files to AVIF/WebP when enabled.
|
||||
*
|
||||
* Auto optimization can be disabled for uploads via Customizer.
|
||||
* Manual optimization may still force conversion through a request-scoped flag.
|
||||
*
|
||||
* @param array $formats Output format map.
|
||||
* @return array
|
||||
*/
|
||||
function zeitfresser_image_output_format( $formats ) {
|
||||
|
||||
$auto_enabled = get_theme_mod( 'ztfr_auto_optimize', true );
|
||||
$force_enabled = ! empty( $GLOBALS['zeitfresser_force_image_optimization'] );
|
||||
|
||||
if ( ! $auto_enabled && ! $force_enabled ) {
|
||||
return $formats;
|
||||
}
|
||||
|
||||
if ( function_exists( 'wp_image_editor_supports' ) ) {
|
||||
|
||||
// Prefer AVIF if supported.
|
||||
if ( wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) {
|
||||
$formats['image/jpeg'] = 'image/avif';
|
||||
$formats['image/png'] = 'image/avif';
|
||||
|
||||
// Fallback to WebP.
|
||||
} elseif ( wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
|
||||
$formats['image/jpeg'] = 'image/webp';
|
||||
$formats['image/png'] = 'image/webp';
|
||||
}
|
||||
}
|
||||
|
||||
return $formats;
|
||||
}
|
||||
add_filter( 'image_editor_output_format', 'zeitfresser_image_output_format' );
|
||||
|
||||
/**
|
||||
* Mark images as optimized only when optimization is actually active.
|
||||
*
|
||||
* @param array $metadata Attachment metadata.
|
||||
* @param int $attachment_id Attachment ID.
|
||||
* @return array
|
||||
*/
|
||||
function zeitfresser_mark_new_images_optimized( $metadata, $attachment_id ) {
|
||||
|
||||
if ( ! wp_attachment_is_image( $attachment_id ) ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$auto_enabled = get_theme_mod( 'ztfr_auto_optimize', true );
|
||||
$force_enabled = ! empty( $GLOBALS['zeitfresser_force_image_optimization'] );
|
||||
|
||||
if ( ! $auto_enabled && ! $force_enabled ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
update_post_meta(
|
||||
$attachment_id,
|
||||
'_zeitfresser_media_optimized_version',
|
||||
ZEITFRESSER_IMAGE_OPTIMIZATION_VERSION
|
||||
);
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
add_filter( 'wp_generate_attachment_metadata', 'zeitfresser_mark_new_images_optimized', 20, 2 );
|
||||
|
||||
/**
|
||||
* Auto Optimize Hook
|
||||
*/
|
||||
add_filter(
|
||||
'wp_generate_attachment_metadata',
|
||||
'zeitfresser_auto_optimize_on_upload',
|
||||
15,
|
||||
2
|
||||
);
|
||||
|
||||
function zeitfresser_auto_optimize_on_upload( $metadata, $attachment_id ) {
|
||||
|
||||
// Only images
|
||||
if ( ! wp_attachment_is_image( $attachment_id ) ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
// Feature toggle
|
||||
if ( ! get_theme_mod( 'ztfr_auto_optimize', true ) ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$file = get_attached_file( $attachment_id );
|
||||
|
||||
if ( ! $file || ! file_exists( $file ) ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
// DO NOT overwrite captured original
|
||||
if ( ! get_post_meta( $attachment_id, '_zeitfresser_original_file', true ) ) {
|
||||
update_post_meta( $attachment_id, '_zeitfresser_original_file', $file );
|
||||
}
|
||||
|
||||
// Mark optimized (IMPORTANT: no re-trigger here)
|
||||
update_post_meta(
|
||||
$attachment_id,
|
||||
'_zeitfresser_media_optimized_version',
|
||||
ZEITFRESSER_IMAGE_OPTIMIZATION_VERSION
|
||||
);
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto Delete Hook
|
||||
*/
|
||||
add_filter(
|
||||
'wp_generate_attachment_metadata',
|
||||
'zeitfresser_auto_delete_original_after_upload',
|
||||
30,
|
||||
2
|
||||
);
|
||||
|
||||
function zeitfresser_auto_delete_original_after_upload( $metadata, $attachment_id ) {
|
||||
|
||||
if ( ! wp_attachment_is_image( $attachment_id ) ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$auto_enabled = get_theme_mod( 'ztfr_auto_optimize', true );
|
||||
$delete_enabled = get_theme_mod( 'ztfr_auto_delete', false );
|
||||
|
||||
if ( ! $auto_enabled || ! $delete_enabled ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$original = get_post_meta(
|
||||
$attachment_id,
|
||||
'_zeitfresser_original_file',
|
||||
true
|
||||
);
|
||||
|
||||
if ( ! $original ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$ext = strtolower( pathinfo( $original, PATHINFO_EXTENSION ) );
|
||||
|
||||
// Skip modern formats
|
||||
if ( in_array( $ext, [ 'webp', 'avif' ], true ) ) {
|
||||
update_post_meta( $attachment_id, '_zeitfresser_original_deleted', 1 );
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
// 🔥 Wenn nichts mehr existiert → fertig
|
||||
if ( ! zeitfresser_original_family_exists( $attachment_id, $original ) ) {
|
||||
update_post_meta( $attachment_id, '_zeitfresser_original_deleted', 1 );
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
// 🔥 HIER passiert der Fix
|
||||
zeitfresser_delete_original_family_files( $attachment_id, $original );
|
||||
|
||||
// Final check
|
||||
if ( ! zeitfresser_original_family_exists( $attachment_id, $original ) ) {
|
||||
update_post_meta( $attachment_id, '_zeitfresser_original_deleted', 1 );
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep generated image quality balanced for file size and visual fidelity.
|
||||
*
|
||||
* @param int $quality Proposed image quality.
|
||||
* @param string $mime_type Image mime type.
|
||||
* @return int
|
||||
*/
|
||||
function zeitfresser_image_quality( $quality, $mime_type = 'image/jpeg' ) {
|
||||
|
||||
$auto_enabled = get_theme_mod( 'ztfr_auto_optimize', true );
|
||||
$force_enabled = ! empty( $GLOBALS['zeitfresser_force_image_optimization'] );
|
||||
|
||||
if ( ! $auto_enabled && ! $force_enabled ) {
|
||||
return $quality;
|
||||
}
|
||||
|
||||
return match ($mime_type) {
|
||||
'image/avif' => 50,
|
||||
'image/webp' => 75,
|
||||
default => 82,
|
||||
};
|
||||
}
|
||||
add_filter( 'wp_editor_set_quality', 'zeitfresser_image_quality', 10, 2 );
|
||||
|
||||
/**
|
||||
* Improve responsive image sizes attribute.
|
||||
*
|
||||
* @param string $sizes Existing sizes attribute.
|
||||
* @param array $size Requested image size.
|
||||
* @return string
|
||||
*/
|
||||
function zeitfresser_responsive_image_sizes( $sizes, $size ) {
|
||||
|
||||
// Single post content
|
||||
if ( is_singular() ) {
|
||||
return '(max-width: 768px) 100vw, (max-width: 1200px) 720px, 720px';
|
||||
}
|
||||
|
||||
// Archive / blog overview
|
||||
if ( is_home() || is_front_page() || is_archive() || is_search() ) {
|
||||
return '(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 400px';
|
||||
}
|
||||
|
||||
return $sizes;
|
||||
}
|
||||
add_filter( 'wp_calculate_image_sizes', 'zeitfresser_responsive_image_sizes', 10, 2 );
|
||||
|
||||
/**
|
||||
* Delete Cookie Button
|
||||
*/
|
||||
add_filter( 'comment_form_default_fields', function( $fields ) {
|
||||
unset( $fields['cookies'] );
|
||||
return $fields;
|
||||
});
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Theme Customizer Core
|
||||
*
|
||||
* @package zeitfresser
|
||||
*/
|
||||
|
||||
function zeitfresser_customize_register( $wp_customize ) {
|
||||
|
||||
// Live Preview support
|
||||
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
|
||||
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
|
||||
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
|
||||
|
||||
if ( isset( $wp_customize->selective_refresh ) ) {
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
'blogname',
|
||||
array(
|
||||
'selector' => '.site-title a',
|
||||
'render_callback' => 'zeitfresser_customize_partial_blogname',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
'blogdescription',
|
||||
array(
|
||||
'selector' => '.site-description',
|
||||
'render_callback' => 'zeitfresser_customize_partial_blogdescription',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'customize_register', 'zeitfresser_customize_register' );
|
||||
|
||||
/**
|
||||
* Partial refresh helpers
|
||||
*/
|
||||
function zeitfresser_customize_partial_blogname() {
|
||||
bloginfo( 'name' );
|
||||
}
|
||||
|
||||
function zeitfresser_customize_partial_blogdescription() {
|
||||
bloginfo( 'description' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Live preview JS
|
||||
*/
|
||||
function zeitfresser_customize_preview_js() {
|
||||
wp_enqueue_script(
|
||||
'zeitfresser-customizer',
|
||||
get_template_directory_uri() . '/js/customizer.js',
|
||||
array( 'customize-preview' ),
|
||||
ZEITFRESSER_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
add_action( 'customize_preview_init', 'zeitfresser_customize_preview_js' );
|
||||
@@ -1,42 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Theme Customizer Core
|
||||
* Image Optimizer (Settings + UI)
|
||||
*
|
||||
* @package zeitfresser
|
||||
*/
|
||||
|
||||
function zeitfresser_customize_register( $wp_customize ) {
|
||||
|
||||
// Live Preview support
|
||||
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
|
||||
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
|
||||
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';
|
||||
|
||||
if ( isset( $wp_customize->selective_refresh ) ) {
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
'blogname',
|
||||
array(
|
||||
'selector' => '.site-title a',
|
||||
'render_callback' => 'zeitfresser_customize_partial_blogname',
|
||||
)
|
||||
);
|
||||
|
||||
$wp_customize->selective_refresh->add_partial(
|
||||
'blogdescription',
|
||||
array(
|
||||
'selector' => '.site-description',
|
||||
'render_callback' => 'zeitfresser_customize_partial_blogdescription',
|
||||
)
|
||||
);
|
||||
}
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Settings
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
function zeitfresser_customize_image_optimizer_settings( $wp_customize ) {
|
||||
|
||||
/**
|
||||
* Performance Tools Section
|
||||
* Image Optimizer Section
|
||||
*/
|
||||
$wp_customize->add_section(
|
||||
'ztfr_performance_tools',
|
||||
'ztfr_image_optimizer',
|
||||
array(
|
||||
'title' => 'Performance Tools Settings',
|
||||
'title' => 'Image Optimizer',
|
||||
'priority' => 160,
|
||||
)
|
||||
);
|
||||
@@ -56,7 +38,7 @@ function zeitfresser_customize_register( $wp_customize ) {
|
||||
'ztfr_auto_optimize',
|
||||
array(
|
||||
'type' => 'checkbox',
|
||||
'section' => 'ztfr_performance_tools',
|
||||
'section' => 'ztfr_image_optimizer',
|
||||
'label' => 'Auto Optimize Pictures on Upload',
|
||||
'description' => 'Automatically converts images to AVIF/WebP.',
|
||||
)
|
||||
@@ -77,43 +59,21 @@ function zeitfresser_customize_register( $wp_customize ) {
|
||||
'ztfr_auto_delete',
|
||||
array(
|
||||
'type' => 'checkbox',
|
||||
'section' => 'ztfr_performance_tools',
|
||||
'section' => 'ztfr_image_optimizer',
|
||||
'label' => 'Auto Delete Original Pictures',
|
||||
'description' => 'Deletes originals after optimization.',
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'customize_register', 'zeitfresser_customize_register' );
|
||||
add_action( 'customize_register', 'zeitfresser_customize_image_optimizer_settings' );
|
||||
|
||||
|
||||
/**
|
||||
* Partial refresh helpers
|
||||
* ------------------------------------------------------------------------
|
||||
* UI Logic (JS)
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
function zeitfresser_customize_partial_blogname() {
|
||||
bloginfo( 'name' );
|
||||
}
|
||||
|
||||
function zeitfresser_customize_partial_blogdescription() {
|
||||
bloginfo( 'description' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Live preview JS
|
||||
*/
|
||||
function zeitfresser_customize_preview_js() {
|
||||
wp_enqueue_script(
|
||||
'zeitfresser-customizer',
|
||||
get_template_directory_uri() . '/js/customizer.js',
|
||||
array( 'customize-preview' ),
|
||||
ZEITFRESSER_VERSION,
|
||||
true
|
||||
);
|
||||
}
|
||||
add_action( 'customize_preview_init', 'zeitfresser_customize_preview_js' );
|
||||
|
||||
/**
|
||||
* Dependency UI logic
|
||||
*/
|
||||
function zeitfresser_customize_controls_dependency_js() {
|
||||
function zeitfresser_customize_image_optimizer_ui() {
|
||||
?>
|
||||
<script>
|
||||
(function() {
|
||||
@@ -193,7 +153,6 @@ function zeitfresser_customize_controls_dependency_js() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Retry max 10x
|
||||
if (attempts < 10) {
|
||||
attempts++;
|
||||
setTimeout(tryInit, 200);
|
||||
@@ -225,20 +184,27 @@ function zeitfresser_customize_controls_dependency_js() {
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
add_action( 'customize_controls_enqueue_scripts', 'zeitfresser_customize_controls_dependency_js' );
|
||||
add_action( 'customize_controls_enqueue_scripts', 'zeitfresser_customize_image_optimizer_ui' );
|
||||
|
||||
|
||||
/**
|
||||
* Small UI polish
|
||||
* ------------------------------------------------------------------------
|
||||
* UI Styles
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
add_action( 'customize_controls_enqueue_scripts', function() {
|
||||
?>
|
||||
<style>
|
||||
#customize-control-ztfr_auto_optimize > label,
|
||||
#customize-control-ztfr_auto_delete > label {
|
||||
display:flex;
|
||||
align-items:flex-start;
|
||||
gap:6px;
|
||||
function zeitfresser_customize_image_optimizer_ui_styles() {
|
||||
?>
|
||||
<style>
|
||||
#customize-control-ztfr_auto_optimize > label,
|
||||
#customize-control-ztfr_auto_delete > label {
|
||||
display:flex;
|
||||
align-items:flex-start;
|
||||
gap:6px;
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
});
|
||||
add_action(
|
||||
'customize_controls_enqueue_scripts',
|
||||
'zeitfresser_customize_image_optimizer_ui_styles'
|
||||
);
|
||||
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
/**
|
||||
* Performance tweaks.
|
||||
*
|
||||
* @package Zeitfresser
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Defer non-critical JavaScript
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* Prevents JS from blocking page rendering.
|
||||
*/
|
||||
function zeitfresser_defer_scripts( $tag, $handle, $src ) {
|
||||
|
||||
$defer_scripts = array(
|
||||
'zeitfresser-navigation',
|
||||
'zeitfresser-scripts',
|
||||
);
|
||||
|
||||
if ( in_array( $handle, $defer_scripts, true ) ) {
|
||||
return str_replace( ' src=', ' defer src=', $tag );
|
||||
}
|
||||
|
||||
return $tag;
|
||||
}
|
||||
add_filter( 'script_loader_tag', 'zeitfresser_defer_scripts', 10, 3 );
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Image Loading Optimization (LCP + Lazy Loading)
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* Ensures the first visible image loads immediately (LCP),
|
||||
* while all other images are lazy-loaded for performance.
|
||||
*/
|
||||
function zeitfresser_optimize_image_attributes( $attr, $attachment, $size ) {
|
||||
|
||||
static $is_first = true;
|
||||
|
||||
if ( ! is_admin() ) {
|
||||
|
||||
if ( $is_first ) {
|
||||
// First image (critical for LCP)
|
||||
$attr['loading'] = 'eager';
|
||||
$is_first = false;
|
||||
} else {
|
||||
// All other images
|
||||
$attr['loading'] = 'lazy';
|
||||
}
|
||||
|
||||
// Improve decoding performance
|
||||
$attr['decoding'] = 'async';
|
||||
}
|
||||
|
||||
return $attr;
|
||||
}
|
||||
add_filter( 'wp_get_attachment_image_attributes', 'zeitfresser_optimize_image_attributes', 10, 3 );
|
||||
|
||||
/**
|
||||
* Lower the threshold for WordPress scaled originals when auto optimization is enabled.
|
||||
*
|
||||
* When automatic optimization is disabled, original uploads should remain untouched.
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
function zeitfresser_big_image_size_threshold() {
|
||||
|
||||
$auto_enabled = get_theme_mod( 'ztfr_auto_optimize', true );
|
||||
$force_enabled = ! empty( $GLOBALS['zeitfresser_force_image_optimization'] );
|
||||
|
||||
if ( ! $auto_enabled && ! $force_enabled ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1800;
|
||||
}
|
||||
add_filter( 'big_image_size_threshold', 'zeitfresser_big_image_size_threshold' );
|
||||
|
||||
/**
|
||||
* Skip generating oversized core intermediate sizes we do not use.
|
||||
*
|
||||
* @param array $sizes Registered intermediate sizes.
|
||||
* @return array
|
||||
*/
|
||||
function zeitfresser_filter_intermediate_image_sizes( $sizes ) {
|
||||
|
||||
$auto_enabled = get_theme_mod( 'ztfr_auto_optimize', true );
|
||||
$force_enabled = ! empty( $GLOBALS['zeitfresser_force_image_optimization'] );
|
||||
|
||||
if ( ! $auto_enabled && ! $force_enabled ) {
|
||||
return $sizes;
|
||||
}
|
||||
|
||||
unset(
|
||||
$sizes['1536x1536'],
|
||||
$sizes['2048x2048']
|
||||
);
|
||||
|
||||
return $sizes;
|
||||
}
|
||||
add_filter( 'intermediate_image_sizes_advanced', 'zeitfresser_filter_intermediate_image_sizes' );
|
||||
|
||||
/**
|
||||
* Improve attachment image attributes for layout stability and fetch priority.
|
||||
*
|
||||
* @param array $attr Image markup attributes.
|
||||
* @param WP_Post $attachment Attachment post object.
|
||||
* @param string|array $size Requested image size.
|
||||
* @return array
|
||||
*/
|
||||
function zeitfresser_improve_attachment_dimensions( $attr, $attachment, $size ) {
|
||||
|
||||
if ( empty( $attr['width'] ) || empty( $attr['height'] ) ) {
|
||||
$metadata = wp_get_attachment_metadata( $attachment->ID );
|
||||
|
||||
if ( is_array( $metadata ) && ! empty( $metadata['width'] ) && ! empty( $metadata['height'] ) ) {
|
||||
if ( empty( $attr['width'] ) ) {
|
||||
$attr['width'] = (int) $metadata['width'];
|
||||
}
|
||||
|
||||
if ( empty( $attr['height'] ) ) {
|
||||
$attr['height'] = (int) $metadata['height'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $attr['fetchpriority'] ) && ! is_admin() && ! is_feed() ) {
|
||||
static $did_set_high_priority = false;
|
||||
|
||||
if ( ! $did_set_high_priority && is_singular() ) {
|
||||
$attr['fetchpriority'] = 'high';
|
||||
$did_set_high_priority = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $attr;
|
||||
}
|
||||
add_filter( 'wp_get_attachment_image_attributes', 'zeitfresser_improve_attachment_dimensions', 11, 3 );
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Preload critical fonts
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* Preloads only the fonts that are needed for initial rendering
|
||||
* (headings + body text). This improves LCP and avoids render delays.
|
||||
*/
|
||||
function zeitfresser_preload_fonts() {
|
||||
?>
|
||||
<!-- Critical Fonts Only -->
|
||||
<link rel="preload" href="<?php echo zeitfresser_asset('/fonts/oswald-400.woff2'); ?>" as="font" type="font/woff2" crossorigin>
|
||||
<link rel="preload" href="<?php echo zeitfresser_asset('/fonts/oswald-700.woff2'); ?>" as="font" type="font/woff2" crossorigin>
|
||||
<link rel="preload" href="<?php echo zeitfresser_asset('/fonts/roboto-400.woff2'); ?>" as="font" type="font/woff2" crossorigin>
|
||||
<link rel="preload" href="<?php echo zeitfresser_asset('/fonts/roboto-500.woff2'); ?>" as="font" type="font/woff2" crossorigin>
|
||||
<?php
|
||||
}
|
||||
add_action('wp_head', 'zeitfresser_preload_fonts', 0);
|
||||
|
||||
/**
|
||||
* Optimize font loading with preconnect
|
||||
*/
|
||||
add_filter( 'wp_resource_hints', function( $urls, $relation_type ) {
|
||||
|
||||
if ( 'preconnect' === $relation_type ) {
|
||||
$urls[] = [
|
||||
'href' => get_template_directory_uri(),
|
||||
'crossorigin' => 'anonymous',
|
||||
];
|
||||
}
|
||||
|
||||
return $urls;
|
||||
|
||||
}, 10, 2 );
|
||||
|
||||
/**
|
||||
* ------------------------------------------------------------------------
|
||||
* Critical CSS (inline for faster first render)
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
* We inline only the minimal CSS required for initial layout.
|
||||
* This ensures the page structure renders immediately without
|
||||
* waiting for the full stylesheet.
|
||||
*/
|
||||
function zeitfresser_inline_critical_css() {
|
||||
?>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
background: #1e1f29;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: var(--container-width, 1140px);
|
||||
margin: 0 auto;
|
||||
padding: 0 70px;
|
||||
}
|
||||
|
||||
@media (max-width: 800px) {
|
||||
.container {
|
||||
padding: 0 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.custom-grid-view {
|
||||
display: grid;
|
||||
}
|
||||
|
||||
header.site-header {
|
||||
background: var(--light-color);
|
||||
}
|
||||
</style>
|
||||
<?php
|
||||
}
|
||||
add_action('wp_head', 'zeitfresser_inline_critical_css', 1);
|
||||
|
||||
function zeitfresser_performance_setup() {
|
||||
if ( ! is_admin() ) {
|
||||
wp_deregister_script( 'wp-embed' );
|
||||
}
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'zeitfresser_performance_setup', 100 );
|
||||
|
||||
function zeitfresser_cleanup_wp_head() {
|
||||
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
|
||||
remove_action( 'wp_print_styles', 'print_emoji_styles' );
|
||||
remove_action( 'wp_head', 'rsd_link' );
|
||||
remove_action( 'wp_head', 'wlwmanifest_link' );
|
||||
remove_action( 'wp_head', 'wp_generator' );
|
||||
}
|
||||
add_action( 'init', 'zeitfresser_cleanup_wp_head' );
|
||||
@@ -0,0 +1,243 @@
|
||||
<?php
|
||||
/**
|
||||
* Simplified Code Block Feature
|
||||
*
|
||||
* Handles:
|
||||
* - Frontend assets
|
||||
* - Editor assets
|
||||
* - Classic Editor button
|
||||
* - Gutenberg block
|
||||
* - Server-side wrapping for code blocks
|
||||
*
|
||||
* @package Zeitfresser
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current post content contains code blocks.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function ztfr_has_code_block() {
|
||||
|
||||
if ( is_admin() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! is_singular() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
global $post;
|
||||
|
||||
if ( ! isset( $post ) || empty( $post->post_content ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( has_block( 'ztfr/code-block', $post ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false !== strpos( $post->post_content, '<pre' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get asset version from file modification time.
|
||||
*
|
||||
* @param string $relative_path Relative path inside the theme directory.
|
||||
* @return string
|
||||
*/
|
||||
function ztfr_code_asset_version( $relative_path ) {
|
||||
$file_path = get_template_directory() . $relative_path;
|
||||
|
||||
if ( file_exists( $file_path ) ) {
|
||||
return (string) filemtime( $file_path );
|
||||
}
|
||||
|
||||
return (string) ZEITFRESSER_VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue frontend assets.
|
||||
*/
|
||||
function ztfr_enqueue_code_assets() {
|
||||
|
||||
if ( is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ! ztfr_has_code_block() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$code_css_version = ztfr_code_asset_version( '/assets/css/code.css' );
|
||||
$prism_version = ztfr_code_asset_version( '/assets/js/prism.js' );
|
||||
$code_js_version = ztfr_code_asset_version( '/assets/js/code-block.js' );
|
||||
|
||||
wp_enqueue_style(
|
||||
'ztfr-code',
|
||||
get_template_directory_uri() . '/assets/css/code.css',
|
||||
[],
|
||||
$code_css_version
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'ztfr-prism',
|
||||
get_template_directory_uri() . '/assets/js/prism.js',
|
||||
[],
|
||||
$prism_version,
|
||||
true
|
||||
);
|
||||
|
||||
/**
|
||||
* Disable Prism auto-highlighting.
|
||||
*
|
||||
* Prism auto-runs on DOM ready unless Prism.manual is set before the core
|
||||
* script executes. We disable auto-run so highlighting happens only once
|
||||
* in our custom script after the DOM is ready.
|
||||
*/
|
||||
wp_add_inline_script(
|
||||
'ztfr-prism',
|
||||
'window.Prism = window.Prism || {}; window.Prism.manual = true;',
|
||||
'before'
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'ztfr-code-block',
|
||||
get_template_directory_uri() . '/assets/js/code-block.js',
|
||||
[ 'ztfr-prism' ],
|
||||
$code_js_version,
|
||||
true
|
||||
);
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'ztfr_enqueue_code_assets' );
|
||||
|
||||
/**
|
||||
* Enqueue block editor assets.
|
||||
*/
|
||||
function ztfr_enqueue_code_block_editor_assets() {
|
||||
$editor_js_version = ztfr_code_asset_version( '/assets/js/editor.js' );
|
||||
$code_css_version = ztfr_code_asset_version( '/assets/css/code.css' );
|
||||
$editor_css_version = ztfr_code_asset_version( '/assets/css/editor.css' );
|
||||
|
||||
wp_enqueue_script(
|
||||
'ztfr-code-editor',
|
||||
get_template_directory_uri() . '/assets/js/editor.js',
|
||||
[
|
||||
'wp-blocks',
|
||||
'wp-element',
|
||||
'wp-i18n',
|
||||
'wp-components',
|
||||
'wp-block-editor',
|
||||
],
|
||||
$editor_js_version,
|
||||
true
|
||||
);
|
||||
|
||||
wp_enqueue_style(
|
||||
'ztfr-code-editor-preview',
|
||||
get_template_directory_uri() . '/assets/css/code.css',
|
||||
[],
|
||||
$code_css_version
|
||||
);
|
||||
|
||||
wp_enqueue_style(
|
||||
'ztfr-editor',
|
||||
get_template_directory_uri() . '/assets/css/editor.css',
|
||||
[],
|
||||
$editor_css_version
|
||||
);
|
||||
}
|
||||
add_action( 'enqueue_block_editor_assets', 'ztfr_enqueue_code_block_editor_assets' );
|
||||
|
||||
/**
|
||||
* Register Classic Editor button only for users who can edit and use rich text.
|
||||
*/
|
||||
function ztfr_register_classic_code_button() {
|
||||
|
||||
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'true' !== get_user_option( 'rich_editing' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_filter( 'mce_external_plugins', 'ztfr_add_classic_code_plugin' );
|
||||
add_filter( 'mce_buttons', 'ztfr_add_classic_code_button' );
|
||||
}
|
||||
add_action( 'admin_init', 'ztfr_register_classic_code_button' );
|
||||
|
||||
/**
|
||||
* Add TinyMCE plugin script.
|
||||
*
|
||||
* @param array $plugins TinyMCE plugins.
|
||||
* @return array
|
||||
*/
|
||||
function ztfr_add_classic_code_plugin( $plugins ) {
|
||||
$plugins['ztfr_code_block'] = get_template_directory_uri() . '/assets/js/editor.js';
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add TinyMCE toolbar button.
|
||||
*
|
||||
* @param array $buttons TinyMCE buttons.
|
||||
* @return array
|
||||
*/
|
||||
function ztfr_add_classic_code_button( $buttons ) {
|
||||
$buttons[] = 'ztfr_code_block';
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap code blocks server-side.
|
||||
*
|
||||
* This keeps Classic Editor, Gutenberg and pasted raw code blocks
|
||||
* compatible with the frontend styling without runtime DOM manipulation.
|
||||
*
|
||||
* @param string $content Post content.
|
||||
* @return string
|
||||
*/
|
||||
function ztfr_wrap_code_blocks( $content ) {
|
||||
|
||||
if ( is_admin() ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
if ( false === strpos( $content, '<pre' ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
$content = preg_replace_callback(
|
||||
'/<pre([^>]*)><code([^>]*)>(.*?)<\/code><\/pre>/s',
|
||||
function ( $matches ) {
|
||||
|
||||
$pre_attrs = $matches[1];
|
||||
$code_attrs = $matches[2];
|
||||
$code = $matches[3];
|
||||
|
||||
if ( false === strpos( $pre_attrs, 'language-' ) ) {
|
||||
$pre_attrs .= ' class="language-yaml"';
|
||||
}
|
||||
|
||||
if ( false === strpos( $code_attrs, 'language-' ) ) {
|
||||
$code_attrs .= ' class="language-yaml"';
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'<div class="ztfr-code"><pre%s><code%s>%s</code></pre></div>',
|
||||
$pre_attrs,
|
||||
$code_attrs,
|
||||
$code
|
||||
);
|
||||
},
|
||||
$content
|
||||
);
|
||||
|
||||
return $content;
|
||||
}
|
||||
add_filter( 'the_content', 'ztfr_wrap_code_blocks', 20 );
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Performance tools for existing media.
|
||||
* Image Optimizer
|
||||
*
|
||||
* @package zeitfresser
|
||||
*/
|
||||
@@ -10,18 +10,284 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register admin page
|
||||
* ------------------------------------------------------------------------
|
||||
* Upload Handling (Original File Tracking)
|
||||
* ------------------------------------------------------------------------
|
||||
*/
|
||||
function zeitfresser_register_performance_tools_page() {
|
||||
add_theme_page(
|
||||
'Performance Tools',
|
||||
'Performance Tools',
|
||||
'manage_options',
|
||||
'zeitfresser-performance-tools',
|
||||
'zeitfresser_render_performance_tools_page'
|
||||
function zeitfresser_capture_original_upload( $upload, $context ) {
|
||||
|
||||
if ( empty( $upload['file'] ) ) {
|
||||
return $upload;
|
||||
}
|
||||
|
||||
// Store temporarily (request-scoped)
|
||||
$GLOBALS['zeitfresser_last_uploaded_file'] = $upload['file'];
|
||||
|
||||
return $upload;
|
||||
}
|
||||
add_filter( 'wp_handle_upload', 'zeitfresser_capture_original_upload', 10, 2 );
|
||||
|
||||
/**
|
||||
* Persist original file path to attachment meta
|
||||
*/
|
||||
function zeitfresser_store_original_file( $attachment_id ) {
|
||||
|
||||
if ( ! wp_attachment_is_image( $attachment_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( empty( $GLOBALS['zeitfresser_last_uploaded_file'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$file = $GLOBALS['zeitfresser_last_uploaded_file'];
|
||||
|
||||
// Safety: ensure file still exists
|
||||
if ( ! file_exists( $file ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent overwrite if already set
|
||||
if ( get_post_meta( $attachment_id, '_zeitfresser_original_file', true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
update_post_meta(
|
||||
$attachment_id,
|
||||
'_zeitfresser_original_file',
|
||||
$file
|
||||
);
|
||||
}
|
||||
add_action( 'admin_menu', 'zeitfresser_register_performance_tools_page' );
|
||||
add_action( 'add_attachment', 'zeitfresser_store_original_file' );
|
||||
|
||||
/**
|
||||
* Convert generated JPEG and PNG files to AVIF/WebP when enabled.
|
||||
*
|
||||
* Auto optimization can be disabled for uploads via Customizer.
|
||||
* Manual optimization may still force conversion through a request-scoped flag.
|
||||
*
|
||||
* @param array $formats Output format map.
|
||||
* @return array
|
||||
*/
|
||||
function zeitfresser_image_output_format( $formats ) {
|
||||
|
||||
$auto_enabled = get_theme_mod( 'ztfr_auto_optimize', true );
|
||||
$force_enabled = ! empty( $GLOBALS['zeitfresser_force_image_optimization'] );
|
||||
|
||||
if ( ! $auto_enabled && ! $force_enabled ) {
|
||||
return $formats;
|
||||
}
|
||||
|
||||
if ( function_exists( 'wp_image_editor_supports' ) ) {
|
||||
|
||||
// Prefer AVIF if supported.
|
||||
if ( wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) {
|
||||
$formats['image/jpeg'] = 'image/avif';
|
||||
$formats['image/png'] = 'image/avif';
|
||||
|
||||
// Fallback to WebP.
|
||||
} elseif ( wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
|
||||
$formats['image/jpeg'] = 'image/webp';
|
||||
$formats['image/png'] = 'image/webp';
|
||||
}
|
||||
}
|
||||
|
||||
return $formats;
|
||||
}
|
||||
add_filter( 'image_editor_output_format', 'zeitfresser_image_output_format' );
|
||||
|
||||
/**
|
||||
* Mark images as optimized only when optimization is actually active.
|
||||
*
|
||||
* @param array $metadata Attachment metadata.
|
||||
* @param int $attachment_id Attachment ID.
|
||||
* @return array
|
||||
*/
|
||||
function zeitfresser_mark_new_images_optimized( $metadata, $attachment_id ) {
|
||||
|
||||
if ( ! wp_attachment_is_image( $attachment_id ) ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$auto_enabled = get_theme_mod( 'ztfr_auto_optimize', true );
|
||||
$force_enabled = ! empty( $GLOBALS['zeitfresser_force_image_optimization'] );
|
||||
|
||||
if ( ! $auto_enabled && ! $force_enabled ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
update_post_meta(
|
||||
$attachment_id,
|
||||
'_zeitfresser_media_optimized_version',
|
||||
ZEITFRESSER_IMAGE_OPTIMIZATION_VERSION
|
||||
);
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
add_filter( 'wp_generate_attachment_metadata', 'zeitfresser_mark_new_images_optimized', 20, 2 );
|
||||
|
||||
/**
|
||||
* Auto Optimize Hook
|
||||
*/
|
||||
add_filter(
|
||||
'wp_generate_attachment_metadata',
|
||||
'zeitfresser_auto_optimize_on_upload',
|
||||
15,
|
||||
2
|
||||
);
|
||||
|
||||
function zeitfresser_auto_optimize_on_upload( $metadata, $attachment_id ) {
|
||||
|
||||
// Only images
|
||||
if ( ! wp_attachment_is_image( $attachment_id ) ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
// Feature toggle
|
||||
if ( ! get_theme_mod( 'ztfr_auto_optimize', true ) ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$file = get_attached_file( $attachment_id );
|
||||
|
||||
if ( ! $file || ! file_exists( $file ) ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
// DO NOT overwrite captured original
|
||||
if ( ! get_post_meta( $attachment_id, '_zeitfresser_original_file', true ) ) {
|
||||
update_post_meta( $attachment_id, '_zeitfresser_original_file', $file );
|
||||
}
|
||||
|
||||
// Mark optimized (IMPORTANT: no re-trigger here)
|
||||
update_post_meta(
|
||||
$attachment_id,
|
||||
'_zeitfresser_media_optimized_version',
|
||||
ZEITFRESSER_IMAGE_OPTIMIZATION_VERSION
|
||||
);
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto Delete Hook
|
||||
*/
|
||||
add_filter(
|
||||
'wp_generate_attachment_metadata',
|
||||
'zeitfresser_auto_delete_original_after_upload',
|
||||
30,
|
||||
2
|
||||
);
|
||||
|
||||
function zeitfresser_auto_delete_original_after_upload( $metadata, $attachment_id ) {
|
||||
|
||||
if ( ! wp_attachment_is_image( $attachment_id ) ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$auto_enabled = get_theme_mod( 'ztfr_auto_optimize', true );
|
||||
$delete_enabled = get_theme_mod( 'ztfr_auto_delete', false );
|
||||
|
||||
if ( ! $auto_enabled || ! $delete_enabled ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$original = get_post_meta(
|
||||
$attachment_id,
|
||||
'_zeitfresser_original_file',
|
||||
true
|
||||
);
|
||||
|
||||
if ( ! $original ) {
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
$ext = strtolower( pathinfo( $original, PATHINFO_EXTENSION ) );
|
||||
|
||||
// Skip modern formats
|
||||
if ( in_array( $ext, [ 'webp', 'avif' ], true ) ) {
|
||||
update_post_meta( $attachment_id, '_zeitfresser_original_deleted', 1 );
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
// 🔥 Wenn nichts mehr existiert → fertig
|
||||
if ( ! zeitfresser_original_family_exists( $attachment_id, $original ) ) {
|
||||
update_post_meta( $attachment_id, '_zeitfresser_original_deleted', 1 );
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
// 🔥 HIER passiert der Fix
|
||||
zeitfresser_delete_original_family_files( $attachment_id, $original );
|
||||
|
||||
// Final check
|
||||
if ( ! zeitfresser_original_family_exists( $attachment_id, $original ) ) {
|
||||
update_post_meta( $attachment_id, '_zeitfresser_original_deleted', 1 );
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep generated image quality balanced for file size and visual fidelity.
|
||||
*
|
||||
* @param int $quality Proposed image quality.
|
||||
* @param string $mime_type Image mime type.
|
||||
* @return int
|
||||
*/
|
||||
function zeitfresser_image_quality( $quality, $mime_type = 'image/jpeg' ) {
|
||||
|
||||
$auto_enabled = get_theme_mod( 'ztfr_auto_optimize', true );
|
||||
$force_enabled = ! empty( $GLOBALS['zeitfresser_force_image_optimization'] );
|
||||
|
||||
if ( ! $auto_enabled && ! $force_enabled ) {
|
||||
return $quality;
|
||||
}
|
||||
|
||||
return match ($mime_type) {
|
||||
'image/avif' => 50,
|
||||
'image/webp' => 75,
|
||||
default => 82,
|
||||
};
|
||||
}
|
||||
add_filter( 'wp_editor_set_quality', 'zeitfresser_image_quality', 10, 2 );
|
||||
|
||||
/**
|
||||
* Improve responsive image sizes attribute.
|
||||
*
|
||||
* @param string $sizes Existing sizes attribute.
|
||||
* @param array $size Requested image size.
|
||||
* @return string
|
||||
*/
|
||||
function zeitfresser_responsive_image_sizes( $sizes, $size ) {
|
||||
|
||||
// Single post content
|
||||
if ( is_singular() ) {
|
||||
return '(max-width: 768px) 100vw, (max-width: 1200px) 720px, 720px';
|
||||
}
|
||||
|
||||
// Archive / blog overview
|
||||
if ( is_home() || is_front_page() || is_archive() || is_search() ) {
|
||||
return '(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 400px';
|
||||
}
|
||||
|
||||
return $sizes;
|
||||
}
|
||||
add_filter( 'wp_calculate_image_sizes', 'zeitfresser_responsive_image_sizes', 10, 2 );
|
||||
|
||||
|
||||
/**
|
||||
* Register admin page
|
||||
*/
|
||||
function zeitfresser_register_image_optimizer_page() {
|
||||
add_theme_page(
|
||||
'Image Optimizer',
|
||||
'Image Optimizer',
|
||||
'manage_options',
|
||||
'zeitfresser-image-optimizer',
|
||||
'zeitfresser_render_image_optimizer_page'
|
||||
);
|
||||
}
|
||||
add_action( 'admin_menu', 'zeitfresser_register_image_optimizer_page' );
|
||||
|
||||
/**
|
||||
* Count pending images
|
||||
@@ -427,7 +693,7 @@ function zeitfresser_ajax_optimize_images() {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
check_ajax_referer( 'zeitfresser_performance_tools', 'nonce' );
|
||||
check_ajax_referer( 'zeitfresser_image_optimizer', 'nonce' );
|
||||
|
||||
$results = zeitfresser_process_legacy_images_batch( 25 );
|
||||
|
||||
@@ -465,7 +731,7 @@ function zeitfresser_ajax_delete_originals() {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
check_ajax_referer( 'zeitfresser_performance_tools', 'nonce' );
|
||||
check_ajax_referer( 'zeitfresser_image_optimizer', 'nonce' );
|
||||
|
||||
$deleted = zeitfresser_delete_originals_batch( 10 );
|
||||
$total = zeitfresser_get_total_originals_count();
|
||||
@@ -486,7 +752,7 @@ add_action( 'wp_ajax_zeitfresser_delete_originals', 'zeitfresser_ajax_delete_ori
|
||||
/**
|
||||
* Render UI
|
||||
*/
|
||||
function zeitfresser_render_performance_tools_page() {
|
||||
function zeitfresser_render_image_optimizer_page() {
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
return;
|
||||
@@ -519,7 +785,7 @@ function zeitfresser_render_performance_tools_page() {
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1>Zeitfresser Performance Tools</h1>
|
||||
<h1>Zeitfresser Image Optimizer</h1>
|
||||
|
||||
<div class="notice notice-info" style="max-width:800px;margin-top:20px;">
|
||||
<p>
|
||||
@@ -532,7 +798,7 @@ function zeitfresser_render_performance_tools_page() {
|
||||
• Once optimized, original images can be deleted to save disk space.<br><br>
|
||||
|
||||
<strong>Automation:</strong><br>
|
||||
• You can enable automatic optimization on upload in the Customizer under <em>Performance Tools Settings</em>.<br>
|
||||
• You can enable automatic optimization on upload in the Customizer under <em>Image Optimizer Settings</em>.<br>
|
||||
• Optionally, original images can also be deleted automatically after successful optimization.<br><br>
|
||||
|
||||
<strong>Safety:</strong><br>
|
||||
@@ -653,7 +919,7 @@ function deleteBatch() {
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||||
body: new URLSearchParams({
|
||||
action: 'zeitfresser_delete_originals',
|
||||
nonce: '<?php echo wp_create_nonce('zeitfresser_performance_tools'); ?>'
|
||||
nonce: '<?php echo wp_create_nonce('zeitfresser_image_optimizer'); ?>'
|
||||
})
|
||||
})
|
||||
.then(res => res.json())
|
||||
@@ -732,7 +998,7 @@ function processBatch() {
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||||
body: new URLSearchParams({
|
||||
action: 'zeitfresser_optimize_images',
|
||||
nonce: '<?php echo wp_create_nonce('zeitfresser_performance_tools'); ?>'
|
||||
nonce: '<?php echo wp_create_nonce('zeitfresser_image_optimizer'); ?>'
|
||||
})
|
||||
})
|
||||
.then(res => res.json())
|
||||
@@ -224,3 +224,11 @@ if ( ! function_exists( 'zeitfresser_asset' ) ) {
|
||||
return get_template_directory_uri() . '/assets/' . ltrim($path, '/');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete Cookie Button
|
||||
*/
|
||||
add_filter( 'comment_form_default_fields', function( $fields ) {
|
||||
unset( $fields['cookies'] );
|
||||
return $fields;
|
||||
});
|
||||
@@ -5,7 +5,7 @@ Author: Zeitfresser
|
||||
Author URI: https://ztfr.eu/
|
||||
Theme URI: https://ztfr.eu/
|
||||
Description: Zeitfresser Wordpress Theme
|
||||
Version: 2.5
|
||||
Version: 2.8
|
||||
Tested up to: 6.2
|
||||
Requires PHP: 7.0
|
||||
License: GNU General Public License v2 or later
|
||||
@@ -247,6 +247,16 @@ textarea {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Article Justifiy */
|
||||
|
||||
.entry-content p,
|
||||
.post-content p {
|
||||
text-align: justify;
|
||||
hyphens: auto;
|
||||
word-break: normal;
|
||||
overflow-wrap: break-word;
|
||||
}
|
||||
|
||||
/* Header Wrapper */
|
||||
|
||||
.header-wrapper {
|
||||
@@ -305,8 +315,11 @@ textarea {
|
||||
background-color: var(--footer-color);
|
||||
color: var(--light-color);
|
||||
|
||||
border-radius: 0;
|
||||
border: 1px solid rgba(248, 248, 242, 0.08);
|
||||
|
||||
padding: 1rem;
|
||||
margin-bottom: 2rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.widget ul li {
|
||||
@@ -755,12 +768,6 @@ input[type=button]:hover {
|
||||
fill: var(--hover-color);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.social-links {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* Navigation Icons */
|
||||
|
||||
#nav-icon3 {
|
||||
@@ -997,7 +1004,7 @@ header.site-header .social-links svg:hover {
|
||||
}
|
||||
|
||||
.site-header .search-field::placeholder {
|
||||
color: var(--light-color) !important;
|
||||
color: var(--dark-color) !important;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
@@ -1148,6 +1155,10 @@ header.site-header .social-links svg:hover {
|
||||
|
||||
.custom-box {
|
||||
background-color: var(--footer-color);
|
||||
|
||||
border-radius: 0;
|
||||
border: 1px solid rgba(248, 248, 242, 0.08);
|
||||
|
||||
padding: 0.1rem 1rem;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
@@ -1160,33 +1171,62 @@ header.site-header .social-links svg:hover {
|
||||
|
||||
.widget_search .wp-block-search__inside-wrapper {
|
||||
display: grid;
|
||||
grid-template-columns: 4fr 1fr;
|
||||
grid-template-columns: 1fr auto;
|
||||
gap: 0;
|
||||
background: transparent;
|
||||
border: none;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
.widget_search .wp-block-search__inside-wrapper {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.widget_search .wp-block-search__inside-wrapper {
|
||||
display: grid;
|
||||
}
|
||||
}
|
||||
|
||||
.widget_search input[type="search"] {
|
||||
.widget_search .wp-block-search__input,
|
||||
.sidebar .wp-block-search__input {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 1rem 1.5rem;
|
||||
border-radius: 0;
|
||||
height: 36px;
|
||||
padding: 0 12px;
|
||||
|
||||
background-color: rgba(255,255,255,0.04) !important;
|
||||
color: var(--light-color);
|
||||
|
||||
border: 1px solid rgba(255,255,255,0.1) !important;
|
||||
border-radius: 0 !important;
|
||||
box-shadow: none !important;
|
||||
outline: none !important;
|
||||
transition: border-color 0.2s ease, background-color 0.2s ease;
|
||||
|
||||
appearance: none;
|
||||
}
|
||||
|
||||
.widget_search .wp-block-search__input:focus,
|
||||
.sidebar .wp-block-search__input:focus {
|
||||
border-color: var(--hover-color) !important;
|
||||
outline: none !important;
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.widget_search .wp-block-search__input::placeholder,
|
||||
.sidebar .wp-block-search__input::placeholder {
|
||||
color: rgba(248,248,242,0.5);
|
||||
}
|
||||
|
||||
.widget_search input[type="submit"],
|
||||
.widget_search .wp-block-search__button {
|
||||
width: 100%;
|
||||
padding: 1rem 2rem;
|
||||
height: 36px;
|
||||
padding: 0 14px;
|
||||
|
||||
border: none;
|
||||
border-radius: 0;
|
||||
|
||||
background-color: var(--footer-color);
|
||||
color: var(--light-color);
|
||||
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.widget_search .wp-block-search__button:hover {
|
||||
background-color: var(--hover-color);
|
||||
color: var(--dark-color);
|
||||
}
|
||||
|
||||
/* Empty State (404 + Search) */
|
||||
@@ -1205,9 +1245,12 @@ header.site-header .social-links svg:hover {
|
||||
.error-404 .page-content,
|
||||
.search-no-results .page-content {
|
||||
background-color: var(--footer-color);
|
||||
|
||||
border-radius: 0;
|
||||
border: 1px solid rgba(248, 248, 242, 0.08);
|
||||
|
||||
padding: 2rem;
|
||||
margin: 1.5rem auto 0;
|
||||
border-radius: 6px;
|
||||
max-width: 500px;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
@@ -1238,6 +1281,8 @@ header.site-header .social-links svg:hover {
|
||||
background-color: rgba(255,255,255,0.04);
|
||||
border: 1px solid rgba(255,255,255,0.1);
|
||||
color: var(--light-color);
|
||||
|
||||
transition: color 0.2s ease, background-size 0.2s ease, border-color 0.2s ease;
|
||||
}
|
||||
|
||||
.error-404 .search-field:focus,
|
||||
@@ -1248,12 +1293,13 @@ header.site-header .social-links svg:hover {
|
||||
|
||||
.error-404 .search-submit,
|
||||
.search-no-results .search-submit {
|
||||
background-color: var(--footer-color);
|
||||
color: var(--light-color);
|
||||
background-color: var(--light-color);
|
||||
color: var(--dark-color);
|
||||
|
||||
border: 1px solid rgba(255,255,255,0.15);
|
||||
|
||||
padding: 0.75rem 1.5rem;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
@@ -1275,71 +1321,6 @@ header.site-header .social-links svg:hover {
|
||||
}
|
||||
}
|
||||
|
||||
/* Search Widget */
|
||||
|
||||
.site-header .search-field:focus {
|
||||
width: 320px;
|
||||
|
||||
background-color: rgba(255,255,255,0.85);
|
||||
background-image: url(images/search-b.svg);
|
||||
|
||||
cursor: text;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
@media (max-width: 500px) {
|
||||
.site-header .search-field:focus {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.site-header .search-field::placeholder {
|
||||
color: var(--dark-color);
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.site-header .search-submit {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Sidebar Search */
|
||||
|
||||
.widget_search form {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 32px;
|
||||
border: 1px solid #4a4d61;
|
||||
border-radius: 4px;
|
||||
background-color: #383a4a;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.widget_search input[type="search"] {
|
||||
flex: 1;
|
||||
padding: 0 10px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: var(--light-color);
|
||||
}
|
||||
|
||||
.widget_search button[type="submit"] {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 0 12px;
|
||||
height: 100%;
|
||||
border: none;
|
||||
background-color: var(--hover-color);
|
||||
color: var(--dark-color);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
text-transform: uppercase;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.widget_search form:focus-within {
|
||||
border-color: var(--hover-color);
|
||||
}
|
||||
|
||||
/* Posts and Pages */
|
||||
|
||||
.sticky {
|
||||
@@ -1366,12 +1347,6 @@ header.site-header .social-links svg:hover {
|
||||
margin-bottom: var(--space-md);
|
||||
}
|
||||
|
||||
.entry-content,
|
||||
.post-content,
|
||||
.inner-article-content {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.single-post .entry-content > * + * {
|
||||
margin-top: var(--space-md);
|
||||
}
|
||||
@@ -1582,7 +1557,6 @@ header.page-header h1 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
|
||||
font-family: var(--primary-font);
|
||||
margin: 0.5rem 0;
|
||||
}
|
||||
@@ -1590,7 +1564,7 @@ header.page-header h1 {
|
||||
.comments a {
|
||||
background: none;
|
||||
color: inherit;
|
||||
transform: translateY(-1px);
|
||||
transform: translateY(-0.5px);
|
||||
}
|
||||
|
||||
.comments svg {
|
||||
@@ -1685,21 +1659,6 @@ header.page-header h1 {
|
||||
color: var(--light-color);
|
||||
}
|
||||
|
||||
/* Readmore KANN WEG? */
|
||||
|
||||
.readmore {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
|
||||
font-family: var(--primary-font);
|
||||
}
|
||||
|
||||
.readmore svg {
|
||||
height: 1.2em;
|
||||
fill: currentColor;
|
||||
}
|
||||
|
||||
/* Header / Footer Meta */
|
||||
|
||||
.info.ihead,
|
||||
@@ -1742,6 +1701,10 @@ header.page-header h1 {
|
||||
.comment-list .comment {
|
||||
background-color: var(--footer-color);
|
||||
color: var(--light-color);
|
||||
|
||||
border-radius: 0;
|
||||
border: 1px solid rgba(248, 248, 242, 0.08);
|
||||
|
||||
padding: 20px;
|
||||
margin-bottom: 15px;
|
||||
border-left: 4px solid var(--hover-color);
|
||||
@@ -1804,6 +1767,7 @@ header.page-header h1 {
|
||||
background-color: rgba(255,255,255,0.04);
|
||||
color: var(--light-color);
|
||||
border: 1px solid rgba(255,255,255,0.1);
|
||||
transition: border-color 0.2s ease, background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.comment-form input:not([type="submit"]):focus,
|
||||
@@ -1846,6 +1810,9 @@ header.page-header h1 {
|
||||
color: var(--light-color);
|
||||
padding: 2rem 0;
|
||||
margin-top: 3rem;
|
||||
|
||||
border-radius: 0;
|
||||
border-top: 1px solid rgba(248, 248, 242, 0.08);
|
||||
}
|
||||
|
||||
.site-footer .site-info {
|
||||
@@ -1855,7 +1822,7 @@ header.page-header h1 {
|
||||
}
|
||||
|
||||
.site-footer a {
|
||||
color: inherit; /* inherits light-color */
|
||||
color: inherit;
|
||||
border-bottom: 1px solid rgba(255,255,255,0.2);
|
||||
}
|
||||
|
||||
@@ -1972,16 +1939,19 @@ header.page-header h1 {
|
||||
.zeitfresser-floating-toc__item a {
|
||||
transform: translateZ(0);
|
||||
display: block;
|
||||
padding-left: 14px;
|
||||
|
||||
border-left: 3px solid transparent;
|
||||
|
||||
color: var(--light-color);
|
||||
font-size: 0.92rem;
|
||||
line-height: 1.35;
|
||||
text-decoration: none;
|
||||
|
||||
transition: color 0.18s ease, border-color 0.18s ease;
|
||||
}
|
||||
|
||||
.zeitfresser-floating-toc__item.level-2 a {
|
||||
padding-left: 14px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
@@ -1990,7 +1960,7 @@ header.page-header h1 {
|
||||
}
|
||||
|
||||
.zeitfresser-floating-toc__item.level-4 a {
|
||||
padding-left: 26px;
|
||||
padding-left: 22px;
|
||||
}
|
||||
|
||||
.zeitfresser-floating-toc__item a:hover,
|
||||
|
||||
Reference in New Issue
Block a user