Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-16235

URLs in WordPress based upon unrelated post/page

    Details

    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Needs Funding

      Description

      When a post remains in "the loop" in WordPress, the CRM_Utils_System_WordPress::url() function decides to base all CiviCRM URLs off of it.

      It's clear that in many places, this is appropriate. For example, you may have a page at example.org/shindig for and info page for your fundraising shindig. It's a nice feature that the registration link ends up as
      example.org/shindig?page=CiviCRM&q=civicrm/event/register&id=123&reset=1
      instead of
      example.org/normal-base-page?page=CiviCRM&q=civicrm/event/register&id=123&reset=1

      However, in other situations, this is inappropriate. The most glaring example is if you have a widget of recent posts on the sidebar. If you install CiviCRM in a clean copy of WordPress 4.1.1 with all of its defaults (but with the post title as the permalink), and you visit the public event listing page at
      example.org/?page=CiviCRM&q=civicrm/event/ical&list=1&html=1&reset=1
      you'll notice that the event URLs are all like
      example.org/hello-world/?page=CiviCRM&q=civicrm/event/info&reset=1&id=1
      Similarly, go to an event info page like
      example.org/?page=CiviCRM&q=civicrm/event/info&reset=1&id=1
      and find that the registration button points to
      example.org/hello-world/?page=CiviCRM&q=civicrm/event/info&reset=1&id=1
      I imagine the same thing happens for PCPs.

      As best as I can tell, the issue is that the widget runs through The Loop, and when it's through, the $post object is still set to that post. CRM_Utils_System_WordPress::url() blindly gets its URL and makes that the base page for links:
      https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Utils/System/WordPress.php#L172

      So, this has two consequences for site administrators. First, there's the simple SEO problem when you have multiple links to the same place. A site admin has no way to clean this up reliably, and it'll be a new URL every few days for the same event, since the URL will pick up the permalink of the recent post over on the side.

      The second issue is even bigger. If you have your theme setting layout, colors, and/or headings based upon the page, you won't want to have that change at random for events and personal campaign pages as people link from one CiviCRM page to the next. At least, the branding will be off. At worst, a weird page layout could discourage event registrations and PCP donors.

      I don't have a firm opinion on how to address this. I tried to check whether CiviCRM_For_WordPress::$context == 'shortcode', but that causes the follow-up steps of event registration to break, because their context is "basepage". I think the best plan would be yet another argument passed to CRM_Utils_System::url()--something like "$followOn". If $followOn is true (set that way for multi-step forms that can be shortcodes), the shortcode becomes the basepage. Otherwise, the site-wide basepage is it.

      Any other opinions?

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                andrewhunt Andrew Hunt
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: