Init commit

This commit is contained in:
2025-03-06 15:19:05 +00:00
commit 03785483e8
58 changed files with 9792 additions and 0 deletions

View File

@@ -0,0 +1,206 @@
<?php
/**
* Functions which enhance the theme by hooking into WordPress
*
* @package FamiliaRosaTheme
*/
/**
* Add a pingback url auto-discovery header for single posts, pages, or attachments.
*/
function familiarosatheme_pingback_header() {
if ( is_singular() && pings_open() ) {
printf( '<link rel="pingback" href="%s">', esc_url( get_bloginfo( 'pingback_url' ) ) );
}
}
add_action( 'wp_head', 'familiarosatheme_pingback_header' );
/**
* Changes comment form default fields.
*
* @param array $defaults The default comment form arguments.
*
* @return array Returns the modified fields.
*/
function familiarosatheme_comment_form_defaults( $defaults ) {
$comment_field = $defaults['comment_field'];
// Adjust height of comment form.
$defaults['comment_field'] = preg_replace( '/rows="\d+"/', 'rows="5"', $comment_field );
return $defaults;
}
add_filter( 'comment_form_defaults', 'familiarosatheme_comment_form_defaults' );
/**
* Filters the default archive titles.
*/
function familiarosatheme_get_the_archive_title() {
if ( is_category() ) {
$title = __( 'Category Archives: ', 'familiarosatheme' ) . '<span>' . single_term_title( '', false ) . '</span>';
} elseif ( is_tag() ) {
$title = __( 'Tag Archives: ', 'familiarosatheme' ) . '<span>' . single_term_title( '', false ) . '</span>';
} elseif ( is_author() ) {
$title = __( 'Author Archives: ', 'familiarosatheme' ) . '<span>' . get_the_author_meta( 'display_name' ) . '</span>';
} elseif ( is_year() ) {
$title = __( 'Yearly Archives: ', 'familiarosatheme' ) . '<span>' . get_the_date( _x( 'Y', 'yearly archives date format', 'familiarosatheme' ) ) . '</span>';
} elseif ( is_month() ) {
$title = __( 'Monthly Archives: ', 'familiarosatheme' ) . '<span>' . get_the_date( _x( 'F Y', 'monthly archives date format', 'familiarosatheme' ) ) . '</span>';
} elseif ( is_day() ) {
$title = __( 'Daily Archives: ', 'familiarosatheme' ) . '<span>' . get_the_date() . '</span>';
} elseif ( is_post_type_archive() ) {
$cpt = get_post_type_object( get_queried_object()->name );
$title = sprintf(
/* translators: %s: Post type singular name */
esc_html__( '%s Archives', 'familiarosatheme' ),
$cpt->labels->singular_name
);
} elseif ( is_tax() ) {
$tax = get_taxonomy( get_queried_object()->taxonomy );
$title = sprintf(
/* translators: %s: Taxonomy singular name */
esc_html__( '%s Archives', 'familiarosatheme' ),
$tax->labels->singular_name
);
} else {
$title = __( 'Archives:', 'familiarosatheme' );
}
return $title;
}
add_filter( 'get_the_archive_title', 'familiarosatheme_get_the_archive_title' );
/**
* Determines whether the post thumbnail can be displayed.
*/
function familiarosatheme_can_show_post_thumbnail() {
return apply_filters( 'familiarosatheme_can_show_post_thumbnail', ! post_password_required() && ! is_attachment() && has_post_thumbnail() );
}
/**
* Returns the size for avatars used in the theme.
*/
function familiarosatheme_get_avatar_size() {
return 60;
}
/**
* Create the continue reading link
*
* @param string $more_string The string shown within the more link.
*/
function familiarosatheme_continue_reading_link( $more_string ) {
if ( ! is_admin() ) {
$continue_reading = sprintf(
/* translators: %s: Name of current post. */
wp_kses( __( 'Continue reading %s', 'familiarosatheme' ), array( 'span' => array( 'class' => array() ) ) ),
the_title( '<span class="sr-only">"', '"</span>', false )
);
$more_string = '<a href="' . esc_url( get_permalink() ) . '">' . $continue_reading . '</a>';
}
return $more_string;
}
// Filter the excerpt more link.
add_filter( 'excerpt_more', 'familiarosatheme_continue_reading_link' );
// Filter the content more link.
add_filter( 'the_content_more_link', 'familiarosatheme_continue_reading_link' );
/**
* Outputs a comment in the HTML5 format.
*
* This function overrides the default WordPress comment output in HTML5
* format, adding the required class for Tailwind Typography. Based on the
* `html5_comment()` function from WordPress core.
*
* @param WP_Comment $comment Comment to display.
* @param array $args An array of arguments.
* @param int $depth Depth of the current comment.
*/
function familiarosatheme_html5_comment( $comment, $args, $depth ) {
$tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
$commenter = wp_get_current_commenter();
$show_pending_links = ! empty( $commenter['comment_author'] );
if ( $commenter['comment_author_email'] ) {
$moderation_note = __( 'Your comment is awaiting moderation.', 'familiarosatheme' );
} else {
$moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.', 'familiarosatheme' );
}
?>
<<?php echo esc_attr( $tag ); ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( $comment->has_children ? 'parent' : '', $comment ); ?>>
<article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
<footer class="comment-meta">
<div class="comment-author vcard">
<?php
if ( 0 !== $args['avatar_size'] ) {
echo get_avatar( $comment, $args['avatar_size'] );
}
?>
<?php
$comment_author = get_comment_author_link( $comment );
if ( '0' === $comment->comment_approved && ! $show_pending_links ) {
$comment_author = get_comment_author( $comment );
}
printf(
/* translators: %s: Comment author link. */
wp_kses_post( __( '%s <span class="says">says:</span>', 'familiarosatheme' ) ),
sprintf( '<b class="fn">%s</b>', wp_kses_post( $comment_author ) )
);
?>
</div><!-- .comment-author -->
<div class="comment-metadata">
<?php
printf(
'<a href="%s"><time datetime="%s">%s</time></a>',
esc_url( get_comment_link( $comment, $args ) ),
esc_attr( get_comment_time( 'c' ) ),
esc_html(
sprintf(
/* translators: 1: Comment date, 2: Comment time. */
__( '%1$s at %2$s', 'familiarosatheme' ),
get_comment_date( '', $comment ),
get_comment_time()
)
)
);
edit_comment_link( __( 'Edit', 'familiarosatheme' ), ' <span class="edit-link">', '</span>' );
?>
</div><!-- .comment-metadata -->
<?php if ( '0' === $comment->comment_approved ) : ?>
<em class="comment-awaiting-moderation"><?php echo esc_html( $moderation_note ); ?></em>
<?php endif; ?>
</footer><!-- .comment-meta -->
<div <?php familiarosatheme_content_class( 'comment-content' ); ?>>
<?php comment_text(); ?>
</div><!-- .comment-content -->
<?php
if ( '1' === $comment->comment_approved || $show_pending_links ) {
comment_reply_link(
array_merge(
$args,
array(
'add_below' => 'div-comment',
'depth' => $depth,
'max_depth' => $args['max_depth'],
'before' => '<div class="reply">',
'after' => '</div>',
)
)
);
}
?>
</article><!-- .comment-body -->
<?php
}

