SlideShare a Scribd company logo
ryan welcher • @ryanwelcher • me@ryanwelcher.com
G E T T I N G S TA RT E D W I T H
W O R D P R E S S D E V E L O P M E N T
RYA N W E L C H E R
ryan welcher • @ryanwelcher • me@ryanwelcher.com
A B O U T M E
• Ryan Welcher - me@ryanwelcher.com
• Web Developer for over 10 years
• Been working with WordPress since 2009
• Web Engineer at 10up
ryan welcher • @ryanwelcher • me@ryanwelcher.com
T H I S P R E S E N TAT I O N
• Sharing gotcha’s with the noobs :) - where to start and what not to do.
• Aimed at developers or designers just getting into WordPress
development.
• Not an introduction to programming concepts.
• Lots of topics, not a lot of depth for each.
• Assuming that you can install WordPress and are comfortable looking
at PHP.
• Open to suggestions.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
P O S S I B L E TO P I C S
• local development
server
• Vagrant
• Varying Vagrant
Vagrants
• Development plugins
• WP_DEBUG
• Error handling
• Browser tools
• Software tools
• Getting WordPress core
• Coding standards
• Documentation
• PHPDocs
• PHP gotcha’s
• Single vs double quotes
• The White Screen of
Death
• Defensive development
• Shorthand control
structures
• Ternary operators
• Hacking core
• Data sanitization
• Nonces and security
• Actions
• Filters
• WP_Query
• custom post types
• custom taxonomies
• custom fields
• query_posts()
• get_posts()
• $wpdb
• shortcodes
• Widgets
• Writing a plugin
• Plugin headers
• Object-oriented
programming
• Design patterns
• Creating a theme
• Creating a child theme
• Theme template
hierarchy
• Enqueueing JS/CSS
correctly
• AJAX
• JSON
• The Command line
• WP_CLI
• Bash scripting
• Grunt
• my head just
exploded…
ryan welcher • @ryanwelcher • me@ryanwelcher.com
ryan welcher • @ryanwelcher • me@ryanwelcher.com
A C T U A L TO P I C S
• Setting up
• Tools
• Local Development Server
• Getting WordPress Core
• WordPress file structure
• Setting up WP_DEBUG
• Development Plugins
• PHP
• General PHP
• The White Screen of Death
• Defensive Development
• Single vs Double Quotes
• Shorthand Control Structures
• Ternary Operators
• WordPress
• Where does my code go?
• Hacking Core
• Hooks
• Path Helper Methods
• Adding Javascript and CSS correctly
• jQuery no-conflict mode
• The Loop
• Creating secondary loops
• Resource Links
ryan welcher • @ryanwelcher • me@ryanwelcher.com
S E T T I N G U P
ryan welcher • @ryanwelcher • me@ryanwelcher.com
ryan welcher • @ryanwelcher • me@ryanwelcher.com
TO O L S
• Code Editor / IDE ( Integrated Development Environment )
• Theme/Plugin editor in WordPress is too volatile!
• No word processing software.
• Software:
• Sublime Text - www.sublimetext.com
• Dreamweaver - www.adobe.com
• TextMate - macromates.com
• Phpstorm - www.jetbrains.com
ryan welcher • @ryanwelcher • me@ryanwelcher.com
TO O L S
• FTP (File Transfer Protocol) software.
• Copy files to and from a remote server.
• Software:
• Transmit - panic.com/transmit
• FileZilla - filezilla-project.org
• Fetch - fetchsoftworks.com
• Beyond Compare - www.scootersoftware.com
ryan welcher • @ryanwelcher • me@ryanwelcher.com
TO O L S
• Web Browser Tools
• Will help with debugging in the browser - i.e Javascript errors.
• Most modern browsers have tools either built-in or easily
installed.
• Usually right clicking and choosing “inspect element” will
open the tools.
• Internet Explorer - press F12
• FireFox - Install FireBug add-on first.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
L O C A L D E V E L O P M E N T S E RV E R
• Why set one up?
• Gives you a safe “sandbox” to make mistakes with your code.
• Proper debugging configuration.
• Saves time vs FTP upload*
• How do I set one up?
• MAMP - www.mamp.info
• WAMP - www.wampserver.com
• Vagrant and VVV ( Varying Vagrant Vagrants )
ryan welcher • @ryanwelcher • me@ryanwelcher.com
G E T T I N G W O R D P R E S S C O R E
F I L E S T R U C T U R E
• wp-config.php -
contains your website’s
base configuration
details such as database
connection info.
• wp-content - contains
all of the plugins, themes
and uploaded content.
• Everything else is
WordPress core and
should be left alone.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
W P _ D E B U G
Open wp-config.php and change this…
ryan welcher • @ryanwelcher • me@ryanwelcher.com
W P _ D E B U G
E D I T I N G W P - C O N F I G :
H T T P : / / C O D E X . W O R D P R E S S . O R G / E D I T I N G _ W P - C O N F I G . P H P
To this.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
P L U G I N S
• Developer - https://wordpress.org/plugins/developer/
• Helps you optimize your development environment by making sure that you have
all the essential tools and plugins installed.
• Log Deprecated Notices - https://wordpress.org/plugins/log-deprecated-
notices/
• Logs the usage of deprecated files, functions, and function arguments, and
identifies where the deprecated functionality is being used.
• Debug Bar - https://wordpress.org/plugins/debug-bar/
• Adds a debug menu to the admin bar that shows query, cache, and other helpful
debugging information.
• Lots of add-on plugins available
ryan welcher • @ryanwelcher • me@ryanwelcher.com
S TA RT D E V E L O P I N G
ryan welcher • @ryanwelcher • me@ryanwelcher.com
ryan welcher • @ryanwelcher • me@ryanwelcher.com
G E N E R A L P H P
• PHP variables must start with a $ followed by a letter or underscore
• Valid: $foo, $_foo
• Invalid: _foo, $123_foo, $!foo
• Don’t use shorthand PHP tags
• Good: <?php … ?>
• Bad : <?= … ?> or <? … ?>
• Your php.ini file may not allow shorthand tags and will cause a world of hurt.
• PHP lines must always end with a semi-colon.
• You’ll know if you forgot one … duh duh duhhhhhh.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
W H I T E S C R E E N O F D E AT H
ryan welcher • @ryanwelcher • me@ryanwelcher.com
W H I T E S C R E E N O F D E AT H
• Check your syntax
• Missing a $ or invalid variable name.
• Missing semi-colon.
• Missing a curly brace.
• Too many or not enough parens.
• Check your debug.log file in wp-content folder.
• The last line will give you a file name and line number.
• PHP {ERROR _TYPE}: { ERROR_DESC } in { FILENAME } on line { # }
• PHP Parse error : syntax error, unexpected ‘=‘ in / … /functions.php on line
62
ryan welcher • @ryanwelcher • me@ryanwelcher.com
W H I T E S C R E E N O F D E AT H
ryan welcher • @ryanwelcher • me@ryanwelcher.com
D E F E N S I V E D E V E L O P M E N T
• Planning for and handling
failure.
• Checking all the things
BEFORE using them.
• Example functions:
• isset()
• gettype()
• empty()
• function_exists()
• defined()
• is_wp_error()
• WordPress functions can
return on failure:
• False
• WP_Error object
ryan welcher • @ryanwelcher • me@ryanwelcher.com
D E F E N S I V E D E V E L O P M E N T
ryan welcher • @ryanwelcher • me@ryanwelcher.com
D E F E N S I V E D E V E L O P M E N T
ryan welcher • @ryanwelcher • me@ryanwelcher.com
D E F E N S I V E D E V E L O P M E N T
ryan welcher • @ryanwelcher • me@ryanwelcher.com
S I N G L E V S D O U B L E Q U O T E S
• Double quotes parse variables as their value.
• Use single quotes unless you have something to parse.
S H O RT H A N D
C O N T R O L
S T R U C T U R E S
• if, while, foreach, etc
statements without the
curly braces.
• Nice for switching
between PHP and HTML
cleanly.
• Gotcha - IDE’s will not
catch errors.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
S H O RT H A N D C O N T R O L S T R U C T U R E S
ryan welcher • @ryanwelcher • me@ryanwelcher.com
S H O RT H A N D C O N T R O L S T R U C T U R E S
ryan welcher • @ryanwelcher • me@ryanwelcher.com
T E R N A RY O P E R ATO R S
• Single line if/else statement
• Handy for variable assignment
• Format: ( if statement is true ) ? do this : else, do this;
ryan welcher • @ryanwelcher • me@ryanwelcher.com
W O R D P R E S S
ryan welcher • @ryanwelcher • me@ryanwelcher.com
W H E R E D O E S M Y C O D E G O ?
• Plugins
• wp-content
• plugins
• your-plugin
• your-plugin.php
• Themes
• wp-content
• themes
• your-theme
• functions.php
ryan welcher • @ryanwelcher • me@ryanwelcher.com
H A C K I N G C O R E
ryan welcher • @ryanwelcher • me@ryanwelcher.com
H A C K I N G C O R E
• What?
• Make code changes to files outside of the wp-content folder.
• Also applies to downloaded themes/plugins.
• Why not?
• Site is no longer future-proof.
• Compatibility issues with other plugins/themes.
• May introduce security holes.
• When core/theme/plugin updates, your changes are gone!
• Your hacking what plugins are meant to do - use hooks instead.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
H O O K S
• Provided by WordPress to allow us to 'hook' our code into
the rest of WordPress Core.
• A hook is a function that invokes an event that triggers all
other functions hooked into that event.
• 2 Kinds of hooks:
• Actions - Points in the code where WordPress gives us
the ability to add tasks.
• Filters - Allow us to edit content/data before it’s output.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
A C T I O N S
• has_action()
• add_action()
• do_action()
• do_action_ref_array()
• did_action()
• remove_action()
• remove_all_actions()
• doing_action()
A C T I O N S : H T T P : / / C O D E X . W O R D P R E S S . O R G / P L U G I N _ A P I /
A C T I O N _ R E F E R E N C E
ryan welcher • @ryanwelcher • me@ryanwelcher.com
A C T I O N S
• do_action( $tag, $arg … )
• Invokes an action.
• Use to invoke your own actions.
• add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 )
• Hooks into an action invoked by do_action().
• remove_action( $tag, $function_to_remove, $priority )
• removes a function from an invoked action.
• arguments must match the add_action call exactly.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
A C T I O N S
ryan welcher • @ryanwelcher • me@ryanwelcher.com
A C T I O N S
ryan welcher • @ryanwelcher • me@ryanwelcher.com
F I LT E R S : H T T P : / / C O D E X . W O R D P R E S S . O R G / P L U G I N _ A P I /
F I LT E R _ R E F E R E N C E
• has_filter()
• add_filter()
• apply_filters()
• apply_filters_ref_array()
• current_filter()
• remove_filter()
• remove_all_filters()
• doing_filter()
F I LT E R S
ryan welcher • @ryanwelcher • me@ryanwelcher.com
F I LT E R S
• apply_filters( $tag, $value, $var … )
• Invokes a filter.
• Returns the result of $value after all hooked functions are applied to it.
• Use to invoke your own filters.
• add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 )
• Hooks into a filter invoked by apply_filter().
• $function_to_add always takes a parameter and must return data.
• remove_filter( $tag, $function_to_remove, $priority )
• removes a function from an invoked filter.
• arguments must match the add_filter call exactly.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
F I LT E R S
ryan welcher • @ryanwelcher • me@ryanwelcher.com
F I LT E R S
ryan welcher • @ryanwelcher • me@ryanwelcher.com
PAT H H E L P E R M E T H O D S
Let WordPress do the work for you!
ryan welcher • @ryanwelcher • me@ryanwelcher.com
PAT H H E L P E R M E T H O D S
• Plugins
• plugins_url()
• plugin_dir_url()
• plugin_dir_path()
• plugin_basename()
• Themes
• get_template_directory_uri()
• get_stylesheet_directory_uri()
• get_stylesheet_uri()
• get_theme_root_uri()
• get_theme_root()
• get_theme_roots()
• get_stylesheet_directory()
• get_template_directory()
• Site Home
• home_url()
• get_home_path()
• WordPress
• admin_url()
• site_url()
• content_url()
• includes_url()
• wp_upload_dir()
• get_bloginfo()
ryan welcher • @ryanwelcher • me@ryanwelcher.com
A D D I N G J S A N D C S S C O R R E C T LY
• wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer )
• Handles dependencies, load order and duplication of files.
• wp_enqueue_style( $handle, $src, $deps, $ver, $media )
• Both are used with the wp_enqueue_scripts action for the front-end.
• Other hooks
• admin_enqueue_scripts
• login_enqueue_scripts
ryan welcher • @ryanwelcher • me@ryanwelcher.com
A D D I N G J S A N D C S S C O R R E C T LY
ryan welcher • @ryanwelcher • me@ryanwelcher.com
J Q U E RY N O - C O N F L I C T
• WordPress loads it’s version of jQuery in no-conflict
mode to play nicely with other libraries.
• $ shorthand is replaced with jQuery
ryan welcher • @ryanwelcher • me@ryanwelcher.com
T H E L O O P
• “The Loop” is the main process of WordPress.
• You use The Loop in your template files to show content to
visitors.
• Any HTML or PHP code in The Loop will be processed on each
post.
• There are special functions or Template Tags that are meant to
be used inside The Loop.
• The Loop uses global variables called $wp_query and $post
behind the scenes.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
T H E L O O P
ryan welcher • @ryanwelcher • me@ryanwelcher.com
T E M P L AT E TA G S
• the_category()
• the_title()
• the_title_attribute()
• the_meta()
• the_content()
• the_excerpt()
• the_permalink()
• the_ID()
• the_tags()
• the_date()
• the_time()
• the_shortlink()
ryan welcher • @ryanwelcher • me@ryanwelcher.com
C R E AT I N G S E C O N D A RY L O O P S
• As a developer you will be creating secondary loops all
the time.
• 3 options to create secondary loop:
• query_posts()
• get_posts()
• WP_Query Class
• We have to be careful not to interfere with “The Loop”.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
C R E AT I N G S E C O N D A RY L O O P S
• query_posts()
• Don’t use this, even the Codex says you shouldn’t.
• Inefficient.
• Alters The Loop.
• If that’s your goal, use the pre_get_posts hook instead.
• If you have to use it, always call wp_reset_query()
afterwards to reset The Loop.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
C R E AT I N G S E C O N D A RY L O O P S
• get_posts( $args )
• Safe to use anywhere.
• $args can be a string or an associative array.
• Returns an array of WP_Post objects.
• Need to use setup_postdata() in order to have access to Template Tags like
the_title() and the_content()
• You must pass $post to setup_postdata() no other variable name will work.
• It will change the global $post variable used by The Loop.
• Must be followed by a call to wp_reset_postdata() to reset the global $post
variable.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
C R E AT I N G S E C O N D A RY L O O P S
ryan welcher • @ryanwelcher • me@ryanwelcher.com
C R E AT I N G S E C O N D A RY L O O P S
• WP_Query Class
• Powers both query_posts() and get_posts() behind the scenes.
• You can create your own instances and use them safely anywhere.
• Less restrictive but more complicated.
• Methods:
• have_posts()
• the_post()
• will change the global $post variable used by The Loop.
• Must be followed by a call to wp_reset_postdata() to reset the global $post
variable.
ryan welcher • @ryanwelcher • me@ryanwelcher.com
C R E AT I N G S E C O N D A RY L O O P S
ryan welcher • @ryanwelcher • me@ryanwelcher.com
L E A R N I N G R E S O U R C E S
• The Codex - codex.wordpress.org
• WordPress Stack Exchange - wordpress.stackexchange.com
• WordPress Support Forums - wordpress.org/support
• WordPress Core
• WordPress coding standards - make.wordpress.org/core/handbook/coding-
standards/
• PHP Documentation - php.net/manual/en
• lynda.com
• Tuts+ - http://tutsplus.com/
ryan welcher • @ryanwelcher • me@ryanwelcher.com
T H A N K Y O U !

More Related Content

What's hot

How to: Reporting Issues
How to: Reporting IssuesHow to: Reporting Issues
How to: Reporting Issues
John Havlik
 
Schema Markup Basics - Pubcon 2017
Schema Markup Basics - Pubcon 2017Schema Markup Basics - Pubcon 2017
Schema Markup Basics - Pubcon 2017
Carrie Hill
 
Pragmatic REST: recent trends in API design
Pragmatic REST: recent trends in API designPragmatic REST: recent trends in API design
Pragmatic REST: recent trends in API design
Marsh Gardiner
 
Pragmatic REST APIs
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIs
amesar0
 
goaを使った開発TIPS@六本木一丁目
goaを使った開発TIPS@六本木一丁目goaを使った開発TIPS@六本木一丁目
goaを使った開発TIPS@六本木一丁目
jumpei chikamori
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Mike Schinkel
 
Dangerous Google searching for secrets
Dangerous Google searching for secretsDangerous Google searching for secrets
Dangerous Google searching for secretsPim Piepers
 
Avoiding API Waterfalls
Avoiding API WaterfallsAvoiding API Waterfalls
Avoiding API WaterfallsJakub Nesetril
 
All you need is front
All you need is frontAll you need is front
All you need is front
Israel Gutiérrez
 
The Power of RxJS in Nativescript + Angular
The Power of RxJS in Nativescript + AngularThe Power of RxJS in Nativescript + Angular
The Power of RxJS in Nativescript + Angular
Tracy Lee
 
