Upload
tom-jenkins
View
552
Download
0
Tags:
Embed Size (px)
Citation preview
Before we dive in a little info about myselfThat is the extent of my photoshop skills; hence the reason I’m a developer and not a designer.
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?
Making WordPress Bend To Your Will
WTF Does That Mean?
I wasn’t sure at first what this meant either.
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.
APIWORDPRESS
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
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
Plugins
Another way is the through loading plugins already created by the many developers out there that work in WordPress
Template Tags
The most basic way to extend a theme while putting forth a minimal amount of effort is Template Tags.
Template TagsA template tag is code that instructs WordPress to "do" or "get" something.
http://codex.wordpress.org/Template_Tags
read quote - example - template tag page
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.
APIHooks
ActionsActions 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
APIHooks
FiltersFilters 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
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
How Do I Use Them?
add_action ( 'hook_name', 'your_function_name', [priority], [accepted_args] );
http://adambrown.info/p/wp_hooks
add_filter ( 'hook_name', 'your_filter', [priority], [accepted_args] );
For actions and filters the syntax for calling them is nearly identicalhook_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?
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.
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.
Widgets APIclass 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 structureexample
Plugin API<?php/*Plugin Name: Name Of The PluginPlugin URI: http://URI_Of_Page_Describing_Plugin_and_UpdatesDescription: A brief description of the Plugin.Version: The Plugin's Version Number, e.g.: 1.0Author: Name Of The Plugin AuthorAuthor URI: http://URI_Of_The_Plugin_AuthorLicense: A "Slug" license name e.g. GPL2*/?>
Here is the way that WordPress knows that it should look for a pluginexample
Options API
// Create an option to the databaseadd_option( $option, $value = , $deprecated = , $autoload = 'yes' );
// Removes option by name.delete_option( $option );
// Fetch a saved optionget_option( $option, $default = false );
// Update the value of an option that was already added.update_option( $option, $newvalue );
The Options API is a simple and standardized way of storing data in the database.
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.
Data Validation
http://codex.wordpress.org/Data_Validation
Custom Post Typeregister_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
Questions?
Tom Jenkinshttp://[email protected]@techguytom