=== Indesign Nepali Post Date ===
Contributors: indesignmedia
Plugin URI: https://indesignmedia.net/plugins/indesign-nepali-post-date
Tags: nepali date, nepali calendar, bikram sambat, BS date, nepali post date
Requires at least: 5.3
Tested up to: 7.0
Requires PHP: 8.2
Stable tag: 3.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Show your WordPress dates in Bikram Sambat (BS). Shortcodes, PHP helpers, and a settings page.

== Description ==

This plugin converts Gregorian (AD) dates into Bikram Sambat (BS) so you can display Nepali dates on posts, pages, widgets, or anywhere in your theme.

Handy if you run a Nepali news site, a blog, or any WordPress site that needs BS dates for the publish date, modified date, or just today's date.

**What it does:**

* Converts any AD date to BS, in Nepali or English digits
* Nepali month names (e.g. असार) and weekday names (e.g. मंगलबार)
* Custom date format from the settings page
* Optional CSS wrapper class if you want to style the output
* Four shortcodes and a few PHP helpers
* A monthly BS calendar shortcode with clickable day-archive links and a picker for your brand accent color
* A filter hook if you want to change the output
* Covers BS 2000 to 2101 (AD 1943 to 2044)
* No jQuery, no REST calls, no external dependencies

== Features ==

= Shortcodes =

* **[indnpd_post_date]** Prints the current post's publish date in BS. Takes optional `format` and `lang` attributes.
* **[indnpd_today_date]** Prints today's BS date. Good for headers, footers, or widgets. Takes optional `format` and `lang` attributes.
* **[indnpd_number number="123"]** Converts a number to Nepali glyphs (e.g. 123 to १२३). Takes an optional `lang` attribute.
* **[indnpd_post_calendar]** Shows a monthly BS calendar. Days that have at least one published post link to the day archive. Takes optional `year`, `month`, and `lang` attributes. Prev / next arrows navigate between months.

= PHP Functions =

Primary names (introduced in 3.0.0):

* `indesign_nepali_post_date_get( $datetime )`: Convert a date string or timestamp into a formatted BS string.
* `indesign_nepali_post_date_today()`: Return today's date in BS.
* `indesign_nepali_post_date_convert( $number )`: Convert a number to Nepali glyphs.
* `indnpd_get_date( $timestamp, $format, $lang )`: Same idea, with format and language you can pass in.

Legacy aliases (kept for backward compatibility, still work exactly the same):

* `id_nepali_post_date_get( $datetime )`
* `id_nepali_post_date_today()`
* `id_nepali_post_date_convert( $number )`

= Developer API =

* `\IndesignMedia\NPD\Manager::convert( $timestamp, $format, $lang )`: Static method if you'd rather not use the global function.
* `indesign_nepali_post_date_output` filter: Wrap or modify the HTML before it's returned.

= Date Format Tokens =

* `d` - Day number
* `m` - Month number
* `M` - Month name (e.g. असार)
* `y` - 2-digit year
* `Y` - 4-digit year
* `l` - Weekday name (e.g. मंगलबार)

= Admin Settings Panel =

Four tabs: Settings, Shortcodes, Post Calendar, Developer.

* **Localization Style**: Pick Traditional Nepali glyphs (०१२) or English digits (012).
* **Date Pattern**: Set a custom format string using the tokens above.
* **CSS Wrapper Class**: Optionally wrap every date in `<span class="your-class">` so you can style it.
* **Real-time Preview**: The preview at the top updates as you change the pattern or switch digits.
* **Post Calendar tab**: Live preview of the calendar plus two controls that persist to the front-end - a toggle for the day-archive post links and an accent color picker for the weekday header, today's outline, and linked-day styling.
* **Developer tab**: Copy-ready snippets for the PHP function, the output filter, and a starter CSS badge style.

== Screenshots ==

1. Admin: Settings tab (localization, date pattern, wrapper class)
2. Admin: Shortcodes tab (copy-ready shortcode reference)
3. Admin: Post Calendar tab (live preview with post-links toggle and accent color picker)
4. Admin: Developer tab (PHP function, output filter, and CSS snippet)
5. Front-end: Nepali post calendar with clickable day-archive links
6. Front-end: Nepali BS date rendered on a post

== Installation ==

1. Upload the `indesign-nepali-post-date` folder to `/wp-content/plugins/`, or install it from the Plugins screen.
2. Activate it from the **Plugins** screen.
3. Open **Nepali Post Date** in the admin sidebar and set the date format, digit style, and (if you want one) a wrapper class.
4. Drop any of the shortcodes into a post, page, or widget: `[indnpd_post_date]`, `[indnpd_today_date]`, `[indnpd_number number="123"]`, or `[indnpd_post_calendar]`.

== Frequently Asked Questions ==

= Which calendar does it use? =

Gregorian (AD) to Bikram Sambat (BS), the official calendar of Nepal. AD 2024 lands around BS 2081.

= What date range works? =

BS 2000 to BS 2101 (AD 1943-04-14 to AD 2044). Dates outside that range come back unchanged.

= How do I show the post date in Nepali from my theme? =

Inside The Loop:

`<?php echo indesign_nepali_post_date_get( get_the_date('Y-m-d H:i:s') ); ?>`

Or if you want to pass your own format and language:

`<?php echo indnpd_get_date( get_the_date('Y-m-d H:i:s'), 'd M Y, l', 'nepali' ); ?>`

The older `id_nepali_post_date_get()` name still works if you already have it in your theme.

