116 lines
3.3 KiB
PHP
116 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: THALIM Newsletter
|
|
* Plugin URI: https://thalim.fr
|
|
* Description: Compose and export monthly newsletter digests from site content
|
|
* Version: 1.0.0
|
|
* Author: THALIM Dev
|
|
* Author URI: https://thalim.fr
|
|
* License: GPL v2 or later
|
|
* Text Domain: thalim-newsletter
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
// Plugin constants
|
|
define('THALIM_NL_VERSION', '1.0.0');
|
|
define('THALIM_NL_PLUGIN_DIR', plugin_dir_path(__FILE__));
|
|
define('THALIM_NL_PLUGIN_URL', plugin_dir_url(__FILE__));
|
|
|
|
// Category IDs (verified in DB 2026-03-20)
|
|
define('THALIM_NL_CAT_APPELS', 8);
|
|
define('THALIM_NL_CAT_COLLOQUES', 10);
|
|
define('THALIM_NL_CAT_SEMINAIRES', 11);
|
|
define('THALIM_NL_CAT_COMMS', 13);
|
|
define('THALIM_NL_CAT_SOUTENANCES', 14);
|
|
define('THALIM_NL_CAT_OUVRAGES', 15);
|
|
define('THALIM_NL_CAT_ARTICLES', 16);
|
|
define('THALIM_NL_CAT_NEWSLETTER', 20);
|
|
|
|
// Pods IDs (verified in DB 2026-03-20)
|
|
define('THALIM_NL_POD_ID_POST', 8);
|
|
define('THALIM_NL_FIELD_ID_CAT', 16);
|
|
|
|
/**
|
|
* Main plugin class — singleton
|
|
*/
|
|
class Thalim_Newsletter {
|
|
|
|
private static $instance = null;
|
|
|
|
public static function get_instance() {
|
|
if (self::$instance === null) {
|
|
self::$instance = new self();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
private function __construct() {
|
|
$this->load_dependencies();
|
|
$this->init_hooks();
|
|
}
|
|
|
|
private function load_dependencies() {
|
|
require_once THALIM_NL_PLUGIN_DIR . 'includes/class-post-query.php';
|
|
require_once THALIM_NL_PLUGIN_DIR . 'includes/class-html-exporter.php';
|
|
require_once THALIM_NL_PLUGIN_DIR . 'includes/class-admin-page.php';
|
|
}
|
|
|
|
private function init_hooks() {
|
|
add_action('admin_menu', [$this, 'add_admin_menu']);
|
|
add_action('admin_enqueue_scripts', [$this, 'enqueue_assets']);
|
|
add_action('wp_ajax_thalim_nl_load_month', [new Thalim_NL_Admin_Page(), 'handle_ajax_load_month']);
|
|
add_action('wp_ajax_thalim_nl_export_html', [new Thalim_NL_Admin_Page(), 'handle_ajax_export_html']);
|
|
}
|
|
|
|
public function add_admin_menu() {
|
|
add_management_page(
|
|
'Newsletter',
|
|
'Newsletter',
|
|
'edit_others_posts',
|
|
'thalim-newsletter',
|
|
[$this, 'render_admin_page']
|
|
);
|
|
}
|
|
|
|
public function enqueue_assets($hook) {
|
|
if ($hook !== 'tools_page_thalim-newsletter') {
|
|
return;
|
|
}
|
|
wp_enqueue_style(
|
|
'thalim-newsletter-admin',
|
|
THALIM_NL_PLUGIN_URL . 'assets/admin.css',
|
|
[],
|
|
THALIM_NL_VERSION
|
|
);
|
|
wp_enqueue_script(
|
|
'thalim-newsletter-admin',
|
|
THALIM_NL_PLUGIN_URL . 'assets/admin.js',
|
|
['jquery'],
|
|
THALIM_NL_VERSION,
|
|
true
|
|
);
|
|
wp_localize_script('thalim-newsletter-admin', 'thalimNL', [
|
|
'ajaxUrl' => admin_url('admin-ajax.php'),
|
|
'nonce' => wp_create_nonce('thalim_newsletter_ajax'),
|
|
]);
|
|
}
|
|
|
|
public function render_admin_page() {
|
|
$page = new Thalim_NL_Admin_Page();
|
|
$page->render();
|
|
}
|
|
}
|
|
|
|
// Activation hook
|
|
register_activation_hook(__FILE__, function () {
|
|
add_option('thalim_nl_version', THALIM_NL_VERSION);
|
|
});
|
|
|
|
// Initialize plugin
|
|
add_action('plugins_loaded', function () {
|
|
Thalim_Newsletter::get_instance();
|
|
});
|