306
theme/inc/template-tags.php Normal file
View File

@@ -0,0 +1,306 @@
<?php
/**
* Custom template tags for this theme
*
* Eventually, some functionality here could be replaced by core features.
*
* @package FamiliaRosaTheme
*/
if ( ! function_exists( 'familiarosatheme_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time.
*/
function familiarosatheme_posted_on() {
$time_string = '<time datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time datetime="%1$s">%2$s</time><time datetime="%3$s">%4$s</time>';
}
$time_string = sprintf(
$time_string,
esc_attr( get_the_date( DATE_W3C ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( DATE_W3C ) ),
esc_html( get_the_modified_date() )
);
printf(
'<a href="%1$s" rel="bookmark">%2$s</a>',
esc_url( get_permalink() ),
$time_string // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
endif;
if ( ! function_exists( 'familiarosatheme_posted_by' ) ) :
/**
* Prints HTML with meta information about theme author.
*/
function familiarosatheme_posted_by() {
printf(
/* translators: 1: posted by label, only visible to screen readers. 2: author link. 3: post author. */
'<span class="sr-only">%1$s</span><span class="author vcard"><a class="url fn n" href="%2$s">%3$s</a></span>',
esc_html__( 'Posted by', 'familiarosatheme' ),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_html( get_the_author() )
);
}
endif;
if ( ! function_exists( 'familiarosatheme_comment_count' ) ) :
/**
* Prints HTML with the comment count for the current post.
*/
function familiarosatheme_comment_count() {
if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
/* translators: %s: Name of current post. Only visible to screen readers. */
comments_popup_link( sprintf( __( 'Leave a comment<span class="sr-only"> on %s</span>', 'familiarosatheme' ), get_the_title() ) );
}
}
endif;
if ( ! function_exists( 'familiarosatheme_entry_meta' ) ) :
/**
* Prints HTML with meta information for the categories, tags and comments.
* This template tag is used in the entry header.
*/
function familiarosatheme_entry_meta() {
// Hide author, post date, category and tag text for pages.
if ( 'post' === get_post_type() ) {
// Posted by.
familiarosatheme_posted_by();
// Posted on.
familiarosatheme_posted_on();
/* translators: used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'familiarosatheme' ) );
if ( $categories_list ) {
printf(
/* translators: 1: posted in label, only visible to screen readers. 2: list of categories. */
'<span class="sr-only">%1$s</span>%2$s',
esc_html__( 'Posted in', 'familiarosatheme' ),
$categories_list // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
/* translators: used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'familiarosatheme' ) );
if ( $tags_list ) {
printf(
/* translators: 1: tags label, only visible to screen readers. 2: list of tags. */
'<span class="sr-only">%1$s</span>%2$s',
esc_html__( 'Tags:', 'familiarosatheme' ),
$tags_list // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
}
// Comment count.
if ( ! is_singular() ) {
familiarosatheme_comment_count();
}
// Edit post link.
edit_post_link(
sprintf(
wp_kses(
/* translators: %s: Name of current post. Only visible to screen readers. */
__( 'Edit <span class="sr-only">%s</span>', 'familiarosatheme' ),
array(
'span' => array(
'class' => array(),
),
)
),
get_the_title()
)
);
}
endif;
if ( ! function_exists( 'familiarosatheme_entry_footer' ) ) :
/**
* Prints HTML with meta information for the categories, tags and comments.
*/
function familiarosatheme_entry_footer() {
// Hide author, post date, category and tag text for pages.
if ( 'post' === get_post_type() ) {
// Posted by.
familiarosatheme_posted_by();
// Posted on.
familiarosatheme_posted_on();
/* translators: used between list items, there is a space after the comma. */
$categories_list = get_the_category_list( __( ', ', 'familiarosatheme' ) );
if ( $categories_list ) {
printf(
/* translators: 1: posted in label, only visible to screen readers. 2: list of categories. */
'<span class="sr-only">%1$s</span>%2$s',
esc_html__( 'Posted in', 'familiarosatheme' ),
$categories_list // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
/* translators: used between list items, there is a space after the comma. */
$tags_list = get_the_tag_list( '', __( ', ', 'familiarosatheme' ) );
if ( $tags_list ) {
printf(
/* translators: 1: tags label, only visible to screen readers. 2: list of tags. */
'<span class="sr-only">%1$s</span>%2$s',
esc_html__( 'Tags:', 'familiarosatheme' ),
$tags_list // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
}
// Comment count.
if ( ! is_singular() ) {
familiarosatheme_comment_count();
}
// Edit post link.
edit_post_link(
sprintf(
wp_kses(
/* translators: %s: Name of current post. Only visible to screen readers. */
__( 'Edit <span class="sr-only">%s</span>', 'familiarosatheme' ),
array(
'span' => array(
'class' => array(),
),
)
),
get_the_title()
)
);
}
endif;
if ( ! function_exists( 'familiarosatheme_post_thumbnail' ) ) :
/**
* Displays an optional post thumbnail, wrapping the post thumbnail in an
* anchor element except when viewing a single post.
*/
function familiarosatheme_post_thumbnail() {
if ( ! familiarosatheme_can_show_post_thumbnail() ) {
return;
}
if ( is_singular() ) :
?>
<figure>
<?php the_post_thumbnail(); ?>
</figure><!-- .post-thumbnail -->
<?php
else :
?>
<figure>
<a href="<?php the_permalink(); ?>" aria-hidden="true" tabindex="-1">
<?php the_post_thumbnail(); ?>
</a>
</figure>
<?php
endif; // End is_singular().
}
endif;
if ( ! function_exists( 'familiarosatheme_comment_avatar' ) ) :
/**
* Returns the HTML markup to generate a user avatar.
*
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user_id, gravatar md5 hash,
* user email, WP_User object, WP_Post object, or WP_Comment object.
*/
function familiarosatheme_get_user_avatar_markup( $id_or_email = null ) {
if ( ! isset( $id_or_email ) ) {
$id_or_email = get_current_user_id();
}
return sprintf( '<div class="vcard">%s</div>', get_avatar( $id_or_email, familiarosatheme_get_avatar_size() ) );
}
endif;
if ( ! function_exists( 'familiarosatheme_discussion_avatars_list' ) ) :
/**
* Displays a list of avatars involved in a discussion for a given post.
*
* @param array $comment_authors Comment authors to list as avatars.
*/
function familiarosatheme_discussion_avatars_list( $comment_authors ) {
if ( empty( $comment_authors ) ) {
return;
}
echo '<ol>', "\n";
foreach ( $comment_authors as $id_or_email ) {
printf(
"<li>%s</li>\n",
familiarosatheme_get_user_avatar_markup( $id_or_email ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);
}
echo '</ol>', "\n";
}
endif;
if ( ! function_exists( 'familiarosatheme_the_posts_navigation' ) ) :
/**
* Wraps `the_posts_pagination` for use throughout the theme.
*/
function familiarosatheme_the_posts_navigation() {
the_posts_pagination(
array(
'mid_size' => 2,
'prev_text' => __( 'Newer posts', 'familiarosatheme' ),
'next_text' => __( 'Older posts', 'familiarosatheme' ),
)
);
}
endif;
if ( ! function_exists( 'familiarosatheme_content_class' ) ) :
/**
* Displays the class names for the post content wrapper.
*
* This allows us to add Tailwind Typographys modifier classes throughout
* the theme without repeating them in multiple files. (They can be edited
* at the top of the `../functions.php` file via the
* FAMILIAROSATHEME_TYPOGRAPHY_CLASSES constant.)
*
* Based on WordPress cores `body_class` and `get_body_class` functions.
*
* @param string|string[] $classes Space-separated string or array of class
* names to add to the class list.
*/
function familiarosatheme_content_class( $classes = '' ) {
$all_classes = array( $classes, FAMILIAROSATHEME_TYPOGRAPHY_CLASSES );
foreach ( $all_classes as &$class_groups ) {
if ( ! empty( $class_groups ) ) {
if ( ! is_array( $class_groups ) ) {
$class_groups = preg_split( '#\s+#', $class_groups );
}
} else {
// Ensure that we always coerce class to being an array.
$class_groups = array();
}
}
$combined_classes = array_merge( $all_classes[0], $all_classes[1] );
$combined_classes = array_map( 'esc_attr', $combined_classes );
// Separates class names with a single space, preparing them for the
// post content wrapper.
echo 'class="' . esc_attr( implode( ' ', $combined_classes ) ) . '"';
}
endif;