Check if $post defined before trying to use its field values.
authorTom Anderson <twocs@users.noreply.github.com>
Sun, 16 Aug 2020 02:37:36 +0000 (12:07 +0930)
committerGitHub <noreply@github.com>
Sun, 16 Aug 2020 02:37:36 +0000 (12:07 +0930)
Admin pages (e.g. in a custom plugin) may see $post as undefined. The existing usage to get permalinks for these pages can fill debug logs with PHP Notices.

CRM/Utils/System/WordPress.php

index 1e3aaac78e0986a5c044cfb933e8cae5c45ebb9c..f3691eff7c04c085ac6bb9a40fcb921e2a65af6b 100644 (file)
@@ -319,9 +319,9 @@ class CRM_Utils_System_WordPress extends CRM_Utils_System_Base {
     if ($config->userFrameworkFrontend) {
       global $post;
       if (get_option('permalink_structure') != '') {
-        $script = get_permalink($post->ID);
+        $script = $post ? get_permalink($post->ID) : "";
       }
-      if ($config->wpBasePage == $post->post_name) {
+      if ($post && $config->wpBasePage == $post->post_name) {
         $basepage = TRUE;
       }
       // when shortcode is included in page