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.files', function () {
58 $upload_dir = wp_get_upload_dir();
60 'path' => $upload_dir['basedir'] . DIRECTORY_SEPARATOR
. 'civicrm' . DIRECTORY_SEPARATOR
,
61 'url' => $upload_dir['baseurl'] . '/civicrm/',
64 Civi
::paths()->register('civicrm.root', function () {
66 'path' => CIVICRM_PLUGIN_DIR
. 'civicrm' . DIRECTORY_SEPARATOR
,
67 'url' => CIVICRM_PLUGIN_URL
. 'civicrm/',
70 Civi
::paths()->register('wp.frontend.base', function () {
72 'url' => home_url('/'),
75 Civi
::paths()->register('wp.frontend', function () {
76 $config = CRM_Core_Config
::singleton();
77 $basepage = get_page_by_path($config->wpBasePage
);
79 'url' => get_permalink($basepage->ID
),
82 Civi
::paths()->register('wp.backend.base', function () {
87 Civi
::paths()->register('wp.backend', function() {
89 'url' => admin_url('admin.php'),
94 // Legacy support - only relevant for older extern routes.
96 ->register('wp.frontend.base', function () {
97 return ['url' => rtrim(CIVICRM_UF_BASEURL
, '/') . '/'];
99 ->register('wp.frontend', function () {
100 $config = \CRM_Core_Config
::singleton();
101 $suffix = defined('CIVICRM_UF_WP_BASEPAGE') ? CIVICRM_UF_WP_BASEPAGE
: $config->wpBasePage
;
103 'url' => Civi
::paths()->getVariable('wp.frontend.base', 'url') . $suffix,
106 ->register('wp.backend.base', function () {
107 return ['url' => rtrim(CIVICRM_UF_BASEURL
, '/') . '/wp-admin/'];
109 ->register('wp.backend', function () {
111 'url' => Civi
::paths()->getVariable('wp.backend.base', 'url') . 'admin.php',
120 public function setTitle($title, $pageTitle = NULL) {
125 // FIXME: Why is this global?
126 global $civicrm_wp_title;
127 $civicrm_wp_title = $title;
129 // yes, set page title, depending on context
130 $context = civi_wp()->civicrm_context_get();
134 $template = CRM_Core_Smarty
::singleton();
135 $template->assign('pageTitle', $pageTitle);
140 * Moved from CRM_Utils_System_Base
142 public function getDefaultFileStorage() {
143 $config = CRM_Core_Config
::singleton();
144 $cmsUrl = CRM_Utils_System
::languageNegotiationURL($config->userFrameworkBaseURL
, FALSE, TRUE);
145 $cmsPath = $this->cmsRootPath();
146 $filesPath = CRM_Utils_File
::baseFilePath();
147 $filesRelPath = CRM_Utils_File
::relativize($filesPath, $cmsPath);
148 $filesURL = rtrim($cmsUrl, '/') . '/' . ltrim($filesRelPath, ' /');
150 'url' => CRM_Utils_File
::addTrailingSlash($filesURL, '/'),
151 'path' => CRM_Utils_File
::addTrailingSlash($filesPath),
156 * Determine the location of the CiviCRM source tree.
159 * - url: string. ex: "http://example.com/sites/all/modules/civicrm"
160 * - path: string. ex: "/var/www/sites/all/modules/civicrm"
162 public function getCiviSourceStorage() {
163 global $civicrm_root;
165 // Don't use $config->userFrameworkBaseURL; it has garbage on it.
166 // More generally, we shouldn't be using $config here.
167 if (!defined('CIVICRM_UF_BASEURL')) {
168 throw new RuntimeException('Undefined constant: CIVICRM_UF_BASEURL');
171 $cmsPath = $this->cmsRootPath();
173 // $config = CRM_Core_Config::singleton();
174 // overkill? // $cmsUrl = CRM_Utils_System::languageNegotiationURL($config->userFrameworkBaseURL, FALSE, TRUE);
175 $cmsUrl = CIVICRM_UF_BASEURL
;
176 if (CRM_Utils_System
::isSSL()) {
177 $cmsUrl = str_replace('http://', 'https://', $cmsUrl);
179 $civiRelPath = CRM_Utils_File
::relativize(realpath($civicrm_root), realpath($cmsPath));
180 $civiUrl = rtrim($cmsUrl, '/') . '/' . ltrim($civiRelPath, ' /');
182 'url' => CRM_Utils_File
::addTrailingSlash($civiUrl, '/'),
183 'path' => CRM_Utils_File
::addTrailingSlash($civicrm_root),
190 public function appendBreadCrumb($breadCrumbs) {
191 $breadCrumb = wp_get_breadcrumb();
193 if (is_array($breadCrumbs)) {
194 foreach ($breadCrumbs as $crumbs) {
195 if (stripos($crumbs['url'], 'id%%')) {
196 $args = ['cid', 'mid'];
197 foreach ($args as $a) {
198 $val = CRM_Utils_Request
::retrieve($a, 'Positive', CRM_Core_DAO
::$_nullObject,
202 $crumbs['url'] = str_ireplace("%%{$a}%%", $val, $crumbs['url']);
206 $breadCrumb[] = "<a href=\"{$crumbs['url']}\">{$crumbs['title']}</a>";
210 $template = CRM_Core_Smarty
::singleton();
211 $template->assign_by_ref('breadcrumb', $breadCrumb);
212 wp_set_breadcrumb($breadCrumb);
218 public function resetBreadCrumb() {
220 wp_set_breadcrumb($bc);
226 public function addHTMLHead($head) {
227 static $registered = FALSE;
230 add_action('wp_head', [__CLASS__
, '_showHTMLHead']);
232 add_action('admin_head', [__CLASS__
, '_showHTMLHead']);
234 CRM_Core_Region
::instance('wp_head')->add([
240 * WP action callback.
242 public static function _showHTMLHead() {
243 $region = CRM_Core_Region
::instance('wp_head', FALSE);
245 echo $region->render('');
252 public function mapConfigToSSL() {
254 $base_url = str_replace('http://', 'https://', $base_url);
266 $forceBackend = FALSE,
269 $config = CRM_Core_Config
::singleton();
273 $fragment = isset($fragment) ?
('#' . $fragment) : '';
275 $path = CRM_Utils_String
::stripPathChars($path);
278 //this means wp function we are trying to use is not available,
280 // FIXME: Why bootstrap in url()? Generally want to define 1-2 strategic places to put bootstrap
281 if (!function_exists('get_option')) {
282 $this->loadBootStrap();
285 if ($config->userFrameworkFrontend
) {
287 if (get_option('permalink_structure') != '') {
288 $script = get_permalink($post->ID
);
290 if ($config->wpBasePage
== $post->post_name
) {
293 // when shortcode is included in page
294 // also make sure we have valid query object
295 // FIXME: $wpPageParam has no effect and is only set on the *basepage*
297 if (get_option('permalink_structure') == '' && method_exists($wp_query, 'get')) {
298 if (get_query_var('page_id')) {
299 $wpPageParam = "page_id=" . get_query_var('page_id');
301 elseif (get_query_var('p')) {
302 // when shortcode is inserted in post
303 $wpPageParam = "p=" . get_query_var('p');
308 $base = $this->getBaseUrl($absolute, $frontend, $forceBackend);
310 if (!isset($path) && !isset($query)) {
311 // FIXME: This short-circuited codepath is the same as the general one below, except
312 // in that it ignores "permlink_structure" / $wpPageParam / $script . I don't know
313 // why it's different (and I can only find two obvious use-cases for this codepath,
314 // of which at least one looks gratuitous). A more ambitious person would simply remove
316 return $base . $fragment;
319 if (!$forceBackend && get_option('permalink_structure') != '' && ($wpPageParam ||
$script != '')) {
326 // not using clean URLs
328 // requesting an admin URL
329 ||
((is_admin() && !$frontend) ||
$forceBackend)
331 ||
(!$basepage && $script != '')
334 // pre-existing logic
336 // Admin URLs still need "page=CiviCRM", front-end URLs do not.
337 if ((is_admin() && !$frontend) ||
$forceBackend) {
338 $queryParts[] = 'page=CiviCRM';
341 $queryParts[] = 'civiwp=CiviCRM';
343 $queryParts[] = 'q=' . rawurlencode($path);
346 $queryParts[] = $wpPageParam;
348 if (!empty($query)) {
349 $queryParts[] = $query;
352 $final = $base . '?' . implode($separator, $queryParts) . $fragment;
359 $base = trailingslashit($base) . str_replace('civicrm/', '', $path) . '/';
362 $query = ltrim($query, '=?&');
363 $queryParts[] = $query;
366 if (!empty($queryParts)) {
367 $final = $base . '?' . implode($separator, $queryParts) . $fragment;
370 $final = $base . $fragment;
380 * CRM-16421 CRM-17633 WIP Changes to support WP in it's own directory
381 * https://wiki.civicrm.org/confluence/display/CRM/WordPress+installed+in+its+own+directory+issues
382 * For now leave hard coded wp-admin references.
383 * TODO: remove wp-admin references and replace with admin_url() in the future. Look at best way to get path to admin_url
387 * @param $forceBackend
389 * @return mixed|null|string
391 private function getBaseUrl($absolute, $frontend, $forceBackend) {
392 $config = CRM_Core_Config
::singleton();
393 if ((is_admin() && !$frontend) ||
$forceBackend) {
394 return Civi
::paths()->getUrl('[wp.backend]/.', $absolute ?
'absolute' : 'relative');
397 return Civi
::paths()->getUrl('[wp.frontend]/.', $absolute ?
'absolute' : 'relative');
404 public function authenticate($name, $password, $loadCMSBootstrap = FALSE, $realPath = NULL) {
405 $config = CRM_Core_Config
::singleton();
407 if ($loadCMSBootstrap) {
408 $config->userSystem
->loadBootStrap([
414 $user = wp_authenticate($name, $password);
415 if (is_a($user, 'WP_Error')) {
419 // TODO: need to change this to make sure we matched only one row
421 CRM_Core_BAO_UFMatch
::synchronizeUFMatch($user->data
, $user->data
->ID
, $user->data
->user_email
, 'WordPress');
422 $contactID = CRM_Core_BAO_UFMatch
::getContactId($user->data
->ID
);
426 return [$contactID, $user->data
->ID
, mt_rand()];
430 * FIXME: Do something
432 * @param string $message
434 public function setMessage($message) {
438 * @param \string $user
442 public function loadUser($user) {
443 $userdata = get_user_by('login', $user);
444 if (!$userdata->data
->ID
) {
448 $uid = $userdata->data
->ID
;
449 wp_set_current_user($uid);
450 $contactID = CRM_Core_BAO_UFMatch
::getContactId($uid);
452 // lets store contact id and user id in session
453 $session = CRM_Core_Session
::singleton();
454 $session->set('ufID', $uid);
455 $session->set('userID', $contactID);
460 * FIXME: Use CMS-native approach
461 * @throws \CRM_Core_Exception
463 public function permissionDenied() {
464 throw new CRM_Core_Exception(ts('You do not have permission to access this page.'));
468 * Determine the native ID of the CMS user.
470 * @param string $username
474 public function getUfId($username) {
475 $userdata = get_user_by('login', $username);
476 if (!$userdata->data
->ID
) {
479 return $userdata->data
->ID
;
485 public function logout() {
491 wp_redirect(wp_login_url());
497 public function getUFLocale() {
498 // Bail early if method is called when WordPress isn't bootstrapped.
499 // Additionally, the function checked here is located in pluggable.php
500 // and is required by wp_get_referer() - so this also bails early if it is
501 // called too early in the request lifecycle.
502 // @see https://core.trac.wordpress.org/ticket/25294
503 if (!function_exists('wp_validate_redirect')) {
507 // Default to WordPress User locale.
508 $locale = get_user_locale();
510 // Is this a "back-end" AJAX call?
512 if (wp_doing_ajax() && FALSE !== strpos(wp_get_referer(), admin_url())) {
516 // Ignore when in WordPress admin or it's a "back-end" AJAX call.
517 if (!(is_admin() ||
$is_backend)) {
519 // Reaching here means it is very likely to be a front-end context.
521 // Default to WordPress locale.
522 $locale = get_locale();
524 // Maybe override with the locale that Polylang reports.
525 if (function_exists('pll_current_language')) {
526 $pll_locale = pll_current_language('locale');
527 if (!empty($pll_locale)) {
528 $locale = $pll_locale;
532 // Maybe override with the locale that WPML reports.
533 elseif (defined('ICL_LANGUAGE_CODE')) {
534 $languages = apply_filters('wpml_active_languages', NULL);
535 foreach ($languages as $language) {
536 if ($language['active']) {
537 $locale = $language['default_locale'];
543 // TODO: Set locale for other WordPress plugins.
544 // @see https://wordpress.org/plugins/tags/multilingual/
545 // A hook would be nice here.
549 if (!empty($locale)) {
550 // If for some reason only we get a language code, convert it to a locale.
551 if (2 === strlen($locale)) {
552 $locale = CRM_Core_I18n_PseudoConstant
::longForShort($locale);
564 public function setUFLocale($civicrm_language) {
565 // TODO (probably not possible with WPML?)
570 * Load wordpress bootstrap.
572 * @param array $params
573 * Optional credentials
574 * - name: string, cms username
575 * - pass: string, cms password
576 * @param bool $loadUser
577 * @param bool $throwError
578 * @param mixed $realPath
581 * @throws \CRM_Core_Exception
583 public function loadBootStrap($params = [], $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) {
584 global $wp, $wp_rewrite, $wp_the_query, $wp_query, $wpdb, $current_site, $current_blog, $current_user;
586 $name = $params['name'] ??
NULL;
587 $pass = $params['pass'] ??
NULL;
589 if (!defined('WP_USE_THEMES')) {
590 define('WP_USE_THEMES', FALSE);
593 $cmsRootPath = $this->cmsRootPath();
595 throw new CRM_Core_Exception("Could not find the install directory for WordPress");
597 $path = Civi
::settings()->get('wpLoadPhp');
601 elseif (file_exists($cmsRootPath . DIRECTORY_SEPARATOR
. 'wp-load.php')) {
602 require_once $cmsRootPath . DIRECTORY_SEPARATOR
. 'wp-load.php';
605 throw new CRM_Core_Exception("Could not find the bootstrap file for WordPress");
607 $wpUserTimezone = get_option('timezone_string');
608 if ($wpUserTimezone) {
609 date_default_timezone_set($wpUserTimezone);
610 CRM_Core_Config
::singleton()->userSystem
->setMySQLTimeZone();
612 require_once $cmsRootPath . DIRECTORY_SEPARATOR
. 'wp-includes/pluggable.php';
613 $uid = $params['uid'] ??
NULL;
615 $name = $name ?
$name : trim(CRM_Utils_Array
::value('name', $_REQUEST));
616 $pass = $pass ?
$pass : trim(CRM_Utils_Array
::value('pass', $_REQUEST));
618 $uid = wp_authenticate($name, $pass);
621 echo '<br />Sorry, unrecognized username or password.';
629 if ($uid instanceof WP_User
) {
630 $account = wp_set_current_user($uid->ID
);
633 $account = wp_set_current_user($uid);
635 if ($account && $account->data
->ID
) {
649 public function validInstallDir($dir) {
650 $includePath = "$dir/wp-includes";
651 if (@file_exists
("$includePath/version.php")) {
658 * Determine the location of the CMS root.
660 * @return string|NULL
661 * local file system path to CMS root, or NULL if it cannot be determined
663 public function cmsRootPath() {
665 // Return early if the path is already set.
666 global $civicrm_paths;
667 if (!empty($civicrm_paths['cms.root']['path'])) {
668 return $civicrm_paths['cms.root']['path'];
671 // Return early if constant has been defined.
672 if (defined('CIVICRM_CMSDIR')) {
673 if ($this->validInstallDir(CIVICRM_CMSDIR
)) {
674 return CIVICRM_CMSDIR
;
678 // Return early if path to wp-load.php can be retrieved from settings.
679 $setting = Civi
::settings()->get('wpLoadPhp');
680 if (!empty($setting)) {
681 $path = str_replace('wp-load.php', '', $setting);
682 $cmsRoot = rtrim($path, '/\\');
683 if ($this->validInstallDir($cmsRoot)) {
689 * Keep previous logic as fallback of last resort.
691 * At some point, it would be good to remove this because there are serious
692 * problems in correctly locating WordPress in this manner. In summary, it
693 * is impossible to do so reliably.
695 * @see https://github.com/civicrm/civicrm-wordpress/pull/63#issuecomment-61792328
696 * @see https://github.com/civicrm/civicrm-core/pull/11086#issuecomment-335454992
698 $cmsRoot = $valid = NULL;
700 $pathVars = explode('/', str_replace('\\', '/', $_SERVER['SCRIPT_FILENAME']));
702 // Might be Windows installation.
703 $firstVar = array_shift($pathVars);
705 $cmsRoot = $firstVar;
708 // Start with CMS dir search.
709 foreach ($pathVars as $var) {
711 if ($this->validInstallDir($cmsRoot)) {
712 // Stop as we found bootstrap.
718 return ($valid) ?
$cmsRoot : NULL;
724 public function createUser(&$params, $mail) {
727 'user_pass' => $params['cms_pass'],
728 'user_login' => $params['cms_name'],
729 'user_email' => $params[$mail],
730 'nickname' => $params['cms_name'],
731 'role' => get_option('default_role'),
733 if (isset($params['contactID'])) {
734 $contactType = CRM_Contact_BAO_Contact
::getContactType($params['contactID']);
735 if ($contactType == 'Individual') {
736 $user_data['first_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
737 $params['contactID'], 'first_name'
739 $user_data['last_name'] = CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact',
740 $params['contactID'], 'last_name'
745 $uid = wp_insert_user($user_data);
748 $creds['user_login'] = $params['cms_name'];
749 $creds['user_password'] = $params['cms_pass'];
750 $creds['remember'] = TRUE;
751 $user = wp_signon($creds, FALSE);
753 wp_new_user_notification($uid, $user_data['user_pass']);
760 public function updateCMSName($ufID, $ufName) {
762 if (function_exists('wp_update_user')) {
763 $ufID = CRM_Utils_Type
::escape($ufID, 'Integer');
764 $ufName = CRM_Utils_Type
::escape($ufName, 'String');
766 $values = ['ID' => $ufID, 'user_email' => $ufName];
768 wp_update_user($values);
774 * @param array $params
776 * @param string $emailName
778 public function checkUserNameEmailExists(&$params, &$errors, $emailName = 'email') {
779 $config = CRM_Core_Config
::singleton();
781 $dao = new CRM_Core_DAO();
782 $name = $dao->escape(CRM_Utils_Array
::value('name', $params));
783 $email = $dao->escape(CRM_Utils_Array
::value('mail', $params));
785 if (!empty($params['name'])) {
786 if (!validate_username($params['name'])) {
787 $errors['cms_name'] = ts("Your username contains invalid characters");
789 elseif (username_exists(sanitize_user($params['name']))) {
790 $errors['cms_name'] = ts('The username %1 is already taken. Please select another username.', [1 => $params['name']]);
794 if (!empty($params['mail'])) {
795 if (!is_email($params['mail'])) {
796 $errors[$emailName] = "Your email is invaid";
798 elseif (email_exists($params['mail'])) {
799 $errors[$emailName] = ts('The email address %1 already has an account associated with it. <a href="%2">Have you forgotten your password?</a>',
800 [1 => $params['mail'], 2 => wp_lostpassword_url()]
809 public function isUserLoggedIn() {
811 if (function_exists('is_user_logged_in')) {
812 $isloggedIn = is_user_logged_in();
821 public function isUserRegistrationPermitted() {
822 if (!get_option('users_can_register')) {
831 public function isPasswordUserGenerated() {
838 public function getLoggedInUserObject() {
839 if (function_exists('is_user_logged_in') &&
842 global $current_user;
844 return $current_user;
850 public function getLoggedInUfID() {
852 $current_user = $this->getLoggedInUserObject();
853 return $current_user->ID ??
NULL;
859 public function getLoggedInUniqueIdentifier() {
860 $user = $this->getLoggedInUserObject();
861 return $this->getUniqueIdentifierFromUserObject($user);
865 * Get User ID from UserFramework system (Joomla)
866 * @param object $user
867 * Object as described by the CMS.
871 public function getUserIDFromUserObject($user) {
872 return !empty($user->ID
) ?
$user->ID
: NULL;
878 public function getUniqueIdentifierFromUserObject($user) {
879 return empty($user->user_email
) ?
NULL : $user->user_email
;
885 public function getLoginURL($destination = '') {
886 $config = CRM_Core_Config
::singleton();
887 $loginURL = wp_login_url();
892 * FIXME: Do something.
894 * @param \CRM_Core_Form $form
896 * @return NULL|string
898 public function getLoginDestination(&$form) {
905 public function getVersion() {
906 if (function_exists('get_bloginfo')) {
907 return get_bloginfo('version', 'display');
917 public function getTimeZoneString() {
918 return get_option('timezone_string');
924 public function getUserRecordUrl($contactID) {
925 $uid = CRM_Core_BAO_UFMatch
::getUFId($contactID);
926 if (CRM_Core_Session
::singleton()
927 ->get('userID') == $contactID || CRM_Core_Permission
::checkAnyPerm(['cms:administer users'])
929 return CRM_Core_Config
::singleton()->userFrameworkBaseURL
. "wp-admin/user-edit.php?user_id=" . $uid;
934 * Append WP js to coreResourcesList.
936 * @param \Civi\Core\Event\GenericHookEvent $e
938 public function appendCoreResources(\Civi\Core\Event\GenericHookEvent
$e) {
939 $e->list[] = 'js/crm.wordpress.js';
945 public function alterAssetUrl(\Civi\Core\Event\GenericHookEvent
$e) {
946 // Set menubar breakpoint to match WP admin theme
947 if ($e->asset
== 'crm-menubar.css') {
948 $e->params
['breakpoint'] = 783;
955 public function synchronizeUsers() {
956 $config = CRM_Core_Config
::singleton();
957 if (PHP_SAPI
!= 'cli') {
961 $mail = 'user_email';
963 $uf = $config->userFramework
;
966 $contactMatching = 0;
968 // Previously used the $wpdb global - which means WordPress *must* be bootstrapped.
969 $wpUsers = get_users(array(
970 'blog_id' => get_current_blog_id(),
974 foreach ($wpUsers as $wpUserData) {
976 if ($match = CRM_Core_BAO_UFMatch
::synchronizeUFMatch($wpUserData,
990 if (is_object($match)) {
996 'contactCount' => $contactCount,
997 'contactMatching' => $contactMatching,
998 'contactCreated' => $contactCreated,
1003 * Send an HTTP Response base on PSR HTTP RespnseInterface response.
1005 * @param \Psr\Http\Message\ResponseInterface $response
1007 public function sendResponse(\Psr\Http\Message\ResponseInterface
$response) {
1008 // use WordPress function status_header to ensure 404 response is sent
1009 status_header($response->getStatusCode());
1010 foreach ($response->getHeaders() as $name => $values) {
1011 CRM_Utils_System
::setHttpHeader($name, implode(', ', (array) $values));
1013 echo $response->getBody();
1014 CRM_Utils_System
::civiExit();
1018 * Start a new session if there's no existing session ID.
1020 * Checks are needed to prevent sessions being started when not necessary.
1022 public function sessionStart() {
1023 $session_id = session_id();
1025 // Check WordPress pseudo-cron.
1027 if (function_exists('wp_doing_cron') && wp_doing_cron()) {
1033 if (defined('WP_CLI') && WP_CLI
) {
1037 // Check PHP on the command line - e.g. `cv`.
1039 if (PHP_SAPI
!== 'cli') {
1043 // Maybe start session.
1044 if (empty($session_id) && !$wp_cron && !$wp_cli && !$php_cli) {