SOURCEFIX_FS_ID, 'slug' => 'sourcefix', 'type' => 'plugin', 'public_key' => SOURCEFIX_FS_PUBLIC_KEY, 'is_premium' => false, 'has_premium_version' => true, 'has_paid_plans' => true, 'is_org_compliant' => true, 'menu' => array( 'slug' => 'sourcefix', 'account' => true, 'pricing' => true, 'support' => true, 'contact' => true, ), ) ); } else { $sourcefix_fs = null; } } return $sourcefix_fs; } sourcefix_fs(); do_action( 'sourcefix_fs_loaded' ); } require_once SOURCEFIX_PLUGIN_DIR . 'includes/class-sourcefix-licensing.php'; require_once SOURCEFIX_PLUGIN_DIR . 'includes/class-sourcefix-store.php'; require_once SOURCEFIX_PLUGIN_DIR . 'includes/class-sourcefix-api.php'; // Test-only paid-plan overrides. The file is NEVER shipped (it must be // excluded from the release zip and the WordPress.org submission); when // it is absent, the override block in current_plan() is dead code and // no code on the site can unlock a paid plan. if ( file_exists( SOURCEFIX_PLUGIN_DIR . 'includes/test-overrides.php' ) ) { require_once SOURCEFIX_PLUGIN_DIR . 'includes/test-overrides.php'; } require_once SOURCEFIX_PLUGIN_DIR . 'includes/class-sourcefix-scanner.php'; require_once SOURCEFIX_PLUGIN_DIR . 'includes/class-sourcefix-applier.php'; require_once SOURCEFIX_PLUGIN_DIR . 'includes/sourcefix-publish.php'; require_once SOURCEFIX_PLUGIN_DIR . 'includes/class-sourcefix-statement.php'; require_once SOURCEFIX_PLUGIN_DIR . 'admin/class-sourcefix-admin.php'; /** * Activation: create the database tables, set defaults, create the * statement page, and record the activation in the audit log. */ function sourcefix_activate() { SourceFix_Store::create_tables(); update_option( 'sourcefix_db_version', SOURCEFIX_VERSION ); add_option( 'sourcefix_api_url', SOURCEFIX_API_URL ); // Auto-apply defaults to OFF on new installs (audit M-2): the // admin opts in from Settings after seeing the approval queue // once. add_option() never overwrites an existing value, so // upgrading installs keep whatever the admin already chose. add_option( 'sourcefix_auto_apply', '0' ); add_option( 'sourcefix_month_key', gmdate( 'Y-m' ) ); add_option( 'sourcefix_month_count', 0 ); // No network on activation (WP.org Guideline 7): the site is NOT // registered with the backend here. Registration sends the site // URL and plan to the authoring service, so it happens only after // the admin explicitly clicks "Connect" on the SourceFix screens // (see SourceFix_Admin::handle_connect). Until then the plugin // works fully offline: scans still detect issues and queue them // for manual writing, and the approval queue, auto-apply setting, // terminology memory, statement, and agency dashboard all work. // A site that already connected keeps its stored key, so the // publish-time scan loop is unchanged for connected sites. SourceFix_Statement::maybe_create_page(); // Daily maintenance: prune the audit log and the fixes table to // the 12-month retention (the same for every site). if ( ! wp_next_scheduled( 'sourcefix_daily_maintenance' ) ) { wp_schedule_event( time(), 'daily', 'sourcefix_daily_maintenance' ); } SourceFix_Store::audit_log( 0, 'plugin_activated', __( 'SourceFix activated.', 'sourcefix' ) ); } register_activation_hook( __FILE__, 'sourcefix_activate' ); /** * Deactivation: nothing destructive. Tables and options stay so a * re-activation keeps the approval history. The maintenance cron is * cleared; it is re-registered on the next activation. */ function sourcefix_deactivate() { wp_clear_scheduled_hook( 'sourcefix_daily_maintenance' ); SourceFix_Store::audit_log( 0, 'plugin_deactivated', __( 'SourceFix deactivated.', 'sourcefix' ) ); } register_deactivation_hook( __FILE__, 'sourcefix_deactivate' ); /** * Daily maintenance: prune the audit log and the fixes table to the * 12-month retention (the same for every site, on every plan). */ function sourcefix_daily_maintenance() { $days = SourceFix_Licensing::audit_retention_days(); $deleted = SourceFix_Store::prune_audit_log( $days ); if ( $deleted > 0 ) { SourceFix_Store::audit_log( 0, 'audit_pruned', sprintf( __( 'Removed %d audit log entries older than the 12-month retention.', 'sourcefix' ), $deleted ) ); } $fixes_deleted = SourceFix_Store::prune_fixes( $days ); if ( $fixes_deleted > 0 ) { SourceFix_Store::audit_log( 0, 'fixes_pruned', sprintf( __( 'Removed %d applied or rejected fixes older than the 12-month retention.', 'sourcefix' ), $fixes_deleted ) ); } } add_action( 'sourcefix_daily_maintenance', 'sourcefix_daily_maintenance' ); /** * Register the admin screens and the public statement shortcode. * * Also runs the database migration: plugin updates do NOT re-run the * activation hook, so a schema change (audit H-8 added the `occurrence` * column to the fixes table) would never land on an updated site * otherwise. create_tables() is idempotent (dbDelta adds only what is * missing) and runs at most once per version. */ function sourcefix_init() { if ( SOURCEFIX_VERSION !== get_option( 'sourcefix_db_version', '' ) ) { SourceFix_Store::create_tables(); update_option( 'sourcefix_db_version', SOURCEFIX_VERSION ); } SourceFix_Admin::init(); SourceFix_Statement::init(); } add_action( 'init', 'sourcefix_init' );