SlideShare a Scribd company logo
EXTENDING
WORDPRESS AS
A PRO
Marko Heijnen

WordSesh December 2014
MARKO HEIJNEN
• Founder  of  CodeKitchen  
• Working  for  1&1  
• Lead  developer  of  GlotPress  
• Core  contributor  for  WordPress  
• Plugin  developer  
• Organizer  for  WordCamp  Belgrade

http://2015.belgrade.wordcamp.org/
WORDPRESS DEVELOPER
The Netherlands
TODAY’S

TOPICS
• Current ways to extend WordPress

• Expect the unexpectable

• Demo wpcentral.io

• Build for the future

• Look at new technologies

• Demo opensesh.org

• Questions
EXTENDING
WORDPRESS
HOOKS
• Hooks are a way for one piece of code to interact
with and modify another piece of code. They make
up the foundation for how plugins and themes
interact with WordPress Core, but they’re also
used extensively by Core itself

• Two types of hooks: Actions and Filters
DROP-INS
Single site
• advanced-cache.php

• object-cache.php

• db.php

• db-error.php

• install.php

• maintenance.php

Multisite
• sunrise.php

• blog-deleted.php

• blog-inactive.php

• blog-suspended.php
PLUGGABLE FUNCTIONS
• These functions let you override certain core
functions via plugins

• Pluggable functions are no longer being added to
WordPress core

• All new functions instead use filters on their output
to allow for similar overriding of their functionality

• See http://codex.wordpress.org/Pluggable_Functions
PLUGGABLE CLASSES
• Using a filter to replace the class that should be
loaded like session_token_manager

• Be able to add your class to be loaded like
wp_image_editors filter
EXPECT THE
UNEXPECTABLE
Check out: http://wpcentral.io/
WP CENTRAL

WHAT IS IT?
• Showing download history

• Showing version usage history

• List all locales and their current state

• Showing contributors data (currently API only)

• Collects history of locale progress
11
12
13
14
WP CENTRAL

HOW IT WORKS
• A lot of data handling by wp_remote_get

• Scrapping profiles.WordPress.org to read data

• Bugs

• Storing 0 values

• Storing invalid data after failed wp_remote_get
requests

• Not checking HTML output from

DOMDocument / DomXPath
WP CENTRAL
CACHING STRATEGY
• Expensive query result caching

• Cron job to retrieve download counts and version
usage

• 24 hour cache per locale on request with a max of
5 locales per time

• Using WP CLI to run it command line

• Creating contributor data on request of the API
BUILD FOR
THE FUTURE
BUILD FOR THE FUTURE
• When writing code, keep the changes you want to
make in mind

• Future proofing is making sure you can easily add
code/features without breaking existing
functionality

• Make the code robust against unexpected problem
situations allowing for graceful recovery or fail-fast,
but do not write code for possible future uses.
LOOK AT NEW
TECHNOLOGIES
http://opensesh.org
20
NODE.JS
NODEJS.ORG
• JavaScript platform

• Uses an event-driven, non-blocking I/O model

• Lightweight and efficient

• Ideal for real time application

• Lot’s of modules you can use

• Manage with NPM - https://www.npmjs.org
OPENSESH
OPENSESH.ORG
• A platform for conferences like WordSesh

• Community driven project for the open source community

• Node.js lets you push new sessions

• This with the help of Socket.IO

• When the session is over, you can simply replace it

• Be able to use YouTube files as wait music

• Possible other ideas:

• Create a hangout through WordPress

• Have a personal schedule
THE SITE
MANAGING CHANNELS
BREAK TIME
CONNECTING TO WORDPRESS
• Node.js checks cookie data to indicate if user is logged in

• Validates over JSON API and retrieve more user data

• Returns a WP_User object

• Has basic capability check support
BASIC CONFIGURATION
var config = {}, channels = [], clients = [];

config.port = 9000;

config.application_host = ‘http://opensesh.com’;

config.application_port = 80;

var app = require('http').createServer(handler),

	 io = require('socket.io').listen(app),

	 wordpress = require("wordpress-utils");

app.listen(config.port);

