CRM-14089 AJAX callbacks fail on WP front-end pages

    Details

      Description

      I have made a fresh install of 4.4.3 and Wordpress 3.7.1 and 4.4.3 and WP 3.8, in neither case do state dropdowns work. In addition "shortcode" selection of Contribution pages do not work within Wordpress either.

      here is a javascript error (see attached).

      WP sites running 3.7.1 + Civi 4.3.8 do not experience this problem. Drupal sites using 4.4.3 do not experience this issue. The WP+Civi demo site is down at the time of this filing.

      I have spent nearly three hours debugging this and have not come to a solution. I believe this to be a serious technical issue I lack the skills to fix myself and request help. But I can offer my debugging efforts (attached) and my opinion that CiviCRM 4.4.3 with Wordpress is having trouble with the JSON "data" variable somehow being corrupted or misinterpreted as HTML when parsed through eval() and the Wordpress engine.

      I offer my testing site as an example (freshly installed with no plugins except Civi)
      http://wp.civiteacher.com/?page=CiviCRM&q=civicrm/contribute/transact&reset=1&id=1

        Attachments

        1. cw_console.png
          28 kB
          Stoob
        2. cw_syntax-unexpected.png
          13 kB
          Stoob
        3. cw-working.png
          10 kB
          Stoob

          Issue Links

            Activity

            [CRM-14089] AJAX callbacks fail on WP front-end pages
            Stoob added a comment -

            Thank you for looking into this so promptly, Coleman. FYI I have tried alternatives to eval() such as jQuery.parseJSON() but could not get a different result. Maybe I misunderstood how these work, or maybe eval() is not the problem.

            Coleman Watts added a comment -

            The problem is that the WP theme is outputting markup for the header on front-end pages before the civi code runs. I think the solution to this and another related problem (CRM-13634) is to hook into the pagerun process much earlier.

            Coleman Watts added a comment -

            After a bit more investigation I can confirm that this is a regression from 4.3. However the solution in 4.3 was very much a hack (checking for $_GET['snippet'] or 'civicrm/ajax' and assuming json).

            Coleman Watts added a comment -

            OK Found the problem. https://github.com/civicrm/civicrm-wordpress/commit/7ea9f900036cafad6dc3d731baac596f49bc48c5
            In this commit the code was simplified but incorrectly - in_array() cannot be used to check for a string within a string.

            Coleman Watts added a comment -

            Fixed the ajax hack to work as originally intended. However it is still a hack and should be cleaned up.

              People

              • Assignee:
                Coleman Watts
                Reporter:
                Stoob

                Dates

                • Created:
                  Updated:
                  Resolved: