Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction To Simple WordPress Plugin Development

Similar presentations


Presentation on theme: "Introduction To Simple WordPress Plugin Development"— Presentation transcript:

1 Introduction To Simple WordPress Plugin Development
Develop the skills of planning and developing your plugins with emphasis on hooks, callback functions and more!

2 About Bruce Chamoff CEO of Hot Web Ideas, Inc, hotwebideas.net, a New York based web development firm of over 20 years with a portfolio of over 1,000 websites including Korg, JP Morgan Chase, Whirlpool, UBS A WordPress theme and plugin developer of 9 years Instructor on 5 Udemy.com WordPress Development Courses A contributor to the WordPress.org development forums Speaker at WordCamps. Dad with one daughter.

3 What Exactly Is a Plugin?
It is a PHP script that extends WordPress to perform new functions out of the box. Allows developers to change the WordPress core without modifying any of its code. Contains a combination of PHP, HTML, CSS, and Javascript. The PHP code of any plugin consists of a combination of one or more WordPress hooks and one or more callback functions. Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

4 Why Do We Need Plugins?* DON’T HACK THE CORE!
To prevent hacking the WordPress core To protect our code from WordPress updates To extend the basic WordPress installation and allow it to perform new functionality DON’T HACK THE CORE! Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

5 What Is The WordPress Core?
All folders and files outside of the wp-content directory including: Root WP-includes WP-admin We CAN edit anything under the WP-Content directory Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

6 Where is the Code for Plugins Stored?
Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

7 How To Name a Plugin Since plugins are PHP files, they can have any file name with a .PHP extension, but for best practices, identical to its folder name. They can be stored in a folder or directly in the wp-content /plugins directory. Examples of plugin folders and names include: wp-content /plugins/folder-name/my-plugin.php wp-content /plugins/my-plugin.php Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

8 Simple Plugin Plan Planning your plugin involves 5 simple questions:
Who will use your plugin? When will your plugin run? Where will your plugin run? What will execute? How will it execute? Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

9 Plugin Architecture & Coding Structure
1. File Header 2. Hook add_filter(‘HOOK NAME’,’CALLBACK FUNCTION REFERENCE’); or add_action These 2 must match. 3. Callback Function function CALLBACK FUNCTION () { All PHP content which can include WordPress API code, wp_content, get_posts. return data, PHP variable, object, array, string literal, etc; }

10 More About Hooks There are two types of hooks: action and filter hooks. Action hooks tell WordPress to perform an action. Filter hooks tell WordPress to change some part of the content. Hooks are a necessary part of any plugin as they instruct WordPress to act on a certain feature or piece of content. They tell WordPress when, where, and for whom to run the code inside the plugin. Themes can also include hooks in their functions.php file. Interesting Fact: Drupal also uses hooks in its modules. There are hundreds of hooks listed at: Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

11 My Most Frequently Used Hooks
Action Hooks: admin_menu rest_api_init init admin_init admin_notices wp_dashboard_setup admin_bar_menu wp_enqueue_scripts show_user_profile edit_user_profile personal_options_update edit_user_profile_update login_form_login widgets_init customize_register after_setup_theme Filter Hooks: the_content admin_footer_text body_class login_headertitle wp_footer the_modified_time Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

12 Hook Example: Announce New FB Page
Where: At the end of every blog post. When: N/A Who: Any public user (non-admin role) Use: the_content Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

13 Hook Example: Greet an Admin
Where: In the WordPress back end When: When an admin entered the back end Who: Someone with the administrator or editor user role Use: admin_notices Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

14 Hook Example: Greet an Admin
Where: In the WordPress user editing screen When: Any user clicks the Edit Profile link Who: Any user with rights to edit his/her profile. Use: edit_user_profile Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

15 Hook Example: Run Javascript Files
Where: Anywhere Javascript is needed When: Our plugin executes Who: N/A Use: wp_enqueue_scripts Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

16 More About The Callback Function
It is a regular PHP function. Besides PHP code, it can contain WordPress API code. See Next Slide The function name must match the callback function’s reference in the referring hook. The code for callback functions can also be written as object-oriented code as well. Depending on the hook calling the function, it can accept any number of parameters or none. Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

17 My Most Frequently Used WordPress APIs in Plugin Callback Functions
Options API Transients API Metadata API Theme Customization API (also used in themes known as the customizer) Shortcode API Widgets API Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

18 Review: Steps For Developing Our Plugin
Open our text editor (Notepad++, Edit Plus, BBEdit, Notepad, etc.) Add the PHP directives. Write our plugin header. Write our hook. Write our callback function. Add supporting files (images, HTML, CSS, Javascript) Save our plugin as a PHP script under wp-content/plugins/folder-name/plugin-name.php Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

19 A Simple Plugin: Add Your URL To All Posts and Pages
<?php /* Plugin Name: Add My URL Description: Add any URL to the end of all WordPress posts and pages Version 1.0 Author: Bruce Chamoff Author URL: */ add_filter(‘the_content’, ’add_my_website’); function add_my_website($content) { $new_content = $content . ‘<p><a href=“ My Website</a></p>’; return $new_content; } ?> Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at

20 How To Customize This Plugin
Look at the slide titled All the code you need or click this link. Open your favorite text editor and copy the PHP code to a new file. Save the file as specialid_add_to_the_end.php where specialid can be any ID you want such as hwi_add_to_the_end.php

21 How To Customize This Plugin (continued)
Customize the header: /* header Plugin Name: Add My URL Description: Add any URL to the end of all WordPress posts and pages Version 1.0 Author: Bruce Chamoff replace with your name Author URL: replace with your URL */ Change the author name to YOUR name. 2. Change the URL to YOUR URL or social media page.

22 How To Customize This Plugin (continued)
Customize the callback function: //callback function function add_my_website($content) { $new_content = $content . ‘<p><a href=“ My Website</a></p>’; return $new_content; } 1. Change the URL to your new site or social media page. 2. Change the call to action to any thing you want.

23 Installing Your New Plugin
Now, you can upload it to your WordPress site. Follow these steps: Save your plugin as a zip file. Log into your WordPress admin. Click on PluginsAdd New. Continued on next page.

24 Installing Your New Plugin (Continued)
Click Upload Plugin.

25 Installing Your New Plugin (Continued)
Click Choose File.

26 Installing Your New Plugin (Continued)
Navigate to your zip file and double-click it.

27 Installing Your New Plugin (Continued)
Click Install Now.

28 Activating Your New Plugin (Continued)
Click Activate Plugin.

29 Activating Your New Plugin (Continued)
Congratulations! Your new plugin is activated and should now display your new URL at the end of every blog post!

30 Contact & Q&A Contact Me For Plugin Help I will answer any question…
WebDesignerMall.com Udemy.com Get 50% Off My WordPress Development courses with coupon code WORDCAMP I will answer any question… Website: WebDesignerMall.com / WordPress.org: hotwebideas / I teach WordPress Development Courses at


Download ppt "Introduction To Simple WordPress Plugin Development"

Similar presentations


Ads by Google