1

So I managed to get dynamically generated versions of jquery tinymce to work in wordpress and work with the bundled wplink js plugin - albeit pretty badly hacked together.

Was wondering if anyone has figured out or can deduce from my hack a more elegant way to load the exact scripts I need to get wp link working. I checked this thread but cannot seem to get the bundled wp link plugin to load properly. If I leave out the two 'hacky' lines, I get the error

wplink.js?ver=4.1:142    Uncaught TypeError: Cannot read property 'select' of undefined

This is the start of my more elegant solution. This initialises the editor, its css and a couple lines of hacking to get 'wp link' working;

$js_src = includes_url('js/tinymce/') . 'tinymce.min.js';
$css_src = includes_url('css/') . 'editor.css';

// wp_enqueue doesn't seem to work at all
echo '<script src="' . $js_src . '" type="text/javascript"></script>';

wp_register_style('tinymce_css', $css_src);
wp_enqueue_style('tinymce_css');

...tinymce stuff...
tinymce.init({
      plugins: ["wordpress wpdialogs wplink"], // Throwing stuff at the wall here
      toolbar: "bold italic underline | link unlink"
             });
...more tinymce stuff...


// hacky
require_once(get_home_path() . 'wp/' . WPINC . "/class-wp-editor.php");

wp_enqueue_script('wplink');

// hacky
_WP_Editors::wp_link_dialog();

I have an idea I will need to load the 'wp dialogs' plugin before 'wp link', as 'wp link' seems to rely on this (as my colleague helped me hack in).

The analogy of 'don't fix what ain't broken' comes to mind, but considering there seems to be next to no information on this stuff I was hoping this could help people in future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.