SlideShare a Scribd company logo
Single Page Web Apps As WordPress
Admin Interfaces Using AngularJS &
The WordPress REST API
Josh Pollock
JoshPress.net - IngotHQ.com -- CalderaWP.com
@Josh412
http://jpwp.me/ingot-admin-js
WHY?
Part One
THIS IS THE
NEW WAY
● WordPress is showing its
age…
● This is how it catches up.
6 Changes, No Page Refresh
State Change != Page Load
Deep Linking With Router
BTW: Angular UI Router > NG Router
Probably, but don't.
Common
UI/UX Pattern
● Portable
● Familiar
Custom REST
APIs In
WordPress
● Easy
● Testable
● Standardized
Why Angular?
● Respects standards &
separation of concerns
● Relatively easy to learn
● Testable
● Someone else pays to
maintain it. #thanksgoogle
Why Angular?
● Accessible dynamic
interfaces are not easy.
● Angular ARIA is a great
start.
HOW?
Part Two
Setting It Up
http://jpwp.me/ingot-admin-load
● Admin page callback prints basic
HTML
● http://jpwp.me/ingot-main-page-partial
● Use wp_localize_script() for:
○ Partials directory path
○ Translation strings
Don't Forget To Make Your API
● Part 3 of my course
● Chapter 8 of my book
● My WordCamp NYC 2015 talk on
WordPress.TV
This Is A Different Talk
Angular UI
Router
● What URL uses what
controller and template?
● http://jpwp.me/ingot-router
ingotApp.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise("/");
$stateProvider
//click tests
.state('clickTests', {
url: "/click-tests",
templateUrl: INGOT_ADMIN.partials + "/click-groups.html"
})
.state('clickTests.list', {
url: "/click-tests/all",
templateUrl: INGOT_ADMIN.partials + "/list.html",
controller: 'clickGroups'
} )
.state('clickTests.edit', {
url: "/click-tests/edit/:groupID",
templateUrl: INGOT_ADMIN.partials + "/click-group.html",
controller: 'clickGroup'
} )
.state('clickTests.new', {
url: "/click-tests/new",
templateUrl: INGOT_ADMIN.partials + "/click-group.html",
controller: 'clickGroup'
} )
});
Start It Up
● Include dependencies
● Adding translations to
$rootScope
var ingotApp = angular.module('ingotApp', [
'ui.router',
'ui.bootstrap',
'colorpicker.module',
'ngAria',
'ngResource',
'ngclipboard',
'ngSanitize'
] )
.run( function( $rootScope, $state ) {
$rootScope.translate = INGOT_TRANSLATION;
$rootScope.partials_url = INGOT_ADMIN.partials;
}
);
Angular $http
● Similar to jQuery AJAX
● Use to update $scope and
$state
ingotApp.controller( 'clickDelete', ['$scope', '$http',
'$stateParams', '$state', function( $scope, $http, $stateParams,
$state ){
$http({
url: INGOT_ADMIN.api + 'groups/' + $stateParams.groupID + '?
_wpnonce=' + INGOT_ADMIN.nonce,
method:'DELETE',
headers: {
'X-WP-Nonce': INGOT_ADMIN.nonce
}
} ).then(
function successCallback() {
swal( INGOT_TRANSLATION.deleted, "", "success" );
$scope.group = {};
$state.go('clickTests.list' );
}, function errorCallback( response ) {
var data = response.data;
var text = INGOT_TRANSLATION.sorry;
if( _.isObject( data ) && _.isDefined( data.message )
){
text = data.message;
}
$state.go('clickTests.list' );
}
);
}]);
Factories
● Reusable code for HTTP
● Makes data a injected
dependency -- easily
mocked/ modified
● http://jpwp.me/ingot-factory
ingotApp.factory( 'groupsFactory', function( $resource ) {
return $resource( INGOT_ADMIN.api + 'groups/:id', {
id: '@id',
_wpnonce: INGOT_ADMIN.nonce,
context: 'admin'
},{
'query' : {
transformResponse: function( data, headers ) {
var response = {
data: data,
headers: headers()
};
return response;
}
},
'update':{
method:'PUT',
headers: {
'X-WP-Nonce': INGOT_ADMIN.nonce
}
},
})
});
Factories
● Think of it as your own API
client
● http://jpwp.me/ingot-factory-
in-use
ingotApp.controller( 'clickGroups', ['$scope', '$http',
'groupsFactory', '$sce', function( $scope, $http, groupsFactory, $sce
) {
var page_limit = 10;
$scope.description = $sce.trustAsHtml( INGOT_TRANSLATION.
descriptions.click );
groupsFactory.query( {
page: 1,
limit: page_limit,
context: 'admin',
type: 'click'
}, function ( res ) {
if ( res.data.indexOf( 'No matching' ) > -1 ) {
$scope.groups = {};
return;
};
$scope.groups = JSON.parse( res.data );
var total_groups = parseInt( res.headers[ 'x-ingot-total' ]
);
var total_pages = total_groups / page_limit;
$scope.total_pages = new Array( Math.round( total_pages ) );
$scope.groups.shortcode = [];
} );
}]);
OTHER
BENEFITS?
Part Three
API-Driven Plugins
● REST API Isn't a bolt on
● Easier & alternative method for 3rd-party
integrations
● Jump to SAAS Is Easier
Empower
Others To Be
Providers
Decentralize All The Things!
YOU?
Part Four
GO DO IT!
● Angular's docs are great read them
● More links, slides, examples:
● JoshPress.net/wordcamp-miami-angular/
Questions?
Josh Pollock - JoshPress.net - @Josh412
Ingot - IngotHQ.com - @IngotHQ.com

