prefix . 'ascr_events'; $amar_new_table = self::get_events_table(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $legacy_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $amar_legacy_table ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $new_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $amar_new_table ) ); if ( $legacy_exists === $amar_legacy_table && $new_exists !== $amar_new_table ) { // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter $wpdb->query( "RENAME TABLE {$amar_legacy_table} TO {$amar_new_table}" ); // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter } } /** * Create custom tables. */ public static function create_tables() { global $wpdb; $table_name = self::get_events_table(); $charset_collate = $wpdb->get_charset_collate(); require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $sql = "CREATE TABLE {$table_name} ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, event_type varchar(50) NOT NULL, object_type varchar(50) NOT NULL DEFAULT '', object_name varchar(191) NOT NULL DEFAULT '', object_slug varchar(191) NOT NULL DEFAULT '', old_version varchar(50) NOT NULL DEFAULT '', new_version varchar(50) NOT NULL DEFAULT '', notes text NOT NULL, created_at datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, created_by bigint(20) unsigned NOT NULL DEFAULT 0, PRIMARY KEY (id), KEY event_type (event_type), KEY created_at (created_at) ) {$charset_collate};"; dbDelta( $sql ); } /** * Get the events table name. * * @return string */ public static function get_events_table() { global $wpdb; return $wpdb->prefix . 'amar_events'; } }