What I Wish I'd Known When I Started

What I Wish I'd Known When I Started

WordPress provides many convenient functions, perhaps too many. All too often, new developers reinvent the wheel, as the cliche goes, when Core already has a function or utility to accomplish the same. Five years on and thinking back to when I started building WordPress plugins, I could’ve saved a lot of time and avoided a lot of anxiety if I’d known where to look.


Erick Hitter

June 13, 2015


  1. What I Wish I’d Known When I Started Erick Hitter

    @ethitter https://ethitter.com/
  2. FIRST Can’t check if the user’s logged in until init

  3. SECOND The query isn’t available until wp

  4. THIRD Never build a manual link again

  5. Link Functions •get_permalink()   •get_page_by_path(  'about'  )   •get_post_type_archive_link(  'waffles'

     )   •user_trailingslashit()   •get_year_link()   •get_adjacent_post()
  6. Link Functions •add_query_arg()   •remove_query_arg()

  7. Link Functions •home_url(  '/'  )
 Many more

  8. FOURTH Escaping and Sanitization

  9. FIFTH Nonces

  10. SIXTH Ajax is easy with WordPress

  11. Ajax • Hook your function to one of two variable

    actions • Use the same action name with the request to admin-­‐ajax.php •check_ajax_referer() or use a nonce
  12. Ajax •wp_ajax_{$your_action}   •wp_ajax_nopriv_{$your_action}   • Hook to both if

    logged-in state isn’t relevant.
  13. SEVENTH Database Interactions

  14. Database Interactions • Use custom post types and custom taxonomies

    instead. • If you must, always $wpdb-­‐>prepare() your queries.
  15. Database Interactions •$wpdb-­‐>get_var()   •$wpdb-­‐>get_col()   •$wpdb-­‐>get_row()   •$wpdb-­‐>insert(  $table,

     $data,  $format  )   •$wpdb-­‐>update(  $table,  $data,  $where,   $format,  $where_format  )   •$wpdb-­‐>query()
  16. EIGHTH Enqueue All The Things

  17. Register, then enqueue! •wp_register_style()   •wp_register_script()

  18. Enqueue! •wp_enqueue_style()   •wp_enqueue_script()

  19. But why? • Reusable • Dependencies • Versioning • Minification

    • Concatenation • CDN
  20. NINTH Cache All The Things

  21. Caching • Transients • Object Cache

  22. TENTH Remote Requests

  23. WP HTTP API •wp_remote_get()   •wp_remote_post()   •wp_remote_head()   •wp_remote_request()

  24. ELEVENTH Miscellany

  25. Miscellany •get_queried_object()   •get_queried_object_id()   •wp_parse_args()

  26. Thanks Erick Hitter @ethitter https://ethitter.com/ https://eth.pw/wcywg15