{"id":259,"date":"2016-01-24T22:04:47","date_gmt":"2016-01-25T04:04:47","guid":{"rendered":"http:\/\/www.p14nd4.com\/blog\/?p=259"},"modified":"2016-01-24T22:04:47","modified_gmt":"2016-01-25T04:04:47","slug":"multi-page-toolkit-plugin-insert-page-fix","status":"publish","type":"post","link":"http:\/\/www.p14nd4.com\/blog\/2016\/01\/24\/multi-page-toolkit-plugin-insert-page-fix\/","title":{"rendered":"Multi-page Toolkit Plugin &#8216;Insert Page&#8217; Fix"},"content":{"rendered":"<p>One of the sites I run, <a href=\"http:\/\/www.TechwareLabs.com\/\">Techware Labs<\/a>, uses <a href=\"https:\/\/wordpress.org\/\">WordPress<\/a> for its <acronym title=\"content management system\">CMS<\/acronym>. (As an aside, we previously used our own home-grown CMS, which had a variety of benefits, but didn&#8217;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 <a href=\"https:\/\/wordpress.org\/plugins\/multi-page-toolkit\/\">Multi-Page Toolkit<\/a> plugin to paginate articles (since WordPress just sticks the entire post on a single page by default), which seemed reasonable at the time&mdash;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.<\/p>\n<p>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. <q>Mostly,<\/q> however, isn&#8217;t quite the same as <q>entirely,<\/q> and some people get cranky when one thing goes wrong. (Take the <a href=\"https:\/\/en.wikipedia.org\/wiki\/LZ_129_Hindenburg\">Hindenburg<\/a>, for example; why doesn&#8217;t anyone talk about its 62 successful flights?)<\/p>\n<p><!--more--><\/p>\n<p>OK, maybe the Hindenburg isn&#8217;t quite the best analogy, but I do want to point out that the core functionality of the plugin <em>has<\/em> continued to work for the past ~seven years, which I think should reflect highly on the developers of WordPress, <a href=\"https:\/\/www.tinymce.com\/\">TinyMCE<\/a>, and the Multi-page Toolkit plugin.<\/p>\n<h3>Get on with it&#8230;<\/h3>\n<p>The issue reported to me was that the button to <q>Insert Title<\/q> in the WP visual editor wasn&#8217;t working; screenshots were helpfully provided to demonstrate the workflow:<\/p>\n<p><a href=\"\/blog\/wp-content\/uploads\/2016\/01\/title.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2016\/01\/title-300x138.png\" alt=\"Insert Title Button\" width=\"300\" height=\"138\" class=\"aligncenter size-medium wp-image-261\" srcset=\"http:\/\/www.p14nd4.com\/blog\/wp-content\/uploads\/2016\/01\/title-300x138.png 300w, http:\/\/www.p14nd4.com\/blog\/wp-content\/uploads\/2016\/01\/title.png 969w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a> <a href=\"\/blog\/wp-content\/uploads\/2016\/01\/title2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2016\/01\/title2-300x142.png\" alt=\"Broken UI\" width=\"300\" height=\"142\" class=\"aligncenter size-medium wp-image-262\" srcset=\"http:\/\/www.p14nd4.com\/blog\/wp-content\/uploads\/2016\/01\/title2-300x142.png 300w, http:\/\/www.p14nd4.com\/blog\/wp-content\/uploads\/2016\/01\/title2.png 690w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>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:<\/p>\n<blockquote style=\"font-family: monospace;\"><p>Uncaught TypeError: Cannot read property &#8216;mce_inline&#8217; of undefined tinyMCEPopup.getWindowArg @ tiny_mce_popup.js:47<\/p><\/blockquote>\n<blockquote style=\"font-family: monospace;\"><p>Uncaught TypeError: Cannot read property &#8216;plugin_url&#8217; of undefined tinyMCEPopup.getWindowArg @ tiny_mce_popup.js:47<\/p><\/blockquote>\n<p>I immediately suspected the TinyMCE version had changed in some incompatible way since the time of this plugin&#8217;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&#8217;t seem <a href=\"https:\/\/www.tinymce.com\/docs\/advanced\/migration-guide-from-3.x\/\"><em>terribly<\/em> different<\/a>, I&#8217;m lazy, so was pleased to discover that TinyMCE 4 has a <a href=\"https:\/\/www.tinymce.com\/docs\/plugins\/compat3x\/\">3.x compatibility plugin<\/a>, so I only had to fix enough to work with that! (I did briefly start trying to actually migrate, but ain&#8217;t nobody got time for that!)<\/p>\n<p>In the end, just the two scripts in wp-content\/plugins\/multi-page-toolkit\/buttons\/js needed to be patched as follows:<\/p>\n<p><code>--- dialog-orig.js  2009-04-08 21:53:39.000000000 -0500<br \/>\n+++ dialog.js   2016-01-24 18:30:00.320786435 -0600<br \/>\n@@ -23,4 +23,4 @@<br \/>\n        }<br \/>\n };<\/p>\n<p>-tinyMCEPopup.onInit.add(PageTitleDialog.init, PageTitleDialog);<br \/>\n+tinyMCEPopup.editor.onInit.add(PageTitleDialog.init, PageTitleDialog);<\/code><\/p>\n<p>and<\/p>\n<p><code>--- tiny_mce_popup-orig.js  2016-01-24 17:00:00.308056097 -0600<br \/>\n+++ tiny_mce_popup.js   2016-01-24 18:53:20.791169867 -0600<br \/>\n@@ -20,7 +20,7 @@<br \/>\n                tinymce = w.tinymce;<br \/>\n                tinyMCE = w.tinyMCE;<br \/>\n                t.editor = tinymce.EditorManager.activeEditor;<br \/>\n-               t.params = t.editor.windowManager.params;<br \/>\n+               t.params = t.editor.windowManager.getParams();<\/p>\n<p>                \/\/ Setup local DOM<br \/>\n                t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document);<br \/>\n@@ -28,7 +28,7 @@<\/p>\n<p>                \/\/ Setup on init listeners<br \/>\n                t.listeners = [];<br \/>\n-               t.onInit = {<br \/>\n+               t.editor.onInit = {<br \/>\n                        add : function(f, s) {<br \/>\n                                t.listeners.push({func : f, scope : s});<br \/>\n                        }<\/code><\/p>\n<p>I&#8217;ve also posted the fix on the <a href=\"https:\/\/wordpress.org\/support\/topic\/solved-patch-for-js-errors-insert-title-button?replies=1\">WordPress Support Forums<\/a> for the plugin. Please let me know if this helps you, or if you have any improvements!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,4],"tags":[17,19,11],"class_list":["post-259","post","type-post","status-publish","format-standard","hentry","category-technical","category-techwarelabs","tag-error","tag-solved","tag-wordpress"],"_links":{"self":[{"href":"http:\/\/www.p14nd4.com\/blog\/wp-json\/wp\/v2\/posts\/259","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.p14nd4.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.p14nd4.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.p14nd4.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.p14nd4.com\/blog\/wp-json\/wp\/v2\/comments?post=259"}],"version-history":[{"count":3,"href":"http:\/\/www.p14nd4.com\/blog\/wp-json\/wp\/v2\/posts\/259\/revisions"}],"predecessor-version":[{"id":264,"href":"http:\/\/www.p14nd4.com\/blog\/wp-json\/wp\/v2\/posts\/259\/revisions\/264"}],"wp:attachment":[{"href":"http:\/\/www.p14nd4.com\/blog\/wp-json\/wp\/v2\/media?parent=259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.p14nd4.com\/blog\/wp-json\/wp\/v2\/categories?post=259"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.p14nd4.com\/blog\/wp-json\/wp\/v2\/tags?post=259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}