Files
C1024_2026/functions.php
T

132 lines
5.0 KiB
PHP

<?php
/** Theme functions for Commander 1024 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' );
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' );
// 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' );