3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * WordPress specific stuff goes here
21 class CRM_Utils_System_WordPress
extends CRM_Utils_System_Base
{
25 public function __construct() {
27 * deprecated property to check if this is a drupal install. The correct method is to have functions on the UF classes for all UF specific
28 * functions and leave the codebase oblivious to the type of CMS
32 $this->is_drupal
= FALSE;
33 $this->is_wordpress
= TRUE;
36 public function initialize() {
38 $this->registerPathVars();
42 * Specify the default computation for various paths/URLs.
44 protected function registerPathVars():void
{
45 $isNormalBoot = function_exists('get_option');
47 // Normal mode - CMS boots first, then calls Civi. "Normal" web pages and newer extern routes.
48 // To simplify the code-paths, some items are re-registered with WP-specific functions.
49 $cmsRoot = function() {
51 'path' => untrailingslashit(ABSPATH
),
55 Civi
::paths()->register('cms', $cmsRoot);
56 Civi
::paths()->register('cms.root', $cmsRoot);
57 Civi
::paths()->register('civicrm.root', function () {
59 'path' => CIVICRM_PLUGIN_DIR
. 'civicrm' . DIRECTORY_SEPARATOR
,
60 'url' => CIVICRM_PLUGIN_URL
. 'civicrm/',
63 Civi
::paths()->register('wp.frontend.base', function () {
65 'url' => home_url('/'),
68 Civi
::paths()->register('wp.frontend', function () {
69 $config = CRM_Core_Config
::singleton();
70 $basepage = get_page_by_path($config->wpBasePage
);
72 'url' => get_permalink($basepage->ID
),
75 Civi
::paths()->register('wp.backend.base', function () {
80 Civi
::paths()->register('wp.backend', function() {
82 'url' => admin_url('admin.php'),
85 Civi
::paths()->register('civicrm.files', function () {
86 $upload_dir = wp_get_upload_dir();
88 $old = CRM_Core_Config
::singleton()->userSystem
->getDefaultFileStorage();
90 'path' => $upload_dir['basedir'] . DIRECTORY_SEPARATOR
. 'civicrm' . DIRECTORY_SEPARATOR
,
91 'url' => $upload_dir['baseurl'] . '/civicrm/',
94 if ($old['path'] === $new['path']) {
98 $oldExists = file_exists($old['path']);
99 $newExists = file_exists($new['path']);
101 if ($oldExists && !$newExists) {
104 elseif (!$oldExists && $newExists) {
107 elseif (!$oldExists && !$newExists) {
108 // neither exists. but that's ok. we're in one of these two cases:
109 // - we're just starting installation... which will get sorted in a moment
110 // when someone calls mkdir().
111 // - we're running a bespoke setup... which will get sorted in a moment
112 // by applying $civicrm_paths.
115 elseif ($oldExists && $newExists) {
116 // situation ambiguous. encourage admin to set value explicitly.
117 if (!isset($GLOBALS['civicrm_paths']['civicrm.files'])) {
118 \Civi
::log()->warning("The system has data from both old+new conventions. Please use civicrm.settings.php to set civicrm.files explicitly.");
125 // Legacy support - only relevant for older extern routes.
127 ->register('wp.frontend.base', function () {
128 return ['url' => rtrim(CIVICRM_UF_BASEURL
, '/') . '/'];
130 ->register('wp.frontend', function () {
131 $config = \CRM_Core_Config
::singleton();
132 $suffix = defined('CIVICRM_UF_WP_BASEPAGE') ? CIVICRM_UF_WP_BASEPAGE
: $config->wpBasePage
;
134 'url' => Civi
::paths()->getVariable('wp.frontend.base', 'url') . $suffix,
137 ->register('wp.backend.base', function () {
138 return ['url' => rtrim(CIVICRM_UF_BASEURL
, '/') . '/wp-admin/'];
140 ->register('wp.backend', function () {
142 'url' => Civi
::paths()->getVariable('wp.backend.base', 'url') . 'admin.php',
151 public function setTitle($title, $pageTitle = NULL) {
156 // FIXME: Why is this global?
157 global $civicrm_wp_title;
158 $civicrm_wp_title = $title;
160 // yes, set page title, depending on context
161 $context = civi_wp()->civicrm_context_get();
165 $template = CRM_Core_Smarty
::singleton();
166 $template->assign('pageTitle', $pageTitle);
171 * Moved from CRM_Utils_System_Base
173 public function getDefaultFileStorage() {
174 // NOTE: On WordPress, this will be circumvented in the future. However,
175 // should retain it to allow transitional/upgrade code determine the old value.
177 $config = CRM_Core_Config
::singleton();
178 $cmsUrl = CRM_Utils_System
::languageNegotiationURL($config->userFrameworkBaseURL
, FALSE, TRUE);
179 $cmsPath = $this->cmsRootPath();
180 $filesPath = CRM_Utils_File
::baseFilePath();
181 $filesRelPath = CRM_Utils_File
::relativize($filesPath, $cmsPath);
182 $filesURL = rtrim($cmsUrl, '/') . '/' . ltrim($filesRelPath, ' /');
184 'url' => CRM_Utils_File
::addTrailingSlash($filesURL, '/'),
185 'path' => CRM_Utils_File
::addTrailingSlash($filesPath),
190 * Determine the location of the CiviCRM source tree.
193 * - url: string. ex: "http://example.com/sites/all/modules/civicrm"
194 * - path: string. ex: "/var/www/sites/all/modules/civicrm"
196 public function getCiviSourceStorage() {
197 global $civicrm_root;
199 // Don't use $config->userFrameworkBaseURL; it has garbage on it.
200 // More generally, we shouldn't be using $config here.
201 if (!defined('CIVICRM_UF_BASEURL')) {
202 throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL');
205 $cmsPath = $this->cmsRootPath();
207 // $config = CRM_Core_Config::singleton();
208 // overkill? // $cmsUrl = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
209 $cmsUrl = CIVICRM_UF_BASEURL
;
210 if (CRM_Utils_System
::isSSL()) {
211 $cmsUrl = str_replace('http://', 'https://', $cmsUrl);
213 $civiRelPath = CRM_Utils_File
::relativize(realpath($civicrm_root), realpath($cmsPath));
214 $civiUrl = rtrim($cmsUrl, '/') . '/' . ltrim($civiRelPath, ' /');
216 'url' => CRM_Utils_File
::addTrailingSlash($civiUrl, '/'),
217 'path' => CRM_Utils_File
::addTrailingSlash($civicrm_root),
224 public function appendBreadCrumb($breadCrumbs) {
225 $breadCrumb = wp_get_breadcrumb();
227 if (is_array($breadCrumbs)) {
228 foreach ($breadCrumbs as $crumbs) {
229 if (stripos($crumbs['url'], 'id%%')) {
230 $args = ['cid', 'mid'];
231 foreach ($args as $a) {
232 $val = CRM_Utils_Request
::retrieve($a, 'Positive', CRM_Core_DAO
::$_nullObject,
236 $crumbs['url'] = str_ireplace("%%{$a}%%", $val, $crumbs['url']);
240 $breadCrumb[] = "<a href=\"{$crumbs['url']}\">{$crumbs['title']}</a>";
244 $template = CRM_Core_Smarty
::singleton();
245 $template->assign_by_ref('breadcrumb', $breadCrumb);
246 wp_set_breadcrumb($breadCrumb);
252 public function resetBreadCrumb() {
254 wp_set_breadcrumb($bc);
260 public function addHTMLHead($head) {
261 static $registered = FALSE;
264 add_action('wp_head', [__CLASS__
, '_showHTMLHead']);
266 add_action('admin_head', [__CLASS__
, '_showHTMLHead']);
268 CRM_Core_Region
::instance('wp_head')->add([
274 * WP action callback.
276 public static function _showHTMLHead() {
277 $region = CRM_Core_Region
::instance('wp_head', FALSE);
279 echo $region->render('');
286 public function mapConfigToSSL() {
288 $base_url = str_replace('http://', 'https://', $base_url);
300 $forceBackend = FALSE,
303 $config = CRM_Core_Config
::singleton();
307 $fragment = isset($fragment) ?
('#' . $fragment) : '';
309 $path = CRM_Utils_String
::stripPathChars($path);
312 //this means wp function we are trying to use is not available,
314 // FIXME: Why bootstrap in url()? Generally want to define 1-2 strategic places to put bootstrap
315 if (!function_exists('get_option')) {
316 $this->loadBootStrap();
319 if ($config->userFrameworkFrontend
) {
321 if (get_option('permalink_structure') != '') {
322 $script = $post ?
get_permalink($post->ID
) : "";
324 if ($post && $config->wpBasePage
== $post->post_name
) {
327 // when shortcode is included in page
328 // also make sure we have valid query object
329 // FIXME: $wpPageParam has no effect and is only set on the *basepage*
331 if (get_option('permalink_structure') == '' && method_exists($wp_query, 'get')) {
332 if (get_query_var('page_id')) {
333 $wpPageParam = "page_id=" . get_query_var('page_id');
335 elseif (get_query_var('p')) {
336 // when shortcode is inserted in post
337 $wpPageParam = "p=" . get_query_var('p');
342 $base = $this->getBaseUrl($absolute, $frontend, $forceBackend);
344 if (!isset($path) && !isset($query)) {
345 // FIXME: This short-circuited codepath is the same as the general one below, except
346 // in that it ignores "permlink_structure" / $wpPageParam / $script . I don't know
347 // why it's different (and I can only find two obvious use-cases for this codepath,
348 // of which at least one looks gratuitous). A more ambitious person would simply remove
350 return $base . $fragment;
353 if (!$forceBackend && get_option('permalink_structure') != '' && ($wpPageParam ||
$script != '')) {
360 // not using clean URLs
362 // requesting an admin URL
363 ||
((is_admin() && !$frontend) ||
$forceBackend)
365 ||
(!$basepage && $script != '')
368 // pre-existing logic
370 // Admin URLs still need "page=CiviCRM", front-end URLs do not.
371 if ((is_admin() && !$frontend) ||
$forceBackend) {
372 $queryParts[] = 'page=CiviCRM';
375 $queryParts[] = 'civiwp=CiviCRM';
377 $queryParts[] = 'q=' . rawurlencode($path);
380 $queryParts[] = $wpPageParam;
382 if (!empty($query)) {
383 $queryParts[] = $query;
386 $final = $base . '?' . implode($separator, $queryParts) . $fragment;
393 $base = trailingslashit($base) . str_replace('civicrm/', '', $path) . '/';
396 $query = ltrim($query, '=?&');
397 $queryParts[] = $query;
400 if (!empty($queryParts)) {
401 $final = $base . '?' . implode($separator, $queryParts) . $fragment;
404 $final = $base . $fragment;
414 * CRM-16421 CRM-17633 WIP Changes to support WP in it's own directory
415 * https://wiki.civicrm.org/confluence/display/CRM/WordPress+installed+in+its+own+directory+issues
416 * For now leave hard coded wp-admin references.
417 * TODO: remove wp-admin references and replace with admin_url() in the future. Look at best way to get path to admin_url
421 * @param $forceBackend
423 * @return mixed|null|string
425 private function getBaseUrl($absolute, $frontend, $forceBackend) {
426 $config = CRM_Core_Config
::singleton();
427 if ((is_admin() && !$frontend) ||
$forceBackend) {
428 return Civi
::paths()->getUrl('[wp.backend]/.', $absolute ?
'absolute' : 'relative');
431 return Civi
::paths()->getUrl('[wp.frontend]/.', $absolute ?
'absolute' : 'relative');
438 public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
439 $config = CRM_Core_Config
::singleton();
441 if ($loadCMSBootstrap) {
442 $config->userSystem
->loadBootStrap([
448 $user = wp_authenticate($name, $password);
449 if (is_a($user, 'WP_Error')) {
453 // TODO: need to change this to make sure we matched only one row
455 CRM_Core_BAO_UFMatch
::synchronizeUFMatch($user->data
, $user->data
->ID
, $user->data
->user_email
, 'WordPress');
456 $contactID = CRM_Core_BAO_UFMatch
::getContactId($user->data
->ID
);
460 return [$contactID, $user->data
->ID
, mt_rand()];
464 * FIXME: Do something
466 * @param string $message
468 public function setMessage($message) {
472 * @param \string $user
476 public function loadUser($user) {
477 $userdata = get_user_by('login', $user);
478 if (!$userdata->data
->ID
) {
482 $uid = $userdata->data
->ID
;
483 wp_set_current_user($uid);
484 $contactID = CRM_Core_BAO_UFMatch
::getContactId($uid);
486 // lets store contact id and user id in session
487 $session = CRM_Core_Session
::singleton();
488 $session->set('ufID', $uid);
489 $session->set('userID', $contactID);
494 * FIXME: Use CMS-native approach
495 * @throws \CRM_Core_Exception
497 public function permissionDenied() {
498 throw new CRM_Core_Exception(ts('You do not have permission to access this page.'));
502 * Determine the native ID of the CMS user.
504 * @param string $username
508 public function getUfId($username) {
509 $userdata = get_user_by('login', $username);
510 if (!$userdata->data
->ID
) {
513 return $userdata->data
->ID
;
519 public function logout() {
525 wp_redirect(wp_login_url());
531 public function getUFLocale() {
532 // Bail early if method is called when WordPress isn't bootstrapped.
533 // Additionally, the function checked here is located in pluggable.php
534 // and is required by wp_get_referer() - so this also bails early if it is
535 // called too early in the request lifecycle.
536 // @see https://core.trac.wordpress.org/ticket/25294
537 if (!function_exists('wp_validate_redirect')) {
541 // Default to WordPress User locale.
542 $locale = get_user_locale();
544 // Is this a "back-end" AJAX call?
546 if (wp_doing_ajax() && FALSE !== strpos(wp_get_referer(), admin_url())) {
550 // Ignore when in WordPress admin or it's a "back-end" AJAX call.
551 if (!(is_admin() ||
$is_backend)) {
553 // Reaching here means it is very likely to be a front-end context.
555 // Default to WordPress locale.
556 $locale = get_locale();
558 // Maybe override with the locale that Polylang reports.
559 if (function_exists('pll_current_language')) {
560 $pll_locale = pll_current_language('locale');
561 if (!empty($pll_locale)) {
562 $locale = $pll_locale;
566 // Maybe override with the locale that WPML reports.
567 elseif (defined('ICL_LANGUAGE_CODE')) {
568 $languages = apply_filters('wpml_active_languages', NULL);
569 foreach ($languages as $language) {
570 if ($language['active']) {
571 $locale = $language['default_locale'];
577 // TODO: Set locale for other WordPress plugins.
578 // @see https://wordpress.org/plugins/tags/multilingual/
579 // A hook would be nice here.
583 if (!empty($locale)) {
584 // If for some reason only we get a language code, convert it to a locale.
585 if (2 === strlen($locale)) {
586 $locale = CRM_Core_I18n_PseudoConstant
::longForShort($locale);
598 public function setUFLocale($civicrm_language) {
599 // TODO (probably not possible with WPML?)
604 * Load wordpress bootstrap.
606 * @param array $params
607 * Optional credentials
608 * - name: string, cms username
609 * - pass: string, cms password
610 * @param bool $loadUser
611 * @param bool $throwError
612 * @param mixed $realPath
615 * @throws \CRM_Core_Exception
617 public function loadBootStrap($params = [], $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) {
618 global $wp, $wp_rewrite, $wp_the_query, $wp_query, $wpdb, $current_site, $current_blog, $current_user;
620 $name = $params['name'] ??
NULL;
621 $pass = $params['pass'] ??
NULL;
623 if (!defined('WP_USE_THEMES')) {
624 define('WP_USE_THEMES', FALSE);
627 $cmsRootPath = $this->cmsRootPath();
629 throw new CRM_Core_Exception("Could not find the install directory for WordPress");
631 $path = Civi
::settings()->get('wpLoadPhp');
635 elseif (file_exists($cmsRootPath . DIRECTORY_SEPARATOR
. 'wp-load.php')) {
636 require_once $cmsRootPath . DIRECTORY_SEPARATOR
. 'wp-load.php';
639 throw new CRM_Core_Exception("Could not find the bootstrap file for WordPress");
641 $wpUserTimezone = get_option('timezone_string');
642 if ($wpUserTimezone) {
643 date_default_timezone_set($wpUserTimezone);
644 CRM_Core_Config
::singleton()->userSystem
->setMySQLTimeZone();
646 require_once $cmsRootPath . DIRECTORY_SEPARATOR
. 'wp-includes/pluggable.php';
647 $uid = $params['uid'] ??
NULL;
649 $name = $name ?
$name : trim(CRM_Utils_Array
::value('name', $_REQUEST));
650 $pass = $pass ?
$pass : trim(CRM_Utils_Array
::value('pass', $_REQUEST));
652 $uid = wp_authenticate($name, $pass);
655 echo '<br />Sorry, unrecognized username or password.';
663 if ($uid instanceof WP_User
) {
664 $account = wp_set_current_user($uid->ID
);
667 $account = wp_set_current_user($uid);
669 if ($account && $account->data
->ID
) {
683 public function validInstallDir($dir) {
684 $includePath = "$dir/wp-includes";
685 if (@file_exists
("$includePath/version.php")) {
692 * Determine the location of the CMS root.
694 * @return string|NULL
695 * local file system path to CMS root, or NULL if it cannot be determined
697 public function cmsRootPath() {
699 // Return early if the path is already set.
700 global $civicrm_paths;
701 if (!empty($civicrm_paths['cms.root']['path'])) {
702 return $civicrm_paths['cms.root']['path'];
705 // Return early if constant has been defined.
706 if (defined('CIVICRM_CMSDIR')) {
707 if ($this->validInstallDir(CIVICRM_CMSDIR
)) {
708 return CIVICRM_CMSDIR
;
712 // Return early if path to wp-load.php can be retrieved from settings.
713 $setting = Civi
::settings()->get('wpLoadPhp');
714 if (!empty($setting)) {
715 $path = str_replace('wp-load.php', '', $setting);
716 $cmsRoot = rtrim($path, '/\\');
717 if ($this->validInstallDir($cmsRoot)) {
723 * Keep previous logic as fallback of last resort.
725 * At some point, it would be good to remove this because there are serious
726 * problems in correctly locating WordPress in this manner. In summary, it
727 * is impossible to do so reliably.
729 * @see https://github.com/civicrm/civicrm-wordpress/pull/63#issuecomment-61792328
730 * @see https://github.com/civicrm/civicrm-core/pull/11086#issuecomment-335454992
732 $cmsRoot = $valid = NULL;
734 $pathVars = explode('/', str_replace('\\', '/', $_SERVER['SCRIPT_FILENAME']));
736 // Might be Windows installation.
737 $firstVar = array_shift($pathVars);
739 $cmsRoot = $firstVar;
742 // Start with CMS dir search.
743 foreach ($pathVars as $var) {
745 if ($this->validInstallDir($cmsRoot)) {
746 // Stop as we found bootstrap.
752 return ($valid) ?
$cmsRoot : NULL;
758 public function createUser(&$params, $mail) {
761 'user_pass' => $params['cms_pass'],
762 'user_login' => $params['cms_name'],
763 'user_email' => $params[$mail],
764 'nickname' => $params['cms_name'],
765 'role' => get_option('default_role'),
767 if (isset($params['contactID'])) {
768 $contactType = CRM_Contact_BAO_Contact
::getContactType($params['contactID']);
769 if ($contactType == 'Individual') {
770 $user_data['first_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
771 $params['contactID'], 'first_name'
773 $user_data['last_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
774 $params['contactID'], 'last_name'
779 $uid = wp_insert_user($user_data);
782 $creds['user_login'] = $params['cms_name'];
783 $creds['user_password'] = $params['cms_pass'];
784 $creds['remember'] = TRUE;
785 $user = wp_signon($creds, FALSE);
787 wp_new_user_notification($uid, $user_data['user_pass']);
794 public function updateCMSName($ufID, $ufName) {
796 if (function_exists('wp_update_user')) {
797 $ufID = CRM_Utils_Type
::escape($ufID, 'Integer');
798 $ufName = CRM_Utils_Type
::escape($ufName, 'String');
800 $values = ['ID' => $ufID, 'user_email' => $ufName];
802 wp_update_user($values);
808 * @param array $params
810 * @param string $emailName
812 public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
813 $config = CRM_Core_Config
::singleton();
815 $dao = new CRM_Core_DAO();
816 $name = $dao->escape(CRM_Utils_Array
::value('name', $params));
817 $email = $dao->escape(CRM_Utils_Array
::value('mail', $params));
819 if (!empty($params['name'])) {
820 if (!validate_username($params['name'])) {
821 $errors['cms_name'] = ts("Your username contains invalid characters");
823 elseif (username_exists(sanitize_user($params['name']))) {
824 $errors['cms_name'] = ts('The username %1 is already taken. Please select another username.', [1 => $params['name']]);
828 if (!empty($params['mail'])) {
829 if (!is_email($params['mail'])) {
830 $errors[$emailName] = "Your email is invaid";
832 elseif (email_exists($params['mail'])) {
833 $errors[$emailName] = ts('The email address %1 already has an account associated with it. <a href="%2">Have you forgotten your password?</a>',
834 [1 => $params['mail'], 2 => wp_lostpassword_url()]
843 public function isUserLoggedIn() {
845 if (function_exists('is_user_logged_in')) {
846 $isloggedIn = is_user_logged_in();
855 public function isUserRegistrationPermitted() {
856 if (!get_option('users_can_register')) {
865 public function isPasswordUserGenerated() {
872 public function getLoggedInUserObject() {
873 if (function_exists('is_user_logged_in') &&
876 global $current_user;
878 return $current_user;
884 public function getLoggedInUfID() {
886 $current_user = $this->getLoggedInUserObject();
887 return $current_user->ID ??
NULL;
893 public function getLoggedInUniqueIdentifier() {
894 $user = $this->getLoggedInUserObject();
895 return $this->getUniqueIdentifierFromUserObject($user);
899 * Get User ID from UserFramework system (Joomla)
900 * @param object $user
901 * Object as described by the CMS.
905 public function getUserIDFromUserObject($user) {
906 return !empty($user->ID
) ?
$user->ID
: NULL;
912 public function getUniqueIdentifierFromUserObject($user) {
913 return empty($user->user_email
) ?
NULL : $user->user_email
;
919 public function getLoginURL($destination = '') {
920 $config = CRM_Core_Config
::singleton();
921 $loginURL = wp_login_url();
926 * FIXME: Do something.
928 * @param \CRM_Core_Form $form
930 * @return NULL|string
932 public function getLoginDestination(&$form) {
939 public function getVersion() {
940 if (function_exists('get_bloginfo')) {
941 return get_bloginfo('version', 'display');
951 public function getTimeZoneString() {
952 return get_option('timezone_string');
958 public function getUserRecordUrl($contactID) {
959 $uid = CRM_Core_BAO_UFMatch
::getUFId($contactID);
960 if (CRM_Core_Session
::singleton()
961 ->get('userID') == $contactID || CRM_Core_Permission
::checkAnyPerm(['cms:administer users'])
963 return CRM_Core_Config
::singleton()->userFrameworkBaseURL
. "wp-admin/user-edit.php?user_id=" . $uid;
968 * Append WP js to coreResourcesList.
970 * @param \Civi\Core\Event\GenericHookEvent $e
972 public function appendCoreResources(\Civi\Core\Event\GenericHookEvent
$e) {
973 $e->list[] = 'js/crm.wordpress.js';
979 public function alterAssetUrl(\Civi\Core\Event\GenericHookEvent
$e) {
980 // Set menubar breakpoint to match WP admin theme
981 if ($e->asset
== 'crm-menubar.css') {
982 $e->params
['breakpoint'] = 783;
989 public function synchronizeUsers() {
990 $config = CRM_Core_Config
::singleton();
991 if (PHP_SAPI
!= 'cli') {
995 $mail = 'user_email';
997 $uf = $config->userFramework
;
1000 $contactMatching = 0;
1002 // Previously used the $wpdb global - which means WordPress *must* be bootstrapped.
1003 $wpUsers = get_users(array(
1004 'blog_id' => get_current_blog_id(),
1008 foreach ($wpUsers as $wpUserData) {
1010 if ($match = CRM_Core_BAO_UFMatch
::synchronizeUFMatch($wpUserData,
1024 if (is_object($match)) {
1030 'contactCount' => $contactCount,
1031 'contactMatching' => $contactMatching,
1032 'contactCreated' => $contactCreated,
1037 * Send an HTTP Response base on PSR HTTP RespnseInterface response.
1039 * @param \Psr\Http\Message\ResponseInterface $response
1041 public function sendResponse(\Psr\Http\Message\ResponseInterface
$response) {
1042 // use WordPress function status_header to ensure 404 response is sent
1043 status_header($response->getStatusCode());
1044 foreach ($response->getHeaders() as $name => $values) {
1045 CRM_Utils_System
::setHttpHeader($name, implode(', ', (array) $values));
1047 echo $response->getBody();
1048 CRM_Utils_System
::civiExit();
1052 * Start a new session if there's no existing session ID.
1054 * Checks are needed to prevent sessions being started when not necessary.
1056 public function sessionStart() {
1057 $session_id = session_id();
1059 // Check WordPress pseudo-cron.
1061 if (function_exists('wp_doing_cron') && wp_doing_cron()) {
1067 if (defined('WP_CLI') && WP_CLI
) {
1071 // Check PHP on the command line - e.g. `cv`.
1073 if (PHP_SAPI
!== 'cli') {
1077 // Maybe start session.
1078 if (empty($session_id) && !$wp_cron && !$wp_cli && !$php_cli) {