Improve Permission denied handling in WordPress
[civicrm-core.git] / CRM / Utils / System / WordPress.php
index 241eeaca6c728a94896bc68b2e7748202b2d0e78..4f2bf719b5ed09ff6e6021f349222d23c6cf9158 100644 (file)
@@ -602,6 +602,8 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
    */
   public function permissionDenied() {
     status_header(403);
+    global $civicrm_wp_title;
+    $civicrm_wp_title = ts('You do not have permission to access this page.');
     throw new CRM_Core_Exception(ts('You do not have permission to access this page.'));
   }
 
@@ -1473,4 +1475,21 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
     return !$this->isUserRegistrationPermitted();
   }
 
+  /**
+   * Should the current execution exit after a fatal error?
+   *
+   * In WordPress, it is not usually possible to trigger theming outside of the WordPress theme process,
+   * meaning that in order to render an error inside the theme we cannot exit on error.
+   *
+   * @return bool
+   */
+  public function exitAfterFatal() {
+    $ret = TRUE;
+    if (!is_admin() && !wp_doing_ajax()) {
+      $ret = FALSE;
+    }
+
+    return apply_filters('civicrm_exit_after_fatal', $ret);
+  }
+
 }