CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Pages with CiviCRM shortcodes in Wordpress and missing JS
Pages: [1]

Author Topic: Pages with CiviCRM shortcodes in Wordpress and missing JS  (Read 776 times)

ChrisChinchilla

  • I post occasionally
  • **
  • Posts: 104
  • Karma: 3
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 6 & 7
Pages with CiviCRM shortcodes in Wordpress and missing JS
November 08, 2014, 07:04:58 am
Hi everyone,

I've seen a few discussions around this in the forums but no real resolution or anything that quite matches my issue. I'm also not very knowledgeable with Wordpress, but have one client who uses it with CiviCRM.

To summarise:

There are pages with Wordpress shortcodes and on these pages no CiviCRM JavaScript gets loaded (I can also see 'CRM' / 'cj' not defined JS messages in console), so lots of functionality ends up being missing. With a WP default theme they do work, this is a virtue premium theme. I have seen other posts here regarding ensuring that the theme is using wp_head functions, it is. I also had some word back from the WP theme developer who says that the method CiviCRM is using to inject the CiviCRM header into shortcode pages (via an add_filter) is not the correct way to do this.

Alongside this I also have lots of JavaScript functionality not quite working (inconsistently) on CiviCRM admin pages, but with no error messages.

Can anyone shed some light on this? I have been trawling through the CiviCRM / Wordpress integration code but can't really figure out what and where the problem is. The only step I got close to was that in the function that CiviCRM loads in it's add_action function (wp_head).

      add_action( 'wp_head', array( $this, 'wp_head' ) );

In a page that has a shortcode, the crucial variable - global $civicrm_root is always empty and thus the rest of the function is not rendered.
Melbourne CiviCRM meetup group - http://www.meetup.com/MelbourneCiviCRM/

EranSch

  • I post occasionally
  • **
  • Posts: 40
  • Karma: 3
    • Personal Blog
  • CiviCRM version: 4.5.X
  • CMS version: 4.X
  • MySQL version: 5.5.X
  • PHP version: 5.5.X
Re: Pages with CiviCRM shortcodes in Wordpress and missing JS
November 12, 2014, 12:57:08 pm
Have you updated to 4.5.3 yet? I think there has been some progress made on this issue but I'm not entirely sure.

I'll be updating as well here soon so I'm excited to see for myself!

ChrisChinchilla

  • I post occasionally
  • **
  • Posts: 104
  • Karma: 3
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 6 & 7
Re: Pages with CiviCRM shortcodes in Wordpress and missing JS
November 12, 2014, 11:27:01 pm
I'll give it a go! Will report back…
Melbourne CiviCRM meetup group - http://www.meetup.com/MelbourneCiviCRM/

ChrisChinchilla

  • I post occasionally
  • **
  • Posts: 104
  • Karma: 3
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 6 & 7
Re: Pages with CiviCRM shortcodes in Wordpress and missing JS
November 13, 2014, 07:23:26 am
Nope, no difference :/

I suspect it's the theme, but the theme developer wont help and I'm not very knowledgeable on Wordpress.
Melbourne CiviCRM meetup group - http://www.meetup.com/MelbourneCiviCRM/

ChrisChinchilla

  • I post occasionally
  • **
  • Posts: 104
  • Karma: 3
  • CiviCRM version: 4.1.2
  • CMS version: Drupal 6 & 7
Re: Pages with CiviCRM shortcodes in Wordpress and missing JS
December 10, 2014, 06:07:01 am
OK, we have a fix for this, but apologie, right now, I don't have time to post a patch, heopfulyl someone else can…

In civicrm.php at the top level of the civicrm plugin folder

Line 261:

      add_filter( 'get_header', array( $this, 'add_shortcode_includes' ) );

Should be:

      add_action( 'the_post', array( $this, 'add_shortcode_includes' ) );

Then the updated function is:

  public function add_shortcode_includes($post) {

    // global $post;

    // don't parse content when there's no post object, eg on 404 pages
    if ( ! is_object( $post ) ) return;

    // check for existence of shortcode in content
    if ( preg_match( '/\[civicrm/', $post->post_content ) ) {

      if (!$this->initialize()) {
        return;
      }

      $config = CRM_Core_Config::singleton();
      $config->userFrameworkFrontend = TRUE;

      // add CiviCRM core resources
      CRM_Core_Resources::singleton()->addCoreResources();

    }

  }
Melbourne CiviCRM meetup group - http://www.meetup.com/MelbourneCiviCRM/

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM (Moderator: Dave Greenberg) »
  • Pages with CiviCRM shortcodes in Wordpress and missing JS

This forum was archived on 2017-11-26.