Writing a WordPress Plugin: #heweb12

12
WRITING A WORDPRESS PLUGIN

description

During this workshop, we will write a simple WordPress plugin. I will take you through the basic steps of creating the plugin file, including the proper header, and using some basic API functions available in WordPress. As part of the plugin, we'll develop a new shortcode to be used anywhere within the content of posts and we'll develop a widget to be used in widgetized areas (such as sidebars and footers). We will also review the process of creating the "settings" area for the plugin to be displayed in the administration area of WordPress.

Transcript of Writing a WordPress Plugin: #heweb12

Page 1: Writing a WordPress Plugin: #heweb12

WRIT

ING A

WORDPR

ESS

PLUGIN

Page 2: Writing a WordPress Plugin: #heweb12

GETTING STARTED

• Create a blank PHP file• Add the plugin header - http://j.mp/TgCGXP

• Plan your plugin• What should it do?• What features/options should it have?

• Create another blank PHP file• Open and close a new PHP class

Page 3: Writing a WordPress Plugin: #heweb12

BUILD T

HE BASE

BE

GI N

CR

EA

TI N

G T

HE

BA

SI C

FU

NC

TI O

NA

L I TY

Page 4: Writing a WordPress Plugin: #heweb12

CREATE A SHORTCODE

• Implement a new shortcode

• Implement the base functionality

• Register the new shortcode• http://codex.wordpress.org/Function_Reference/add_shortcode

Instantiate the plugin class

Page 5: Writing a WordPress Plugin: #heweb12

TRY

IT O

UT

Page 6: Writing a WordPress Plugin: #heweb12

ADD SOME OPTIONS

• Register new admin page• http://codex.wordpress.org/Function_Reference/add_submenu_page

• Create options page

• Register/whitelist settings section, settings fields• http://codex.wordpress.org/Function_Reference/add_settings_section• http://codex.wordpress.org/Function_Reference/add_settings_field

• Sanitize your settings

Page 7: Writing a WordPress Plugin: #heweb12

TRY

IT O

UT

Page 8: Writing a WordPress Plugin: #heweb12

MAKE A WIDGET

• Another blank PHP file

• Open a class that extends WP_Widget

• Create the four required functions• http://codex.wordpress.org/Widgets_API#Developing_Widgets

Page 9: Writing a WordPress Plugin: #heweb12

TRY

IT O

UT

Page 10: Writing a WordPress Plugin: #heweb12

OTHER RESOURCES/FUNCTIONS

• plugins_url – automatically build the URL to a specific file

• plugin_dir_path – automatically retrieve absolute path to directory

• WPDB Class – access and manipulate the WordPress database

• WP_HTTP Class – retrieve Web resources without depending on cURL

• Transients API – store cache information with explicit expiration times

Page 11: Writing a WordPress Plugin: #heweb12

RESOURCES

• The WordPress Codex• Plugin API - http://codex.wordpress.org/Plugin_API/• Settings API - http://codex.wordpress.org/Settings_API• Function Reference - http://

codex.wordpress.org/Function_Reference• Professional WordPress Plugin Development - http://

j.mp/MxjUfG• WordPress Plugin Developer Center - http://j.mp/MxkDNR• Subversion Utilities

• TortoiseSVN (Windows) - http://tortoisesvn.net/• SVNX (MacOS) - http://code.google.com/p/svnx/• RabbitVCS (Linux) - http://rabbitvcs.org/

Page 12: Writing a WordPress Plugin: #heweb12

QUESTIONS? COMMENTS?

Twitter: @cgrymalaWebsite(s): http://umw.edu/ (Multi-Network Setup)

http://ten-321.com/http://svn.ten-321.com/ (SVN

Repo)Email: [email protected]

[email protected]: http://spkr8.com/s/10608

http://about.me/cgrymala