Newsletter */ if (!defined('ABSPATH')) { exit; } class Thalim_NL_Admin_Page { // ------------------------------------------------------------------------- // Main render // ------------------------------------------------------------------------- public function render() { if (!current_user_can('edit_others_posts')) { wp_die('Unauthorized'); } // Determine active month $year_month = sanitize_text_field($_GET['nl_month'] ?? ''); if (!preg_match('/^\d{4}-\d{2}$/', $year_month)) { $year_month = date('Y-m'); } // Handle synchronous save $save_message = null; if (isset($_POST['thalim_nl_save']) && wp_verify_nonce($_POST['_wpnonce'] ?? '', 'thalim_nl_save')) { $save_message = $this->handle_save_newsletter(); // Re-read month after save (may have been changed in form) $posted_month = sanitize_text_field($_POST['nl_month'] ?? ''); if (preg_match('/^\d{4}-\d{2}$/', $posted_month)) { $year_month = $posted_month; } } // Load existing newsletter for this month (if any) $existing = $this->get_newsletter_post_for_month($year_month); $existing_sections = []; $intro_content = ''; $conclusion_content = ''; $subscribe_url = ''; $unsubscribe_url = ''; if ($existing) { $existing_sections = json_decode(get_post_meta($existing->ID, '_newsletter_sections', true), true) ?: []; $intro_content = get_post_meta($existing->ID, '_newsletter_intro', true) ?: ''; $conclusion_content = get_post_meta($existing->ID, '_newsletter_conclusion', true) ?: ''; $subscribe_url = get_post_meta($existing->ID, '_newsletter_subscribe_url', true) ?: ''; $unsubscribe_url = get_post_meta($existing->ID, '_newsletter_unsubscribe_url', true) ?: ''; } // Query posts for current month $query = new Thalim_NL_Post_Query(); $month_data = $query->get_posts_for_month($year_month); if ($existing) { $month_data = $query->merge_selected_items($month_data, $existing_sections); } // Past newsletters $past_newsletters = get_posts([ 'post_type' => 'post', 'post_status' => ['draft', 'publish', 'pending'], 'posts_per_page' => -1, 'meta_key' => '_newsletter_month', 'orderby' => 'meta_value', 'order' => 'DESC', ]); $past_newsletters = array_filter($past_newsletters, function ($p) { return !empty(get_post_meta($p->ID, '_newsletter_month', true)); }); ?>
Aucune newsletter enregistrée.
| Mois | Actions |
|---|---|
| Modifier |
À venir (au-delà du mois — à cocher au besoin)
render_post_row((int) $cat_id, $post, $check_all, $checked_in_section); ?>