<?php

/**
 * Plugin Name:       Dynamiques Modification Date
 * Description:       Un plugin pour ajouter une date de modification aux posts
 * Author:            Deligraph
 * Text Domain:       dynamiques-modification-date
 */

if (! defined('ABSPATH')) {
	exit; // Exit if accessed directly.
}

add_action('init', function () {
	register_post_meta('articles', 'article_modification_date', [
		'show_in_rest' => true,
		'single'       => true,
		'type'         => 'string', // stockera la date en string (YYYY-MM-DD)
		'auth_callback' => function (): bool {
			return current_user_can('edit_posts');
		}
	]);
});

add_action('enqueue_block_editor_assets', function () {
	$asset_file = include(plugin_dir_path(__FILE__) . 'build/index.asset.php');

	wp_enqueue_script(
		'modification-date-panel',
		plugin_dir_url(__FILE__) . 'build/index.js',
		$asset_file['dependencies'],
		$asset_file['version'],
		true
	);

	// Optionnel : Enqueue les styles si nécessaire
	if (file_exists(plugin_dir_path(__FILE__) . 'build/index.css')) {
		wp_enqueue_style(
			'modification-date-panel-style',
			plugin_dir_url(__FILE__) . 'build/index.css',
			[],
			$asset_file['version']
		);
	}
});
