admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'wmw_admin_nonce' ),
'confirm_delete' => __( 'Wirklich löschen?', 'wp-multi-wiki' ),
) );
wp_enqueue_editor();
}
// ── Meta Boxes ────────────────────────────────────────────────────────────
public function add_meta_boxes() {
add_meta_box( 'wmw_wiki_options', 'Wiki-Optionen', array( $this, 'mb_wiki_options' ), 'wmw_wiki', 'side' );
add_meta_box( 'wmw_article_meta', 'Artikel-Einstellungen', array( $this, 'mb_article_meta' ), 'wmw_article', 'side' );
}
public function mb_wiki_options( $post ) {
wp_nonce_field( 'wmw_save_wiki', 'wmw_wiki_nonce' );
$icon = get_post_meta( $post->ID, '_wmw_icon', true ) ?: '📖';
$color = get_post_meta( $post->ID, '_wmw_color', true ) ?: '#2271b1';
$ver = get_post_meta( $post->ID, '_wmw_version', true ) ?: '1.0.0';
?>
ID, '_wmw_wiki_id', true );
$order = (int) get_post_meta( $post->ID, '_wmw_order', true );
$wikis = wmw_get_wikis();
?>
update_search_index( $post_id, $wiki_id );
}
}
private function update_search_index( $article_id, $wiki_id ) {
global $wpdb;
$post = get_post( $article_id );
$keywords = wp_strip_all_tags( $post->post_title . ' ' . $post->post_content . ' ' . $post->post_excerpt );
$table = $wpdb->prefix . 'wmw_search_index';
$wpdb->replace( $table, array(
'article_id' => $article_id,
'wiki_id' => $wiki_id,
'keywords' => $keywords,
) );
}
// ── Column Overrides ─────────────────────────────────────────────────────
public function article_columns( $columns ) {
unset( $columns['date'] );
$columns['wmw_wiki'] = 'Wiki';
$columns['wmw_category'] = 'Kategorie';
$columns['date'] = 'Datum';
return $columns;
}
public function article_column_data( $column, $post_id ) {
if ( 'wmw_wiki' === $column ) {
$wiki = wmw_get_article_wiki( $post_id );
echo $wiki ? '' . esc_html( $wiki->post_title ) . '' : '—';
}
if ( 'wmw_category' === $column ) {
$terms = get_the_terms( $post_id, 'wmw_category' );
echo $terms ? implode( ', ', wp_list_pluck( $terms, 'name' ) ) : '—';
}
}
public function wiki_columns( $columns ) {
unset( $columns['date'] );
$columns['wmw_articles'] = 'Artikel';
$columns['wmw_icon'] = 'Icon';
$columns['wmw_version'] = 'Version';
$columns['date'] = 'Datum';
return $columns;
}
public function wiki_column_data( $column, $post_id ) {
if ( 'wmw_articles' === $column ) {
$count = count( wmw_get_articles( $post_id ) );
echo '' . $count . '';
}
if ( 'wmw_icon' === $column ) {
echo '' . wmw_get_wiki_icon( $post_id ) . '';
}
if ( 'wmw_version' === $column ) {
echo esc_html( get_post_meta( $post_id, '_wmw_version', true ) ?: '1.0.0' );
}
}
// ── Admin Notices ─────────────────────────────────────────────────────────
public function admin_notices() {
if ( isset( $_GET['wmw_saved'] ) ) {
echo '';
}
if ( isset( $_GET['wmw_deleted'] ) ) {
echo '';
}
if ( isset( $_GET['wmw_error'] ) ) {
echo '❌ Fehler: ' . esc_html( $_GET['wmw_error'] ) . '
';
}
}
// ── Pages ─────────────────────────────────────────────────────────────────
public function page_dashboard() {
$wikis = get_posts( array( 'post_type' => 'wmw_wiki', 'post_status' => 'any', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC' ) );
$total_articles = count( get_posts( array( 'post_type' => 'wmw_article', 'post_status' => 'any', 'posts_per_page' => -1 ) ) );
include WMW_PLUGIN_DIR . 'templates/admin/dashboard.php';
}
public function page_new_wiki() {
include WMW_PLUGIN_DIR . 'templates/admin/wiki-form.php';
}
public function page_edit_wiki() {
$wiki_id = absint( $_GET['id'] ?? 0 );
$wiki = $wiki_id ? get_post( $wiki_id ) : null;
if ( ! $wiki || $wiki->post_type !== 'wmw_wiki' ) {
wp_die( 'Wiki nicht gefunden.' );
}
include WMW_PLUGIN_DIR . 'templates/admin/wiki-form.php';
}
public function page_articles() {
$wiki_filter = absint( $_GET['wiki_id'] ?? 0 );
$args = array( 'post_type' => 'wmw_article', 'post_status' => 'any', 'posts_per_page' => 50, 'orderby' => 'title', 'order' => 'ASC' );
if ( $wiki_filter ) {
$args['meta_query'] = array( array( 'key' => '_wmw_wiki_id', 'value' => $wiki_filter ) );
}
$articles = get_posts( $args );
$wikis = wmw_get_wikis();
include WMW_PLUGIN_DIR . 'templates/admin/article-list.php';
}
public function page_new_article() {
$wiki_id = absint( $_GET['wiki_id'] ?? 0 );
$wikis = wmw_get_wikis();
include WMW_PLUGIN_DIR . 'templates/admin/article-form.php';
}
public function page_edit_article() {
$article_id = absint( $_GET['id'] ?? 0 );
$article = $article_id ? get_post( $article_id ) : null;
if ( ! $article || $article->post_type !== 'wmw_article' ) wp_die( 'Artikel nicht gefunden.' );
$wikis = wmw_get_wikis();
include WMW_PLUGIN_DIR . 'templates/admin/article-form.php';
}
public function page_categories() {
include WMW_PLUGIN_DIR . 'templates/admin/categories.php';
}
public function page_gitea_import() {
include WMW_PLUGIN_DIR . 'templates/admin/gitea-importer.php';
}
public function page_settings() {
$saved = false;
// ── Speichern ────────────────────────────────────────────────────
if ( isset( $_POST['wmw_settings_nonce'] )
&& wp_verify_nonce( $_POST['wmw_settings_nonce'], 'wmw_save_settings' )
&& current_user_can( 'manage_options' ) ) {
$settings = array(
'show_toc' => isset( $_POST['show_toc'] ) ? 1 : 0,
'show_breadcrumbs' => isset( $_POST['show_breadcrumbs'] ) ? 1 : 0,
'show_related' => isset( $_POST['show_related'] ) ? 1 : 0,
'show_search' => isset( $_POST['show_search'] ) ? 1 : 0,
'articles_per_page' => absint( $_POST['articles_per_page'] ?? 20 ),
'sidebar_position' => sanitize_key( $_POST['sidebar_position'] ?? 'left' ),
'color_scheme' => sanitize_key( $_POST['color_scheme'] ?? 'auto' ),
'custom_css' => wp_strip_all_tags( $_POST['custom_css'] ?? '' ),
);
update_option( 'wmw_settings', $settings );
$saved = true;
}
// ── Seite anzeigen (nach Speichern ODER normalem Aufruf) ─────────
$settings = get_option( 'wmw_settings', array() );
// Erfolgsmeldung direkt hier ausgeben, kein Redirect nötig
if ( $saved ) {
echo '✅ Einstellungen gespeichert!
';
}
include WMW_PLUGIN_DIR . 'templates/admin/settings.php';
}
}