WordPress functionality not working in custom TinyMCE editor buttons


username

I created a simple TinyMCE plugin as shown below. Basically, this is the new button in the TinyMCE editor that when pressed brings up a lightbox (thick frame).

// create plugin
tinymce.create('tinymce.plugins.callthickbox', {  
    init : function(ed, url) {  
        ed.addButton('callthickbox', {  
            title   : 'This is Thick Box',  
            cmd     : 'showthickbox'
        });
        ed.addCommand('showthickbox', function() {
            ed.execCommand('mceInsertContent', false, callthatthickbox(url,null));
        });

    //blah blah blah the rest...
});
tinymce.PluginManager.add('callthickbox', tinymce.plugins.callthickbox);

and call it with:

// call the PHP form
function callthatthickbox(url) {
    tb_show( "This is Thick Box", url + '/thickbox-form.php', false);   
}

The thick box will pop up and the PHP files (the content of the thick box) will work fine, but all WP functions will not work in these PHP files, such as wp_list_categories() or bloginfo('url') .

Apparently the PHP file lost access to WP functions. I could try passing variables through the URL, but that doesn't seem like a good solution, especially if I want to pass arrays.

Does anyone have a better solution?

Thanks a lot before!

EDIT: I've tried to load wp-load.php into a PHP file and it works fine, but isn't that a bit overkill? Any ideas?

David

Check out the loading process of wordpress. If you are calling functions from plugin files then they will not be loaded.

What you need to do is

add_action('init', 'your function callback name');

Related


How to Add Custom Shortcode Buttons in TinyMCE Editor WordPress

Harun R Rayhan Hi, I am using the latest version of WordPress. I want to add my shortcode in TinyMCE editor like this image : http://prntscr.com/72ycrs My shortcode is: [my_tabs] [my_tab title = "Tab One Title"]Tab One Content Goes Here[/my_tab] [my_tab title

How to Add Custom Shortcode Buttons in TinyMCE Editor WordPress

Harun R Rayhan Hi, I am using the latest version of WordPress. I want to add my shortcode in TinyMCE editor like this image : http://prntscr.com/72ycrs My shortcode is: [my_tabs] [my_tab title = "Tab One Title"]Tab One Content Goes Here[/my_tab] [my_tab title

How to Add Custom Shortcode Buttons in TinyMCE Editor WordPress

Harun R Rayhan Hi, I am using the latest version of WordPress. I want to add my shortcode in TinyMCE editor with an image like this : http://prntscr.com/72ycrs My shortcode is: [my_tabs] [my_tab title = "Tab One Title"]Tab One Content Goes Here[/my_tab] [my_ta

How to Add Custom Shortcode Buttons in TinyMCE Editor WordPress

Harun R Rayhan Hi, I am using the latest version of WordPress. I want to add my shortcode in TinyMCE editor with an image like this : http://prntscr.com/72ycrs My shortcode is: [my_tabs] [my_tab title = "Tab One Title"]Tab One Content Goes Here[/my_tab] [my_ta

Add Custom Buttons to TinyMCE in WordPress

John Smith I want to add a new button with a popup to TinyMCE. But I never see the button. I may be doing something wrong with this modification. How can I insert a new button on that TinyMCE code? I have this TinyMCE code to display in Wordpress frontend:

Add custom text color WordPress 3.9 TinyMCE 4 visual editor

iSaumya I have a code snippet that helps me add some custom colors to the visual editor text color dropdown as well as the default color. I am going to paste the code snippet below. function change_mce_options( $init ) { $default_colours = '000000,993300,333

Add custom text color WordPress 3.9 TinyMCE 4 visual editor

iSaumya I have a code snippet that helps me add some custom colors to the visual editor text color dropdown as well as the default color. I am pasting the code snippet below. function change_mce_options( $init ) { $default_colours = '000000,993300,333300,003

Add custom text color WordPress 3.9 TinyMCE 4 visual editor

iSaumya I have a code snippet that helps me add some custom colors to the visual editor text color dropdown as well as the default color. I am pasting the code snippet below. function change_mce_options( $init ) { $default_colours = '000000,993300,333300,003

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinyMCE custom plugin for WordPress

mark I'm just getting into plugin development for Wordpress. Now I have a function that I pass as a filter to "tiny_mce_before_init" with specific variables to change buttons, add custom styles and other things like that. I'm building an "options page" and I w

tinymce editor resize function not working

Pawans I'm using tinymce editor version 3.5.8 and trying to resize the editor window, which is not possible by default, I tried adding the autoresizeplugin and setting the resize property of the insize function to bothresize : "both" This is my init function t

tinymce editor resize function not working

Pawans I'm using tinymce editor version 3.5.8 and trying to resize the editor window, which is not possible by default, I tried adding the autoresizeplugin and setting the resize property of the insize function to bothresize : "both" This is my init function t

google transliteration not working in tinymce editor

Arshad I am trying to integrate google transliteration into a project where the editor is tinymce . My text area : <textarea id="to_be_translated" style="width:100%"></textarea> I followed this tutorial to integrate google transliteration and gave the id of m

google transliteration not working in tinymce editor

Arshad I am trying to integrate google transliteration into a project where the editor is tinymce . My text area : <textarea id="to_be_translated" style="width:100%"></textarea> I followed this tutorial to integrate google transliteration and gave the id of m

Include TinyMCE plugin in Wordpress wp_editor?

Mathias Svensson Carlson Plugins are currently being written for WordPress, including the TinyMCE plugin for WordPress' built-in editor. However, when I print the TinyMCE editor on the custom admin page with: wp_editor( $content, $editor_id, $settings ); The

Specify TinyMCE editor font color in WordPress?

eclipse I'm using TinyMCE in WordPress and when you type in the editor, the color of the text is #333333 or rgb(51, 51, 51). Oddly, the default color in the "Choose Text Color" button is #eeeeee, but when you type on page load, it's still #333333. I use this f

Specify TinyMCE editor font color in WordPress?

eclipse I'm using TinyMCE in WordPress and when you type in the editor, the color of the text is #333333 or rgb(51, 51, 51). Oddly, the default color in the "Choose Text Color" button is #eeeeee, but when you type on page load, it's still #333333. I use this f

WordPress - Onclick functionality not working in <a> tags

Michael Stokes I created a sliding sidebar menu for my WordPress site using only HTML/CSS/JavaScript. This is a tutorial from YouTube and followed everything exactly. The problem is that when I click the button, the error says "Uncaught ReferenceError: openSli