the struggle is real: developing wordpress plugins · the struggle is real: developing wordpress...

Post on 12-Jul-2020

28 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

The Struggle is Real: Developing WordPress PluginsDaniel Simanek <daniel.simanek@wisc.edu>Research and Graduate Education

Classes

Throwing Things

No Magic

Filter all the Things

Break the(WordPress) Glass

Code like everyoneIs Stupid

Draft Pending Published

Vanilla WordPress Workflow

Draft Pending Published

Hot Swap Workflow

Draft Pending

Parent

Child

Object Classes

lunchbox->num_grapes = 4;

lunchbox->num_grapes = 4;

The programming 101 idea of objects ...

black_box->get_child();

??

Fewer function parameters

Less to remember

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

Function scoping

$this->function_name()

OR

Class_Name::function_name()

OrderAnd

Structure

ReadabilityAnd

Maintainability

PHP Kinda Sucks ...

PHP Kinda Sucks ...

http://phpsadness.com/

Return Value?

What is FALSE as an INT?

Don’t be like PHP ...

and pass errors in return values ...

Throw Exceptions!

and pass errors in return values ...

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

PHP keeps going, no matter what ...

Death by exception

Use Constants

… and not Magic Numbers

What are Magic Numbers?

What are Magic Numbers?

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

if( $x == ‘supercalifragilisticexpialidocious’ )

Why are Magic Numbers bad?

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

if( $x == ‘supercalifragilisticexpialidocious’ )

Why are Magic Numbers bad?

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

if( $x == $song_name )

Magic Numbers, WordPress Style

$cat_id = 7;

$user_id = 64;

$post_id = 527;

Two versions of Constants

Global

Class

BYO Filters

apply_filters( ‘name_of_my_filter’, $value_to_be_filtered );

e.g.

apply_filters( ‘hot_swap/use_cloning’, $cloning_enabled );

Using apply_filters()

hot_swap/use_cloning

Naming Filters

my_awesome_plugin/options/save

hot_pocket/remove_from_microwave

search_plugin/results

hot_swap/excluded_post_types

Only call apply_filters() once per filter

Break out of WordPress

Code like everyone is stupid

Code like everyone is stupid

Objects/classes

Code like everyone is stupid

Objects/classes

Throwing exceptions

Code like everyone is stupid

Objects/classes

Throwing exceptions

Constants

Questions?

The Struggle is Real: Developing WordPress PluginsDaniel Simanek <daniel.simanek@wisc.edu>Research and Graduate Education

top related