<?php
/**
 * Plugin Name: Announcements Manager
 * Plugin URI: https://plugincompass.com/plugins/pc-announcements-274
 * Description: Create and manage announcements that display at the top of public pages with scheduling capabilities.
 * Version: 1.0.0
 * Author: Plugin Compass
 * Author URI: https://plugincompass.com
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: pc-announcements-274
 * Domain Path: /languages
 * Requires at least: 5.0
 * Requires PHP: 7.4
 * Update URI: false
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

// Define plugin constants
define('PC_ANNOUNCEMENTS_274_VERSION', '1.0.0');
define('PC_ANNOUNCEMENTS_274_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('PC_ANNOUNCEMENTS_274_PLUGIN_URL', plugin_dir_url(__FILE__));
define('PC_ANNOUNCEMENTS_274_PLUGIN_BASENAME', plugin_basename(__FILE__));

// Prevent WordPress.org update checks
add_filter('site_transient_update_plugins', function($value) {
    $plugin_file = plugin_basename(__FILE__);
    if (isset($value->response[$plugin_file])) {
        unset($value->response[$plugin_file]);
    }
    return $value;
});

/**
 * Main plugin class
 */
class PC_Announcements_274 {
    
    /**
     * 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() {
        add_action('plugins_loaded', array($this, 'init'));
    }
    
    /**
     * Initialize plugin
     */
    public function init() {
        // Load text domain
        load_plugin_textdomain('pc-announcements-274', false, dirname(PC_ANNOUNCEMENTS_274_PLUGIN_BASENAME) . '/languages');
        
        // Include required files
        $this->includes();
        
        // Initialize admin
        if (is_admin()) {
            new PC_Announcements_274_Admin();
        }
        
        // Initialize frontend
        new PC_Announcements_274_Frontend();
    }
    
    /**
     * Include required files
     */
    private function includes() {
        $files = array(
            PC_ANNOUNCEMENTS_274_PLUGIN_DIR . 'includes/class-install.php',
            PC_ANNOUNCEMENTS_274_PLUGIN_DIR . 'admin/class-admin.php',
            PC_ANNOUNCEMENTS_274_PLUGIN_DIR . 'public/class-frontend.php'
        );
        
        foreach ($files as $file_path) {
            if (file_exists($file_path)) {
                require_once $file_path;
            }
        }
    }
    
    /**
     * Activate plugin
     */
    public static function activate() {
        // Ensure install class is available during activation (plugins_loaded hasn't run yet)
        if (!class_exists('PC_Announcements_274_Install')) {
            require_once PC_ANNOUNCEMENTS_274_PLUGIN_DIR . 'includes/class-install.php';
        }
        PC_Announcements_274_Install::install();
        flush_rewrite_rules();
    }
    
    /**
     * Deactivate plugin
     */
    public static function deactivate() {
        flush_rewrite_rules();
    }
}

// Initialize plugin
PC_Announcements_274::get_instance();

// Register activation and deactivation hooks
register_activation_hook(__FILE__, array('PC_Announcements_274', 'activate'));
register_deactivation_hook(__FILE__, array('PC_Announcements_274', 'deactivate'));