Skip to content
wiki.fftac.org

Functions - Source Excerpt 03

Back to Functions

Summary

This source excerpt preserves a bounded section of Anti-Christ.net/wp-content/themes/anti-christ-thin-veil/functions.php so readers can inspect the evidence without opening the full source file.

**Source path:** Anti-Christ.net/wp-content/themes/anti-christ-thin-veil/functions.php

if ( $is_claim_review ) {
			$schema['claimReviewed'] = wp_strip_all_tags( get_post_meta( $post_id, '_actv_claim_review_claim', true ) );
			$schema['reviewRating']  = array(
				'@type'           => 'Rating',
				'ratingValue'     => (int) get_post_meta( $post_id, '_actv_claim_review_rating_value', true ),
				'bestRating'      => 6,
				'worstRating'     => 1,
				'alternateName'   => wp_strip_all_tags( get_post_meta( $post_id, '_actv_claim_review_label', true ) ),
			);
		}
	}

	?>
	<script type="application/ld+json"><?php echo wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ); ?></script>
	<?php
}

/**
 * Return a page URL by slug with a reasonable fallback.
 *
 * @param string $slug Page slug.
 * @return string
 */
function actv_page_url( $slug ) {
	$page = get_page_by_path( $slug );

	if ( $page instanceof WP_Post ) {
		return get_permalink( $page );
	}

	return home_url( '/' . trim( $slug, '/' ) . '/' );
}

/**
 * Return the journal/posts page URL.
 *
 * @return string
 */
function actv_posts_page_url() {
	$posts_page = (int) get_option( 'page_for_posts' );

	if ( $posts_page ) {
		return get_permalink( $posts_page );
	}

	return actv_page_url( 'journal' );
}

/**
 * Return a category archive URL, creating a readable fallback if absent.
 *
 * @param string $slug Category slug.
 * @return string
 */
function actv_category_url( $slug ) {
	$term = get_category_by_slug( $slug );

	if ( $term ) {
		return get_category_link( $term );
	}

	return home_url( '/category/' . trim( $slug, '/' ) . '/' );
}

/**
 * Estimated reading time for journal cards.
 *
 * @param int|null $post_id Post ID.
 * @return string
 */
function actv_reading_time( $post_id = null ) {
	$post_id = $post_id ? $post_id : get_the_ID();
	$content = wp_strip_all_tags( get_post_field( 'post_content', $post_id ) );
	$words   = str_word_count( $content );
	$minutes = max( 1, (int) ceil( $words / 220 ) );

	return sprintf(
		/* translators: %d is a reading time in minutes. */
		esc_html( _n( '%d min read', '%d min read', $minutes, 'anti-christ-thin-veil' ) ),
		$minutes
	);
}

/**
 * Print compact post meta.
 */
function actv_posted_on() {
	?>
	<span class="entry-meta-line">
		<time datetime="<?php echo esc_attr( get_the_date( DATE_W3C ) ); ?>"><?php echo esc_html( get_the_date() ); ?></time>
		<span aria-hidden="true">/</span>
		<span><?php echo esc_html( actv_reading_time() ); ?></span>
	</span>
	<?php
}

/**
 * Render a reusable post card.
 *
 * @param int|null $post_id Post ID.
 */
function actv_render_post_card( $post_id = null ) {
	$post_id = $post_id ? $post_id : get_the_ID();
	$excerpt = get_the_excerpt( $post_id );

	if ( empty( $excerpt ) ) {
		$excerpt = wp_strip_all_tags( get_post_field( 'post_content', $post_id ) );
	}
	?>
	<article <?php post_class( 'post-card veil-card', $post_id ); ?>>
		<a class="post-card-link" href="<?php echo esc_url( get_permalink( $post_id ) ); ?>">
			<span class="card-kicker"><?php echo esc_html( get_the_date( '', $post_id ) ); ?> / <?php echo esc_html( actv_reading_time( $post_id ) ); ?></span>
			<h3><?php echo esc_html( get_the_title( $post_id ) ); ?></h3>
			<p><?php echo esc_html( wp_trim_words( $excerpt, 28, '...' ) ); ?></p>
		</a>
	</article>
	<?php
}