wordpress.set_siteurl( config.application_host );
SERVER HANDLER (PART 1)
function handler(req, res) {

if (req.url == "/status") {

res.writeHead( 200 );

res.end();

return;

}

var wp_user = wordpress.connect( req.headers.cookie, req.headers['x-token'] );

if ( wp_user ) { // More code to come }

res.end();

}
SOCKET CONNECTION
io.on('connection', function (socket) {

clients[socket.id] = socket;

socket.wp_user = wordpress.connect( socket.handshake.headers.cookie,
socket.handshake.query.token );

socket.on('disconnect', function() {

delete clients[socket.id]

});

var channel_id = parseInt(socket.handshake.query.channel);

socket.emit('publish', { channel : channel_id, url :channels[ channel_id ].url });

});
SERVER HANDLER (PART 2)
wp_user.on('wp_connected', function ( data ) {

if ( ! wp_user.can('manage_options') ) {

res.writeHead(403); res.end(); return;

}

var fullBody = ‘';

req.on('data', function(chunk) {

fullBody += chunk.toString();

});

req.on('end', function() { // Access to JSON data }

}
SERVER HANDLER (PART 3)
if (req.url == "/publish") {

var json = JSON.parse(fullBody);

if ( json.channel && json.url ) {

if ( ! channels[ json.channel ] ) {

channels[ json.channel ] = {};

}

channels[ json.channel ].url = json.url;

io.sockets.emit( 'publish', { channel : json.channel, url : json.url } );

}

else { res.writeHead(404); }

res.end();

}
SERVER HANDLER (PART 4)
else if (req.url == "/channels") {

res.writeHead( 200, {'Content-Type': ‘application/json’} );

res.end( JSON.stringify(channels) );

}

res.end();
THANK YOU FOR
LISTENING

QUESTIONS?

@markoheijnen - markoheijnen.com

More Related Content

PDF
Node.js to the rescue
PDF
One Neos CMS - many websites
PDF
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
PPTX
Host, deploy & scale Blazor Server Apps
PDF
Working in harmony
PPTX
Angular.js in XPages
PDF
RESTFul Tools For Lazy Experts - CFSummit 2016
PPTX
PowerShell Basics for Office Apps and Servers
Node.js to the rescue
One Neos CMS - many websites
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
Host, deploy & scale Blazor Server Apps
Working in harmony
Angular.js in XPages
RESTFul Tools For Lazy Experts - CFSummit 2016
PowerShell Basics for Office Apps and Servers

What's hot (20)

PPTX
Azure Serverless Conf
PPTX
Codegen2021 blazor mobile
PPTX
ASP.NET Core 1.0
PPTX
Mobile Applications Made Easy with ColdFusion 11
PDF
Moving from PHP to a nodejs full stack CMS
PPTX
The Next Step in Responsive - RESS
PDF
Webservices: connecting Joomla! with other programs.
PDF
Bring api manager into your stack
PDF
The Dark Side of Single Page Applications
PPTX
Microservices: Yes or not?
PDF
Empowering Your Clients and Be an Advocate for Yourself
PDF
Isomorphic web application
PDF
IBM Domino Modernizing apps with Angularjs
PPTX
The future of web development write once, run everywhere with angular.js and ...
PPTX
Debugging your Way through .NET with Visual Studio 2015
PDF
WordPress as a Service
PPTX
PDF
Apigility-Powered APIs on IBM i
PDF
Create SASSy web parts in SPFx
PDF
Client Vs. Server Rendering
Azure Serverless Conf
Codegen2021 blazor mobile
ASP.NET Core 1.0
Mobile Applications Made Easy with ColdFusion 11
Moving from PHP to a nodejs full stack CMS
The Next Step in Responsive - RESS
Webservices: connecting Joomla! with other programs.
Bring api manager into your stack
The Dark Side of Single Page Applications
Microservices: Yes or not?
Empowering Your Clients and Be an Advocate for Yourself
Isomorphic web application
IBM Domino Modernizing apps with Angularjs
The future of web development write once, run everywhere with angular.js and ...
Debugging your Way through .NET with Visual Studio 2015
WordPress as a Service
Apigility-Powered APIs on IBM i
Create SASSy web parts in SPFx
Client Vs. Server Rendering
Ad

Similar to Extending WordPress as a pro (20)

PPTX
Advanced Web Technology.pptx
PDF
Introduction to Infrastructure as Code & Automation / Introduction to Chef
PPTX
Deep dive into share point framework webparts
PDF
Apigility-powered API's on IBM i
PDF
ITB2017 - Keynote
PPTX
Build Your First SharePoint Framework Webpart
PDF
Shift Remote: JS - Javascript Build Tools: Past & Beyond - Shedrack Akintayo
PPT
Top 10 HTML5 Features for Oracle Cloud Developers
KEY
20120306 dublin js
PDF
You Got React.js in My PHP
PDF
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
PDF
Designing your API Server for mobile apps
PPTX
Best Practices for Building WordPress Applications
PPTX
SOLID Programming with Portable Class Libraries
PDF
Preparing your dockerised application for production deployment
PDF
Building Enterprise Grade Front-End Applications with JavaScript Frameworks
PPTX
Heading to the Cloud : Introduction to deploying a Provider-Hosted App in Azure
PDF
Improving WordPress Development and Deployments with Docker
PDF
Improve WordPress performance with caching and deferred execution of code
PDF
DEV117 - Unleash the Power of the AppDev Pack and Node.js in Domino
Advanced Web Technology.pptx
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Deep dive into share point framework webparts
Apigility-powered API's on IBM i
ITB2017 - Keynote
Build Your First SharePoint Framework Webpart
Shift Remote: JS - Javascript Build Tools: Past & Beyond - Shedrack Akintayo
Top 10 HTML5 Features for Oracle Cloud Developers
20120306 dublin js
You Got React.js in My PHP
Convert your Full Trust Solutions to the SharePoint Framework (SPFx)
Designing your API Server for mobile apps
Best Practices for Building WordPress Applications
SOLID Programming with Portable Class Libraries
Preparing your dockerised application for production deployment
Building Enterprise Grade Front-End Applications with JavaScript Frameworks
Heading to the Cloud : Introduction to deploying a Provider-Hosted App in Azure
Improving WordPress Development and Deployments with Docker
Improve WordPress performance with caching and deferred execution of code
DEV117 - Unleash the Power of the AppDev Pack and Node.js in Domino
Ad

More from Marko Heijnen (20)

PDF
Custom coded projects
PDF
Security, more important than ever!
PDF
My Contributor Story
PDF
WooCommerce & Apple TV
PDF
The moment my site got hacked - WordCamp Sofia
PDF
Mijn site beveiliging
PDF
The moment my site got hacked
PDF
My complicated WordPress site
PDF
Protecting your site by detection
PDF
GlotPress aka translate.wordpress.org
PDF
Writing clean and maintainable code
PDF
Let's create a multilingual site in WordPress
PDF
Bootstrapping your plugin
PDF
The development and future of GlotPress
PDF
Why Javascript matters
PDF
The code history of WordPress
PDF
Building plugins like a pro
PDF
Perfect your images using WordPress - WordCamp Europe 2013
PDF
Dealing with media
PDF
The awesome things you can do with images inside WordPress
Custom coded projects
Security, more important than ever!
My Contributor Story
WooCommerce & Apple TV
The moment my site got hacked - WordCamp Sofia
Mijn site beveiliging
The moment my site got hacked
My complicated WordPress site
Protecting your site by detection
GlotPress aka translate.wordpress.org
Writing clean and maintainable code
Let's create a multilingual site in WordPress
Bootstrapping your plugin
The development and future of GlotPress
Why Javascript matters
The code history of WordPress
Building plugins like a pro
Perfect your images using WordPress - WordCamp Europe 2013
Dealing with media
The awesome things you can do with images inside WordPress

Recently uploaded (20)

PDF
Modernizing your data center with Dell and AMD
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation theory and applications.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
KodekX | Application Modernization Development
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Approach and Philosophy of On baking technology
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
Modernizing your data center with Dell and AMD
The Rise and Fall of 3GPP – Time for a Sabbatical?
Cloud computing and distributed systems.
Encapsulation theory and applications.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Big Data Technologies - Introduction.pptx
Understanding_Digital_Forensics_Presentation.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
The AUB Centre for AI in Media Proposal.docx
Unlocking AI with Model Context Protocol (MCP)
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KodekX | Application Modernization Development
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Approach and Philosophy of On baking technology
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Encapsulation_ Review paper, used for researhc scholars

Extending WordPress as a pro

  • 1. EXTENDING WORDPRESS AS A PRO Marko Heijnen WordSesh December 2014
  • 2. MARKO HEIJNEN • Founder  of  CodeKitchen   • Working  for  1&1   • Lead  developer  of  GlotPress   • Core  contributor  for  WordPress   • Plugin  developer   • Organizer  for  WordCamp  Belgrade
 http://2015.belgrade.wordcamp.org/ WORDPRESS DEVELOPER The Netherlands
  • 3. TODAY’S
 TOPICS • Current ways to extend WordPress • Expect the unexpectable • Demo wpcentral.io • Build for the future • Look at new technologies • Demo opensesh.org • Questions
  • 5. HOOKS • Hooks are a way for one piece of code to interact with and modify another piece of code. They make up the foundation for how plugins and themes interact with WordPress Core, but they’re also used extensively by Core itself • Two types of hooks: Actions and Filters
  • 6. DROP-INS Single site • advanced-cache.php • object-cache.php • db.php • db-error.php • install.php • maintenance.php Multisite • sunrise.php • blog-deleted.php • blog-inactive.php • blog-suspended.php
  • 7. PLUGGABLE FUNCTIONS • These functions let you override certain core functions via plugins • Pluggable functions are no longer being added to WordPress core • All new functions instead use filters on their output to allow for similar overriding of their functionality • See http://codex.wordpress.org/Pluggable_Functions
  • 8. PLUGGABLE CLASSES • Using a filter to replace the class that should be loaded like session_token_manager • Be able to add your class to be loaded like wp_image_editors filter
  • 9. EXPECT THE UNEXPECTABLE Check out: http://wpcentral.io/
  • 10. WP CENTRAL
 WHAT IS IT? • Showing download history • Showing version usage history • List all locales and their current state • Showing contributors data (currently API only) • Collects history of locale progress
  • 11. 11
  • 12. 12
  • 13. 13
  • 14. 14
  • 15. WP CENTRAL
 HOW IT WORKS • A lot of data handling by wp_remote_get • Scrapping profiles.WordPress.org to read data • Bugs • Storing 0 values • Storing invalid data after failed wp_remote_get requests • Not checking HTML output from
 DOMDocument / DomXPath
  • 16. WP CENTRAL CACHING STRATEGY • Expensive query result caching • Cron job to retrieve download counts and version usage • 24 hour cache per locale on request with a max of 5 locales per time • Using WP CLI to run it command line • Creating contributor data on request of the API
  • 18. BUILD FOR THE FUTURE • When writing code, keep the changes you want to make in mind • Future proofing is making sure you can easily add code/features without breaking existing functionality • Make the code robust against unexpected problem situations allowing for graceful recovery or fail-fast, but do not write code for possible future uses.
  • 20. 20
  • 21. NODE.JS NODEJS.ORG • JavaScript platform • Uses an event-driven, non-blocking I/O model • Lightweight and efficient • Ideal for real time application • Lot’s of modules you can use • Manage with NPM - https://www.npmjs.org
  • 23. OPENSESH.ORG • A platform for conferences like WordSesh • Community driven project for the open source community • Node.js lets you push new sessions • This with the help of Socket.IO • When the session is over, you can simply replace it • Be able to use YouTube files as wait music • Possible other ideas: • Create a hangout through WordPress • Have a personal schedule
  • 27. CONNECTING TO WORDPRESS • Node.js checks cookie data to indicate if user is logged in • Validates over JSON API and retrieve more user data • Returns a WP_User object • Has basic capability check support
  • 28. BASIC CONFIGURATION var config = {}, channels = [], clients = []; config.port = 9000; config.application_host = ‘http://opensesh.com’; config.application_port = 80; var app = require('http').createServer(handler), io = require('socket.io').listen(app), wordpress = require("wordpress-utils"); app.listen(config.port); wordpress.set_siteurl( config.application_host );
  • 29. SERVER HANDLER (PART 1) function handler(req, res) { if (req.url == "/status") { res.writeHead( 200 ); res.end(); return; } var wp_user = wordpress.connect( req.headers.cookie, req.headers['x-token'] ); if ( wp_user ) { // More code to come } res.end(); }
  • 30. SOCKET CONNECTION io.on('connection', function (socket) { clients[socket.id] = socket; socket.wp_user = wordpress.connect( socket.handshake.headers.cookie, socket.handshake.query.token ); socket.on('disconnect', function() { delete clients[socket.id] }); var channel_id = parseInt(socket.handshake.query.channel); socket.emit('publish', { channel : channel_id, url :channels[ channel_id ].url }); });
  • 31. SERVER HANDLER (PART 2) wp_user.on('wp_connected', function ( data ) { if ( ! wp_user.can('manage_options') ) { res.writeHead(403); res.end(); return; } var fullBody = ‘'; req.on('data', function(chunk) { fullBody += chunk.toString(); }); req.on('end', function() { // Access to JSON data } }
  • 32. SERVER HANDLER (PART 3) if (req.url == "/publish") { var json = JSON.parse(fullBody); if ( json.channel && json.url ) { if ( ! channels[ json.channel ] ) { channels[ json.channel ] = {}; } channels[ json.channel ].url = json.url; io.sockets.emit( 'publish', { channel : json.channel, url : json.url } ); } else { res.writeHead(404); } res.end(); }
  • 33. SERVER HANDLER (PART 4) else if (req.url == "/channels") { res.writeHead( 200, {'Content-Type': ‘application/json’} ); res.end( JSON.stringify(channels) ); } res.end();