/** * The Archive - Integrated Post Notes (Simple Post Notes port) * Branded, no plugin required, fully compatible. */ class Archive_Post_Notes { public $settings = []; public function __construct() { add_action('admin_init', [$this, 'add_columns']); add_action('admin_enqueue_scripts', [$this, 'enqueue']); add_action('add_meta_boxes', [$this, 'add_meta_box']); add_action('save_post', [$this, 'save_note']); add_action('save_post', [$this, 'save_quickedit_note']); add_action('wp_ajax_archive_note_save_bulk_edit', [$this, 'save_bulkedit_note']); add_action('bulk_edit_custom_box', [$this, 'add_quick_bulk_field'], 10, 2); add_action('quick_edit_custom_box', [$this, 'add_quick_bulk_field'], 10, 2); add_shortcode('archivenote', [$this, 'shortcode']); add_action('pre_get_posts', [$this, 'query_orderby']); } private function get_settings() { if (!empty($this->settings)) return; $this->settings = [ 'post_types' => get_theme_mod('post_notes_post_types', ['post','page']), 'notes_label' => get_theme_mod('post_notes_label', __('Archive Note', 'p12r')), 'notes_placeholder'=> get_theme_mod('post_notes_placeholder', '') ]; } public function add_columns() { $this->get_settings(); foreach ((array)$this->settings['post_types'] as $pt) { add_filter("manage_{$pt}_posts_columns", [$this, 'add_column']); add_action("manage_{$pt}_posts_custom_column", [$this, 'output_column'], 10, 2); add_filter("manage_edit-{$pt}_sortable_columns", [$this, 'register_sortable_column']); } } public function add_column($columns) { $this->get_settings(); $label = wp_kses_data($this->settings['notes_label']); $columns['archive_note'] = $label; return $columns; } public function register_sortable_column($columns) { $columns['archive_note'] = 'archive_note'; return $columns; } public function output_column($column, $post_id) { if ($column !== 'archive_note') return; $note = get_post_meta($post_id, '_archive_note', true); if ($note) echo '
' . nl2br(wp_kses_data($note)) . '
'; } public function query_orderby($query) { if (!is_admin() || $query->get('orderby') !== 'archive_note') return; $query->set('meta_key', '_archive_note'); $query->set('orderby', 'meta_value'); } public function add_meta_box() { $this->get_settings(); $label = wp_kses_data($this->settings['notes_label']); foreach ((array)$this->settings['post_types'] as $screen) { add_meta_box('archive_notes', esc_html($label), [$this, 'metabox'], $screen, 'side', 'high'); } } public function metabox($post) { $this->get_settings(); wp_nonce_field('archive_note_' . $post->ID, 'archive_nonce'); $placeholder = wp_kses_data($this->settings['notes_placeholder']); $note = get_post_meta($post->ID, '_archive_note', true); echo ''; } public function save_note($post_id) { if (!isset($_POST['archive_nonce']) || !wp_verify_nonce($_POST['archive_nonce'], 'archive_note_' . $post_id)) return; if (!current_user_can('edit_posts') || !isset($_POST['archive_note'])) return; update_post_meta($post_id, '_archive_note', sanitize_textarea_field($_POST['archive_note'])); } public function add_quick_bulk_field($column_name, $post_type) { $this->get_settings(); if (!in_array($post_type, (array)$this->settings['post_types']) || $column_name !== 'archive_note') return; $label = wp_kses_data($this->settings['notes_label']); $placeholder = wp_kses_data($this->settings['notes_placeholder']); wp_nonce_field('archive_note_bulk_edit', 'archive_nonce'); echo '
'; } public function save_quickedit_note($post_id) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return; if (!isset($_POST['action']) || $_POST['action'] !== 'inline-save') return; $this->get_settings(); if (!in_array($_POST['post_type'] ?? '', (array)$this->settings['post_types'])) return; if (!wp_verify_nonce($_POST['archive_nonce'] ?? '', 'archive_note_bulk_edit')) return; if (!current_user_can('edit_posts') || !isset($_POST['archive_note'])) return; update_post_meta($post_id, '_archive_note', sanitize_textarea_field($_POST['archive_note'])); } public function save_bulkedit_note() { check_ajax_referer('archive_note_bulk_edit', 'nonce'); if (!current_user_can('edit_posts')) wp_die(); $post_ids = isset($_POST['post_ids']) && is_array($_POST['post_ids']) ? $_POST['post_ids'] : []; $note = isset($_POST['archive_note']) ? sanitize_textarea_field($_POST['archive_note']) : ''; if (empty($post_ids) || empty($note)) return; foreach ($post_ids as $id) { update_post_meta((int)$id, '_archive_note', $note); } } public function enqueue($hook) { // Only on post list / edit screens if (strpos($hook, 'edit-') !== false || strpos($hook, 'post.php') !== false || strpos($hook, 'post-new.php') !== false) { // Quick/bulk edit JS (very small, no external libs) wp_enqueue_script('archive-notes-admin', get_template_directory_uri() . '/admin/js/archive-notes.js', ['jquery'], null, true); } } public function shortcode($atts) { $atts = shortcode_atts(['id' => null], $atts, 'archivenote'); $id = $atts['id'] ? (int)$atts['id'] : get_the_ID(); $note = get_post_meta($id, '_archive_note', true); return $note ? '
' . nl2br(wp_kses_data($note)) . '
' : ''; } } new Archive_Post_Notes(); https://tomdrifter.com/wp-sitemap-posts-post-1.xmlhttps://tomdrifter.com/wp-sitemap-posts-page-1.xmlhttps://tomdrifter.com/wp-sitemap-taxonomies-category-1.xmlhttps://tomdrifter.com/wp-sitemap-users-1.xml