From 5fd30040a4d851fd612ed5c9ac169cd15284b17e Mon Sep 17 00:00:00 2001 From: Sophia Atkinson Date: Sun, 11 May 2025 16:58:27 -0700 Subject: [PATCH] Bump to 1.4.0, made some fixes for 8.2+ --- 404.php | 91 ++++++------ archive.php | 87 +++++------ comments.php | 99 ++++++------- functions.php | 37 +++++ header.php | 160 +++++++-------------- index.php | 72 +++++----- page.php | 36 ++--- search.php | 62 ++++---- single.php | 24 ++-- style.css | 4 +- template-parts/author/post-author-box.php | 28 ++-- template-parts/content.php | 98 ++++++------- template-parts/related/content-related.php | 42 +++--- template-parts/related/related-posts.php | 27 ++-- 14 files changed, 428 insertions(+), 439 deletions(-) diff --git a/404.php b/404.php index e80e587..b888b41 100644 --- a/404.php +++ b/404.php @@ -2,7 +2,7 @@ /** * The template for displaying 404 pages (not found) * - * @link https://codex.wordpress.org/Creating_an_Error_404_Pag + * @link https://developer.wordpress.org/themes/basics/template-hierarchy/#404-not-found * * @package Sophia After Dark * @since 1.0.0 @@ -12,53 +12,54 @@ get_header(); $sophia_after_dark_pnf_latest_posts = get_theme_mod( 'sophia_after_dark_enable_pnf_latest_posts', true ); ?> -
-
+
+
-
-
 
- -
-

-
- - -
- 'post', - 'posts_per_page' => absint( $sophia_after_dark_pnf_latest_post_count ), - 'ignore_sticky_posts' => 1, - ); - $sophia_after_dark_pnf_query = new WP_Query( $sophia_after_dark_pnf_args ); - if ( $sophia_after_dark_pnf_query->have_posts() ) { - echo ''; - } - wp_reset_postdata(); - ?> +
+
+  
- + -
-
+
+

+
+ + + +
+ 'post', + 'posts_per_page' => absint( $sophia_after_dark_pnf_latest_post_count ), + 'ignore_sticky_posts' => 1, + ); + $sophia_after_dark_pnf_query = new WP_Query( $sophia_after_dark_pnf_args ); + + if ( $sophia_after_dark_pnf_query->have_posts() ) : + echo ''; + endif; + + wp_reset_postdata(); + ?> +
+ + +
+
-
-
- '; - } - if ( have_posts() ) : - if ( 'mt-archive--masonry-style' === $archive_style ) { - ?> +
+
+ + +
+ + + + +
- - endwhile; + -
-
- - endif; + +
+
+ - if ( 'mt-archive--block-grid-style' === $archive_style ) { - echo '
'; - } - ?> - -
+ __( 'Previous', 'sophia-after-dark' ), + 'next_text' => __( 'Next', 'sophia-after-dark' ), + 'before_page_number' => '' . esc_html__( 'Page', 'sophia-after-dark' ) . ' ', + ) ); + ?> + + + + + + + + + + + + + - - + + diff --git a/comments.php b/comments.php index 8c90e17..77700a5 100644 --- a/comments.php +++ b/comments.php @@ -20,68 +20,76 @@ if ( post_password_required() ) { return; } -// Remove URL field from comments +// Remove URL field from comment form function sophia_after_dark_remove_url_comments($fields) { - unset($fields['url']); - return $fields; + unset($fields['url']); + return $fields; } add_filter('comment_form_default_fields', 'sophia_after_dark_remove_url_comments'); -// Edit Cookie consent text from comments +// Modify cookie consent field function sophia_after_dark_comment_form_change_cookies($fields) { - $commenter = wp_get_current_commenter(); - $consent = empty($commenter['comment_author_email']) ? '' : ' checked="checked"'; - $fields['cookies'] = ''; - return $fields; + $commenter = wp_get_current_commenter(); + $consent = ! empty( $commenter['comment_author_email'] ); + + $fields['cookies'] = sprintf( + '', + checked( $consent, true, false ), + esc_html__( 'Save my Name & Email for the next time I comment.', 'sophia-after-dark' ) + ); + + return $fields; } add_filter('comment_form_default_fields', 'sophia_after_dark_comment_form_change_cookies'); -// Edit comment-notes text from comments +// Add comment notes above form function sophia_after_dark_modify_text_before_comment_form($arg) { - $arg['comment_notes_before'] = wp_kses_post( - '

' . - esc_html__('All comments are manually reviewed and moderated.', 'sophia-after-dark') . - '
' . - esc_html__('Required fields are marked ', 'sophia-after-dark') . - '*

' - ); - return $arg; + $arg['comment_notes_before'] = wp_kses_post( + '

' . + esc_html__('All comments are manually reviewed and moderated.', 'sophia-after-dark') . + '
' . + esc_html__('Required fields are marked ', 'sophia-after-dark') . + '*

' + ); + return $arg; } add_filter('comment_form_defaults', 'sophia_after_dark_modify_text_before_comment_form'); -// Add note below comment form about privacy policy consent +// Add privacy policy consent note below form function sophia_after_dark_modify_text_comment_form($post_id) { - printf( - '%s', - wp_kses( - __('By commenting, you consent to our Privacy Policy', 'sophia-after-dark'), - array('a' => array('href' => array())) - ) - ); + $link = '' . esc_html__( 'Privacy Policy', 'sophia-after-dark' ) . ''; + printf( + '%s', + sprintf( + wp_kses( + __( 'By commenting, you consent to our %s.', 'sophia-after-dark' ), + array( 'a' => array( 'href' => array() ) ) + ), + $link + ) + ); } add_action('comment_form', 'sophia_after_dark_modify_text_comment_form'); ?>
- -

+ +

' . esc_html(get_the_title()) . '' + /* translators: %s: Post title */ + esc_html__( 'One Comment on “%s”', 'sophia-after-dark' ), + '' . esc_html( get_the_title() ) . '' ); } else { printf( - /* translators: 1: comment count number, 2: title. */ - esc_html( _nx( '%1$s Comments on “%2$s”', '%1$s Comments on “%2$s”', $sophia_after_dark_comment_count, 'comments title', 'sophia-after-dark' ) ), + /* translators: 1: Comment count, 2: Post title */ + esc_html( _nx( '%1$s Comment on “%2$s”', '%1$s Comments on “%2$s”', $sophia_after_dark_comment_count, 'comments title', 'sophia-after-dark' ) ), number_format_i18n( $sophia_after_dark_comment_count ), - '' . esc_html(get_the_title()) . '' + '' . esc_html( get_the_title() ) . '' ); } ?> @@ -92,24 +100,19 @@ add_action('comment_form', 'sophia_after_dark_modify_text_comment_form');
    'ol', - 'short_ping' => true, + 'style' => 'ol', + 'short_ping' => true, + 'reply_text' => __( 'Reply', 'sophia-after-dark' ), ) ); ?>