Mind your lang (for role=drinks at CSUN 2017)
Mind your lang (for role=drinks at CSUN 2017)Mind your lang (for role=drinks at CSUN 2017)
Mind your lang (for role=drinks at CSUN 2017)
Adrian Roselli
 
Building Headless Applications with WordPress & Gutenberg
Building Headless Applications with WordPress & GutenbergBuilding Headless Applications with WordPress & Gutenberg
Building Headless Applications with WordPress & Gutenberg
Roy Sivan
 
Kiran karnad rtc2014 ghdb-final
Kiran karnad rtc2014 ghdb-finalKiran karnad rtc2014 ghdb-final
Kiran karnad rtc2014 ghdb-finalRomania Testing
 

What's hot (13)

How to: Reporting Issues
How to: Reporting IssuesHow to: Reporting Issues
How to: Reporting Issues
 
Schema Markup Basics - Pubcon 2017
Schema Markup Basics - Pubcon 2017Schema Markup Basics - Pubcon 2017
Schema Markup Basics - Pubcon 2017
 
Pragmatic REST: recent trends in API design
Pragmatic REST: recent trends in API designPragmatic REST: recent trends in API design
Pragmatic REST: recent trends in API design
 
Pragmatic REST APIs
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIs
 
goaを使った開発TIPS@六本木一丁目
goaを使った開発TIPS@六本木一丁目goaを使った開発TIPS@六本木一丁目
goaを使った開発TIPS@六本木一丁目
 
Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)Developing Complex WordPress Sites without Fear of Failure (with MVC)
Developing Complex WordPress Sites without Fear of Failure (with MVC)
 