/**
 * Render a static card link for archive pages and fallback launch routes.
 *
 * @param string $title  Card title.
 * @param string $kicker Card eyebrow.
 * @param string $text   Card copy.
 * @param string $url    Card URL.
 */
function actv_render_static_card( $title, $kicker, $text, $url ) {
	?>
	<article class="post-card veil-card">
		<a class="post-card-link" href="<?php echo esc_url( $url ); ?>">
			<span class="card-kicker"><?php echo esc_html( $kicker ); ?></span>
			<h3><?php echo esc_html( $title ); ?></h3>
			<p><?php echo esc_html( $text ); ?></p>
		</a>
	</article>
	<?php
}

/**
 * Render a static card used when the site has not published posts yet.
 *
 * @param string $title Card title.
 * @param string $kicker Card eyebrow.
 * @param string $text Card copy.
 * @param string $url Card URL.
 */
function actv_render_placeholder_card( $title, $kicker, $text, $url = '' ) {
	$url = $url ? $url : actv_posts_page_url();
	?>
	<article class="post-card veil-card placeholder-card">
		<a class="post-card-link" href="<?php echo esc_url( $url ); ?>">
			<span class="card-kicker"><?php echo esc_html( $kicker ); ?></span>
			<h3><?php echo esc_html( $title ); ?></h3>
			<p><?php echo esc_html( $text ); ?></p>
		</a>
	</article>
	<?php
}

/**
 * Submission instructions from the Customizer.
 *
 * @return string
 */
function actv_get_submission_instructions() {
	$default = esc_html__( 'Submissions are welcome as lawful civic writing: essays, records requests, court observations, tax burden accounts, privacy notes, and philosophical fragments. Do not send threats, plans for harm, doxxing, stolen material, or instructions for illegal action.', 'anti-christ-thin-veil' );
	$value   = get_theme_mod( 'actv_submission_instructions', $default );

	return $value ? $value : $default;
}

/**
 * Optional public contact email from the Customizer.
 *
 * @return string
 */
function actv_get_contact_email() {
	return sanitize_email( get_theme_mod( 'actv_contact_email', '' ) );
}

/**
 * Add privacy-first Customizer settings.
 *
 * @param WP_Customize_Manager $wp_customize Customizer object.
 */
function actv_customize_register( $wp_customize ) {
	$wp_customize->add_section(
		'actv_submission_section',
		array(
			'title'       => esc_html__( 'Anti-Christ Submission Notes', 'anti-christ-thin-veil' ),
			'description' => esc_html__( 'Control the privacy-first contact and submission language shown on the home and contact pages.', 'anti-christ-thin-veil' ),
			'priority'    => 160,
		)
	);

	$wp_customize->add_setting(
		'actv_submission_instructions',
		array(
			'default'           => actv_get_submission_instructions(),
			'sanitize_callback' => 'sanitize_textarea_field',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'actv_submission_instructions',
		array(
			'label'   => esc_html__( 'Submission instructions', 'anti-christ-thin-veil' ),
			'section' => 'actv_submission_section',
			'type'    => 'textarea',
		)
	);

	$wp_customize->add_setting(
		'actv_contact_email',
		array(
			'default'           => '',
			'sanitize_callback' => 'sanitize_email',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'actv_contact_email',
		array(
			'label'       => esc_html__( 'Optional public contact email', 'anti-christ-thin-veil' ),
			'description' => esc_html__( 'Leave blank to avoid publishing an email address. The theme does not collect submissions by itself.', 'anti-christ-thin-veil' ),
			'section'     => 'actv_submission_section',
			'type'        => 'email',
		)
	);
}
add_action( 'customize_register', 'actv_customize_register' );