- - if ( ! comments_open() ) : - ?> +

- + + +

diff --git a/functions.php b/functions.php index 6eed9ab..1e7e08f 100644 --- a/functions.php +++ b/functions.php @@ -197,3 +197,40 @@ require get_template_directory() . '/inc/metaboxes/mt-post-sidebar-meta.php'; if ( ! function_exists( 'breadcrumb_trail' ) ) { require get_template_directory() . '/inc/mt-class-breadcrumbs.php'; } + +// Function to allow images in WordPress comments +function allow_images_in_comments($comment_content) { + // Allow only specific HTML tags, including + $allowed_tags = array( + 'a' => array('href' => array(), 'title' => array()), + 'em' => array(), + 'strong' => array(), + 'img' => array( + 'src' => array(), + 'alt' => array(), + 'width' => array(), + 'height' => array(), + 'class' => array(), + ), + ); + + // Strip out disallowed tags but keep allowed ones + return wp_kses($comment_content, $allowed_tags); +} + +// Hook to filter the comment text before displaying it +add_filter('comment_text', 'allow_images_in_comments'); + +// Function to make URLs for images clickable in comments +function clickable_images_in_comments($comment_content) { + // Automatically convert image URLs to HTML tags + $comment_content = preg_replace( + '/(http:\/\/[^\s"]+\.(jpg|jpeg|png|gif))/i', + '', + $comment_content + ); + return $comment_content; +} + +// Hook to make image URLs clickable +add_filter('comment_text', 'clickable_images_in_comments'); diff --git a/header.php b/header.php index 5dd93c7..a688ae8 100644 --- a/header.php +++ b/header.php @@ -14,130 +14,76 @@ > + + + ' . "\n"; - echo '' . "\n"; +if ( is_front_page() ) { + $home_og_image = get_option( 'sophia_after_dark_home_og_image' ); - if (is_front_page()) { - $home_og_image = get_option('sophia_after_dark_home_og_image'); - if ($home_og_image) { - echo '' . "\n"; - } - echo '' . "\n"; - echo '' . "\n"; - echo '' . "\n"; - } elseif (is_single() || is_page()) { - global $post; - if (has_post_thumbnail($post->ID)) { - $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'og-image-size'); - if ($thumbnail) { - echo '' . "\n"; - // $thumbnail_url = esc_url($thumbnail[0]); - // $thumbnail_parts = pathinfo($thumbnail_url); - // $thumbnail_new_url = $thumbnail_parts['dirname'] . '/' . $thumbnail_parts['filename'] . '-1536x878.' . $thumbnail_parts['extension']; - // echo '' . "\n"; - } - } else { - echo '' . "\n"; - } - - echo '' . "\n"; - echo '' . "\n"; - echo '' . "\n"; + if ( $home_og_image ) { + printf( '' . "\n", esc_url( $home_og_image ) ); } - echo '' . "\n"; - wp_head(); + + printf( '' . "\n", esc_attr( get_bloginfo( 'name' ) . ' - ' . get_bloginfo( 'description' ) ) ); + printf( '' . "\n", esc_attr( $author_bio ) ); + printf( '' . "\n", esc_url( home_url( '/' ) ) ); + +} elseif ( is_singular() ) { + global $post; + $thumbnail_url = get_template_directory_uri() . '/assets/images/default-og-image.webp'; + + if ( has_post_thumbnail( $post?->ID ) ) { + $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'og-image-size' ); + if ( ! empty( $image[0] ) ) { + $thumbnail_url = $image[0]; + } + } + + printf( '' . "\n", esc_url( $thumbnail_url ) ); + printf( '' . "\n", esc_attr( get_the_title() ) ); + printf( '' . "\n", esc_attr( get_the_excerpt() ) ); + printf( '' . "\n", esc_url( get_permalink() ) ); +} + +wp_head(); ?> > -
- + +
diff --git a/index.php b/index.php index a2f936a..cd0012f 100644 --- a/index.php +++ b/index.php @@ -12,55 +12,55 @@ * @package Sophia After Dark * @since 1.0.0 */ -$archive_style = get_theme_mod( 'sophia_after_dark_archive_style', 'mt-archive--masonry-style' ); + +declare(strict_types=1); + get_header(); + +$archive_style = get_theme_mod('sophia_after_dark_archive_style', 'mt-archive--masonry-style'); + ?> +
- '; - } - if ( have_posts() ) : - if ( 'mt-archive--masonry-style' === $archive_style ) { - ?> + +
+ + + + +
- - /* - * Include the Post-Type-specific template for the content. - * If you want to override this in a child theme, then include a file - * called content-___.php (where ___ is the Post Type name) and that will be used instead. - */ - get_template_part( 'template-parts/content', get_post_format() ); - endwhile; + - if ( 'mt-archive--masonry-style' === $archive_style ) { - ?> -
-
- +
+
+ - the_posts_pagination(); - else : - get_template_part( 'template-parts/content', 'none' ); - endif; + + + + + + + +
+ - if ( 'mt-archive--block-grid-style' === $archive_style ) { - echo '
'; - } - ?>
- diff --git a/page.php b/page.php index d7dc1d2..0f8b4cc 100644 --- a/page.php +++ b/page.php @@ -15,23 +15,27 @@ get_header(); ?>
-
-
- +
- get_template_part( 'template-parts/content', 'page' ); + + +
+
- // If comments are open or we have at least one comment, load up the comment template. - if ( comments_open() || get_comments_number() ) : - comments_template(); - endif; - endwhile; // End of the loop. - ?> - -
- + +
-
- '; - } +
+ + '; + } + if ( have_posts() ) : - if ( 'mt-archive--masonry-style' === $archive_style ) { + if ( 'mt-archive--masonry-style' === $archive_style ) : ?>
-
-
+
+ '; - } - ?> - - + + if ( 'mt-archive--block-grid-style' === $archive_style ) { + echo ''; + } + ?> + + + + - + +
-
-
- +
+ -
-
+ ?> + + +
+ - + +
- +
- +
- -
- + +
+ - +
- + -
- + +
- : - + : + + +
- -
+
+
\ No newline at end of file diff --git a/template-parts/content.php b/template-parts/content.php index be3fb6d..0c1d2d6 100644 --- a/template-parts/content.php +++ b/template-parts/content.php @@ -9,63 +9,55 @@ */ global $wp_query; -$current_post = $wp_query->current_post; -$archive_style = get_theme_mod( 'sophia_after_dark_archive_style', 'mt-archive--masonry-style' ); -$post_content_type = apply_filters( 'sophia_after_dark_archive_post_content_type', 'excerpt' ); +$current_post = $wp_query->current_post; +$archive_style = get_theme_mod( 'sophia_after_dark_archive_style', 'mt-archive--masonry-style' ); +$post_content_type = apply_filters( 'sophia_after_dark_archive_post_content_type', 'excerpt' ); -if ( has_post_thumbnail() ) { - $post_class = 'has-thumbnail'; -} else { - $post_class = 'no-thumbnail'; -} -if ( $current_post < 3 && 'mt-archive--masonry-style' === $archive_style ) { - $post_class .= ''; -} else { - $post_class .= ' wow fadeInUp'; +// Determine post class +$post_class = has_post_thumbnail() ? 'has-thumbnail' : 'no-thumbnail'; +if ( $current_post >= 3 || 'mt-archive--masonry-style' !== $archive_style ) { + $post_class .= ' wow fadeInUp'; } ?> +
> - '; - sophia_after_dark_post_thumbnail(); - sophia_after_dark_article_categories_list(); - echo ''; - if ( 'post' === get_post_type() ) { - ?> -
- -
- +
+ +
-
- ', '' ); ?> -
+ +
+ +
+ -
- "%s"', 'sophia-after-dark' ), - array( - 'span' => array( - 'class' => array(), - ), - ) - ), - get_the_title() - ) ); - } - ?> -
+
+ ', '' ); ?> +
-
- -
-
\ No newline at end of file +
+ "%s"', 'sophia-after-dark' ), + [ 'span' => [ 'class' => [] ] ] + ), + get_the_title() + ) ); + } + ?> +
+ + + diff --git a/template-parts/related/content-related.php b/template-parts/related/content-related.php index dd245ab..631fee3 100644 --- a/template-parts/related/content-related.php +++ b/template-parts/related/content-related.php @@ -6,40 +6,32 @@ * @since 1.0.0 */ -if (has_post_thumbnail()) { - $post_class = "has-thumbnail wow fadeInUp"; -} else { - $post_class = "no-thumbnail wow fadeInUp"; -} ?> +$post_class = has_post_thumbnail() ? "has-thumbnail wow fadeInUp" : "no-thumbnail wow fadeInUp"; +?> -
> - '; - if (has_post_thumbnail()) { - echo ''; - sophia_after_dark_post_thumbnail(); - echo ""; - } - sophia_after_dark_article_categories_list(); - echo ""; - if ("post" === get_post_type()) { ?> +
> +
+ + + + + + + +
+ +
- +
- ', - "" - ); ?> -
+ ', '' ); ?> +