Files
2026-07-29 12:44:34 +02:00

164 lines
6.3 KiB
PHP

<?php
/** Theme functions for Commander1024 2026. */
function c1024_2026_setup() {
load_theme_textdomain( 'c1024-2026', get_template_directory() . '/languages' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'title-tag' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'responsive-embeds' );
add_theme_support(
'custom-logo',
array(
'flex-width' => true,
'flex-height' => true,
)
);
add_theme_support(
'html5',
array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script' )
);
add_theme_support( 'align-wide' );
add_theme_support( 'editor-styles' );
// Classic-editor stylesheet; the same file is explicitly enqueued for the block editor below.
add_editor_style( 'editor-style.css' );
register_nav_menus(
array(
'primary' => __( 'Primary menu', 'c1024-2026' ),
'footer' => __( 'Footer menu', 'c1024-2026' ),
)
);
}
// Register theme capabilities before WordPress initializes theme-dependent features.
add_action( 'after_setup_theme', 'c1024_2026_setup' );
function c1024_2026_assets() {
wp_enqueue_style( 'c1024-2026-style', get_stylesheet_uri(), array(), '1.0.0' );
wp_enqueue_script( 'c1024-2026-theme', get_template_directory_uri() . '/assets/js/theme.js', array(), '1.0.0', true );
}
// Load public assets through WordPress so dependencies and plugin integrations remain ordered.
add_action( 'wp_enqueue_scripts', 'c1024_2026_assets' );
/**
* Keep W3 Total Cache from converting every image into a JavaScript-only placeholder.
*
* Native browser lazy loading can still be enabled elsewhere, but W3TC's output-buffer
* mutator removes `src` entirely and therefore prevents images from working without JS.
*/
function c1024_2026_disable_w3tc_javascript_lazyload( $can_process ) {
$can_process['enabled'] = false;
$can_process['reason'] = 'Commander1024 theme preserves non-JavaScript image delivery';
return $can_process;
}
add_filter( 'w3tc_lazyload_can_process', 'c1024_2026_disable_w3tc_javascript_lazyload' );
function c1024_2026_block_editor_assets() {
// Load the complete canvas stylesheet inside Gutenberg's editor iframe.
wp_enqueue_style( 'c1024-2026-editor-style', get_theme_file_uri( '/editor-style.css' ), array(), '1.0.0' );
}
add_action( 'enqueue_block_editor_assets', 'c1024_2026_block_editor_assets' );
/** Register the three sitewide widget columns rendered above the footer. */
function c1024_2026_widgets_init() {
for ( $column = 1; $column <= 3; $column++ ) {
register_sidebar(
array(
'name' => sprintf( __( 'Footer column %d', 'c1024-2026' ), $column ),
'id' => 'footer-' . $column,
'description' => __( 'Widgets displayed above the site footer on every page.', 'c1024-2026' ),
'before_widget' => '<section id="%1$s" class="footer-widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="footer-widget-title">',
'after_title' => '</h2>',
)
);
}
}
add_action( 'widgets_init', 'c1024_2026_widgets_init' );
// These settings drive the optional front-page hero without hard-coding media or copy.
function c1024_2026_customize_register( $wp_customize ) {
$wp_customize->add_section(
'c1024_2026_home_hero',
array(
'title' => __( 'Home page video hero', 'c1024-2026' ),
'description' => __( 'Displayed on the site front page.', 'c1024-2026' ),
'priority' => 30,
)
);
$wp_customize->add_setting( 'c1024_2026_hero_video', array( 'sanitize_callback' => 'absint' ) );
$wp_customize->add_control(
new WP_Customize_Media_Control(
$wp_customize,
'c1024_2026_hero_video',
array(
'label' => __( 'Hero video', 'c1024-2026' ),
'section' => 'c1024_2026_home_hero',
'mime_type' => 'video',
)
)
);
$wp_customize->add_setting(
'c1024_2026_hero_title',
array(
'default' => get_bloginfo( 'name' ),
'sanitize_callback' => 'sanitize_text_field',
)
);
$wp_customize->add_control(
'c1024_2026_hero_title',
array(
'label' => __( 'Overlay heading', 'c1024-2026' ),
'section' => 'c1024_2026_home_hero',
'type' => 'text',
)
);
$wp_customize->add_setting( 'c1024_2026_hero_text', array( 'sanitize_callback' => 'sanitize_textarea_field' ) );
$wp_customize->add_control(
'c1024_2026_hero_text',
array(
'label' => __( 'Overlay text', 'c1024-2026' ),
'section' => 'c1024_2026_home_hero',
'type' => 'textarea',
)
);
}
// Customize controls are registered only while the Customizer API is available.
add_action( 'customize_register', 'c1024_2026_customize_register' );
/**
* Render comments without the default avatar-heavy, numbered-list presentation.
*
* WordPress's Walker_Comment closes the wrapping list item after this callback.
*/
function c1024_2026_comment( $comment, $args, $depth ) {
?>
<li <?php comment_class( 'comment-item' ); ?> id="comment-<?php comment_ID(); ?>">
<article class="comment-body" id="div-comment-<?php comment_ID(); ?>">
<header class="comment-meta">
<?php echo get_avatar( $comment, 44, '', sprintf( esc_attr__( 'Avatar for %s', 'c1024-2026' ), get_comment_author( $comment ) ), array( 'class' => 'comment-avatar' ) ); ?>
<div class="comment-identity">
<span class="comment-author"><?php echo wp_kses_post( get_comment_author_link( $comment ) ); ?></span>
<time class="comment-published" datetime="<?php echo esc_attr( get_comment_date( DATE_W3C, $comment ) ); ?>"><?php echo esc_html( get_comment_date( '', $comment ) ); ?></time>
<?php edit_comment_link( esc_html__( 'Edit', 'c1024-2026' ), '<span class="comment-edit-link">', '</span>' ); ?>
</div>
</header>
<?php if ( '0' === $comment->comment_approved ) { ?>
<p class="comment-awaiting-moderation"><?php esc_html_e( 'Your comment is awaiting moderation.', 'c1024-2026' ); ?></p>
<?php } ?>
<div class="comment-content"><?php comment_text(); ?></div>
<footer class="comment-actions">
<?php comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'], 'reply_text' => esc_html__( 'Reply', 'c1024-2026' ) ) ) ); ?>
</footer>
</article>
<?php
}
function c1024_2026_excerpt_more( $more ) {
return '…';
}
// Keep generated excerpts visually concise across all card-based archive loops.
add_filter( 'excerpt_more', 'c1024_2026_excerpt_more' );