Files
Siegel-Umzugsliste/umzugsliste.php
Viktor Miller 64caccc5c1 fix: resolve form submission issues and add CPT detail view
- Rename day/month/year form fields to umzug_day/umzug_month/umzug_year
  to avoid conflict with WordPress reserved public query variables that
  caused a 404 on form POST
- Move form handler instantiation to init_hooks() so handle_submission
  registers on the init action before it fires
- Add standalone template fallback: detect [umzugsliste] shortcode in
  page content when form_page_id option is not set
- Add submission details meta box to CPT entries showing addresses,
  furniture, additional work, and status
- Add German translations for all new admin meta box strings

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-07 13:03:31 +09:00

202 lines
5.1 KiB
PHP

<?php
/**
* Plugin Name: Umzugsliste
* Description: Email-basiertes Möbelauswahlsystem für Siegel Umzüge
* Version: 1.0.0
* Author: Siegel Umzüge
* Text Domain: siegel-umzugsliste
* Domain Path: /languages
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
// Plugin version
define( 'UMZUGSLISTE_VERSION', '1.0.0' );
define( 'UMZUGSLISTE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
define( 'UMZUGSLISTE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
/**
* Load plugin text domain for translations
*/
function siegel_umzugsliste_load_textdomain() {
load_plugin_textdomain(
'siegel-umzugsliste',
false,
dirname( plugin_basename( __FILE__ ) ) . '/languages'
);
}
add_action( 'init', 'siegel_umzugsliste_load_textdomain', 1 );
/**
* Reload text domain on locale change
* Workaround for WordPress core bug #39210 where switch_to_locale() doesn't reload plugin translations
*/
add_action( 'change_locale', function() {
unload_textdomain( 'siegel-umzugsliste' );
load_plugin_textdomain(
'siegel-umzugsliste',
false,
dirname( plugin_basename( __FILE__ ) ) . '/languages'
);
} );
/**
* Main plugin class
*/
class Umzugsliste {
/**
* Single instance of the class
*/
private static $instance = null;
/**
* Get single instance
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct() {
$this->load_dependencies();
$this->init_hooks();
}
/**
* Load required files
*/
private function load_dependencies() {
require_once UMZUGSLISTE_PLUGIN_DIR . 'includes/class-cpt.php';
require_once UMZUGSLISTE_PLUGIN_DIR . 'includes/class-admin-menu.php';
require_once UMZUGSLISTE_PLUGIN_DIR . 'includes/class-settings.php';
require_once UMZUGSLISTE_PLUGIN_DIR . 'includes/class-furniture-data.php';
require_once UMZUGSLISTE_PLUGIN_DIR . 'includes/class-date-helpers.php';
require_once UMZUGSLISTE_PLUGIN_DIR . 'includes/class-captcha.php';
require_once UMZUGSLISTE_PLUGIN_DIR . 'includes/class-form-renderer.php';
require_once UMZUGSLISTE_PLUGIN_DIR . 'includes/class-shortcode.php';
require_once UMZUGSLISTE_PLUGIN_DIR . 'includes/class-email-generator.php';
require_once UMZUGSLISTE_PLUGIN_DIR . 'includes/class-form-handler.php';
}
/**
* Initialize WordPress hooks
*/
private function init_hooks() {
add_action( 'init', array( $this, 'init' ) );
add_filter( 'template_include', array( $this, 'maybe_load_form_template' ) );
// Form handler must register its init hook before init fires
Umzugsliste_Form_Handler::get_instance();
}
/**
* Load standalone form template if current page is the configured form page
*
* @param string $template Current template path
* @return string Template path
*/
public function maybe_load_form_template( $template ) {
if ( is_admin() || ! is_page() ) {
return $template;
}
$use_standalone = false;
// Check configured form page ID
$form_page_id = (int) get_option( 'umzugsliste_form_page_id', 0 );
if ( $form_page_id > 0 && is_page( $form_page_id ) ) {
$use_standalone = true;
}
// Fallback: check if current page contains the [umzugsliste] shortcode
if ( ! $use_standalone ) {
$post = get_queried_object();
if ( $post && isset( $post->post_content ) && has_shortcode( $post->post_content, 'umzugsliste' ) ) {
$use_standalone = true;
}
}
if ( $use_standalone ) {
$custom_template = UMZUGSLISTE_PLUGIN_DIR . 'templates/form-page.php';
if ( file_exists( $custom_template ) ) {
return $custom_template;
}
}
return $template;
}
/**
* Initialize plugin components
*/
public function init() {
// Initialize and register CPT
$cpt = Umzugsliste_CPT::get_instance();
$cpt->register_post_type();
// Initialize admin menu
if ( is_admin() ) {
Umzugsliste_Admin_Menu::get_instance();
}
// Initialize settings
Umzugsliste_Settings::get_instance();
// Initialize shortcode
Umzugsliste_Shortcode::get_instance();
}
}
/**
* Activation hook
*/
function umzugsliste_activate() {
// Initialize CPT to register post type
require_once UMZUGSLISTE_PLUGIN_DIR . 'includes/class-cpt.php';
Umzugsliste_CPT::get_instance();
// Auto-create form page if none exists
$form_page_id = (int) get_option( 'umzugsliste_form_page_id', 0 );
if ( $form_page_id <= 0 || ! get_post( $form_page_id ) ) {
$page_id = wp_insert_post( array(
'post_title' => 'Umzugsliste',
'post_content' => '',
'post_status' => 'publish',
'post_type' => 'page',
) );
if ( $page_id && ! is_wp_error( $page_id ) ) {
update_option( 'umzugsliste_form_page_id', $page_id );
}
}
// Flush rewrite rules
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'umzugsliste_activate' );
/**
* Deactivation hook
*/
function umzugsliste_deactivate() {
// Flush rewrite rules
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'umzugsliste_deactivate' );
/**
* Initialize plugin
*/
function umzugsliste_init() {
return Umzugsliste::get_instance();
}
add_action( 'plugins_loaded', 'umzugsliste_init' );