More Related Content

PDF
Introduction to AngularJS For WordPress Developers
PDF
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
PDF
Caldera Learn - LoopConf WP API + Angular FTW Workshop
PDF
Using the new WordPress REST API
PDF
Extending the WordPress REST API - Josh Pollock
PPTX
Webinar: AngularJS and the WordPress REST API
ODP
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
PDF
Introduction to AJAX In WordPress
Introduction to AngularJS For WordPress Developers
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Using the new WordPress REST API
Extending the WordPress REST API - Josh Pollock
Webinar: AngularJS and the WordPress REST API
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Introduction to AJAX In WordPress

What's hot (20)

PDF
AngularJS with Slim PHP Micro Framework
PDF
Introduction to plugin development
PDF
Bullet: The Functional PHP Micro-Framework
PDF
Keeping it Small: Getting to know the Slim Micro Framework
PPTX
Dart and AngularDart
PDF
Developing apps using Perl
PPT
Slim RedBeanPHP and Knockout
PDF
Keeping it small - Getting to know the Slim PHP micro framework
PPTX
Zend framework
KEY
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
PDF
Codeigniter : Two Step View - Concept Implementation
PDF
Rails 3: Dashing to the Finish
PDF
Head First Zend Framework - Part 1 Project & Application
PDF
Bootstrat REST APIs with Laravel 5
PDF
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
PDF
REST in AngularJS
PPT
Zend Framework 1.8 Features Webinar
PDF
Silex Cheat Sheet
PPTX
Working with WP_Query in WordPress
PDF
Keeping the frontend under control with Symfony and Webpack
AngularJS with Slim PHP Micro Framework
Introduction to plugin development
Bullet: The Functional PHP Micro-Framework
Keeping it Small: Getting to know the Slim Micro Framework
Dart and AngularDart
Developing apps using Perl
Slim RedBeanPHP and Knockout
Keeping it small - Getting to know the Slim PHP micro framework
Zend framework
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Codeigniter : Two Step View - Concept Implementation
Rails 3: Dashing to the Finish
Head First Zend Framework - Part 1 Project & Application
Bootstrat REST APIs with Laravel 5
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
REST in AngularJS
Zend Framework 1.8 Features Webinar
Silex Cheat Sheet
Working with WP_Query in WordPress
Keeping the frontend under control with Symfony and Webpack
Ad

Similar to Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The WordPress REST API (20)

PPTX
Webinar: AngularJS and the WordPress REST API
PDF
Advanced I/O in browser
PPTX
Angular jS Introduction by Google
 
PPTX
Angular - a real world case study
PPTX
Building WordPress sites with AngularJS and the RESTful plugin JSON API @ Dev...
PDF
The State of Front-end At CrowdTwist
PPTX
Pentesting Modern Web Apps: A Primer
PPTX
Building WordPress sites with AngularJS and the RESTful plugin JSON API
PPTX
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
PPTX
REST Easy with AngularJS - ng-grid CRUD Example
PPTX
AngularJS Anatomy & Directives
PDF
Coders Workshop: API First Mobile Development Featuring Angular and Node
PDF
Building a js widget
PDF
A white paper on Fundamentals and Implementations of Angular JS
PDF
05 Web Services
PDF
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
PPTX
APIdays Paris 2014 - The State of Web API Languages
PPTX
Real World Asp.Net WebApi Applications
PDF
[Ebooks PDF] download AngularJS 1st Edition Brad Green full chapters
PPTX
Using-AngularJS-with-Sitefinity.pptx
Webinar: AngularJS and the WordPress REST API
Advanced I/O in browser
Angular jS Introduction by Google
 
