Skip to content

Conversation

sejas
Copy link

@sejas sejas commented Oct 3, 2025

This PR applies the wp_sqlite_default_db_name filter in all cases, even if DB_NAME was defined, so we can override the database name, and fix the behaviour in remote servers where DB_NAME is already defined.

Testing instructions:

Warning

These steps are not currently working, but they represent the desired behavior.

  • Break your database connection:
    • Go to your wp-config.php
    • Copy the value of your DB_NAME
    • Change it to any value to break your database connection
    • Access the homepage of your site and observe the error: Error establishing a database connection
  • Fix your database connection using the filter:
    • Create a new mu-plugin with the code below these instructions.
    • Access your homepage
    • Observe the site loads correctly
<?php

add_filter( 'wp_sqlite_default_db_name', function( $db_name ) {
	return 'database_name_here'; // Or any other value that you copied from your wp-config.php
} );

@sejas
Copy link
Author

sejas commented Oct 3, 2025

@JanJakes, I've created this PR trying to override the DB_NAME when we don't have control over that variable, however the filter is not working. Do you know how should I define the filter?
If the wp-includes/sqlite/db.php file loads before any plugin, why do we have a filter in the first place?

@sejas
Copy link
Author

sejas commented Oct 3, 2025

@sejas sejas closed this Oct 3, 2025
@JanJakes
Copy link
Member

JanJakes commented Oct 6, 2025

@sejas Thanks for looking into this!

Closing in favor of #261

Yeah, good call. This filter is not meant to be used that way and will likely be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants