Merge pull request #14948 from civicrm/5.16
[civicrm-core.git] / CRM / Utils / System / WordPress.php
index a1a9c64fd3442faa8604b7f8f3f29e993cf585eb..bf35954360efa02b4711d693867b1103ffcc9a9d 100644 (file)
@@ -270,11 +270,7 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
       // pre-existing logic
       if (isset($path)) {
         $queryParts[] = 'page=CiviCRM';
-        // Encode all but the *path* placeholder
-        if ($path !== '*path*') {
-          $path = rawurlencode($path);
-        }
-        $queryParts[] = "q={$path}";
+        $queryParts[] = 'q=' . rawurlencode($path);
       }
       if ($wpPageParam) {
         $queryParts[] = $wpPageParam;
@@ -401,7 +397,8 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    * Determine the native ID of the CMS user.
    *
    * @param string $username
-   * @return int|NULL
+   *
+   * @return int|null
    */
   public function getUfId($username) {
     $userdata = get_user_by('login', $username);
@@ -862,4 +859,19 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
     ];
   }
 
+  /**
+   * Send an HTTP Response base on PSR HTTP RespnseInterface response.
+   *
+   * @param \Psr\Http\Message\ResponseInterface $response
+   */
+  public function sendResponse(\Psr\Http\Message\ResponseInterface $response) {
+    // use WordPress function status_header to ensure 404 response is sent
+    status_header($response->getStatusCode());
+    foreach ($response->getHeaders() as $name => $values) {
+      CRM_Utils_System::setHttpHeader($name, implode(', ', (array) $values));
+    }
+    echo $response->getBody();
+    CRM_Utils_System::civiExit();
+  }
+
 }