Jun 262014

(Warning: this is technical, don’t read any further unless you are really interested!)

The Problem

Right from the start of my project to integrate TNG and WordPress I have had problems with certain parts of TNG not working. They worked OK when viewing TNG by itself, but not when viewed via WordPress. The two main functions that failed were the Find button in the Relationship calculator (it did nothing), and the Standard Ancestor chart (for which I got the “Loading” message and it just hung). There seemed to be some inconsistency in what happened, particularly in different browsers.

Throughout this whole process I have been searching for answers and asking questions in many Forums (including WordPress and TNG), and I am grateful to the many people who have provided me with information.
Back to the top of page

Initial Approaches

To begin with I followed the advice I was given which was to find plugins that worked and avoid any that caused problems. This worked OK for a while but I have grown attached to many of the plugins I have used, and when one of them was upgraded and started to cause a problem I decided to investigate as deeply as my technical skills and Google would allow me to. I found the Google Chrome Developer Tools and Javascript Console invaluable in the task.

These led me to the fact that there were two ‘Uncaught TypeError: undefined is not a function’ javascript errors in every TNG page. The source where these occurred looked as though they were from two plugins, and they involved the javascript library called jQuery. Temporarily deactivating these two plugins proved that they were the problem.

The WordPress jQuery library is loaded by WordPress for the plugins that use it, and a Google jQuery library is loaded by TNG in genlib.php. Presumably because these are different libraries both defining the jQuery object javascript was confused. Indeed if I removed the jQuery library load in genlib.php I did not get the two errors (but I did get errors elsewhere so this was just for diagnosis).

I tried using Use Google Libraries to force the WordPress plugins to use the same jQuery library as TNG, but this just meant the one library was loaded twice.

I then investigated finding a way to tell genlib.php to only load the jQuery library if it were not already loaded, or using .NoConflict to ensure that each jQuery library set a different variable (e.g.). I came to realise that this was beyond my level of ability in php/javascript, and there was a simpler way to go. Might it be better long term if both WordPress and TNG loaded their own version of jQuery and did the .NoConflict thing, so they each had their own jQuery variables (e.g. jQuery_wp and jQuery_tng)?
Back to the top of page

The Solution

The end was in sight when I realised that one could disable plugins on certain pages using Plugin Organizer by Jeff Sterup. However when I tried to set the settings I was not able to get it working correctly in my context. Using some of the code it contains, and two other blog posts (How to disable a WP plugin on a certain page by Kamil Grzegorczyk, Disable specified WordPress plugins when doing local development by Mark Jaquith), I was able to develop a little “Must Use” plugin that did the trick. As long as I keep this up-to-date I hope that I will now be able to use any WordPress plugin with TNG.

The outline code for the TNG Plugin Remover plugin can be found here – remember that this code has to be tailored and saved in the wp-content\mu-plugins\ folder. If you would like to comment, or improve the solution, you can do so here, or below.
Back to the top of page

Update after more problems

My conclusion for this site is that the above “don’t load plugins when in TNG” strategy does solve the “Find not working in the Relationship screen” issue. However the “Loading of Standard and Compact Ancestors charts hangs” issue is also to do with TNG being set to Require Logins, and the user not actually being logged in to TNG (and not being asked for a login). My current solution is to set “Require login” to No, and although not ideal it seems to work. To avoid having to do this I suspect there would need to be a change in TNG in the php files affected.

There were conversations on the TNG forum about the above here and here.
Back to the top of page

 Leave a Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">