= Can I use English digits? =

Yes. Open **Nepali Post Date** in the admin sidebar and switch **Localization Style** to **Global English (0123)**. You can also override it per shortcode:

`[indnpd_post_date lang="english"]`

Or pass `"english"` as the third argument to `indnpd_get_date()`.

= Can I change the date format? =

Yes. Set your own **Date Pattern** in the settings, using these tokens: `d` (day), `m` (month number), `M` (month name), `y` (2-digit year), `Y` (4-digit year), `l` (weekday). For example, `d M Y, l` gives you २५ असार २०८१, मंगलबार.

You can also pass a format directly in the shortcode: `[indnpd_post_date format="d M Y"]`

= How do I modify the output from PHP? =

Use the `indesign_nepali_post_date_output` filter. You get the HTML string, the BS date array, and the Unix timestamp.

`add_filter( 'indesign_nepali_post_date_output', function( $html, $bs, $unix ) {
    return '<span class="nepali-badge">' . $html . '</span>';
}, 10, 3 );`

= How do I add the Nepali calendar to a page? =

Drop `[indnpd_post_calendar]` into any post, page, or widget. It shows the current BS month by default. Use the prev / next arrows in the header to browse.

To pin it to a specific month:

`[indnpd_post_calendar year="2083" month="4" lang="english"]`

= What do the clickable days on the calendar do? =

Each past-or-current day cell links to the WordPress day archive for that Gregorian date (the same URL WordPress generates for `/YYYY/MM/DD/`). Clicking a day takes visitors to the list of posts published on that day. Future dates are never linked.

= Can I turn off the day-archive links? =

Yes. Open **Nepali Post Date** in the admin sidebar, go to the **Post Calendar** tab, and switch off the **Post Links** toggle on the calendar preview. Save Changes. The front-end calendar will then render as a plain, non-clickable calendar.

= Can I change the calendar's accent color to match my brand? =

Yes. On the same **Post Calendar** tab, use the color picker on the calendar preview. The color drives the weekday header row, today's outline, and the linked-day text color. Save Changes and the front-end will pick it up.

= Does the calendar highlight today's date? =

Yes. Today (in Nepal time) is outlined with your chosen accent color, regardless of your WordPress site's timezone. The BS day always rolls at Nepal midnight.

= Can I use the calendar in a widget or template file? =

Yes. Widgets that accept shortcodes render `[indnpd_post_calendar]` directly. In a template file:

`<?php echo do_shortcode('[indnpd_post_calendar]'); ?>`

= Will the calendar work with any theme's day archive? =

Yes. It uses WordPress core's `get_day_link()`, which produces the standard `/YYYY/MM/DD/` URL. Any theme that renders the day archive template (`date.php`, `archive.php`, or `index.php`) will handle those links correctly.

== Upgrade Notice ==

= 3.0.0 =
Fixes a one-day drift in the BS calendar table and adds a post calendar shortcode. Old function names still work.

== Changelog ==

= 3.0.0 =
* New: `[indnpd_post_calendar]` shortcode. Renders a monthly BS calendar. Days link to the WordPress day archive for that Gregorian date. Prev / next arrows navigate between BS months. Takes optional `year`, `month`, and `lang` attributes. Future dates are never linked.
* New: Post Calendar admin tab with a live preview, a **Post Links** toggle to enable or disable the day-archive links site-wide, and an accent color picker for the weekday header, today's outline, and linked-day styling.
* New primary function names: `indesign_nepali_post_date_get()`, `indesign_nepali_post_date_today()`, `indesign_nepali_post_date_convert()`. The old `id_nepali_post_date_*` names are kept as backward-compatible aliases so nothing you already wrote stops working.
* Fixed a one-day drift in the BS calendar table. BS 2069 Chaitra was set to 31 days, should be 30. BS 2070 Jestha was set to 31, should be 32. Vaisakh 1 boundaries now match the Government of Nepal patro across BS 2000 to 2101 (checked against 9 anchor dates).
* BS conversion now always uses Asia/Kathmandu (UTC+05:45) for the day boundary, no matter what timezone your WordPress site is set to. The BS date rolls over at Nepal midnight, not your server's midnight.
* Redesigned the settings page. Two columns, pill tabs across the top (Settings, Shortcodes, Post Calendar, Developer), white header card, red gradient for the active tab and Save button. Promo banners moved to the right sidebar.
* The preview at the top of the settings page updates as you type in the Date Pattern or switch digit style. No page reload, no AJAX.

= 2.0.0 =
* Fixed: Date display off by one day for posts published in the evening Nepal time. Root cause was a double timezone conversion: `strtotime()` interpreted the local-timezone datetime string as UTC, then `wp_date()` added the Nepal offset again, pushing evening dates to the next day. Now uses `date_create($raw, wp_timezone())` to parse datetime strings correctly in the WordPress timezone with no offset drift.

= 1.0.0 =
* First release.
* BS date conversion via shortcodes and PHP helpers.
* Covers BS 2000 to 2101 (AD 1943 to 2044).
* PHP 8.2 enum-based month and weekday localization.
* Format tokens: d, m, M, y, Y, l.
* Nepali glyphs or English digits.
* Optional CSS wrapper class.
* Live preview on the settings page.
* `indesign_nepali_post_date_output` filter.
* `indnpd_get_date()` helper and `Manager::convert()` static method.

== Developers ==

Built and maintained by **Indesign Media** (https://indesignmedia.net).

Need help, a custom tweak, or integration work? Head to the plugin page or drop us a line.