Dangerous Google searching for secrets
Dangerous Google searching for secretsDangerous Google searching for secrets
Dangerous Google searching for secrets
 
Avoiding API Waterfalls
Avoiding API WaterfallsAvoiding API Waterfalls
Avoiding API Waterfalls
 
All you need is front
All you need is frontAll you need is front
All you need is front
 
The Power of RxJS in Nativescript + Angular
The Power of RxJS in Nativescript + AngularThe Power of RxJS in Nativescript + Angular
The Power of RxJS in Nativescript + Angular
 
Mind your lang (for role=drinks at CSUN 2017)
Mind your lang (for role=drinks at CSUN 2017)Mind your lang (for role=drinks at CSUN 2017)
Mind your lang (for role=drinks at CSUN 2017)
 
Building Headless Applications with WordPress & Gutenberg
Building Headless Applications with WordPress & GutenbergBuilding Headless Applications with WordPress & Gutenberg
Building Headless Applications with WordPress & Gutenberg
 
Kiran karnad rtc2014 ghdb-final
Kiran karnad rtc2014 ghdb-finalKiran karnad rtc2014 ghdb-final
Kiran karnad rtc2014 ghdb-final
 

Similar to Getting Started with WordPress Development

There's No Crying In Wordpress! (an intro to WP)
There's No Crying In Wordpress! (an intro to WP)There's No Crying In Wordpress! (an intro to WP)
There's No Crying In Wordpress! (an intro to WP)
Grace Solivan
 
Best practices-wordpress-enterprise
Best practices-wordpress-enterpriseBest practices-wordpress-enterprise
Best practices-wordpress-enterpriseTaylor Lovett
 
WordPress Rest API
WordPress Rest APIWordPress Rest API
WordPress Rest API
Brian Layman
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in Enterprise
Taylor Lovett
 
Developing client themes for theme review for WordCamp Edmonton
Developing client themes for theme review for WordCamp EdmontonDeveloping client themes for theme review for WordCamp Edmonton
Developing client themes for theme review for WordCamp Edmonton
Curtis McHale
 
&lt;?php + WordPress
&lt;?php + WordPress&lt;?php + WordPress
&lt;?php + WordPress
Christopher Reding
 
Really Awesome WordPress Plugins You Should Know About
Really Awesome WordPress Plugins You Should Know AboutReally Awesome WordPress Plugins You Should Know About
Really Awesome WordPress Plugins You Should Know About
Angela Bowman
 
Intro to WordPress Plugins
Intro to WordPress PluginsIntro to WordPress Plugins
Intro to WordPress Plugins
zamoose
 
Things you should know about WordPress (but were always too afraid to ask): W...
Things you should know about WordPress (but were always too afraid to ask): W...Things you should know about WordPress (but were always too afraid to ask): W...
Things you should know about WordPress (but were always too afraid to ask): W...
Michael McNeill
 
Deployments in one click!
Deployments in one click!Deployments in one click!
Deployments in one click!
Manuel de la Peña Peña
 
Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016
Ian Wilson
 
WordPress
WordPressWordPress
WordPress
risager
 
