<?php
/**
 * Plugin Name: Betavan Reading Time Demo
 * Description: Adds an estimated reading time through the [betavan_reading_time] shortcode.
 * Version: 0.1.0
 * License: MIT
 */
if (!defined("ABSPATH")) { exit; }
add_shortcode("betavan_reading_time", function () {
    $post = get_post();
    if (!$post) { return ""; }
    $content = wp_strip_all_tags(strip_shortcodes($post->post_content));
    $words = preg_split("/\s+/u", trim($content), -1, PREG_SPLIT_NO_EMPTY);
    $minutes = max(1, (int) ceil(count($words ?: []) / 220));
    return esc_html((string) $minutes) . " min";
});
