5 * Determine default settings for WordPress.
8 if (!defined('CIVI_SETUP')) {
9 exit("Installation plugins must only be loaded by the installer.\n");
12 \Civi\Setup
::dispatcher()
13 ->addListener('civi.setup.checkAuthorized', function (\Civi\Setup\Event\CheckAuthorizedEvent
$e) {
14 $model = $e->getModel();
15 if ($model->cms
!== 'WordPress') {
19 \Civi\Setup
::log()->info(sprintf('[%s] Handle %s', basename(__FILE__
), 'checkAuthorized'));
20 $e->setAuthorized(current_user_can('activate_plugins'));
24 \Civi\Setup
::dispatcher()
25 ->addListener('civi.setup.init', function (\Civi\Setup\Event\InitEvent
$e) {
26 $model = $e->getModel();
27 if ($model->cms
!== 'WordPress' ||
!function_exists('current_user_can')) {
30 \Civi\Setup
::log()->info(sprintf('[%s] Handle %s', basename(__FILE__
), 'init'));
32 // Note: We know WP is bootstrapped, but we don't know if the `civicrm` plugin is active,
33 // so we have to make an educated guess.
34 $civicrmPluginFile = implode(DIRECTORY_SEPARATOR
, [WP_PLUGIN_DIR
, 'civicrm', 'civicrm.php']);
36 // Compute settingsPath.
37 $uploadDir = wp_upload_dir();
38 $preferredSettingsPath = $uploadDir['basedir'] . DIRECTORY_SEPARATOR
. 'civicrm' . DIRECTORY_SEPARATOR
. 'civicrm.settings.php';
39 $oldSettingsPath = plugin_dir_path($civicrmPluginFile) . 'civicrm.settings.php';
40 if (file_exists($preferredSettingsPath)) {
41 $model->settingsPath
= $preferredSettingsPath;
43 elseif (file_exists($oldSettingsPath)) {
44 $model->settingsPath
= $oldSettingsPath;
47 $model->settingsPath
= $preferredSettingsPath;
50 $model->templateCompilePath
= implode(DIRECTORY_SEPARATOR
, [$uploadDir['basedir'], 'civicrm', 'templates_c']);
53 list(/*$host*/, /*$port*/, $socket) = Civi\Setup\DbUtil
::decodeHostPort(DB_HOST
);
54 $model->db
= $model->cmsDb
= array(
55 'server' => $socket ?
sprintf('unix(%s)', $socket) : DB_HOST
,
56 'username' => DB_USER
,
57 'password' => DB_PASSWORD
,
58 'database' => DB_NAME
,
62 $model->cmsBaseUrl
= site_url();
63 $model->paths
['wp.frontend.base']['url'] = home_url() . '/';
64 $model->paths
['wp.backend.base']['url'] = admin_url();
65 $model->mandatorySettings
['userFrameworkResourceURL'] = plugin_dir_url($civicrmPluginFile) . 'civicrm';
67 // Compute default locale.
68 $langs = $model->getField('lang', 'options');
69 $wpLang = get_locale();
70 $model->lang
= isset($langs[$wpLang]) ?
$wpLang : 'en_US';