Slide 1

Slide 1 text

YOU, TOO, CAN WRITE A PLUGIN ALISON BARRETT WORDCAMP ALBUQUERQUE 2013

Slide 2

Slide 2 text

YOUR FIRST PLUGIN

Slide 3

Slide 3 text

GOAL ✤ Show up on the plugins page

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

✤ Making a plugin is easy! ✤ Even the pros use Google. WHAT WE LEARNED

Slide 7

Slide 7 text

THE END QUESTIONS? JK, LOL

Slide 8

Slide 8 text

*THE FIRST ONE THAT ACTUALLY DOES SOMETHING YOUR SECOND PLUGIN*

Slide 9

Slide 9 text

GOALS ✤ Put an author bio at the end of every post ✤ Use the bio field from the author's profile ✤ Show the author's gravatar ✤ Only show on single posts

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Slide 13

Slide 13 text

function  saaba_insert_bio(  $content  )  {        global  $post;        $bio_text  =  wpautop(  get_user_meta(  $post-­‐>post_author,  'description',  true  )  );        $author_bio  =  '
'  .  $bio_text  .  '
';        $content  .=  $author_bio;        return  $content; } add_filter(  'the_content',  'saaba_insert_bio'  );

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

$bio_text  =  wpautop(  get_user_meta(  $post-­‐>post_author,  'description',  true  )  ); $avatar      =  get_avatar(  $post-­‐>post_author,  72  );

Slide 16

Slide 16 text

ob_start(); ?>
       
                       
       
                       

Slide 17

Slide 17 text

ob_start(); ?>
       
                       
       
                       

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

function  saaba_styles()  {        $plugin_url  =  plugins_url(  '',  __FILE__  );        wp_enqueue_style(  'saaba',  $plugin_url  .  '/saaba-­‐style.css'  ); } add_action(  'wp_enqueue_scripts',  'saaba_styles'  );

Slide 20

Slide 20 text

.saaba-­‐author-­‐bio  {        background:  #ffffe0;        border:  1px  solid  #ebe5a6;        padding:  10px;        margin:  20px  auto; } .saaba-­‐gravatar  {        float:  left;        margin-­‐right:  10px; }

Slide 21

Slide 21 text

$bio_text        =  wpautop(  get_user_meta(  $post-­‐>post_author,  'description',  true  )  ); $avatar            =  get_avatar(  $post-­‐>post_author,  72  ); $author_name  =  get_user_meta(  $post-­‐>post_author,  'nickname',  true  );

Slide 22

Slide 22 text

       
                       
       
               

About  

                       

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

function  saaba_insert_bio(  $content  )  {        if  (  !  is_single()  )  {                return  $content;        }        global  $post;        $bio_text        =  wpautop(  get_user_meta(  $post-­‐>post_author,  'description',  true  )  );        $avatar            =  get_avatar(  $post-­‐>post_author,  72  );        $author_name  =  get_user_meta(  $post-­‐>post_author,  'nickname',  true  );

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

WHAT WE LEARNED ✤ Use hooks in plugins to extend WordPress functionality. ✤ Enqueue your stylesheets (same goes for Javascript files).

Slide 28

Slide 28 text

PRO TIPS

Slide 29

Slide 29 text

PLUGIN FILE STRUCTURE ✤ Folder and main plugin file should have the same name (which should match the plugin slug). ✤ If there are a lot of files, use subfolders!

Slide 30

Slide 30 text

WORDPRESS DOES A LOT ✤ Formatting functions: wp-includes/formatting.php ✤ Escaping functions: wp-includes/formatting.php

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

WORDPRESS DOES A LOT ✤ Have no fear! Read code!

Slide 34

Slide 34 text

APIS TO KNOW ✤ Widget API ✤ Settings API ✤ HTTP API ✤ Rewrite API

Slide 35

Slide 35 text

WHAT SHOULD MY PLUGIN DO? ✤ Unique need on a client site? It could be useful to more people. ✤ Something you want to do on your own blog? Others might want to do it too! ✤ Want to learn something new? Make it a plugin & release it.

Slide 36

Slide 36 text

SOME OF MY FIRST PLUGINS ✤ Sidebar widget that listed pages in different colored links ✤ Wowhead search engine sidebar widget ✤ Store locator using Google Maps and custom database tables

Slide 37

Slide 37 text

THE END (FOR REALS) @ALISOTHEGEEK HTTP://ALISO.ME/MYFIRSTPLUGIN