2015 rubyconf - 百大媒體網站從 Wordpress 到 Rails 的大小事
2015 rubyconf - 百大媒體網站從 Wordpress 到 Rails 的大小事2015 rubyconf - 百大媒體網站從 Wordpress 到 Rails 的大小事
2015 rubyconf - 百大媒體網站從 Wordpress 到 Rails 的大小事
Ronald Hsu
 
WordPress 4.4 and Beyond
WordPress 4.4 and BeyondWordPress 4.4 and Beyond
WordPress 4.4 and Beyond
Scott Taylor
 
Exploring Content API Options - March 23rd 2016
Exploring Content API Options - March 23rd 2016Exploring Content API Options - March 23rd 2016
Exploring Content API Options - March 23rd 2016
Jani Tarvainen
 
Ryan Markel - WordCamp US 2017
Ryan Markel - WordCamp US 2017Ryan Markel - WordCamp US 2017
Ryan Markel - WordCamp US 2017
ryanmarkel
 
High quality Front-End
High quality Front-EndHigh quality Front-End
High quality Front-End
David Simons
 
A Noob's Journey to the Core
A Noob's Journey to the CoreA Noob's Journey to the Core
A Noob's Journey to the Core
Ryan Welcher
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
Taylor Lovett
 
Wordpress Questions & Answers
Wordpress Questions & AnswersWordpress Questions & Answers
Wordpress Questions & Answers
Nicole Dion
 

Similar to Getting Started with WordPress Development (20)

There's No Crying In Wordpress! (an intro to WP)
There's No Crying In Wordpress! (an intro to WP)There's No Crying In Wordpress! (an intro to WP)
There's No Crying In Wordpress! (an intro to WP)
 
Best practices-wordpress-enterprise
Best practices-wordpress-enterpriseBest practices-wordpress-enterprise
Best practices-wordpress-enterprise
 
WordPress Rest API
WordPress Rest APIWordPress Rest API
WordPress Rest API
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in Enterprise
 
Developing client themes for theme review for WordCamp Edmonton
Developing client themes for theme review for WordCamp EdmontonDeveloping client themes for theme review for WordCamp Edmonton
Developing client themes for theme review for WordCamp Edmonton
 
&lt;?php + WordPress
&lt;?php + WordPress&lt;?php + WordPress
&lt;?php + WordPress
 
Really Awesome WordPress Plugins You Should Know About
Really Awesome WordPress Plugins You Should Know AboutReally Awesome WordPress Plugins You Should Know About
Really Awesome WordPress Plugins You Should Know About
 
Intro to WordPress Plugins
Intro to WordPress PluginsIntro to WordPress Plugins
Intro to WordPress Plugins
 
Things you should know about WordPress (but were always too afraid to ask): W...
Things you should know about WordPress (but were always too afraid to ask): W...Things you should know about WordPress (but were always too afraid to ask): W...
Things you should know about WordPress (but were always too afraid to ask): W...
 
Deployments in one click!
Deployments in one click!Deployments in one click!
Deployments in one click!
 
Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016
 
WordPress
WordPressWordPress
WordPress
 
2015 rubyconf - 百大媒體網站從 Wordpress 到 Rails 的大小事
2015 rubyconf - 百大媒體網站從 Wordpress 到 Rails 的大小事2015 rubyconf - 百大媒體網站從 Wordpress 到 Rails 的大小事
2015 rubyconf - 百大媒體網站從 Wordpress 到 Rails 的大小事
 
WordPress 4.4 and Beyond
WordPress 4.4 and BeyondWordPress 4.4 and Beyond
WordPress 4.4 and Beyond
 
Exploring Content API Options - March 23rd 2016
Exploring Content API Options - March 23rd 2016Exploring Content API Options - March 23rd 2016
Exploring Content API Options - March 23rd 2016
 
Ryan Markel - WordCamp US 2017
Ryan Markel - WordCamp US 2017Ryan Markel - WordCamp US 2017
Ryan Markel - WordCamp US 2017
 
High quality Front-End
High quality Front-EndHigh quality Front-End
High quality Front-End
 
A Noob's Journey to the Core
A Noob's Journey to the CoreA Noob's Journey to the Core
A Noob's Journey to the Core
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
 
Wordpress Questions & Answers
Wordpress Questions & AnswersWordpress Questions & Answers
Wordpress Questions & Answers
 

Recently uploaded

test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
CIOWomenMagazine
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
keoku
 
Bài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docxBài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docx
nhiyenphan2005
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
3ipehhoa
 
Italy Agriculture Equipment Market Outlook to 2027
Italy Agriculture Equipment Market Outlook to 2027Italy Agriculture Equipment Market Outlook to 2027
Italy Agriculture Equipment Market Outlook to 2027
harveenkaur52
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
nirahealhty
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
Javier Lasa
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
ufdana
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
laozhuseo02
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
laozhuseo02
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
JungkooksNonexistent
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
GTProductions1
 

Recently uploaded (20)

test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
 
Bài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docxBài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docx
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
 
Italy Agriculture Equipment Market Outlook to 2027
Italy Agriculture Equipment Market Outlook to 2027Italy Agriculture Equipment Market Outlook to 2027
Italy Agriculture Equipment Market Outlook to 2027
 
This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!This 7-second Brain Wave Ritual Attracts Money To You.!
This 7-second Brain Wave Ritual Attracts Money To You.!
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
Latest trends in computer networking.pptx
Latest trends in computer networking.pptxLatest trends in computer networking.pptx
Latest trends in computer networking.pptx
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
Comptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guideComptia N+ Standard Networking lesson guide
Comptia N+ Standard Networking lesson guide
 

