4. Tom Jenkins
#bendwordpresstoyourwillbecauseyoucananditisfuntodoso
Hear is the hashtag - if nothing else comes out of this talk I’d like to see this trending in KC
on twitter
Whats the level of WordPress knowledge in the room?
How many PHP devs are here?
Designers wanting to do more?
Content creators who want to know whats running under the hood?
5. Making WordPress
Bend To Your Will
WTF Does That Mean?
I wasn’t sure at first what this meant either.
6. This lady came up with the title so it was my job to come up with the content.
So I spent some time thinking about it and we’re not bending WordPress to do anything.
We’re extending it.
7. API
WORDPRESS
WordPress has grown leaps and bounds over the last several versions so we’re going to take
a closer look at what the WordPress API exposes for us to help us create our own
implementations. We’ll start with the basic small stuff and work our way up the ladder. Feel
free to ask questions along the way if you have any.
Review some site demos to show what can be done
8.
9. Themes
The easiest and code free way is to use a Theme that has the built in functionality that you
want. There are 1,411 free themes to choose from at WordPress.org and hundreds, if not
thousands more at Premium theme shops around the web
10. Plugins
Another way is the through loading plugins already created by the many developers out there
that work in WordPress
11. Template Tags
The most basic way to extend a theme while putting forth a minimal amount of effort is
Template Tags.
12. Template Tags
A template tag is code that instructs WordPress to "do" or "get" something.
http://codex.wordpress.org/Template_Tags
read quote - example - template tag page
13. But you don’t want to do things the lazy way, you want to get your hands a little dirty and do
things that allow for a little more power.
14. API
Hooks
So lets start getting into some of the API known as Hooks
15. API
Hooks
Actions
Actions are the hooks that the WordPress core launches at
specific points during execution, or when specific events
occur.
ex. Actions are triggered by specific events that take place
in WordPress, such as publishing a post, changing themes,
or displaying a page of the admin panel.
Hooks are broken down into two types, The first is Actions
16. API
Hooks
Filters
Filters are the hooks that WordPress launches to modify
text of various types before adding it to the database or
sending it to the browser screen.
Filters sit between the database and the browser (when
WordPress is generating pages), and between the browser
and the database (when WordPress is adding new posts and
comments to the database); most input and output in
WordPress passes through at least one filter.
Next up we have Filters
17. How Do I Use Them?
http://adambrown.info/p/wp_hooks
How Do I Use Them?
I’m glad you asked.
To get a better understanding of what you can even hook into within wordpress I recommend
visiting this website.
show them and step through an example
18. How Do I Use Them?
http://adambrown.info/p/wp_hooks
add_action ( 'hook_name', 'your_function_name', [priority], [accepted_args] );
add_filter ( 'hook_name', 'your_filter', [priority], [accepted_args] );
For actions and filters the syntax for calling them is nearly identical
hook_name
The name of an action hook provided by WordPress, that tells what event your function should be associated with.
your_function_name
The name of the function that you want to be executed following the event specified by hook_name. This can be a standard php function, a function present in the
WordPress core, or a function defined by you in the plugin file (such as 'email_friends'defined above).
priority
An optional integer argument that can be used to specify the order in which the functions associated with a particular action are executed (default: 10). Lower numbers
correspond with earlier execution, and functions with the same priority are executed in the order in which they were added to the action.
accepted_args
An optional integer argument defining how many arguments your function can accept (default 1), useful because some hooks can pass more than one argument to your
function. This parameter is new in release 1.5.1.
We looked at what actions are available, the syntax around an action call, but how you know
when an action if fired if you don’t want to read through Core everytime?
19. I can assure you that actions and filters are not an evil duo...
20. But in fact co-exist to bring give us access to all that Core has to offer. But we don’t have to
settle for that.
21. Create Your Own!!
do_action( $tag, $arg );
$myvar = apply_filters( $tag, $value );
To further extend the concept of actions and filters we aren’t limited to just using what is
given to us by core, we can also create our own actions and filter in the same way by adding
do_action and apply_filters. There are also ways to remove existing actions and filters from
firing but I’ll let you explore that on your own.
22. Now lets start to run and look at some other API’s WordPress has to offer.
23. Widgets API
class My_Widget extends WP_Widget {
function My_Widget() {
// widget actual processes
}
function form($instance) {
// outputs the options form on admin
}
function update($new_instance, $old_instance) {
// processes widget options to be saved
}
function widget($args, $instance) {
// outputs the content of the widget
}
}
register_widget('My_Widget');
review the structure
example
24. Plugin API
<?php
/*
Plugin Name: Name Of The Plugin
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: A brief description of the Plugin.
Version: The Plugin's Version Number, e.g.: 1.0
Author: Name Of The Plugin Author
Author URI: http://URI_Of_The_Plugin_Author
License: A "Slug" license name e.g. GPL2
*/
?>
Here is the way that WordPress knows that it should look for a plugin
example
25. Options API
The Options API is a simple and standardized way of storing data in the database.
// Create an option to the database
add_option( $option, $value = , $deprecated = , $autoload = 'yes' );
// Removes option by name.
delete_option( $option );
// Fetch a saved option
get_option( $option, $default = false );
// Update the value of an option that was already added.
update_option( $option, $newvalue );
Options API is for storing generic or universal data that relates to the theme or plugin.
Drawbacks to using the API for themes is once the theme is changed, the customization is
gone.
28. Custom Post Type
register_post_type( $post_type, $args )
Custom Post Types have gotten a lot of press and for good reason, This functionality is part
of what many consider the reason why WordPress can now be used as a content management
system.
The arguments are extensive though, but not all are needed.
example