prefix . 'ailm_link_monitor'; } /** * Create the custom table for storing link scan results. * This should be called on plugin activation. */ public static function create_table() { global $wpdb; $table_name = self::get_table_name(); $charset_collate = $wpdb->get_charset_collate(); // SQL statement for table creation $sql = "CREATE TABLE $table_name ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, post_id bigint(20) unsigned NOT NULL, url varchar(2048) NOT NULL, anchor text, link_origin varchar(20) NOT NULL DEFAULT 'manual', /* 'manual' or 'ailm' */ link_type varchar(20) NOT NULL DEFAULT 'internal', /* 'internal' or 'external' */ status_code int(5) NOT NULL DEFAULT 0, /* 0 means pending check */ last_checked datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, PRIMARY KEY (id), KEY post_id (post_id), KEY status_code (status_code) ) $charset_collate;"; // We need dbDelta to safely create or update the table schema require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); } /** * Optional: Clear all records from the table. */ public static function truncate_table() { global $wpdb; $table_name = self::get_table_name(); // Using TRUNCATE is more efficient for emptying a table. // The table name is safe as it's constructed internally. // phpcs:ignore WordPress.DB.DirectDatabaseQuery, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( "TRUNCATE TABLE `{$table_name}`" ); } }