SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
Extending
WordPress'
WYSIWYG Editor
Hristo Chakarov
Senior JavaScript developer @ Netclime Inc.
About me
● I'm in the web since 2002
○ professionally since 2007
● Currently working as a
Senior JavaScript developer @ Netclime Inc.
○ the product is SiteKreator - website builder
http://sitekreator.com
● Love WordPress
○ 2 plugins on the official plugins page
○ several commercial projects on top of the platform
○ co-founder of WordPress Bulgarian User Group
(WPBGUG)
http://wpbgug.org/
Table of Content
1. Content Management Systems (CMS) - what
are they?
2. What stands for WYSIWYG, what it is good
for and how it works
3. MceHelloWorld plugin for WordPress
○ features
○ file structure
○ how it works (Admin Area)
4. Shortcodes vs Placeholders in content area
- why I think the latter is better
5. Data saving & on-page printing
6. Demo
Quick Questions
● How many of you have heard about
WordPress?
● And do you use WordPress?
● How many of you have written a plugin for
WordPress?
● How many people have written at least 10
lines of pure JavaScript in his/her life? (NB -
jQuery code does not count :) )
Overview of a CMS
The ideal CMS should:
● keep only content in Database (text, files,
data) - no markup!
● use HTML + CSS for content presentation
However, that is hardly possible :)
Why we need Rich Text Editor in a
CMS
● makes our life easier when updating the site
content (better than writing HTML on our
own)
● customers (non-IT people) are able to
update their own site
● it is a WYSIWYG - you (or better - your
client) sees instantly what s/he will get on
Page
Anatomy of a RTE
● any HTML element can be editable
<div contenteditable="true"></div>
○ but it's better to use <iframe/> for the editable area as
browsers can have multiple window selections (IE
doesn't, surprised?)
● uses browsers' API
○ execCommand
○ WindowSelection
○ SelectionRange
● the fun starts here: browsers' API is different
○ better use existing RTE and not reinvent the wheel
WordPress & TinyMCE
● since v2.0 (not sure) WP uses TinyMCE for its
default WYSIWYG editor
● TinyMCE can be extended via plug-ins
● WordPress can be extended via plug-ins
● ..this means that we can extend WordPress'
TinyMCE!
MceHelloWorld plug-in for WP
Features:
● registers toolbar button
MceHelloWorld plug-in for WP
Features:
● inserts placeholder in content area
MceHelloWorld plug-in for WP
Features:
● prints "Hello, <name>" on Page in a box
File Structure
● /wp-content/plugins/mcehelloworld/
○ plugin.php (hooks to WordPress actions & filters)
○ css/
■ style.css (CSS for on-page rendering)
○ tinymce/plugins/mcehelloworld/
■ dialog.htm (property form of the plugin)
■ plugin.js (our TinyMCE plugin)
■ img/
● button.png
● placeholder.gif
● space.gif
■ lang/
● en.js
Admin Area - plugin.php
● register the toolbar button
● require the main plugin JS file
Admin Area - plugin.js
● register & init the TinyMCE plugin
tinymce.create
tinymce.PluginManager.requireLangPack
tinymce.PluginManager.add
● register custom TinyMCE command
editor_instance.addCommand
● register toolbar button
editor_instance.addButton
● manage the dialog window
editor_instance.windowManager.open
editor_instance.windowManager.close
● observes editable area for selection change
editor_instance.onNodeChange
● we start with a Closure
Admin Area - plugin.js
Init the TinyMCE Plugin
Translation
// langs/en.js
// define translatable strings as key:value hash
tinyMCE.addI18n("en.mcehelloworld", {
desc : 'Hello, TinyMCE!'
});
// plugin.js
// Load plugin specific language pack
tinymce.PluginManager.requireLangPack('mcehelloworld');
The Dialog Window
● manages the plugin properties
○ name
○ width
○ height
● on Save, executes a callback function in the
parent window and passes the properties as
JSON string
● the Dialog Window should get the
environment (properties, callback function)
○ we pass them as URL params
Get Query Parameters from URL HTML Form
f Executing the Save Callback
and populate Form Fields
Save Callback
● save the properties
○ data will be received as JSON string
○ JSON.parse it
○ create query string (?name=Hristo&width=100...)
○ insert a placeholder <img> in content area
○ store the data (query string) in placeholder's url
● close the dialog window
Shortcode vs Placeholder
● most TinyMCE plugins insert shortcode in
the content area
[shortcode property="value"]
● this does not give real idea of what we will
get on page (especially if our content will be bigger
than 1 line (95% of cases))
● placeholders have dimensions
○ and easily resized in most browsers
● placeholders can be drag-n-dropped easily
○ (quick demo)
Shortcode vs Placeholder
Shortcode
In Content Area On Page
Placeholder
In Content Area On Page
Save Callback
On-Page printing - plugin.php
● plugin.php takes care for data visualization
on Page
● we hook to add_filter
add_filter('the_content', 'mcehelloworld_the_content');
function mcehelloworld_the_content( $content ) {
// parse the content and replace all placeholders
return $content;
}
● we get the content as a string - better parse
it and work on DOM level
○ Simple HTML DOM (php) helps us
include 'simple_html_dom.php';
Finally - Some Styling
Require the CSS
on Page
The CSS
Demo
Questions?
Resources
● WordPress Codex: TinyMCE Overview http://codex.
wordpress.org/TinyMCE
● WordPress Codex: TinyMCE Custom Buttons http:
//codex.wordpress.org/TinyMCE_Custom_Buttons
● TinyMCE: Create a Plug-in http://www.tinymce.com/wiki.
php/Creating_a_plugin
● API:
http://www.tinymce.com/wiki.php/API3:tinymce.api.3.x
● Simple HTML DOM
http://simplehtmldom.sourceforge.net
Thank You!
mail@ickata.net
blog.ickata.net
facebook.com/ickatanet
github.com/ickata/

Más contenido relacionado

La actualidad más candente

Chrome Extension Develop Starts
Chrome Extension Develop StartsChrome Extension Develop Starts
Chrome Extension Develop Startstaobao.com
 
Building Chrome Extensions
Building Chrome ExtensionsBuilding Chrome Extensions
Building Chrome ExtensionsRon Reiter
 
Making Chrome Extension with AngularJS
Making Chrome Extension with AngularJSMaking Chrome Extension with AngularJS
Making Chrome Extension with AngularJSBen Lau
 
Wade.Go Introduction Speech - SFD HCMC 2014
Wade.Go Introduction Speech - SFD HCMC 2014Wade.Go Introduction Speech - SFD HCMC 2014
Wade.Go Introduction Speech - SFD HCMC 2014Nguyễn Thành Hải
 
JavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web frameworkJavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web frameworkAlive Kuo
 
Video synced interactive web visualisations
Video synced interactive web visualisationsVideo synced interactive web visualisations
Video synced interactive web visualisationsEastMidsLT
 
Discovering Chrome Extensions
Discovering Chrome ExtensionsDiscovering Chrome Extensions
Discovering Chrome ExtensionsÀlex Cabrera Gil
 
Node.js Jump Start
Node.js Jump StartNode.js Jump Start
Node.js Jump StartHaim Michael
 
HTML5 e CSS3 (slides della sessione tenuta al DIMI di Udine)
HTML5 e CSS3 (slides della sessione tenuta al DIMI di Udine) HTML5 e CSS3 (slides della sessione tenuta al DIMI di Udine)
HTML5 e CSS3 (slides della sessione tenuta al DIMI di Udine) Gabriele Gigliotti
 
Building your own Chrome Extension
Building your own Chrome ExtensionBuilding your own Chrome Extension
Building your own Chrome ExtensionSaptak Sengupta
 
Introduction of chrome extension development
Introduction of chrome extension developmentIntroduction of chrome extension development
Introduction of chrome extension developmentBalduran Chang
 
Frameworks in JavaScript
Frameworks in JavaScriptFrameworks in JavaScript
Frameworks in JavaScriptHaim Michael
 
Ui automation
Ui automationUi automation
Ui automationtest test
 
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScriptENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScriptHoracio Gonzalez
 
Upstate CSCI 450 jQuery
Upstate CSCI 450 jQueryUpstate CSCI 450 jQuery
Upstate CSCI 450 jQueryDanWooster1
 
Css,javascript,php,mysql
Css,javascript,php,mysqlCss,javascript,php,mysql
Css,javascript,php,mysqlvurimi prasad
 

La actualidad más candente (20)

Chrome Extension Develop Starts
Chrome Extension Develop StartsChrome Extension Develop Starts
Chrome Extension Develop Starts
 
Building Chrome Extensions
Building Chrome ExtensionsBuilding Chrome Extensions
Building Chrome Extensions
 
Making Chrome Extension with AngularJS
Making Chrome Extension with AngularJSMaking Chrome Extension with AngularJS
Making Chrome Extension with AngularJS
 
Chrome extensions
Chrome extensionsChrome extensions
Chrome extensions
 
Wade.Go Introduction Speech - SFD HCMC 2014
Wade.Go Introduction Speech - SFD HCMC 2014Wade.Go Introduction Speech - SFD HCMC 2014
Wade.Go Introduction Speech - SFD HCMC 2014
 
JavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web frameworkJavascriptMVC: Another choice of web framework
JavascriptMVC: Another choice of web framework
 
Video synced interactive web visualisations
Video synced interactive web visualisationsVideo synced interactive web visualisations
Video synced interactive web visualisations
 
Discovering Chrome Extensions
Discovering Chrome ExtensionsDiscovering Chrome Extensions
Discovering Chrome Extensions
 
Node.js Jump Start
Node.js Jump StartNode.js Jump Start
Node.js Jump Start
 
HTML5 e CSS3 (slides della sessione tenuta al DIMI di Udine)
HTML5 e CSS3 (slides della sessione tenuta al DIMI di Udine) HTML5 e CSS3 (slides della sessione tenuta al DIMI di Udine)
HTML5 e CSS3 (slides della sessione tenuta al DIMI di Udine)
 
Building your own Chrome Extension
Building your own Chrome ExtensionBuilding your own Chrome Extension
Building your own Chrome Extension
 
Introduction of chrome extension development
Introduction of chrome extension developmentIntroduction of chrome extension development
Introduction of chrome extension development
 
Frameworks in JavaScript
Frameworks in JavaScriptFrameworks in JavaScript
Frameworks in JavaScript
 
Ui automation
Ui automationUi automation
Ui automation
 
Wordpress Shortcode
Wordpress ShortcodeWordpress Shortcode
Wordpress Shortcode
 
Develop Chrome Extension
Develop Chrome ExtensionDevelop Chrome Extension
Develop Chrome Extension
 
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScriptENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript
ENIB 2015-2016 - CAI Web - S01E01- La forge JavaScript
 
Upstate CSCI 450 jQuery
Upstate CSCI 450 jQueryUpstate CSCI 450 jQuery
Upstate CSCI 450 jQuery
 
How browser work
How browser workHow browser work
How browser work
 
Css,javascript,php,mysql
Css,javascript,php,mysqlCss,javascript,php,mysql
Css,javascript,php,mysql
 

Destacado

Edte 314 presentation week 3
Edte 314 presentation week 3Edte 314 presentation week 3
Edte 314 presentation week 3Jess Hall
 
Trend journal 1 the space age resurfaces
Trend journal 1   the space age resurfacesTrend journal 1   the space age resurfaces
Trend journal 1 the space age resurfacesAidenn Mullen
 
Finding and understanding patterns in distant reading.
Finding and understanding patterns in distant reading.Finding and understanding patterns in distant reading.
Finding and understanding patterns in distant reading.Ted Underwood
 
Busi 710 final slidedeck
Busi 710 final slidedeckBusi 710 final slidedeck
Busi 710 final slidedeckAidenn Mullen
 
Design thinking project plan draft for Apex
Design thinking project plan draft for ApexDesign thinking project plan draft for Apex
Design thinking project plan draft for ApexAidenn Mullen
 
Contextual Research design brief
Contextual Research design brief Contextual Research design brief
Contextual Research design brief Aidenn Mullen
 
Ethnographic research final - graduate design management
Ethnographic research final - graduate design management Ethnographic research final - graduate design management
Ethnographic research final - graduate design management Aidenn Mullen
 
Synthesis and targetting of mitochondrial proteins
Synthesis and targetting of mitochondrial proteinsSynthesis and targetting of mitochondrial proteins
Synthesis and targetting of mitochondrial proteinsAjay Badyal
 

Destacado (9)

Edte 314 presentation week 3
Edte 314 presentation week 3Edte 314 presentation week 3
Edte 314 presentation week 3
 
Trend journal 1 the space age resurfaces
Trend journal 1   the space age resurfacesTrend journal 1   the space age resurfaces
Trend journal 1 the space age resurfaces
 
Finding and understanding patterns in distant reading.
Finding and understanding patterns in distant reading.Finding and understanding patterns in distant reading.
Finding and understanding patterns in distant reading.
 
Busi 710 final slidedeck
Busi 710 final slidedeckBusi 710 final slidedeck
Busi 710 final slidedeck
 
Design thinking project plan draft for Apex
Design thinking project plan draft for ApexDesign thinking project plan draft for Apex
Design thinking project plan draft for Apex
 
Why Django for Web Development
Why Django for Web DevelopmentWhy Django for Web Development
Why Django for Web Development
 
Contextual Research design brief
Contextual Research design brief Contextual Research design brief
Contextual Research design brief
 
Ethnographic research final - graduate design management
Ethnographic research final - graduate design management Ethnographic research final - graduate design management
Ethnographic research final - graduate design management
 
Synthesis and targetting of mitochondrial proteins
Synthesis and targetting of mitochondrial proteinsSynthesis and targetting of mitochondrial proteins
Synthesis and targetting of mitochondrial proteins
 

Similar a Extending WordPress' TinyMCE

ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...Horacio Gonzalez
 
You Can Work on the Web Patform! (GOSIM 2023)
You Can Work on the Web Patform! (GOSIM 2023)You Can Work on the Web Patform! (GOSIM 2023)
You Can Work on the Web Patform! (GOSIM 2023)Igalia
 
How QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsHow QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsQing-Cheng Li
 
WordPress Plugin Development 201
WordPress Plugin Development 201WordPress Plugin Development 201
WordPress Plugin Development 201ylefebvre
 
Creating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPressCreating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPressHristo Chakarov
 
wd project.pptx
wd project.pptxwd project.pptx
wd project.pptxdsffsdf1
 
Introduction to Gutenberg- Imran Sayed
Introduction to Gutenberg- Imran SayedIntroduction to Gutenberg- Imran Sayed
Introduction to Gutenberg- Imran SayedImran Sayed
 
[DevDay2018] Embrace the challenge – working as a developer in Content Manage...
[DevDay2018] Embrace the challenge – working as a developer in Content Manage...[DevDay2018] Embrace the challenge – working as a developer in Content Manage...
[DevDay2018] Embrace the challenge – working as a developer in Content Manage...DevDay.org
 
Developing high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web workerDeveloping high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web workerSuresh Patidar
 
GWT - Building Rich Internet Applications Using OO Tools
GWT - Building Rich Internet Applications Using OO ToolsGWT - Building Rich Internet Applications Using OO Tools
GWT - Building Rich Internet Applications Using OO Toolsbarciszewski
 
Neoito — How modern browsers work
Neoito — How modern browsers workNeoito — How modern browsers work
Neoito — How modern browsers workNeoito
 
Word press optimizations
Word press optimizations Word press optimizations
Word press optimizations Shawn DeWolfe
 
Plugin development demystified 2017
Plugin development demystified 2017Plugin development demystified 2017
Plugin development demystified 2017ylefebvre
 
Responsive Design: Building for a Modern Web
Responsive Design: Building for a Modern WebResponsive Design: Building for a Modern Web
Responsive Design: Building for a Modern WebHarvard Web Working Group
 
9 Useful Things that Every Web Developer Needs to Know
9 Useful Things that Every Web Developer Needs to Know9 Useful Things that Every Web Developer Needs to Know
9 Useful Things that Every Web Developer Needs to KnowSimobo
 
Discover the power of browser developer tools
Discover the power of browser developer toolsDiscover the power of browser developer tools
Discover the power of browser developer toolsylefebvre
 

Similar a Extending WordPress' TinyMCE (20)

ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
ENIB 2015 2016 - CAI Web S02E01- Côté Navigateur 3/3 - Web Components avec Po...
 
You Can Work on the Web Patform! (GOSIM 2023)
You Can Work on the Web Patform! (GOSIM 2023)You Can Work on the Web Patform! (GOSIM 2023)
You Can Work on the Web Patform! (GOSIM 2023)
 
How QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsHow QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser Extensions
 
WordPress Plugin Development 201
WordPress Plugin Development 201WordPress Plugin Development 201
WordPress Plugin Development 201
 
Creating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPressCreating Extensible Plugins for WordPress
Creating Extensible Plugins for WordPress
 
HTML 5
HTML 5HTML 5
HTML 5
 
wd project.pptx
wd project.pptxwd project.pptx
wd project.pptx
 
Introduction to Gutenberg- Imran Sayed
Introduction to Gutenberg- Imran SayedIntroduction to Gutenberg- Imran Sayed
Introduction to Gutenberg- Imran Sayed
 
How to develop browser extension
How to develop browser extensionHow to develop browser extension
How to develop browser extension
 
[DevDay2018] Embrace the challenge – working as a developer in Content Manage...
[DevDay2018] Embrace the challenge – working as a developer in Content Manage...[DevDay2018] Embrace the challenge – working as a developer in Content Manage...
[DevDay2018] Embrace the challenge – working as a developer in Content Manage...
 
Developing high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web workerDeveloping high performance and responsive web apps using web worker
Developing high performance and responsive web apps using web worker
 
GWT - Building Rich Internet Applications Using OO Tools
GWT - Building Rich Internet Applications Using OO ToolsGWT - Building Rich Internet Applications Using OO Tools
GWT - Building Rich Internet Applications Using OO Tools
 
Html5
Html5Html5
Html5
 
Neoito — How modern browsers work
Neoito — How modern browsers workNeoito — How modern browsers work
Neoito — How modern browsers work
 
Word press optimizations
Word press optimizations Word press optimizations
Word press optimizations
 
Plugin development demystified 2017
Plugin development demystified 2017Plugin development demystified 2017
Plugin development demystified 2017
 
Html5
Html5Html5
Html5
 
Responsive Design: Building for a Modern Web
Responsive Design: Building for a Modern WebResponsive Design: Building for a Modern Web
Responsive Design: Building for a Modern Web
 
9 Useful Things that Every Web Developer Needs to Know
9 Useful Things that Every Web Developer Needs to Know9 Useful Things that Every Web Developer Needs to Know
9 Useful Things that Every Web Developer Needs to Know
 
Discover the power of browser developer tools
Discover the power of browser developer toolsDiscover the power of browser developer tools
Discover the power of browser developer tools
 

Más de Hristo Chakarov

Cross-platform JavaScript
Cross-platform JavaScriptCross-platform JavaScript
Cross-platform JavaScriptHristo Chakarov
 
DOM Performance (JSNext Bulgaria)
DOM Performance (JSNext Bulgaria)DOM Performance (JSNext Bulgaria)
DOM Performance (JSNext Bulgaria)Hristo Chakarov
 
Атоматизация с Grunt
Атоматизация с GruntАтоматизация с Grunt
Атоматизация с GruntHristo Chakarov
 
Choosing the best JavaScript framework/library/toolkit
Choosing the best JavaScript framework/library/toolkitChoosing the best JavaScript framework/library/toolkit
Choosing the best JavaScript framework/library/toolkitHristo Chakarov
 
Choosing the right JavaScript library/framework/toolkit for our project
Choosing the right JavaScript library/framework/toolkit for our projectChoosing the right JavaScript library/framework/toolkit for our project
Choosing the right JavaScript library/framework/toolkit for our projectHristo Chakarov
 
Creating a simple Custom Post Type sort UI
Creating a simple Custom Post Type sort UICreating a simple Custom Post Type sort UI
Creating a simple Custom Post Type sort UIHristo Chakarov
 

Más de Hristo Chakarov (8)

Cross-platform JavaScript
Cross-platform JavaScriptCross-platform JavaScript
Cross-platform JavaScript
 
DOM Performance (JSNext Bulgaria)
DOM Performance (JSNext Bulgaria)DOM Performance (JSNext Bulgaria)
DOM Performance (JSNext Bulgaria)
 
Атоматизация с Grunt
Атоматизация с GruntАтоматизация с Grunt
Атоматизация с Grunt
 
Choosing the best JavaScript framework/library/toolkit
Choosing the best JavaScript framework/library/toolkitChoosing the best JavaScript framework/library/toolkit
Choosing the best JavaScript framework/library/toolkit
 
WP-Boot
WP-BootWP-Boot
WP-Boot
 
Choosing the right JavaScript library/framework/toolkit for our project
Choosing the right JavaScript library/framework/toolkit for our projectChoosing the right JavaScript library/framework/toolkit for our project
Choosing the right JavaScript library/framework/toolkit for our project
 
Dom manipulation
Dom manipulationDom manipulation
Dom manipulation
 
Creating a simple Custom Post Type sort UI
Creating a simple Custom Post Type sort UICreating a simple Custom Post Type sort UI
Creating a simple Custom Post Type sort UI
 

Extending WordPress' TinyMCE

  • 1. Extending WordPress' WYSIWYG Editor Hristo Chakarov Senior JavaScript developer @ Netclime Inc.
  • 2. About me ● I'm in the web since 2002 ○ professionally since 2007 ● Currently working as a Senior JavaScript developer @ Netclime Inc. ○ the product is SiteKreator - website builder http://sitekreator.com ● Love WordPress ○ 2 plugins on the official plugins page ○ several commercial projects on top of the platform ○ co-founder of WordPress Bulgarian User Group (WPBGUG) http://wpbgug.org/
  • 3. Table of Content 1. Content Management Systems (CMS) - what are they? 2. What stands for WYSIWYG, what it is good for and how it works 3. MceHelloWorld plugin for WordPress ○ features ○ file structure ○ how it works (Admin Area) 4. Shortcodes vs Placeholders in content area - why I think the latter is better 5. Data saving & on-page printing 6. Demo
  • 4. Quick Questions ● How many of you have heard about WordPress? ● And do you use WordPress? ● How many of you have written a plugin for WordPress? ● How many people have written at least 10 lines of pure JavaScript in his/her life? (NB - jQuery code does not count :) )
  • 5. Overview of a CMS The ideal CMS should: ● keep only content in Database (text, files, data) - no markup! ● use HTML + CSS for content presentation However, that is hardly possible :)
  • 6. Why we need Rich Text Editor in a CMS ● makes our life easier when updating the site content (better than writing HTML on our own) ● customers (non-IT people) are able to update their own site ● it is a WYSIWYG - you (or better - your client) sees instantly what s/he will get on Page
  • 7. Anatomy of a RTE ● any HTML element can be editable <div contenteditable="true"></div> ○ but it's better to use <iframe/> for the editable area as browsers can have multiple window selections (IE doesn't, surprised?) ● uses browsers' API ○ execCommand ○ WindowSelection ○ SelectionRange ● the fun starts here: browsers' API is different ○ better use existing RTE and not reinvent the wheel
  • 8. WordPress & TinyMCE ● since v2.0 (not sure) WP uses TinyMCE for its default WYSIWYG editor ● TinyMCE can be extended via plug-ins ● WordPress can be extended via plug-ins ● ..this means that we can extend WordPress' TinyMCE!
  • 9. MceHelloWorld plug-in for WP Features: ● registers toolbar button
  • 10. MceHelloWorld plug-in for WP Features: ● inserts placeholder in content area
  • 11. MceHelloWorld plug-in for WP Features: ● prints "Hello, <name>" on Page in a box
  • 12. File Structure ● /wp-content/plugins/mcehelloworld/ ○ plugin.php (hooks to WordPress actions & filters) ○ css/ ■ style.css (CSS for on-page rendering) ○ tinymce/plugins/mcehelloworld/ ■ dialog.htm (property form of the plugin) ■ plugin.js (our TinyMCE plugin) ■ img/ ● button.png ● placeholder.gif ● space.gif ■ lang/ ● en.js
  • 13. Admin Area - plugin.php ● register the toolbar button ● require the main plugin JS file
  • 14. Admin Area - plugin.js ● register & init the TinyMCE plugin tinymce.create tinymce.PluginManager.requireLangPack tinymce.PluginManager.add ● register custom TinyMCE command editor_instance.addCommand ● register toolbar button editor_instance.addButton ● manage the dialog window editor_instance.windowManager.open editor_instance.windowManager.close ● observes editable area for selection change editor_instance.onNodeChange
  • 15. ● we start with a Closure Admin Area - plugin.js
  • 17. Translation // langs/en.js // define translatable strings as key:value hash tinyMCE.addI18n("en.mcehelloworld", { desc : 'Hello, TinyMCE!' }); // plugin.js // Load plugin specific language pack tinymce.PluginManager.requireLangPack('mcehelloworld');
  • 18. The Dialog Window ● manages the plugin properties ○ name ○ width ○ height ● on Save, executes a callback function in the parent window and passes the properties as JSON string ● the Dialog Window should get the environment (properties, callback function) ○ we pass them as URL params
  • 19. Get Query Parameters from URL HTML Form f Executing the Save Callback and populate Form Fields
  • 20. Save Callback ● save the properties ○ data will be received as JSON string ○ JSON.parse it ○ create query string (?name=Hristo&width=100...) ○ insert a placeholder <img> in content area ○ store the data (query string) in placeholder's url ● close the dialog window
  • 21. Shortcode vs Placeholder ● most TinyMCE plugins insert shortcode in the content area [shortcode property="value"] ● this does not give real idea of what we will get on page (especially if our content will be bigger than 1 line (95% of cases)) ● placeholders have dimensions ○ and easily resized in most browsers ● placeholders can be drag-n-dropped easily ○ (quick demo)
  • 22. Shortcode vs Placeholder Shortcode In Content Area On Page Placeholder In Content Area On Page
  • 24. On-Page printing - plugin.php ● plugin.php takes care for data visualization on Page ● we hook to add_filter add_filter('the_content', 'mcehelloworld_the_content'); function mcehelloworld_the_content( $content ) { // parse the content and replace all placeholders return $content; } ● we get the content as a string - better parse it and work on DOM level ○ Simple HTML DOM (php) helps us include 'simple_html_dom.php';
  • 25.
  • 26. Finally - Some Styling Require the CSS on Page The CSS
  • 27. Demo
  • 29. Resources ● WordPress Codex: TinyMCE Overview http://codex. wordpress.org/TinyMCE ● WordPress Codex: TinyMCE Custom Buttons http: //codex.wordpress.org/TinyMCE_Custom_Buttons ● TinyMCE: Create a Plug-in http://www.tinymce.com/wiki. php/Creating_a_plugin ● API: http://www.tinymce.com/wiki.php/API3:tinymce.api.3.x ● Simple HTML DOM http://simplehtmldom.sourceforge.net