SlideShare a Scribd company logo
JavaScript & AJAX
WordPress Webinar
Igor Benić
WordPress Developer & Educator
WP.org: profiles.wordpress.org/ibenic
Twitter: @igorbenic
Web: https://www.ibenic.com
Plugins: Simple Giveaways, Live Scores for
SportsPress, EDD Tab Manager and more
Books: WooCommerce for Developers, Easy
Digital Downloads for Developers, Beginners’
Guide to WordPress Customizer
JavaScript & AJAX
WordPress Webinar
@igorbenic | ibenic.com
• Including JavaScript in WordPress
• Creating Global JavaScript Objects
• How AJAX works in WordPress
• Example: Front Form Submission
JavaScript & AJAX
WordPress Webinar
@igorbenic | ibenic.com
Summary
wp-includes/functions.wp-scripts.php
wp_register_script (
$handle, // Unique String (can be used to dequeue it).
$src = '', // HTTP(S) source to the script
$deps = array(), // Dependancies, such as jquery. Using registered handles
$ver = false, // Version.
$in_footer = false // Include it in footer?
);
wp_enqueue_script( … ) - $handle is required. Must be registered before if
only $handle is passed.
wp_add_inline_script( $handle, $data, $position = ‘after’ ); //$data should not
contain <script>. Just JavaScript. $handle must be enqueued before.
JavaScript & AJAX
WordPress Webinar
@igorbenic | ibenic.com
Including JavaScript in WordPress
Front
add_action( ‘wp_enqueue_scripts’,
‘function_that_calls_enqueue_functions’);
Admin
add_action( ‘admin_enqueue_scripts’,
‘function_that_calls_enqueue_functions’);
JavaScript & AJAX
WordPress Webinar
@igorbenic | ibenic.com
Including JavaScript in WordPress
wp_localize_script(
$handle, // Registered/Enqueued Handle
$object_name, // Object name used in JavaScript
$l10n // Array of key => value pairs
);
—
PHP:
wp_localize_script( ‘my-script’, ‘wp_webinar’, array( ‘load_text’ =>
__( ‘Loading…’, ‘textdomain’ ) );
JS:
$(button).html( wp_webinar.load_text ); //Button will show now: Loading…
JavaScript & AJAX
WordPress Webinar
@igorbenic | ibenic.com
Creating Global JavaScript Objects
wp-admin/admin-ajax.php
No ‘action’ in $_REQUEST ($_POST, $_GET) - Response: 0.
If user logged in:
do_action( ‘wp_ajax_’ . $_REQUEST[‘action’] );
If not logged in (Regular visitor):
do_action( ‘wp_ajax_nopriv_’ . $_REQUEST[‘action’] );
JavaScript & AJAX
WordPress Webinar
@igorbenic | ibenic.com
How AJAX Works in WordPress
Our Job as a Developer:
PHP:
add_action( ‘wp_ajax_our_action’, ‘function_to_be_called’ );
// Should this be available to regular visitors?
add_action( ‘wp_ajax_no_priv_our_action’, ‘function_to_be_called’ );
JS:
// jQuery AJAX
$.ajax(url:URL_TO_admin-ajax.php, data: { action: ‘our_action’, …// other
data to be passed }, …);
JavaScript & AJAX
WordPress Webinar
@igorbenic | ibenic.com
How AJAX Works in WordPress
JavaScript & AJAX
WordPress Webinar
@igorbenic | ibenic.com
Let’s Code
“Become a WordPress Developer” - $47
https://ibenic.com/course
• 12 Hours of Content
• All my eBooks for FREE: WooCommerce for Developers, EDD for Developers,
Beginner’s Guide to WordPress Customizer, Practical WordPress…
• Slack channel
Or become a member on my site - $3/month
https://ibenic.com/register
• Premium Content
• Premium Code
• Unlimited Replays of Webinars
JavaScript & AJAX
WordPress Webinar
@igorbenic | ibenic.com
Learn more from me
Ad

More Related Content

What's hot (20)

Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIsDécouplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Nicolas Blanco
 
jQuery Performance Rules
jQuery Performance RulesjQuery Performance Rules
jQuery Performance Rules
nagarajhubli
 
WooCommerce: payment gateways
WooCommerce: payment gatewaysWooCommerce: payment gateways
WooCommerce: payment gateways
Rodolfo Melogli
 
A piece of sugar in your client-side development
A piece of sugar in your client-side developmentA piece of sugar in your client-side development
A piece of sugar in your client-side development
Nicolas Blanco
 
Presentation on Ember.js
Presentation on Ember.js Presentation on Ember.js
Presentation on Ember.js
Jyaasa Technologies
 
Building applications with WordPress [WordCamp NYC 2016]
Building applications with WordPress [WordCamp NYC 2016]Building applications with WordPress [WordCamp NYC 2016]
Building applications with WordPress [WordCamp NYC 2016]
SlipFire LLC.
 
Html1
Html1Html1
Html1
riddhimpopat
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le Wagon
Alex Benoit
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
Mike Subelsky
 
Mechanize at the Ruby Drink-up of Sophia, November 2011
Mechanize at the Ruby Drink-up of Sophia, November 2011Mechanize at the Ruby Drink-up of Sophia, November 2011
Mechanize at the Ruby Drink-up of Sophia, November 2011
rivierarb
 
Hooked on WordPress: WordCamp Columbus
Hooked on WordPress: WordCamp ColumbusHooked on WordPress: WordCamp Columbus
Hooked on WordPress: WordCamp Columbus
Shawn Hooper
 
Geekspeak: Javascript
Geekspeak: JavascriptGeekspeak: Javascript
Geekspeak: Javascript
lisakennelly
 
User Switcher for Cascade Server
User Switcher for Cascade ServerUser Switcher for Cascade Server
User Switcher for Cascade Server
hannonhill
 
Kickstarter Your Node.JS Application
Kickstarter Your Node.JS ApplicationKickstarter Your Node.JS Application
Kickstarter Your Node.JS Application
Hengki Sihombing
 
BBUI
BBUIBBUI
BBUI
Anoop Nayak
 
Admin footer
Admin footerAdmin footer
Admin footer
Dịch vụ sửa nhà
 
12-2015-Meetup
12-2015-Meetup12-2015-Meetup
12-2015-Meetup
Hengki Sihombing
 
Outside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and RspecOutside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and Rspec
Joseph Wilk
 
Backbone.js – an introduction
Backbone.js – an introductionBackbone.js – an introduction
Backbone.js – an introduction
bobbyroe
 
Client side development with knockout.js
Client side development with knockout.jsClient side development with knockout.js
Client side development with knockout.js
Valdis Iljuconoks
 
Découplez votre appli en micro-APIs
Découplez votre appli en micro-APIsDécouplez votre appli en micro-APIs
Découplez votre appli en micro-APIs
Nicolas Blanco
 
jQuery Performance Rules
jQuery Performance RulesjQuery Performance Rules
jQuery Performance Rules
nagarajhubli
 
WooCommerce: payment gateways
WooCommerce: payment gatewaysWooCommerce: payment gateways
WooCommerce: payment gateways
Rodolfo Melogli
 
A piece of sugar in your client-side development
A piece of sugar in your client-side developmentA piece of sugar in your client-side development
A piece of sugar in your client-side development
Nicolas Blanco
 
Building applications with WordPress [WordCamp NYC 2016]
Building applications with WordPress [WordCamp NYC 2016]Building applications with WordPress [WordCamp NYC 2016]
Building applications with WordPress [WordCamp NYC 2016]
SlipFire LLC.
 
Rails for Beginners - Le Wagon
Rails for Beginners - Le WagonRails for Beginners - Le Wagon
Rails for Beginners - Le Wagon
Alex Benoit
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
Mike Subelsky
 
Mechanize at the Ruby Drink-up of Sophia, November 2011
Mechanize at the Ruby Drink-up of Sophia, November 2011Mechanize at the Ruby Drink-up of Sophia, November 2011
Mechanize at the Ruby Drink-up of Sophia, November 2011
rivierarb
 
Hooked on WordPress: WordCamp Columbus
Hooked on WordPress: WordCamp ColumbusHooked on WordPress: WordCamp Columbus
Hooked on WordPress: WordCamp Columbus
Shawn Hooper
 
Geekspeak: Javascript
Geekspeak: JavascriptGeekspeak: Javascript
Geekspeak: Javascript
lisakennelly
 
User Switcher for Cascade Server
User Switcher for Cascade ServerUser Switcher for Cascade Server
User Switcher for Cascade Server
hannonhill
 
Kickstarter Your Node.JS Application
Kickstarter Your Node.JS ApplicationKickstarter Your Node.JS Application
Kickstarter Your Node.JS Application
Hengki Sihombing
 
Outside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and RspecOutside-in Development with Cucumber and Rspec
Outside-in Development with Cucumber and Rspec
Joseph Wilk
 
Backbone.js – an introduction
Backbone.js – an introductionBackbone.js – an introduction
Backbone.js – an introduction
bobbyroe
 
Client side development with knockout.js
Client side development with knockout.jsClient side development with knockout.js
Client side development with knockout.js
Valdis Iljuconoks
 

Similar to JavaScript & AJAX in WordPress (20)

WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
Ronald Huereca
 
WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
Jeffrey Zinn
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011
David Carr
 
How to build Client Side Applications with WordPress and WP-API | #wcmia
How to build Client Side Applications with WordPress and WP-API | #wcmiaHow to build Client Side Applications with WordPress and WP-API | #wcmia
How to build Client Side Applications with WordPress and WP-API | #wcmia
Roy Sivan
 
WCLV13 JavaScript
WCLV13 JavaScriptWCLV13 JavaScript
WCLV13 JavaScript
Jeffrey Zinn
 
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmiaBuilding WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Roy Sivan
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
Paul Bearne
 
You're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoYou're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp Orlando
Chris Scott
 
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
Rails is not just Ruby
Rails is not just RubyRails is not just Ruby
Rails is not just Ruby
Marco Otte-Witte
 
Passo a Passo para criar uma aplicação Móvel Híbrida
Passo a Passo para criar uma aplicação Móvel HíbridaPasso a Passo para criar uma aplicação Móvel Híbrida
Passo a Passo para criar uma aplicação Móvel Híbrida
Juliano Martins
 
WordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin PagesWordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin Pages
Brandon Dove
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
Mostafa Soufi
 
AJAX the WordPress way
AJAX the WordPress wayAJAX the WordPress way
AJAX the WordPress way
Justin Foell
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
You're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp AtlantaYou're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp Atlanta
Chris Scott
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query1 ppt-ajax with-j_query
1 ppt-ajax with-j_query
Fajar Baskoro
 
WordPress as a Content Management System
WordPress as a Content Management SystemWordPress as a Content Management System
WordPress as a Content Management System
Valent Mustamin
 
YAP / Open Mail Overview
YAP / Open Mail OverviewYAP / Open Mail Overview
YAP / Open Mail Overview
Jonathan LeBlanc
 
"Your script just killed my site" by Steve Souders
"Your script just killed my site" by Steve Souders"Your script just killed my site" by Steve Souders
"Your script just killed my site" by Steve Souders
Dmitry Makarchuk
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011
David Carr
 
How to build Client Side Applications with WordPress and WP-API | #wcmia
How to build Client Side Applications with WordPress and WP-API | #wcmiaHow to build Client Side Applications with WordPress and WP-API | #wcmia
How to build Client Side Applications with WordPress and WP-API | #wcmia
Roy Sivan
 
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmiaBuilding WordPress Client Side Applications with WP and WP-API - #wcmia
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Roy Sivan
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
Paul Bearne
 
You're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp OrlandoYou're Doing it Wrong - WordCamp Orlando
You're Doing it Wrong - WordCamp Orlando
Chris Scott
 
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
wpnepal
 
Passo a Passo para criar uma aplicação Móvel Híbrida
Passo a Passo para criar uma aplicação Móvel HíbridaPasso a Passo para criar uma aplicação Móvel Híbrida
Passo a Passo para criar uma aplicação Móvel Híbrida
Juliano Martins
 
WordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin PagesWordPress Admin UI - Future Proofing Your Admin Pages
WordPress Admin UI - Future Proofing Your Admin Pages
Brandon Dove
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
Mostafa Soufi
 
AJAX the WordPress way
AJAX the WordPress wayAJAX the WordPress way
AJAX the WordPress way
Justin Foell
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
You're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp AtlantaYou're Doing it Wrong - WordCamp Atlanta
You're Doing it Wrong - WordCamp Atlanta
Chris Scott
 
1 ppt-ajax with-j_query
1 ppt-ajax with-j_query1 ppt-ajax with-j_query
1 ppt-ajax with-j_query
Fajar Baskoro
 
WordPress as a Content Management System
WordPress as a Content Management SystemWordPress as a Content Management System
WordPress as a Content Management System
Valent Mustamin
 
"Your script just killed my site" by Steve Souders
"Your script just killed my site" by Steve Souders"Your script just killed my site" by Steve Souders
"Your script just killed my site" by Steve Souders
Dmitry Makarchuk
 
Ad

Recently uploaded (20)

How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Grade 3 - English - Printable Worksheet (PDF Format)
Grade 3 - English - Printable Worksheet  (PDF Format)Grade 3 - English - Printable Worksheet  (PDF Format)
Grade 3 - English - Printable Worksheet (PDF Format)
Sritoma Majumder
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Political History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptxPolitical History of Pala dynasty Pala Rulers NEP.pptx
Political History of Pala dynasty Pala Rulers NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Grade 3 - English - Printable Worksheet (PDF Format)
Grade 3 - English - Printable Worksheet  (PDF Format)Grade 3 - English - Printable Worksheet  (PDF Format)
Grade 3 - English - Printable Worksheet (PDF Format)
Sritoma Majumder
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Ad

JavaScript & AJAX in WordPress

  • 2. Igor Benić WordPress Developer & Educator WP.org: profiles.wordpress.org/ibenic Twitter: @igorbenic Web: https://www.ibenic.com Plugins: Simple Giveaways, Live Scores for SportsPress, EDD Tab Manager and more Books: WooCommerce for Developers, Easy Digital Downloads for Developers, Beginners’ Guide to WordPress Customizer JavaScript & AJAX WordPress Webinar @igorbenic | ibenic.com
  • 3. • Including JavaScript in WordPress • Creating Global JavaScript Objects • How AJAX works in WordPress • Example: Front Form Submission JavaScript & AJAX WordPress Webinar @igorbenic | ibenic.com Summary
  • 4. wp-includes/functions.wp-scripts.php wp_register_script ( $handle, // Unique String (can be used to dequeue it). $src = '', // HTTP(S) source to the script $deps = array(), // Dependancies, such as jquery. Using registered handles $ver = false, // Version. $in_footer = false // Include it in footer? ); wp_enqueue_script( … ) - $handle is required. Must be registered before if only $handle is passed. wp_add_inline_script( $handle, $data, $position = ‘after’ ); //$data should not contain <script>. Just JavaScript. $handle must be enqueued before. JavaScript & AJAX WordPress Webinar @igorbenic | ibenic.com Including JavaScript in WordPress
  • 6. wp_localize_script( $handle, // Registered/Enqueued Handle $object_name, // Object name used in JavaScript $l10n // Array of key => value pairs ); — PHP: wp_localize_script( ‘my-script’, ‘wp_webinar’, array( ‘load_text’ => __( ‘Loading…’, ‘textdomain’ ) ); JS: $(button).html( wp_webinar.load_text ); //Button will show now: Loading… JavaScript & AJAX WordPress Webinar @igorbenic | ibenic.com Creating Global JavaScript Objects
  • 7. wp-admin/admin-ajax.php No ‘action’ in $_REQUEST ($_POST, $_GET) - Response: 0. If user logged in: do_action( ‘wp_ajax_’ . $_REQUEST[‘action’] ); If not logged in (Regular visitor): do_action( ‘wp_ajax_nopriv_’ . $_REQUEST[‘action’] ); JavaScript & AJAX WordPress Webinar @igorbenic | ibenic.com How AJAX Works in WordPress
  • 8. Our Job as a Developer: PHP: add_action( ‘wp_ajax_our_action’, ‘function_to_be_called’ ); // Should this be available to regular visitors? add_action( ‘wp_ajax_no_priv_our_action’, ‘function_to_be_called’ ); JS: // jQuery AJAX $.ajax(url:URL_TO_admin-ajax.php, data: { action: ‘our_action’, …// other data to be passed }, …); JavaScript & AJAX WordPress Webinar @igorbenic | ibenic.com How AJAX Works in WordPress
  • 9. JavaScript & AJAX WordPress Webinar @igorbenic | ibenic.com Let’s Code
  • 10. “Become a WordPress Developer” - $47 https://ibenic.com/course • 12 Hours of Content • All my eBooks for FREE: WooCommerce for Developers, EDD for Developers, Beginner’s Guide to WordPress Customizer, Practical WordPress… • Slack channel Or become a member on my site - $3/month https://ibenic.com/register • Premium Content • Premium Code • Unlimited Replays of Webinars JavaScript & AJAX WordPress Webinar @igorbenic | ibenic.com Learn more from me