{"id":13911909,"date":"2021-01-15T11:51:49","date_gmt":"2021-01-15T11:51:49","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/administrator-database-config-trigger\/"},"modified":"2021-01-15T11:51:49","modified_gmt":"2021-01-15T11:51:49","slug":"administrator-database-config-trigger","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/administrator-database-config-trigger\/","title":{"rendered":"Administrator Database Config Trigger"},"content":{"rendered":"<p>Hello,<\/p>\n<p>I am trying to add a trigger to the wp-config that changes the database connection if an administrator signs in (user id 1) however, WordPress keeps throwing up errors? If this can not be archived is it possible to create a standalone login page for the admin to sign into using a different wp-config file?<\/p>\n<p><strong>Fatal error: Uncaught Error: Call to undefined function wp_get_current_user()<\/strong><\/p>\n<pre><code>&lt;?php\ndefine( &#039;DB_NAME&#039;, &#039;######&#039; );\n\ndefine( &#039;DB_USER&#039;, &#039;######&#039; );\n\ndefine( &#039;DB_PASSWORD&#039;, &#039;######&#039; );\n\ndefine( &#039;DB_HOST&#039;, &#039;######:####&#039; );\n\ndefine( &#039;DB_CHARSET&#039;, &#039;######&#039; );\n\ndefine( &#039;DB_COLLATE&#039;, &#039;&#039; );\n\ndefine( &#039;AUTH_KEY&#039;,         &#039;################################################################&#039; );\ndefine( &#039;SECURE_AUTH_KEY&#039;,  &#039;################################################################&#039; );\ndefine( &#039;LOGGED_IN_KEY&#039;,    &#039;################################################################&#039; );\ndefine( &#039;NONCE_KEY&#039;,        &#039;################################################################&#039; );\ndefine( &#039;AUTH_SALT&#039;,        &#039;################################################################&#039; );\ndefine( &#039;SECURE_AUTH_SALT&#039;, &#039;################################################################&#039; );\ndefine( &#039;LOGGED_IN_SALT&#039;,   &#039;################################################################&#039; );\ndefine( &#039;NONCE_SALT&#039;,       &#039;################################################################&#039; );\n\n$table_prefix = &#039;1000_0001_&#039;;\n\ndefine( &#039;DOMAIN_CURRENT_SITE&#039;, &#039;website.com&#039; );\ndefine( &#039;PATH_CURRENT_SITE&#039;, &#039;\/stores\/1000-0001\/&#039; );\n\ndefine(\t&#039;WP_DEBUG&#039;, false );\ndefine(\t&#039;WP_DEBUG_LOG&#039;, false );\n\nfunction get_current_user_id()\n{\n    $user = wp_get_current_user();\n    return ( isset( $user-&gt;ID ) ? (int) $user-&gt;ID : 0 );\n}\n\nif (get_current_user_id() == &#039;1&#039;)\n{\n\tdefine( &#039;CUSTOM_USER_TABLE&#039;, &#039;1000_0001_users&#039; );\n\tdefine( &#039;CUSTOM_USER_META_TABLE&#039;, &#039;1000_0001_usermeta&#039; );\n}\nelse\n{\n\tdefine(\t&#039;CUSTOM_USER_TABLE&#039;, &#039;wp_users&#039; );\n\tdefine(\t&#039;CUSTOM_USER_META_TABLE&#039;, &#039;wp_usermeta&#039; );\n}\n\ndefine(\t&#039;COOKIE_DOMAIN&#039;, &#039;website.com&#039; ); \ndefine(\t&#039;COOKIEHASH&#039;, md5( &#039;https:\/\/www.website.com&#039; ) );\n\nif ( ! defined( &#039;ABSPATH&#039; ) ) {\n\tdefine( &#039;ABSPATH&#039;, __DIR__ . &#039;\/&#039; );\n}\nrequire_once ABSPATH . &#039;wp-settings.php&#039;;<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-13911909","topic","type-topic","status-publish","hentry","topic-tag-admin","topic-tag-database","topic-tag-trigger"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13911909","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13911909\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=13911909"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}