Files
WP-Multi-Wiki/includes/class-wmw-core.php
2026-03-18 21:56:45 +01:00

117 lines
3.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* WMW_Core Bootstrap singleton.
* Wires up all sub-systems and handles asset enqueueing.
*/
defined( 'ABSPATH' ) || exit;
final class WMW_Core {
private static ?WMW_Core $instance = null;
private function __construct() {
new WMW_CPT();
new WMW_Admin();
new WMW_Frontend();
new WMW_Search();
new WMW_Shortcodes();
add_action( 'wp_enqueue_scripts', [ $this, 'frontend_assets' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'admin_assets' ] );
add_filter( 'plugin_action_links_' . WMW_BASENAME, [ $this, 'action_links' ] );
add_action( 'init', [ $this, 'load_textdomain' ] );
}
public static function get_instance(): WMW_Core {
if ( self::$instance === null ) {
self::$instance = new self();
}
return self::$instance;
}
/* ── Textdomain ─────────────────────────────────────────────── */
public function load_textdomain(): void {
load_plugin_textdomain( 'wp-multi-wiki', false, dirname( WMW_BASENAME ) . '/languages' );
}
/* ── Frontend Assets ────────────────────────────────────────── */
public function frontend_assets(): void {
if ( ! $this->is_wiki_context() ) return;
// Dashicons on frontend
wp_enqueue_style( 'dashicons' );
wp_enqueue_style(
'wmw-frontend',
WMW_URL . 'assets/css/frontend.css',
[ 'dashicons' ],
WMW_VERSION
);
wp_enqueue_script(
'wmw-frontend',
WMW_URL . 'assets/js/frontend.js',
[ 'jquery' ],
WMW_VERSION,
true
);
wp_localize_script( 'wmw-frontend', 'WMW', [
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'wmw_search' ),
'l10n' => [
'no_results' => __( 'Keine Ergebnisse gefunden.', 'wp-multi-wiki' ),
'searching' => __( 'Suche …', 'wp-multi-wiki' ),
'navigation' => __( 'Navigation', 'wp-multi-wiki' ),
],
] );
}
/* ── Admin Assets ───────────────────────────────────────────── */
public function admin_assets( string $hook ): void {
$screen = get_current_screen();
if ( ! $screen ) return;
$is_wmw = str_contains( $hook, 'wp-multi-wiki' )
|| str_contains( $hook, 'wmw-settings' )
|| in_array( $screen->post_type, [ 'wmw_wiki', 'wmw_article' ], true )
|| in_array( $screen->taxonomy ?? '', [ 'wmw_category', 'wmw_tag' ], true );
if ( ! $is_wmw ) return;
wp_enqueue_style(
'wmw-admin',
WMW_URL . 'assets/css/admin.css',
[],
WMW_VERSION
);
wp_enqueue_script(
'wmw-admin',
WMW_URL . 'assets/js/admin.js',
[ 'jquery' ],
WMW_VERSION,
true
);
}
/* ── Helpers ────────────────────────────────────────────────── */
private function is_wiki_context(): bool {
return is_singular( [ 'wmw_wiki', 'wmw_article' ] )
|| is_post_type_archive( 'wmw_wiki' )
|| is_tax( [ 'wmw_category', 'wmw_tag' ] );
}
public function action_links( array $links ): array {
array_unshift(
$links,
'<a href="' . admin_url( 'admin.php?page=wp-multi-wiki' ) . '">' . __( 'Dashboard', 'wp-multi-wiki' ) . '</a>'
);
return $links;
}
}