Slide 1

Slide 1 text

What I Wish I’d Known When I Started Erick Hitter @ethitter https://ethitter.com/

Slide 2

Slide 2 text

FIRST Can’t check if the user’s logged in until init

Slide 3

Slide 3 text

SECOND The query isn’t available until wp

Slide 4

Slide 4 text

THIRD Never build a manual link again

Slide 5

Slide 5 text

Link Functions •get_permalink()   •get_page_by_path(  'about'  )   •get_post_type_archive_link(  'waffles'  )   •user_trailingslashit()   •get_year_link()   •get_adjacent_post()

Slide 6

Slide 6 text

Link Functions •add_query_arg()   •remove_query_arg()

Slide 7

Slide 7 text

Link Functions •home_url(  '/'  )
 
 
 
 Many more in
 wp-­‐includes/link-­‐template.php.

Slide 8

Slide 8 text

FOURTH Escaping and Sanitization

Slide 9

Slide 9 text

FIFTH Nonces

Slide 10

Slide 10 text

SIXTH Ajax is easy with WordPress

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Ajax •wp_ajax_{$your_action}   •wp_ajax_nopriv_{$your_action}   • Hook to both if logged-in state isn’t relevant.

Slide 13

Slide 13 text

SEVENTH Database Interactions

Slide 14

Slide 14 text

Database Interactions • Use custom post types and custom taxonomies instead. • If you must, always $wpdb-­‐>prepare() your queries.

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

EIGHTH Enqueue All The Things

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Enqueue! •wp_enqueue_style()   •wp_enqueue_script()

Slide 19

Slide 19 text

But why? • Reusable • Dependencies • Versioning • Minification • Concatenation • CDN

Slide 20

Slide 20 text

NINTH Cache All The Things

Slide 21

Slide 21 text

Caching • Transients • Object Cache

Slide 22

Slide 22 text

TENTH Remote Requests

Slide 23

Slide 23 text

WP HTTP API •wp_remote_get()   •wp_remote_post()   •wp_remote_head()   •wp_remote_request()   •wp_remote_retrieve_response_code()

Slide 24

Slide 24 text

ELEVENTH Miscellany

Slide 25

Slide 25 text

Miscellany •get_queried_object()   •get_queried_object_id()   •wp_parse_args()

Slide 26

Slide 26 text

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