The Struggle is Real: Developing WordPress Plugins Daniel Simanek - - PowerPoint PPT Presentation

the struggle is real developing wordpress plugins
SMART_READER_LITE
LIVE PREVIEW

The Struggle is Real: Developing WordPress Plugins Daniel Simanek - - PowerPoint PPT Presentation

The Struggle is Real: Developing WordPress Plugins Daniel Simanek <daniel.simanek@wisc.edu> Research and Graduate Education Throwing Things Classes Filter all the Things No Magic Code like everyone Is Stupid Break the (WordPress)


slide-1
SLIDE 1

The Struggle is Real: Developing WordPress Plugins

Daniel Simanek <daniel.simanek@wisc.edu> Research and Graduate Education

slide-2
SLIDE 2

Classes Throwing Things

slide-3
SLIDE 3

No Magic Filter all the Things

slide-4
SLIDE 4

Break the (WordPress) Glass Code like everyone Is Stupid

slide-5
SLIDE 5

Draft Pending Published Vanilla WordPress Workflow

slide-6
SLIDE 6

Draft Pending Published Hot Swap Workflow Draft Pending

Parent Child

slide-7
SLIDE 7

Object Classes

slide-8
SLIDE 8

lunchbox->num_grapes = 4;

slide-9
SLIDE 9

lunchbox->num_grapes = 4; The programming 101 idea of objects ...

slide-10
SLIDE 10

black_box->get_child();

slide-11
SLIDE 11
slide-12
SLIDE 12
slide-13
SLIDE 13
slide-14
SLIDE 14

??

slide-15
SLIDE 15
slide-16
SLIDE 16
slide-17
SLIDE 17
slide-18
SLIDE 18
slide-19
SLIDE 19
slide-20
SLIDE 20

Fewer function parameters Less to remember

slide-21
SLIDE 21

Function scoping

plugin_function_prefix_function_name() plugin_function_prefix_foo() plugin_function_prefix_bar() plugin_function_prefix_foo_bar() plugin_function_prefix_example() plugin_function_prefix_test() plugin_function_prefix_do_something() plugin_function_prefix_my_amazing_function()

slide-22
SLIDE 22

Function scoping

$this->function_name() OR Class_Name::function_name()

slide-23
SLIDE 23

Order And Structure

slide-24
SLIDE 24

Readability And Maintainability

slide-25
SLIDE 25
slide-26
SLIDE 26

PHP Kinda Sucks ...

slide-27
SLIDE 27

PHP Kinda Sucks ...

http://phpsadness.com/

slide-28
SLIDE 28
slide-29
SLIDE 29

Return Value?

slide-30
SLIDE 30

What is FALSE as an INT?

slide-31
SLIDE 31
slide-32
SLIDE 32

Don’t be like PHP ...

slide-33
SLIDE 33

and pass errors in return values ...

slide-34
SLIDE 34

Throw Exceptions! and pass errors in return values ...

slide-35
SLIDE 35

What does PHP do if I don’t check for errors?

slide-36
SLIDE 36

PHP keeps going, no matter what ...

slide-37
SLIDE 37

Death by exception

slide-38
SLIDE 38

Use Constants

slide-39
SLIDE 39

… and not Magic Numbers

slide-40
SLIDE 40

What are Magic Numbers?

slide-41
SLIDE 41

What are Magic Numbers?

if( $x == 32 ) for( range( 1, 52 ) as $card ) if( $x == ‘supercalifragilisticexpialidocious’ )

slide-42
SLIDE 42

Why are Magic Numbers bad?

if( $x == 32 ) for( range( 1, 52 ) as $card ) if( $x == ‘supercalifragilisticexpialidocious’ )

slide-43
SLIDE 43

Why are Magic Numbers bad?

if( $x == $freezing_point ) for( range( 1, $deck_size ) as $card ) if( $x == $song_name )

slide-44
SLIDE 44

Magic Numbers, WordPress Style

$cat_id = 7; $user_id = 64; $post_id = 527;

slide-45
SLIDE 45

Two versions of Constants

Global Class

slide-46
SLIDE 46

BYO Filters

slide-47
SLIDE 47
slide-48
SLIDE 48

apply_filters( ‘name_of_my_filter’, $value_to_be_filtered ); e.g. apply_filters( ‘hot_swap/use_cloning’, $cloning_enabled );

Using apply_filters()

slide-49
SLIDE 49

hot_swap/use_cloning

Naming Filters

my_awesome_plugin/options/save hot_pocket/remove_from_microwave search_plugin/results hot_swap/excluded_post_types

slide-50
SLIDE 50

Only call apply_filters() once per filter

slide-51
SLIDE 51

Break out of WordPress

slide-52
SLIDE 52
slide-53
SLIDE 53
slide-54
SLIDE 54
slide-55
SLIDE 55

Code like everyone is stupid

slide-56
SLIDE 56

Code like everyone is stupid

Objects/classes

slide-57
SLIDE 57

Code like everyone is stupid

Objects/classes Throwing exceptions

slide-58
SLIDE 58

Code like everyone is stupid

Objects/classes Throwing exceptions Constants

slide-59
SLIDE 59

Questions?

slide-60
SLIDE 60

The Struggle is Real: Developing WordPress Plugins

Daniel Simanek <daniel.simanek@wisc.edu> Research and Graduate Education