Angular - a real world case study
Building WordPress sites with AngularJS and the RESTful plugin JSON API @ Dev...
The State of Front-end At CrowdTwist
Pentesting Modern Web Apps: A Primer
Building WordPress sites with AngularJS and the RESTful plugin JSON API
REST Easy with AngularJS - ng-grid CRUD EXAMPLE
REST Easy with AngularJS - ng-grid CRUD Example
AngularJS Anatomy & Directives
Coders Workshop: API First Mobile Development Featuring Angular and Node
Building a js widget
A white paper on Fundamentals and Implementations of Angular JS
05 Web Services
2013 - Nate Abele: HTTP ALL THE THINGS: Simplificando aplicaciones respetando...
APIdays Paris 2014 - The State of Web API Languages
Real World Asp.Net WebApi Applications
[Ebooks PDF] download AngularJS 1st Edition Brad Green full chapters
Using-AngularJS-with-Sitefinity.pptx
Ad

More from Caldera Labs (14)

PDF
Slightly Advanced Topics in Gutenberg Development
PDF
Financial Forecasting For WordPress Businesses
PDF
Five Attitudes Stopping You From Building Accessible Wordpress Websites
PDF
Our Hybrid Future: WordPress As Part of the Stack #WCNYC
PDF
Our Hybrid Future: WordPress As Part of the Stack
PDF
Introduction to VueJS & The WordPress REST API
PDF
It all starts with a story
PDF
A/B Testing FTW
PDF
Five events in the life of every WordPress request you should know
PDF
WPSessions Composer for WordPress Plugin Development
PDF
Josh Pollock #wcatl using composer to increase your word press development po...
PDF
Content Marketing With WordPress -- Tallahassee WordPress Meetup
PDF
Writing About WordPress: Helping Yourself, by Helping Others -- WordCamp Orl...
PDF
WordPress Tallahassee Meetup: Turning WordPress Sites Into Web & Mobile Apps
Slightly Advanced Topics in Gutenberg Development
Financial Forecasting For WordPress Businesses
Five Attitudes Stopping You From Building Accessible Wordpress Websites
Our Hybrid Future: WordPress As Part of the Stack #WCNYC
Our Hybrid Future: WordPress As Part of the Stack
Introduction to VueJS & The WordPress REST API
It all starts with a story
A/B Testing FTW
Five events in the life of every WordPress request you should know
WPSessions Composer for WordPress Plugin Development
Josh Pollock #wcatl using composer to increase your word press development po...
Content Marketing With WordPress -- Tallahassee WordPress Meetup
Writing About WordPress: Helping Yourself, by Helping Others -- WordCamp Orl...
WordPress Tallahassee Meetup: Turning WordPress Sites Into Web & Mobile Apps

Recently uploaded (20)