Getting Started with WordPress Development

  • 1. ryan welcher • @ryanwelcher • me@ryanwelcher.com G E T T I N G S TA RT E D W I T H W O R D P R E S S D E V E L O P M E N T RYA N W E L C H E R
  • 2. ryan welcher • @ryanwelcher • me@ryanwelcher.com A B O U T M E • Ryan Welcher - me@ryanwelcher.com • Web Developer for over 10 years • Been working with WordPress since 2009 • Web Engineer at 10up
  • 3. ryan welcher • @ryanwelcher • me@ryanwelcher.com T H I S P R E S E N TAT I O N • Sharing gotcha’s with the noobs :) - where to start and what not to do. • Aimed at developers or designers just getting into WordPress development. • Not an introduction to programming concepts. • Lots of topics, not a lot of depth for each. • Assuming that you can install WordPress and are comfortable looking at PHP. • Open to suggestions.
  • 4. ryan welcher • @ryanwelcher • me@ryanwelcher.com P O S S I B L E TO P I C S • local development server • Vagrant • Varying Vagrant Vagrants • Development plugins • WP_DEBUG • Error handling • Browser tools • Software tools • Getting WordPress core • Coding standards • Documentation • PHPDocs • PHP gotcha’s • Single vs double quotes • The White Screen of Death • Defensive development • Shorthand control structures • Ternary operators • Hacking core • Data sanitization • Nonces and security • Actions • Filters • WP_Query • custom post types • custom taxonomies • custom fields • query_posts() • get_posts() • $wpdb • shortcodes • Widgets • Writing a plugin • Plugin headers • Object-oriented programming • Design patterns • Creating a theme • Creating a child theme • Theme template hierarchy • Enqueueing JS/CSS correctly • AJAX • JSON • The Command line • WP_CLI • Bash scripting • Grunt • my head just exploded…
  • 5. ryan welcher • @ryanwelcher • me@ryanwelcher.com
  • 6. ryan welcher • @ryanwelcher • me@ryanwelcher.com A C T U A L TO P I C S • Setting up • Tools • Local Development Server • Getting WordPress Core • WordPress file structure • Setting up WP_DEBUG • Development Plugins • PHP • General PHP • The White Screen of Death • Defensive Development • Single vs Double Quotes • Shorthand Control Structures • Ternary Operators • WordPress • Where does my code go? • Hacking Core • Hooks • Path Helper Methods • Adding Javascript and CSS correctly • jQuery no-conflict mode • The Loop • Creating secondary loops • Resource Links
  • 7. ryan welcher • @ryanwelcher • me@ryanwelcher.com S E T T I N G U P
  • 8. ryan welcher • @ryanwelcher • me@ryanwelcher.com
  • 9. ryan welcher • @ryanwelcher • me@ryanwelcher.com TO O L S • Code Editor / IDE ( Integrated Development Environment ) • Theme/Plugin editor in WordPress is too volatile! • No word processing software. • Software: • Sublime Text - www.sublimetext.com • Dreamweaver - www.adobe.com • TextMate - macromates.com • Phpstorm - www.jetbrains.com
  • 10. ryan welcher • @ryanwelcher • me@ryanwelcher.com TO O L S • FTP (File Transfer Protocol) software. • Copy files to and from a remote server. • Software: • Transmit - panic.com/transmit • FileZilla - filezilla-project.org • Fetch - fetchsoftworks.com • Beyond Compare - www.scootersoftware.com
  • 11. ryan welcher • @ryanwelcher • me@ryanwelcher.com TO O L S • Web Browser Tools • Will help with debugging in the browser - i.e Javascript errors. • Most modern browsers have tools either built-in or easily installed. • Usually right clicking and choosing “inspect element” will open the tools. • Internet Explorer - press F12 • FireFox - Install FireBug add-on first.
  • 12. ryan welcher • @ryanwelcher • me@ryanwelcher.com L O C A L D E V E L O P M E N T S E RV E R • Why set one up? • Gives you a safe “sandbox” to make mistakes with your code. • Proper debugging configuration. • Saves time vs FTP upload* • How do I set one up? • MAMP - www.mamp.info • WAMP - www.wampserver.com • Vagrant and VVV ( Varying Vagrant Vagrants )
  • 13. ryan welcher • @ryanwelcher • me@ryanwelcher.com G E T T I N G W O R D P R E S S C O R E
  • 14. F I L E S T R U C T U R E • wp-config.php - contains your website’s base configuration details such as database connection info. • wp-content - contains all of the plugins, themes and uploaded content. • Everything else is WordPress core and should be left alone.
  • 15. ryan welcher • @ryanwelcher • me@ryanwelcher.com W P _ D E B U G Open wp-config.php and change this…
  • 16. ryan welcher • @ryanwelcher • me@ryanwelcher.com W P _ D E B U G E D I T I N G W P - C O N F I G : H T T P : / / C O D E X . W O R D P R E S S . O R G / E D I T I N G _ W P - C O N F I G . P H P To this.
  • 17. ryan welcher • @ryanwelcher • me@ryanwelcher.com P L U G I N S • Developer - https://wordpress.org/plugins/developer/ • Helps you optimize your development environment by making sure that you have all the essential tools and plugins installed. • Log Deprecated Notices - https://wordpress.org/plugins/log-deprecated- notices/ • Logs the usage of deprecated files, functions, and function arguments, and identifies where the deprecated functionality is being used. • Debug Bar - https://wordpress.org/plugins/debug-bar/ • Adds a debug menu to the admin bar that shows query, cache, and other helpful debugging information. • Lots of add-on plugins available
  • 18. ryan welcher • @ryanwelcher • me@ryanwelcher.com S TA RT D E V E L O P I N G
  • 19. ryan welcher • @ryanwelcher • me@ryanwelcher.com
  • 20. ryan welcher • @ryanwelcher • me@ryanwelcher.com G E N E R A L P H P • PHP variables must start with a $ followed by a letter or underscore • Valid: $foo, $_foo • Invalid: _foo, $123_foo, $!foo • Don’t use shorthand PHP tags • Good: <?php … ?> • Bad : <?= … ?> or <? … ?> • Your php.ini file may not allow shorthand tags and will cause a world of hurt. • PHP lines must always end with a semi-colon. • You’ll know if you forgot one … duh duh duhhhhhh.
  • 21. ryan welcher • @ryanwelcher • me@ryanwelcher.com W H I T E S C R E E N O F D E AT H
  • 22. ryan welcher • @ryanwelcher • me@ryanwelcher.com W H I T E S C R E E N O F D E AT H • Check your syntax • Missing a $ or invalid variable name. • Missing semi-colon. • Missing a curly brace. • Too many or not enough parens. • Check your debug.log file in wp-content folder. • The last line will give you a file name and line number. • PHP {ERROR _TYPE}: { ERROR_DESC } in { FILENAME } on line { # } • PHP Parse error : syntax error, unexpected ‘=‘ in / … /functions.php on line 62
  • 23. ryan welcher • @ryanwelcher • me@ryanwelcher.com W H I T E S C R E E N O F D E AT H
  • 24. ryan welcher • @ryanwelcher • me@ryanwelcher.com D E F E N S I V E D E V E L O P M E N T • Planning for and handling failure. • Checking all the things BEFORE using them. • Example functions: • isset() • gettype() • empty() • function_exists() • defined() • is_wp_error() • WordPress functions can return on failure: • False • WP_Error object
  • 25. ryan welcher • @ryanwelcher • me@ryanwelcher.com D E F E N S I V E D E V E L O P M E N T
  • 26. ryan welcher • @ryanwelcher • me@ryanwelcher.com D E F E N S I V E D E V E L O P M E N T
  • 27. ryan welcher • @ryanwelcher • me@ryanwelcher.com D E F E N S I V E D E V E L O P M E N T
  • 28. ryan welcher • @ryanwelcher • me@ryanwelcher.com S I N G L E V S D O U B L E Q U O T E S • Double quotes parse variables as their value. • Use single quotes unless you have something to parse.
  • 29. S H O RT H A N D C O N T R O L S T R U C T U R E S • if, while, foreach, etc statements without the curly braces. • Nice for switching between PHP and HTML cleanly. • Gotcha - IDE’s will not catch errors.
  • 30. ryan welcher • @ryanwelcher • me@ryanwelcher.com S H O RT H A N D C O N T R O L S T R U C T U R E S
  • 31. ryan welcher • @ryanwelcher • me@ryanwelcher.com S H O RT H A N D C O N T R O L S T R U C T U R E S
  • 32. ryan welcher • @ryanwelcher • me@ryanwelcher.com T E R N A RY O P E R ATO R S • Single line if/else statement • Handy for variable assignment • Format: ( if statement is true ) ? do this : else, do this;
  • 33. ryan welcher • @ryanwelcher • me@ryanwelcher.com W O R D P R E S S
  • 34. ryan welcher • @ryanwelcher • me@ryanwelcher.com W H E R E D O E S M Y C O D E G O ? • Plugins • wp-content • plugins • your-plugin • your-plugin.php • Themes • wp-content • themes • your-theme • functions.php
  • 35. ryan welcher • @ryanwelcher • me@ryanwelcher.com H A C K I N G C O R E
  • 36. ryan welcher • @ryanwelcher • me@ryanwelcher.com H A C K I N G C O R E • What? • Make code changes to files outside of the wp-content folder. • Also applies to downloaded themes/plugins. • Why not? • Site is no longer future-proof. • Compatibility issues with other plugins/themes. • May introduce security holes. • When core/theme/plugin updates, your changes are gone! • Your hacking what plugins are meant to do - use hooks instead.
  • 37. ryan welcher • @ryanwelcher • me@ryanwelcher.com H O O K S • Provided by WordPress to allow us to 'hook' our code into the rest of WordPress Core. • A hook is a function that invokes an event that triggers all other functions hooked into that event. • 2 Kinds of hooks: • Actions - Points in the code where WordPress gives us the ability to add tasks. • Filters - Allow us to edit content/data before it’s output.
  • 38. ryan welcher • @ryanwelcher • me@ryanwelcher.com A C T I O N S • has_action() • add_action() • do_action() • do_action_ref_array() • did_action() • remove_action() • remove_all_actions() • doing_action() A C T I O N S : H T T P : / / C O D E X . W O R D P R E S S . O R G / P L U G I N _ A P I / A C T I O N _ R E F E R E N C E
  • 39. ryan welcher • @ryanwelcher • me@ryanwelcher.com A C T I O N S • do_action( $tag, $arg … ) • Invokes an action. • Use to invoke your own actions. • add_action( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) • Hooks into an action invoked by do_action(). • remove_action( $tag, $function_to_remove, $priority ) • removes a function from an invoked action. • arguments must match the add_action call exactly.
  • 40. ryan welcher • @ryanwelcher • me@ryanwelcher.com A C T I O N S
  • 41. ryan welcher • @ryanwelcher • me@ryanwelcher.com A C T I O N S
  • 42. ryan welcher • @ryanwelcher • me@ryanwelcher.com F I LT E R S : H T T P : / / C O D E X . W O R D P R E S S . O R G / P L U G I N _ A P I / F I LT E R _ R E F E R E N C E • has_filter() • add_filter() • apply_filters() • apply_filters_ref_array() • current_filter() • remove_filter() • remove_all_filters() • doing_filter() F I LT E R S
  • 43. ryan welcher • @ryanwelcher • me@ryanwelcher.com F I LT E R S • apply_filters( $tag, $value, $var … ) • Invokes a filter. • Returns the result of $value after all hooked functions are applied to it. • Use to invoke your own filters. • add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) • Hooks into a filter invoked by apply_filter(). • $function_to_add always takes a parameter and must return data. • remove_filter( $tag, $function_to_remove, $priority ) • removes a function from an invoked filter. • arguments must match the add_filter call exactly.
  • 44. ryan welcher • @ryanwelcher • me@ryanwelcher.com F I LT E R S
  • 45. ryan welcher • @ryanwelcher • me@ryanwelcher.com F I LT E R S
  • 46. ryan welcher • @ryanwelcher • me@ryanwelcher.com PAT H H E L P E R M E T H O D S Let WordPress do the work for you!
  • 47. ryan welcher • @ryanwelcher • me@ryanwelcher.com PAT H H E L P E R M E T H O D S • Plugins • plugins_url() • plugin_dir_url() • plugin_dir_path() • plugin_basename() • Themes • get_template_directory_uri() • get_stylesheet_directory_uri() • get_stylesheet_uri() • get_theme_root_uri() • get_theme_root() • get_theme_roots() • get_stylesheet_directory() • get_template_directory() • Site Home • home_url() • get_home_path() • WordPress • admin_url() • site_url() • content_url() • includes_url() • wp_upload_dir() • get_bloginfo()
  • 48. ryan welcher • @ryanwelcher • me@ryanwelcher.com A D D I N G J S A N D C S S C O R R E C T LY • wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ) • Handles dependencies, load order and duplication of files. • wp_enqueue_style( $handle, $src, $deps, $ver, $media ) • Both are used with the wp_enqueue_scripts action for the front-end. • Other hooks • admin_enqueue_scripts • login_enqueue_scripts
  • 49. ryan welcher • @ryanwelcher • me@ryanwelcher.com A D D I N G J S A N D C S S C O R R E C T LY
  • 50. ryan welcher • @ryanwelcher • me@ryanwelcher.com J Q U E RY N O - C O N F L I C T • WordPress loads it’s version of jQuery in no-conflict mode to play nicely with other libraries. • $ shorthand is replaced with jQuery
  • 51. ryan welcher • @ryanwelcher • me@ryanwelcher.com T H E L O O P • “The Loop” is the main process of WordPress. • You use The Loop in your template files to show content to visitors. • Any HTML or PHP code in The Loop will be processed on each post. • There are special functions or Template Tags that are meant to be used inside The Loop. • The Loop uses global variables called $wp_query and $post behind the scenes.
  • 52. ryan welcher • @ryanwelcher • me@ryanwelcher.com T H E L O O P
  • 53. ryan welcher • @ryanwelcher • me@ryanwelcher.com T E M P L AT E TA G S • the_category() • the_title() • the_title_attribute() • the_meta() • the_content() • the_excerpt() • the_permalink() • the_ID() • the_tags() • the_date() • the_time() • the_shortlink()
  • 54. ryan welcher • @ryanwelcher • me@ryanwelcher.com C R E AT I N G S E C O N D A RY L O O P S • As a developer you will be creating secondary loops all the time. • 3 options to create secondary loop: • query_posts() • get_posts() • WP_Query Class • We have to be careful not to interfere with “The Loop”.
  • 55. ryan welcher • @ryanwelcher • me@ryanwelcher.com C R E AT I N G S E C O N D A RY L O O P S • query_posts() • Don’t use this, even the Codex says you shouldn’t. • Inefficient. • Alters The Loop. • If that’s your goal, use the pre_get_posts hook instead. • If you have to use it, always call wp_reset_query() afterwards to reset The Loop.
  • 56. ryan welcher • @ryanwelcher • me@ryanwelcher.com C R E AT I N G S E C O N D A RY L O O P S • get_posts( $args ) • Safe to use anywhere. • $args can be a string or an associative array. • Returns an array of WP_Post objects. • Need to use setup_postdata() in order to have access to Template Tags like the_title() and the_content() • You must pass $post to setup_postdata() no other variable name will work. • It will change the global $post variable used by The Loop. • Must be followed by a call to wp_reset_postdata() to reset the global $post variable.
  • 57. ryan welcher • @ryanwelcher • me@ryanwelcher.com C R E AT I N G S E C O N D A RY L O O P S
  • 58. ryan welcher • @ryanwelcher • me@ryanwelcher.com C R E AT I N G S E C O N D A RY L O O P S • WP_Query Class • Powers both query_posts() and get_posts() behind the scenes. • You can create your own instances and use them safely anywhere. • Less restrictive but more complicated. • Methods: • have_posts() • the_post() • will change the global $post variable used by The Loop. • Must be followed by a call to wp_reset_postdata() to reset the global $post variable.
  • 59. ryan welcher • @ryanwelcher • me@ryanwelcher.com C R E AT I N G S E C O N D A RY L O O P S
  • 60. ryan welcher • @ryanwelcher • me@ryanwelcher.com L E A R N I N G R E S O U R C E S • The Codex - codex.wordpress.org • WordPress Stack Exchange - wordpress.stackexchange.com • WordPress Support Forums - wordpress.org/support • WordPress Core • WordPress coding standards - make.wordpress.org/core/handbook/coding- standards/ • PHP Documentation - php.net/manual/en • lynda.com • Tuts+ - http://tutsplus.com/
  • 61. ryan welcher • @ryanwelcher • me@ryanwelcher.com T H A N K Y O U !