refactor(inc, image-optimizer): restructure /inc architecture and standardize image optimizer module

- reorganized /inc directory structure for improved separation of concerns
  - grouped files into customizer, utilities, and tools
  - improved naming consistency across files (e.g. *-settings, template-tags, etc.)
  - simplified functions.php includes for better readability and maintainability

- refactored Customizer structure
  - extracted image optimizer settings from core-settings into dedicated module
  - consolidated settings, UI logic, and styles into a single feature file
  - improved naming consistency for hooks and functions

- standardized Image Optimizer admin tool
  - renamed "Performance Tools" to "Image Optimizer" across UI and hooks
  - updated admin page registration, callback names, and menu labels
  - aligned AJAX nonce naming for consistency and clarity

- preserved all existing logic and behavior (no functional changes)
- improved overall code organization and long-term maintainability

no breaking changes
This commit is contained in:
2026-04-30 21:41:19 +02:00
parent 84b2b85bf6
commit 1020442c06
14 changed files with 137 additions and 142 deletions
+15 -20
View File
@@ -24,38 +24,33 @@ if ( ! defined( 'ZEITFRESSER_IMAGE_OPTIMIZATION_VERSION' ) ) {
/** /**
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
* Core Modules * Customizer
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
*/ */
require get_template_directory() . '/inc/customizer/core-settings.php';
// Helpers (foundation) require get_template_directory() . '/inc/customizer/general-settings.php';
require get_template_directory() . '/inc/helpers/zeitfresser-helpers.php'; require get_template_directory() . '/inc/customizer/layout-settings.php';
require get_template_directory() . '/inc/customizer/toc-settings.php';
// Theme logic require get_template_directory() . '/inc/customizer/social-settings.php';
require get_template_directory() . '/inc/zeitfresser-toc.php'; require get_template_directory() . '/inc/customizer/image-optimizer-settings.php';
// Performance layer
require get_template_directory() . '/inc/performance/performance-tools.php';
/** /**
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
* Customizer (modular) * Utilities
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
*/ */
require get_template_directory() . '/inc/customizer/core.php'; require get_template_directory() . '/inc/utilities/helpers.php';
require get_template_directory() . '/inc/customizer/general.php'; require get_template_directory() . '/inc/utilities/template-tags.php';
require get_template_directory() . '/inc/customizer/layout.php'; require get_template_directory() . '/inc/utilities/template-functions.php';
require get_template_directory() . '/inc/customizer/toc.php'; require get_template_directory() . '/inc/utilities/pagination.php';
require get_template_directory() . '/inc/customizer/social.php'; require get_template_directory() . '/inc/utilities/toc.php';
/** /**
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
* Theme Utilities * Tools
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
*/ */
require get_template_directory() . '/inc/template-tags.php'; require get_template_directory() . '/inc/tools/image-optimizer.php';
require get_template_directory() . '/inc/template-functions.php';
require get_template_directory() . '/inc/pagination.php';
/** /**
* ------------------------------------------------------------------------ * ------------------------------------------------------------------------
+58
View File
@@ -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 <?php
/** /**
* Theme Customizer Core * Image Optimizer (Settings + UI)
* *
* @package zeitfresser * @package zeitfresser
*/ */
function zeitfresser_customize_register( $wp_customize ) { /**
* ------------------------------------------------------------------------
// Live Preview support * Settings
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; * ------------------------------------------------------------------------
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; */
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; function zeitfresser_customize_image_optimizer_settings( $wp_customize ) {
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',
)
);
}
/** /**
* Performance Tools Section * Image Optimizer Section
*/ */
$wp_customize->add_section( $wp_customize->add_section(
'ztfr_performance_tools', 'ztfr_image_optimizer',
array( array(
'title' => 'Performance Tools Settings', 'title' => 'Image Optimizer',
'priority' => 160, 'priority' => 160,
) )
); );
@@ -56,7 +38,7 @@ function zeitfresser_customize_register( $wp_customize ) {
'ztfr_auto_optimize', 'ztfr_auto_optimize',
array( array(
'type' => 'checkbox', 'type' => 'checkbox',
'section' => 'ztfr_performance_tools', 'section' => 'ztfr_image_optimizer',
'label' => 'Auto Optimize Pictures on Upload', 'label' => 'Auto Optimize Pictures on Upload',
'description' => 'Automatically converts images to AVIF/WebP.', 'description' => 'Automatically converts images to AVIF/WebP.',
) )
@@ -77,43 +59,21 @@ function zeitfresser_customize_register( $wp_customize ) {
'ztfr_auto_delete', 'ztfr_auto_delete',
array( array(
'type' => 'checkbox', 'type' => 'checkbox',
'section' => 'ztfr_performance_tools', 'section' => 'ztfr_image_optimizer',
'label' => 'Auto Delete Original Pictures', 'label' => 'Auto Delete Original Pictures',
'description' => 'Deletes originals after optimization.', '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() { function zeitfresser_customize_image_optimizer_ui() {
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() {
?> ?>
<script> <script>
(function() { (function() {
@@ -193,7 +153,6 @@ function zeitfresser_customize_controls_dependency_js() {
return; return;
} }
// Retry max 10x
if (attempts < 10) { if (attempts < 10) {
attempts++; attempts++;
setTimeout(tryInit, 200); setTimeout(tryInit, 200);
@@ -225,20 +184,27 @@ function zeitfresser_customize_controls_dependency_js() {
</script> </script>
<?php <?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() { function zeitfresser_customize_image_optimizer_ui_styles() {
?> ?>
<style> <style>
#customize-control-ztfr_auto_optimize > label, #customize-control-ztfr_auto_optimize > label,
#customize-control-ztfr_auto_delete > label { #customize-control-ztfr_auto_delete > label {
display:flex; display:flex;
align-items:flex-start; align-items:flex-start;
gap:6px; gap:6px;
}
</style>
<?php
} }
</style> add_action(
<?php 'customize_controls_enqueue_scripts',
}); 'zeitfresser_customize_image_optimizer_ui_styles'
);
@@ -1,6 +1,6 @@
<?php <?php
/** /**
* Performance tools for existing media. * Image Optimizer
* *
* @package zeitfresser * @package zeitfresser
*/ */
@@ -12,16 +12,16 @@ if ( ! defined( 'ABSPATH' ) ) {
/** /**
* Register admin page * Register admin page
*/ */
function zeitfresser_register_performance_tools_page() { function zeitfresser_register_image_optimizer_page() {
add_theme_page( add_theme_page(
'Performance Tools', 'Image Optimizer',
'Performance Tools', 'Image Optimizer',
'manage_options', 'manage_options',
'zeitfresser-performance-tools', 'zeitfresser-image-optimizer',
'zeitfresser_render_performance_tools_page' 'zeitfresser_render_image_optimizer_page'
); );
} }
add_action( 'admin_menu', 'zeitfresser_register_performance_tools_page' ); add_action( 'admin_menu', 'zeitfresser_register_image_optimizer_page' );
/** /**
* Count pending images * Count pending images
@@ -427,7 +427,7 @@ function zeitfresser_ajax_optimize_images() {
wp_send_json_error(); 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 ); $results = zeitfresser_process_legacy_images_batch( 25 );
@@ -465,7 +465,7 @@ function zeitfresser_ajax_delete_originals() {
wp_send_json_error(); wp_send_json_error();
} }
check_ajax_referer( 'zeitfresser_performance_tools', 'nonce' ); check_ajax_referer( 'zeitfresser_image_optimizer', 'nonce' );
$deleted = zeitfresser_delete_originals_batch( 10 ); $deleted = zeitfresser_delete_originals_batch( 10 );
$total = zeitfresser_get_total_originals_count(); $total = zeitfresser_get_total_originals_count();
@@ -486,7 +486,7 @@ add_action( 'wp_ajax_zeitfresser_delete_originals', 'zeitfresser_ajax_delete_ori
/** /**
* Render UI * Render UI
*/ */
function zeitfresser_render_performance_tools_page() { function zeitfresser_render_image_optimizer_page() {
if ( ! current_user_can( 'manage_options' ) ) { if ( ! current_user_can( 'manage_options' ) ) {
return; return;
@@ -519,7 +519,7 @@ function zeitfresser_render_performance_tools_page() {
?> ?>
<div class="wrap"> <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;"> <div class="notice notice-info" style="max-width:800px;margin-top:20px;">
<p> <p>
@@ -532,7 +532,7 @@ function zeitfresser_render_performance_tools_page() {
Once optimized, original images can be deleted to save disk space.<br><br> Once optimized, original images can be deleted to save disk space.<br><br>
<strong>Automation:</strong><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> Optionally, original images can also be deleted automatically after successful optimization.<br><br>
<strong>Safety:</strong><br> <strong>Safety:</strong><br>
@@ -653,7 +653,7 @@ function deleteBatch() {
headers: {'Content-Type': 'application/x-www-form-urlencoded'}, headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams({ body: new URLSearchParams({
action: 'zeitfresser_delete_originals', 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()) .then(res => res.json())
@@ -732,7 +732,7 @@ function processBatch() {
headers: {'Content-Type': 'application/x-www-form-urlencoded'}, headers: {'Content-Type': 'application/x-www-form-urlencoded'},
body: new URLSearchParams({ body: new URLSearchParams({
action: 'zeitfresser_optimize_images', 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()) .then(res => res.json())
+12 -36
View File
@@ -247,6 +247,16 @@ textarea {
margin: 0; 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 */
.header-wrapper { .header-wrapper {
@@ -997,7 +1007,7 @@ header.site-header .social-links svg:hover {
} }
.site-header .search-field::placeholder { .site-header .search-field::placeholder {
color: var(--light-color) !important; color: var(--dark-color)) !important;
font-weight: 300; font-weight: 300;
} }
@@ -1275,33 +1285,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 */ /* Sidebar Search */
.widget_search form { .widget_search form {
@@ -1366,12 +1349,6 @@ header.site-header .social-links svg:hover {
margin-bottom: var(--space-md); margin-bottom: var(--space-md);
} }
.entry-content,
.post-content,
.inner-article-content {
max-width: 100%;
}
.single-post .entry-content > * + * { .single-post .entry-content > * + * {
margin-top: var(--space-md); margin-top: var(--space-md);
} }
@@ -1582,7 +1559,6 @@ header.page-header h1 {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 0.3rem; gap: 0.3rem;
font-family: var(--primary-font); font-family: var(--primary-font);
margin: 0.5rem 0; margin: 0.5rem 0;
} }
@@ -1590,7 +1566,7 @@ header.page-header h1 {
.comments a { .comments a {
background: none; background: none;
color: inherit; color: inherit;
transform: translateY(-1px); transform: translateY(-0.5px);
} }
.comments svg { .comments svg {