PDF
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
PPT
256065457-Anaesthesia-in-Liver-Disease-Patient.ppt
PPTX
durere- in cancer tu ttresjjnklj gfrrjnrs mhugyfrd
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PPTX
nagasai stick diagrams in very large scale integratiom.pptx
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
PPTX
QR Codes Qr codecodecodecodecocodedecodecode
PDF
Generative AI Foundations: AI Skills for the Future of Work
PDF
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PDF
The Internet -By the Numbers, Sri Lanka Edition
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PDF
www-codemechsolutions-com-whatwedo-cloud-application-migration-services.pdf
PDF
Testing WebRTC applications at scale.pdf
PPTX
CSharp_Syntax_Basics.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
256065457-Anaesthesia-in-Liver-Disease-Patient.ppt
durere- in cancer tu ttresjjnklj gfrrjnrs mhugyfrd
An introduction to the IFRS (ISSB) Stndards.pdf
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
nagasai stick diagrams in very large scale integratiom.pptx
introduction about ICD -10 & ICD-11 ppt.pptx
522797556-Unit-2-Temperature-measurement-1-1.pptx
QR Codes Qr codecodecodecodecocodedecodecode
Generative AI Foundations: AI Skills for the Future of Work
LABUAN4D EXCLUSIVE SERVER STAR GAMING ASIA NO.1
WebRTC in SignalWire - troubleshooting media negotiation
Slides PDF The World Game (s) Eco Economic Epochs.pdf
The Internet -By the Numbers, Sri Lanka Edition
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
www-codemechsolutions-com-whatwedo-cloud-application-migration-services.pdf
Testing WebRTC applications at scale.pdf
CSharp_Syntax_Basics.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Job_Card_System_Styled_lorem_ipsum_.pptx
Decoding a Decade: 10 Years of Applied CTI Discipline

Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The WordPress REST API

  • 1. Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The WordPress REST API Josh Pollock JoshPress.net - IngotHQ.com -- CalderaWP.com
  • 5. THIS IS THE NEW WAY ● WordPress is showing its age… ● This is how it catches up.
  • 6. 6 Changes, No Page Refresh State Change != Page Load
  • 7. Deep Linking With Router BTW: Angular UI Router > NG Router
  • 10. Custom REST APIs In WordPress ● Easy ● Testable ● Standardized
  • 11. Why Angular? ● Respects standards & separation of concerns ● Relatively easy to learn ● Testable ● Someone else pays to maintain it. #thanksgoogle
  • 12. Why Angular? ● Accessible dynamic interfaces are not easy. ● Angular ARIA is a great start.
  • 14. Setting It Up http://jpwp.me/ingot-admin-load ● Admin page callback prints basic HTML ● http://jpwp.me/ingot-main-page-partial ● Use wp_localize_script() for: ○ Partials directory path ○ Translation strings
  • 15. Don't Forget To Make Your API ● Part 3 of my course ● Chapter 8 of my book ● My WordCamp NYC 2015 talk on WordPress.TV This Is A Different Talk
  • 16. Angular UI Router ● What URL uses what controller and template? ● http://jpwp.me/ingot-router ingotApp.config(function($stateProvider, $urlRouterProvider) { $urlRouterProvider.otherwise("/"); $stateProvider //click tests .state('clickTests', { url: "/click-tests", templateUrl: INGOT_ADMIN.partials + "/click-groups.html" }) .state('clickTests.list', { url: "/click-tests/all", templateUrl: INGOT_ADMIN.partials + "/list.html", controller: 'clickGroups' } ) .state('clickTests.edit', { url: "/click-tests/edit/:groupID", templateUrl: INGOT_ADMIN.partials + "/click-group.html", controller: 'clickGroup' } ) .state('clickTests.new', { url: "/click-tests/new", templateUrl: INGOT_ADMIN.partials + "/click-group.html", controller: 'clickGroup' } ) });
  • 17. Start It Up ● Include dependencies ● Adding translations to $rootScope var ingotApp = angular.module('ingotApp', [ 'ui.router', 'ui.bootstrap', 'colorpicker.module', 'ngAria', 'ngResource', 'ngclipboard', 'ngSanitize' ] ) .run( function( $rootScope, $state ) { $rootScope.translate = INGOT_TRANSLATION; $rootScope.partials_url = INGOT_ADMIN.partials; } );
  • 18. Angular $http ● Similar to jQuery AJAX ● Use to update $scope and $state ingotApp.controller( 'clickDelete', ['$scope', '$http', '$stateParams', '$state', function( $scope, $http, $stateParams, $state ){ $http({ url: INGOT_ADMIN.api + 'groups/' + $stateParams.groupID + '? _wpnonce=' + INGOT_ADMIN.nonce, method:'DELETE', headers: { 'X-WP-Nonce': INGOT_ADMIN.nonce } } ).then( function successCallback() { swal( INGOT_TRANSLATION.deleted, "", "success" ); $scope.group = {}; $state.go('clickTests.list' ); }, function errorCallback( response ) { var data = response.data; var text = INGOT_TRANSLATION.sorry; if( _.isObject( data ) && _.isDefined( data.message ) ){ text = data.message; } $state.go('clickTests.list' ); } ); }]);
  • 19. Factories ● Reusable code for HTTP ● Makes data a injected dependency -- easily mocked/ modified ● http://jpwp.me/ingot-factory ingotApp.factory( 'groupsFactory', function( $resource ) { return $resource( INGOT_ADMIN.api + 'groups/:id', { id: '@id', _wpnonce: INGOT_ADMIN.nonce, context: 'admin' },{ 'query' : { transformResponse: function( data, headers ) { var response = { data: data, headers: headers() }; return response; } }, 'update':{ method:'PUT', headers: { 'X-WP-Nonce': INGOT_ADMIN.nonce } }, }) });
  • 20. Factories ● Think of it as your own API client ● http://jpwp.me/ingot-factory- in-use ingotApp.controller( 'clickGroups', ['$scope', '$http', 'groupsFactory', '$sce', function( $scope, $http, groupsFactory, $sce ) { var page_limit = 10; $scope.description = $sce.trustAsHtml( INGOT_TRANSLATION. descriptions.click ); groupsFactory.query( { page: 1, limit: page_limit, context: 'admin', type: 'click' }, function ( res ) { if ( res.data.indexOf( 'No matching' ) > -1 ) { $scope.groups = {}; return; }; $scope.groups = JSON.parse( res.data ); var total_groups = parseInt( res.headers[ 'x-ingot-total' ] ); var total_pages = total_groups / page_limit; $scope.total_pages = new Array( Math.round( total_pages ) ); $scope.groups.shortcode = []; } ); }]);
  • 22. API-Driven Plugins ● REST API Isn't a bolt on ● Easier & alternative method for 3rd-party integrations ● Jump to SAAS Is Easier
  • 25. GO DO IT! ● Angular's docs are great read them ● More links, slides, examples: ● JoshPress.net/wordcamp-miami-angular/
  • 26. Questions? Josh Pollock - JoshPress.net - @Josh412 Ingot - IngotHQ.com - @IngotHQ.com