mirror of
https://github.com/PostgreSQL-For-Wordpress/postgresql-for-wordpress.git
synced 2025-07-31 10:17:13 +02:00
PHP 8 compatibility fixes
This commit is contained in:
@ -9,6 +9,17 @@
|
|||||||
* This file does all the initialisation tasks
|
* This file does all the initialisation tasks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// This is required by class-wpdb so we must load it first
|
||||||
|
require_once ABSPATH . '/wp-includes/cache.php';
|
||||||
|
require_once ABSPATH . '/wp-includes/l10n.php';
|
||||||
|
|
||||||
|
if (!function_exists('wpsql_is_resource')) {
|
||||||
|
function wpsql_is_resource($object)
|
||||||
|
{
|
||||||
|
return $object !== false && $object !== null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Logs are put in the pg4wp directory
|
// Logs are put in the pg4wp directory
|
||||||
define( 'PG4WP_LOG', PG4WP_ROOT.'/logs/');
|
define( 'PG4WP_LOG', PG4WP_ROOT.'/logs/');
|
||||||
// Check if the logs directory is needed and exists or create it if possible
|
// Check if the logs directory is needed and exists or create it if possible
|
||||||
@ -26,13 +37,22 @@ $replaces = array(
|
|||||||
'class wpdb' => 'class wpdb2',
|
'class wpdb' => 'class wpdb2',
|
||||||
'new wpdb' => 'new wpdb2',
|
'new wpdb' => 'new wpdb2',
|
||||||
'mysql_' => 'wpsql_',
|
'mysql_' => 'wpsql_',
|
||||||
|
'is_resource' => 'wpsql_is_resource',
|
||||||
'<?php' => '',
|
'<?php' => '',
|
||||||
'?>' => '',
|
'?>' => '',
|
||||||
);
|
);
|
||||||
|
|
||||||
// Ensure class uses the replaced mysql_ functions rather than mysqli_
|
// Ensure class uses the replaced mysql_ functions rather than mysqli_
|
||||||
define( 'WP_USE_EXT_MYSQL', true);
|
if (!defined('WP_USE_EXT_MYSQL')) {
|
||||||
eval( str_replace( array_keys($replaces), array_values($replaces), file_get_contents(ABSPATH.'/wp-includes/wp-db.php')));
|
define('WP_USE_EXT_MYSQL', true);
|
||||||
|
}
|
||||||
|
if (WP_USE_EXT_MYSQL != true) {
|
||||||
|
throw new \Exception("PG4SQL CANNOT BE ENABLED WITH MYSQLI, REMOVE ANY WP_USE_EXT_MYSQL configuration");
|
||||||
|
}
|
||||||
|
|
||||||
|
eval(str_replace(array_keys($replaces), array_values($replaces), file_get_contents(ABSPATH . '/wp-includes/class-wpdb.php')));
|
||||||
|
|
||||||
// Create wpdb object if not already done
|
// Create wpdb object if not already done
|
||||||
if (! isset($wpdb) && defined('DB_USER'))
|
if (! isset($wpdb) && defined('DB_USER')) {
|
||||||
$wpdb = new wpdb2( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
|
$wpdb = new wpdb2( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
|
||||||
|
}
|
59
pg4wp/db.php
59
pg4wp/db.php
@ -9,32 +9,43 @@ Author URI: http://www.hawkix.net
|
|||||||
License: GPLv2 or newer.
|
License: GPLv2 or newer.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if( !defined('PG4WP_ROOT'))
|
// Ensure we only load this config once
|
||||||
{
|
if(!defined('PG4WP_ROOT')) {
|
||||||
// You can choose the driver to load here
|
|
||||||
define('DB_DRIVER', 'pgsql'); // 'pgsql' or 'mysql' are supported for now
|
|
||||||
|
|
||||||
// Set this to 'true' and check that `pg4wp` is writable if you want debug logs to be written
|
// You can choose the driver to load here
|
||||||
define( 'PG4WP_DEBUG', false);
|
if (!defined('DB_DRIVER')) {
|
||||||
// If you just want to log queries that generate errors, leave PG4WP_DEBUG to "false"
|
define('DB_DRIVER', pgsql);
|
||||||
// and set this to true
|
}
|
||||||
define( 'PG4WP_LOG_ERRORS', true);
|
|
||||||
|
|
||||||
// If you want to allow insecure configuration (from the author point of view) to work with PG4WP,
|
// Set this to 'true' and check that `pg4wp` is writable if you want debug logs to be written
|
||||||
// change this to true
|
if (!defined('PG4WP_DEBUG')) {
|
||||||
define( 'PG4WP_INSECURE', false);
|
define('PG4WP_DEBUG', false);
|
||||||
|
}
|
||||||
|
|
||||||
// This defines the directory where PG4WP files are loaded from
|
if (!defined('PG4WP_LOG_ERRORS')) {
|
||||||
// 3 places checked : wp-content, wp-content/plugins and the base directory
|
// If you just want to log queries that generate errors, leave PG4WP_DEBUG to "false"
|
||||||
if( file_exists( ABSPATH.'/wp-content/pg4wp'))
|
// and set this to true
|
||||||
define( 'PG4WP_ROOT', ABSPATH.'/wp-content/pg4wp');
|
define('PG4WP_LOG_ERRORS', true);
|
||||||
else if( file_exists( ABSPATH.'/wp-content/plugins/pg4wp'))
|
}
|
||||||
define( 'PG4WP_ROOT', ABSPATH.'/wp-content/plugins/pg4wp');
|
|
||||||
else if( file_exists( ABSPATH.'/pg4wp'))
|
|
||||||
define( 'PG4WP_ROOT', ABSPATH.'/pg4wp');
|
|
||||||
else
|
|
||||||
die('PG4WP file directory not found');
|
|
||||||
|
|
||||||
// Here happens all the magic
|
if (!defined('PG4WP_INSECURE')) {
|
||||||
require_once( PG4WP_ROOT.'/core.php');
|
// If you want to allow insecure configuration (from the author point of view) to work with PG4WP,
|
||||||
|
// change this to true
|
||||||
|
define('PG4WP_INSECURE', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// This defines the directory where PG4WP files are loaded from
|
||||||
|
// 3 places checked : wp-content, wp-content/plugins and the base directory
|
||||||
|
if(file_exists(ABSPATH . '/wp-content/pg4wp')) {
|
||||||
|
define('PG4WP_ROOT', ABSPATH . '/wp-content/pg4wp');
|
||||||
|
} elseif(file_exists(ABSPATH . '/wp-content/plugins/pg4wp')) {
|
||||||
|
define('PG4WP_ROOT', ABSPATH . '/wp-content/plugins/pg4wp');
|
||||||
|
} elseif(file_exists(ABSPATH . '/pg4wp')) {
|
||||||
|
define('PG4WP_ROOT', ABSPATH . '/pg4wp');
|
||||||
|
} else {
|
||||||
|
die('PG4WP file directory not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Here happens all the magic
|
||||||
|
require_once(PG4WP_ROOT . '/core.php');
|
||||||
} // Protection against multiple loading
|
} // Protection against multiple loading
|
||||||
|
Reference in New Issue
Block a user