SlideShare une entreprise Scribd logo
1  sur  61
Télécharger pour lire hors ligne
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 !

Contenu connexe

Tendances

How to: Reporting Issues
How to: Reporting IssuesHow to: Reporting Issues
How to: Reporting IssuesJohn Havlik
 
Schema Markup Basics - Pubcon 2017
Schema Markup Basics - Pubcon 2017Schema Markup Basics - Pubcon 2017
Schema Markup Basics - Pubcon 2017Carrie 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 designMarsh Gardiner
 
Pragmatic REST APIs
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIsamesar0
 
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
 
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 + AngularTracy 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 & GutenbergRoy Sivan
 
Kiran karnad rtc2014 ghdb-final
Kiran karnad rtc2014 ghdb-finalKiran karnad rtc2014 ghdb-final
Kiran karnad rtc2014 ghdb-finalRomania Testing
 

Tendances (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
 

Similaire à 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 APIBrian Layman
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseTaylor 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 EdmontonCurtis McHale
 
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 AboutAngela Bowman
 
Intro to WordPress Plugins
Intro to WordPress PluginsIntro to WordPress Plugins
Intro to WordPress Pluginszamoose
 
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
 
Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Ian Wilson
 
WordPress
WordPressWordPress
WordPressrisager
 
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 BeyondScott 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 2016Jani Tarvainen
 
Ryan Markel - WordCamp US 2017
Ryan Markel - WordCamp US 2017Ryan Markel - WordCamp US 2017
Ryan Markel - WordCamp US 2017ryanmarkel
 
High quality Front-End
High quality Front-EndHigh quality Front-End
High quality Front-EndDavid 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 CoreRyan Welcher
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPressTaylor Lovett
 
Wordpress Questions & Answers
Wordpress Questions & AnswersWordpress Questions & Answers
Wordpress Questions & AnswersNicole Dion
 

Similaire à 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
 

Dernier

Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024APNIC
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Servicegwenoracqe6
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLimonikaupta
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Standkumarajju5765
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGAPNIC
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceDelhi Call girls
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Call Girls in Nagpur High Profile
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableSeo
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Delhi Call girls
 

Dernier (20)

Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
DDoS In Oceania and the Pacific, presented by Dave Phelan at NZNOG 2024
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night StandHot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
Hot Call Girls |Delhi |Hauz Khas ☎ 9711199171 Book Your One night Stand
 
Networking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOGNetworking in the Penumbra presented by Geoff Huston at NZNOG
Networking in the Penumbra presented by Geoff Huston at NZNOG
 
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...Top Rated  Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
Top Rated Pune Call Girls Daund ⟟ 6297143586 ⟟ Call Me For Genuine Sex Servi...
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 

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 !