Multi-page Toolkit Plugin ‘Insert Page’ Fix

One of the sites I run, Techware Labs, uses WordPress for its CMS. (As an aside, we previously used our own home-grown CMS, which had a variety of benefits, but didn’t provide quite as much flexibility as we wanted. Rather than putting significant effort into rewriting or massively upgrading it, we decided to leave that heavy lifting to the pros.) We began using WP around May, 2009 (v2.7.1), since which point 17 major releases have occurred (and significantly more minor releases). We selected the Multi-Page Toolkit plugin to paginate articles (since WordPress just sticks the entire post on a single page by default), which seemed reasonable at the time—it was relatively popular, and had been updated a few months prior. Unfortunately, that update a few months prior [to early 2009] is the last update the plugin has received at the time of this writing.

A lot can happen in seven-plus years, especially in a popular software project like WordPress, but miraculously this plugin mostly kept working through it all. Mostly, however, isn’t quite the same as entirely, and some people get cranky when one thing goes wrong. (Take the Hindenburg, for example; why doesn’t anyone talk about its 62 successful flights?)

OK, maybe the Hindenburg isn’t quite the best analogy, but I do want to point out that the core functionality of the plugin has continued to work for the past ~seven years, which I think should reflect highly on the developers of WordPress, TinyMCE, and the Multi-page Toolkit plugin.

Get on with it…

The issue reported to me was that the button to Insert Title in the WP visual editor wasn’t working; screenshots were helpfully provided to demonstrate the workflow:

Insert Title Button Broken UI

After logging in and seeing the problem for myself, I immediately fired up the Chromium developer tools JavaScript console, refreshed the page, and was pleasantly greeted with two errors:

Uncaught TypeError: Cannot read property ‘mce_inline’ of undefined tinyMCEPopup.getWindowArg @ tiny_mce_popup.js:47

Uncaught TypeError: Cannot read property ‘plugin_url’ of undefined tinyMCEPopup.getWindowArg @ tiny_mce_popup.js:47

I immediately suspected the TinyMCE version had changed in some incompatible way since the time of this plugin’s creation, which I confirmed after a little poking around. The jump from TinyMCE 3 to 4 was made in WordPress 3.9, released in the spring of 2014. While the TinyMCE 4 API doesn’t seem terribly different, I’m lazy, so was pleased to discover that TinyMCE 4 has a 3.x compatibility plugin, so I only had to fix enough to work with that! (I did briefly start trying to actually migrate, but ain’t nobody got time for that!)

In the end, just the two scripts in wp-content/plugins/multi-page-toolkit/buttons/js needed to be patched as follows:

--- dialog-orig.js 2009-04-08 21:53:39.000000000 -0500
+++ dialog.js 2016-01-24 18:30:00.320786435 -0600
@@ -23,4 +23,4 @@
}
};

-tinyMCEPopup.onInit.add(PageTitleDialog.init, PageTitleDialog);
+tinyMCEPopup.editor.onInit.add(PageTitleDialog.init, PageTitleDialog);

and

--- tiny_mce_popup-orig.js 2016-01-24 17:00:00.308056097 -0600
+++ tiny_mce_popup.js 2016-01-24 18:53:20.791169867 -0600
@@ -20,7 +20,7 @@
tinymce = w.tinymce;
tinyMCE = w.tinyMCE;
t.editor = tinymce.EditorManager.activeEditor;
- t.params = t.editor.windowManager.params;
+ t.params = t.editor.windowManager.getParams();

// Setup local DOM
t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document);
@@ -28,7 +28,7 @@

// Setup on init listeners
t.listeners = [];
- t.onInit = {
+ t.editor.onInit = {
add : function(f, s) {
t.listeners.push({func : f, scope : s});
}

I’ve also posted the fix on the WordPress Support Forums for the plugin. Please let me know if this helps you, or if you have any improvements!

Tags: , ,

3 Responses to “Multi-page Toolkit Plugin ‘Insert Page’ Fix”

  1. Glent Says:

    Thanks for the fix! testing it now :) I had given up hope

  2. Ramzy Says:

    I tried the patch, but nothing happen, can you please tell where to paste the patch in js line ?

  3. p14nd4 Says:

    @Ramzy
    Inside ‘wp-content/plugins/multi-page-toolkit’ there should be the path/file: buttons/js/dialog.js

    If you have shell access to the machine, you can run something like cd buttons/js && patch -b < /path/to/my/patch/above.patch

    Otherwise, download and patch the files, or in some other way edit them so that you replace the lines prefixed by ‘-‘ with the adjacent line prefixed by ‘-‘. (The ‘-‘ and ‘+’ should not appear in the original or replaced line.) Once complete, replace the files on your server with the modified versions.

Leave a Reply