Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Things you should know about WordPress (but were always too afraid to ask): WordCamp Raleigh 2014


Published on

This talk will cover a few key “Aha” moments that you should have about the way WordPress works. We’ll talk about things like the template hierarchy, where WordPress content is stored, how posts and pages and custom post types are represented in the database, what folks are talking about when they talk about hooks and filters, and just generally review the “behind the scenes” mechanics of how WordPress works. We’ll also touch on a few “tricks of the trade” that you might not realize are out there, mainly version control, development environments, and Vagrant.

Published in: Technology
  • Be the first to comment

Things you should know about WordPress (but were always too afraid to ask): WordCamp Raleigh 2014

  1. 1. THINGS YOU SHOULD KNOW ABOUT WORDPRESS (but were always afraid to ask) Power Users Track WordCamp Raleigh 2014 Saturday, November 8th, 2014 Michael McNeill - @michaelrmcneill #wcraleigh
  2. 2. ABOUT ME • Developer and Support Engineer in ITS Web Services at the University of North Carolina at Chapel Hill, where I help to manage two HUGE multisite networks that operate a total of almost 8,500+ sites. • Owner and Developer at MRMcDEV, Inc. my personal consulting company. • Co-Curator (Executive Director) of TEDxUNC, a non-profit organization dedicated to bringing “Ideas Worth Spreading” to Carolina. • I’ve been using WordPress for over 5 years now, and I use it for almost all my client projects. • I’ve worked on exciting and wide ranging projects, such as Black Enterprise Magazine, Mackay Communications, WiredHoods,, ALOHA, and MAXI Promotion and Records. I’ve also contracted for DRS Technologies, the United States Department of the Defense, and numerous other companies. @michaelrmcneill #wcraleigh
  3. 3. A QUICK ROADMAP… 1. The WordPress APIs - What they are, how to find them, and how to use them. 2. The WordPress Template Hierarchy - What it is, which file generates a certain type of page, and how to use it to your advantage. 3. The WordPress Database - What is stored there, why it is stored there, how is it stored there, and how should you properly use the data inside it. 4. A few “tricks of the trade” - Version Control and Vagrant @michaelrmcneill #wcraleigh
  4. 4. THE WORDPRESS CODEX @michaelrmcneill #wcraleigh
  5. 5. BOOKMARK IT! @michaelrmcneill #wcraleigh
  6. 6. WHAT IS IT? The WordPress Manual written for all users, Designers and Developers alike. @michaelrmcneill #wcraleigh
  7. 7. USE IT & IMPROVE IT. When you first have a question, go to the Codex first. The Codex is a living document, and anyone with a account can edit it and improve it. If you see something out of date, or flat out wrong, update it. @michaelrmcneill #wcraleigh
  8. 8. THE WORDPRESS APIs @michaelrmcneill #wcraleigh
  9. 9. WHAT’S AN API? • APIs are Application Programming Interfaces. • Think about it like this, APIs are basically a contract between two things stating: "If you tell me this, I will do this.” @michaelrmcneill #wcraleigh
  10. 10. WHAT DO THE WORDPRESS APIs DO? • They help you do things using tools that WordPress gives you. • That makes development EASIER!! @michaelrmcneill #wcraleigh
  11. 11. HOW DO I FIND THEM? • Identify what you are trying to do. • Then go to the ___________ and search for it. • If that doesn’t work, try using Google, just remember to cross-check against what the Codex says. @michaelrmcneill #wcraleigh
  12. 12. HOW DO I USE THEM? • The format is basically the same across all function reference articles. • There are 3 primary sections. 1. The description of the function. 2. The parameters the function wants/needs. 3. What values, if any, the function returns. @michaelrmcneill #wcraleigh
  13. 13. WORDPRESS PAGE LIFE CYCLE • The WordPress page life cycle is a combination of the events that take place from when a browser requests a page to when the server returns the rendered page to the browser. • That sounds simple, but there are a lot of things going on that get you the end result. @michaelrmcneill #wcraleigh
  14. 14. @michaelrmcneill #wcraleigh
  15. 15. WORDPRESS HOOKS • Hooks are extremely important to WordPress developers. • They enable us to literally hook into parts of the WordPress page life cycle to retrieve, insert, and modify data, and they allow us to take certain actions behind the scenes, before a user sees what is occurring. @michaelrmcneill #wcraleigh
  16. 16. WORDPRESS HOOKS @michaelrmcneill #wcraleigh • Two Classifications • Actions • Actions are triggered by specific events that take place in WordPress, such as publishing a post, activating a plugin, or loading an admin screen. • For a comprehensive list of actions, check this Codex article out: • Filters • Filters are functions that WordPress passes data through, that are primarily responsible for intercepting, managing, and returning data, before rendering or saving that data. • For a pretty comprehensive list of filters, check this Codex article out:
  17. 17. WORDPRESS HOOKS • I’m sure you have the question, when should I use which hook? • Use actions when you want to add something to the existing page such as stylesheets, JavaScript, or send an email when an event has happened. • Use filters when you want to manipulate data coming out of the database prior to going to the browser, or coming from the browser prior to going into the database. @michaelrmcneill #wcraleigh
  18. 18. THE WORDPRESS PAGE TEMPLATE HIERARCHY @michaelrmcneill #wcraleigh
  19. 19. WHAT IS THE TEMPLATE HIERARCHY? WordPress templates fit together like the pieces of a puzzle to generate the pages on your WordPress site. Some templates (the header and footer templates for example) are used on almost all pages, while others are used only under specific conditions. The template hierarchy decides what template file or files WordPress will use to display a certain type of page. @michaelrmcneill #wcraleigh
  20. 20. @michaelrmcneill #wcraleigh
  21. 21. LET’S LOOK AT THE BASICS @michaelrmcneill #wcraleigh
  22. 22. THE NEEDS OF A THEME • To have a functioning, bare minimum theme you need two things. • style.css - A stylesheet. • index.php - An index file that will render the output of the page. @michaelrmcneill #wcraleigh
  23. 23. header.php @michaelrmcneill #wcraleigh
  24. 24. footer.php @michaelrmcneill #wcraleigh
  25. 25. single.php @michaelrmcneill #wcraleigh
  26. 26. sidebar.php @michaelrmcneill #wcraleigh
  27. 27. SINGLE POST RULES @michaelrmcneill #wcraleigh 1. single-post.php 2. single.php 3. index.php
  28. 28. PAGE TEMPLATE RULES 1. Custom Template defined in WP Admin 2. page-<slug>.php 3. page-<id>.php 4. page.php 5. index.php @michaelrmcneill #wcraleigh
  29. 29. HOME PAGE TEMPLATE RULES • front-page.php • Settings > Reading • Static Page 1. Follows the page template rules. @michaelrmcneill #wcraleigh • Blog Page 1. home.php 2. index.php
  30. 30. SINGLE CUSTOM POST RULES 1. single-<posttype>.php 2. single.php 3. index.php @michaelrmcneill #wcraleigh
  31. 31. CUSTOM POST TYPE RULES 1. archive-<posttype>.php 2. archive.php 3. index.php @michaelrmcneill #wcraleigh
  32. 32. CATEGORY PAGES 1. category-<slug>.php 2. category-<id>.php 3. category.php 4. archive.php 5. index.php @michaelrmcneill #wcraleigh
  33. 33. TAG PAGES @michaelrmcneill #wcraleigh 1. tag-<slug>.php 2. tag-<id>.php 3. tag.php 4. archive.php 5. index.php
  34. 34. AUTHOR PAGES 1. author-<nicename>.php 2. author-<id>.php 3. author.php 4. archive.php 5. index.php @michaelrmcneill #wcraleigh
  35. 35. ATTACHMENT RULES 1. MIME-type.php (e.x. text.php, video.php, image.php) 2. attachment.php 3. single_attachment.php 4. single.php 5. index.php @michaelrmcneill #wcraleigh
  36. 36. CODEX ARTICLE INTERACTIVE WEBSITE! @michaelrmcneill #wcraleigh
  37. 37. WORDPRESS DATA @michaelrmcneill #wcraleigh
  38. 38. WORDPRESS DATA • A WordPress website consists of three main elements: • The WordPress installation itself • The contents of the wp-content directory which includes the themes, plugins and uploads • The database, where all the content is stored. @michaelrmcneill #wcraleigh
  39. 39. TYPES OF WORDPRESS CONTENT @michaelrmcneill #wcraleigh • posts • pages • custom post types • attachments • links • menu items
  40. 40. ASSOCIATED DATA (POSTMETA) • categories • tags • custom taxonomies and terms • post metadata @michaelrmcneill #wcraleigh
  41. 41. OTHER TYPES OF CONTENT @michaelrmcneill #wcraleigh • widgets • options • users • sites (for multisite)
  42. 42. @michaelrmcneill #wcraleigh
  43. 43. A FEW NOTES… • In the next few slides, I’m using the wp_ prefix by default. You can change this (and you might have), but the concepts are the same. • A multisite installation will have some extra tables. I haven't included those here as that's outside the scope of this presentation. @michaelrmcneill #wcraleigh
  44. 44. THE WORDPRESS DATABASE STRUCTURE Most of the tables in the WordPress database are linked to one or more other tables via a specific field. This field is generally a unique ID for each record such as a post_id. @michaelrmcneill #wcraleigh
  45. 45. THE WORDPRESS DATABASE STRUCTURE TABLE DATA STORED LINKED TO wp_posts Posts, pages, attachments, revisions and menu items @michaelrmcneill #wcraleigh wp_postmeta (using post_id) wp_term_relationships (using post_id) wp_postmeta Post metadata wp_posts (using post_id)
  46. 46. THE WORDPRESS DATABASE STRUCTURE TABLE DATA STORED LINKED TO wp_comments Comments @michaelrmcneill #wcraleigh wp_posts (using post_id) wp_commentmeta (using comment_id) wp_commentmeta Comment metadata wp_comments (using comment_id)
  47. 47. THE WORDPRESS DATABASE STRUCTURE TABLE DATA STORED LINKED TO wp_users Users @michaelrmcneill #wcraleigh wp_posts (using post_author) wp_usermeta (using user_id) wp_usermeta Metadata for each user wp_users (using user_id)
  48. 48. THE WORDPRESS DATABASE STRUCTURE TABLE DATA STORED LINKED TO @michaelrmcneill #wcraleigh wp_links (DEPRECATED!) Information related to Links wp_term_relationships (using link_id) wp_options Site settings and options (set via the Settings screens and via plugins and themes) as well as widgets None
  49. 49. THE WORDPRESS DATABASE STRUCTURE TABLE DATA STORED LINKED TO wp_term_relationships Relationships between posts and taxonomies @michaelrmcneill #wcraleigh wp_posts (using post_id) wp_term_taxonomy (using term_taxonomy_id) wp_term_taxonomy Taxonomies (including categories and tags) wp_term_relationships (using term_taxonomy_id) wp_terms Your categories and tags and the terms assigned to custom taxonomies wp_term_taxonomy (using term_id)
  50. 50. HOW TO USE THE WORDPRESS DB? WordPress defines a class called wpdb, which contains a set of functions used to interact with a database. Its purpose is to provide an easy to use interface with the WordPress database. @michaelrmcneill #wcraleigh
  51. 51. $wpdb Methods in the wpdb() class should not be called directly. You should use the global $wpdb object instead. @michaelrmcneill #wcraleigh
  52. 52. A LARGE WARNING Any function that executes SQL queries, can be vulnerable to SQL injection attacks. To prevent that, you should escape all SQL. Make sure to review the ______ to double-check if the function you plan to use escapes SQL for you or leaves it un-escaped! @michaelrmcneill #wcraleigh
  53. 53. TRICKS OF THE TRADE @michaelrmcneill #wcraleigh
  54. 54. VAGRANT AND VVV A great tutorial: development-varying-vagrant-vagrants/ GIT AND GITHUB Great intro guide and cheat sheet: http:// GitHub: Deploy (Automated Deployment): https:// @michaelrmcneill #wcraleigh
  55. 55. QUESTIONS? @michaelrmcneill #wcraleigh