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) Glass
Vanilla WordPress Workflow Pending Draft Published
Hot Swap Workflow Pending Draft Published Parent Pending Draft 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_example() plugin_function_prefix_foo_bar() plugin_function_prefix_bar() 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()
Order And Structure
Readability And 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 ...
and pass errors in return values ... Throw Exceptions!
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’ )
if( $x == 32 ) for( range( 1, 52 ) as $card ) if( $x == ‘supercalifragilisticexpialidocious’ ) Why are Magic Numbers bad?
Why are Magic Numbers bad? for( range( 1, $deck_size ) as $card ) if( $x == $freezing_point ) if( $x == $song_name )
Magic Numbers, WordPress Style $cat_id = 7; $post_id = 527; $user_id = 64;
Two versions of Constants Global Class
BYO Filters
Using apply_filters() apply_filters( ‘name_of_my_filter’, $value_to_be_filtered ); e.g. apply_filters( ‘hot_swap/use_cloning’, $cloning_enabled );
Naming Filters hot_swap/excluded_post_types hot_swap/use_cloning my_awesome_plugin/options/save search_plugin/results hot_pocket/remove_from_microwave
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 Constants Objects/classes Throwing exceptions
Questions?
The Struggle is Real: Developing WordPress Plugins Daniel Simanek <daniel.simanek@wisc.edu> Research and Graduate Education
Recommend
More recommend