6556479417
Features: - Full sync of NorthStar MLS properties via MLS Grid API v2 - Incremental sync using ModificationTimestamp - Local media download and storage - Rate limit compliance (2 req/sec, 7200/hr, 40000/day) - Sync state tracking with resume capability - WP-CLI commands: test, sync, status, stats, cache - Admin settings page with manual sync triggers - Public API functions: mls_get_properties, mls_get_property, etc. Database tables: - mls_properties: Listing data with full field mapping - mls_media: Downloaded images - mls_sync_state: Sync progress tracking - mls_rate_limits: API usage tracking - mls_sync_log: Debug logging Documentation: - docs/CLAUDE.md: AI development guide - docs/API.md: MLS Grid API reference - docs/USAGE.md: User documentation Tested: Connection, auth, sync 10 records, media download verified 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
138 lines
3.8 KiB
PHP
138 lines
3.8 KiB
PHP
<?php
|
|
/**
|
|
* Plugin activator class
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class MLS_Activator {
|
|
|
|
/**
|
|
* Run on plugin activation
|
|
*/
|
|
public static function activate() {
|
|
// Create database tables
|
|
self::create_tables();
|
|
|
|
// Set default options
|
|
self::set_defaults();
|
|
|
|
// Schedule cron events if auto-sync enabled
|
|
self::schedule_cron();
|
|
|
|
// Create upload directory
|
|
self::create_upload_dir();
|
|
|
|
// Store activation time
|
|
update_option('mls_activated_at', current_time('mysql'));
|
|
|
|
// Flush rewrite rules
|
|
flush_rewrite_rules();
|
|
}
|
|
|
|
/**
|
|
* Create database tables
|
|
*/
|
|
public static function create_tables() {
|
|
MLS_DB::create_tables();
|
|
update_option('mls_db_version', MLS_DB_VERSION);
|
|
}
|
|
|
|
/**
|
|
* Set default options
|
|
*/
|
|
private static function set_defaults() {
|
|
$defaults = array(
|
|
'api_url' => defined('MLSGRID_API_URL') ? MLSGRID_API_URL : 'https://api.mlsgrid.com/v2',
|
|
'originating_system' => 'northstar',
|
|
'auto_sync_enabled' => false,
|
|
'sync_interval' => 'hourly',
|
|
'sync_media' => true,
|
|
);
|
|
|
|
$existing = get_option(MLS_Options::OPTION_KEY, array());
|
|
$merged = wp_parse_args($existing, $defaults);
|
|
update_option(MLS_Options::OPTION_KEY, $merged);
|
|
}
|
|
|
|
/**
|
|
* Schedule cron events
|
|
*/
|
|
private static function schedule_cron() {
|
|
// Register custom cron intervals
|
|
add_filter('cron_schedules', array(__CLASS__, 'add_cron_intervals'));
|
|
|
|
// Only schedule if auto-sync is enabled
|
|
$options = get_option(MLS_Options::OPTION_KEY, array());
|
|
if (empty($options['auto_sync_enabled'])) {
|
|
return;
|
|
}
|
|
|
|
$interval = !empty($options['sync_interval']) ? $options['sync_interval'] : 'hourly';
|
|
|
|
if (!wp_next_scheduled('mls_sync_properties')) {
|
|
wp_schedule_event(time(), $interval, 'mls_sync_properties');
|
|
}
|
|
|
|
if (!wp_next_scheduled('mls_sync_media')) {
|
|
wp_schedule_event(time() + 1800, $interval, 'mls_sync_media');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Add custom cron intervals
|
|
*
|
|
* @param array $schedules Existing schedules
|
|
* @return array Modified schedules
|
|
*/
|
|
public static function add_cron_intervals($schedules) {
|
|
$schedules['every_30_minutes'] = array(
|
|
'interval' => 1800,
|
|
'display' => 'Every 30 Minutes',
|
|
);
|
|
|
|
$schedules['every_2_hours'] = array(
|
|
'interval' => 7200,
|
|
'display' => 'Every 2 Hours',
|
|
);
|
|
|
|
$schedules['every_6_hours'] = array(
|
|
'interval' => 21600,
|
|
'display' => 'Every 6 Hours',
|
|
);
|
|
|
|
$schedules['every_12_hours'] = array(
|
|
'interval' => 43200,
|
|
'display' => 'Every 12 Hours',
|
|
);
|
|
|
|
return $schedules;
|
|
}
|
|
|
|
/**
|
|
* Create upload directory for MLS media
|
|
*/
|
|
private static function create_upload_dir() {
|
|
$upload_dir = wp_upload_dir();
|
|
$mls_dir = $upload_dir['basedir'] . '/mls-listings';
|
|
|
|
if (!file_exists($mls_dir)) {
|
|
wp_mkdir_p($mls_dir);
|
|
|
|
// Create .htaccess to prevent directory listing
|
|
$htaccess = $mls_dir . '/.htaccess';
|
|
if (!file_exists($htaccess)) {
|
|
file_put_contents($htaccess, "Options -Indexes\n");
|
|
}
|
|
|
|
// Create index.php for extra protection
|
|
$index = $mls_dir . '/index.php';
|
|
if (!file_exists($index)) {
|
|
file_put_contents($index, "<?php\n// Silence is golden.\n");
|
|
}
|
|
}
|
|
}
|
|
}
|