Recurrence slug keyed by cron hook name. */ public static function cron_events() { return array( self::CRON_CLEANUP_LOGS => Core::SCHEDULE_DAILY, self::CRON_SCAN_DENSITY => Core::SCHEDULE_EVERY_6_HOURS, ); } /** * Activates the plugin. * * @since 1.0.0 * * @return void */ public static function activate() { Database::create_tables(); self::set_default_options(); self::schedule_events(); /* * Module 4's document is a function of settings, content and ownership, * all of which may have changed while the plugin was inactive. The cache * key already makes a stale entry unreachable; clearing it here means an * activation does not leave unreachable rows behind either. */ LlmsCache::flush_all(); /* * Module 4 registers a rewrite rule for /llms.txt. Flushing here means a * freshly activated site serves it without the owner having to re-save * permalinks. This is the expensive-but-correct call that belongs in an * activation hook and nowhere else. */ flush_rewrite_rules(); } /** * Writes the default settings without discarding an existing configuration. * * On a first activation this seeds every default. On a reactivation it keeps * the stored values and only fills in keys a newer version introduced, so an * upgrade never resets the site owner's choices. * * @since 1.0.0 * * @return void */ public static function set_default_options() { $stored = get_option( Helpers::OPTION_KEY, null ); if ( ! is_array( $stored ) ) { add_option( Helpers::OPTION_KEY, Helpers::default_settings() ); return; } $merged = Helpers::merge_settings( $stored ); if ( $merged !== $stored ) { update_option( Helpers::OPTION_KEY, $merged ); } } /** * Schedules the plugin's recurring cron events. * * The custom recurrences come from Core's `cron_schedules` filter. That * filter is registered by the main plugin file at include time, which is * what makes it available here: WordPress includes the plugin file during * activate_plugin(), long after plugins_loaded has fired. * * @since 1.0.0 * * @return void */ public static function schedule_events() { // Defensive: guarantees the recurrences exist even if Core was not bootstrapped. Core::instance()->register_hooks(); foreach ( self::cron_events() as $hook => $recurrence ) { if ( false !== wp_next_scheduled( $hook ) ) { continue; } $scheduled = wp_schedule_event( time(), $recurrence, $hook ); if ( false === $scheduled || is_wp_error( $scheduled ) ) { Helpers::log( 'Failed to schedule cron event.', array( 'hook' => $hook, 'recurrence' => $recurrence, ) ); } } } }