Anyone knows how to achieve this?
It has something to do with meta boxes, but I just can’t figure out the proper syntax.
Anyone knows how to achieve this?
It has something to do with meta boxes, but I just can’t figure out the proper syntax.
Comments are closed.
I remembered that once I done this, yesterday I found where, but that code was… bad.
So today I little improved it and I’m going to share. Before I want to explain what I do.
First of all, there are 3 main things to do:
Most of things need js so we also need to enqueje js in the right pages (post.php and post-new.php).
1st point can’t be done via PHP, because the markup for those buttons are directly echoed from
wp_editor
function, without be processed by any filter.So only chance is add them via javascript.
2nd point, can be easily done via PHP, using a function hooking
the_editor
filter.3rd point again is done via javascript.
For all the code I created a simple plugin containing 3 file:
gmet.php
– the main plugin filegmet.js
– the file containing javascriptgmet-content.php
– this file contain the tab contentI created anotther file for the tab content in this way is easy to customize it, without digging into code.
gmet.php
There are only 3 functions: the first setup the hooks, the second add the javascript in the page, the third is responsible to add the content on the tab page.
gmet.js
Again 3 tasks: on document ready I setup some css and, most important, I add our tab title markup to the editor. Second task run when user click on our tab title: the standard editor is hidden an our content is shown. To hidden standard editor I copyed and pasted som code from
wp-admin/js/editor.js
. Last task is the easiest, when standard tab titles are clicked I hide our tab content and remove the class ‘active’ that from tab title.gmet-content.php
This file contain what is shown in aour tab. This is only an example, customize it as you want, only remember to add everything iside the wrapper div.
Now, just create a folder inside your plugins directory, save all 3 files inside it, and then go to your dasboard and activate the plugin.
All files are available as Gist here.
This isn’t going to be easy to do. This is hard-coded into the core, and has nothing to do with meta boxes.
If you inspect the HTML for these tabs, you can see some classes like
wp-switch-editor switch-html and switch-tmce
. If you search through the core code for these classes, you could find out where its creating these tabs.The hardest part would be to dissect the JavaScript that actually switches it, and add support for your new tab.