the struggle is real: developing wordpress plugins · the struggle is real: developing wordpress...
TRANSCRIPT
![Page 1: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/1.jpg)
The Struggle is Real: Developing WordPress PluginsDaniel Simanek <[email protected]>Research and Graduate Education
![Page 2: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/2.jpg)
Classes
Throwing Things
![Page 3: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/3.jpg)
No Magic
Filter all the Things
![Page 4: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/4.jpg)
Break the(WordPress) Glass
Code like everyoneIs Stupid
![Page 5: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/5.jpg)
Draft Pending Published
Vanilla WordPress Workflow
![Page 6: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/6.jpg)
Draft Pending Published
Hot Swap Workflow
Draft Pending
Parent
Child
![Page 7: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/7.jpg)
Object Classes
![Page 8: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/8.jpg)
lunchbox->num_grapes = 4;
![Page 9: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/9.jpg)
lunchbox->num_grapes = 4;
The programming 101 idea of objects ...
![Page 10: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/10.jpg)
black_box->get_child();
![Page 11: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/11.jpg)
![Page 12: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/12.jpg)
![Page 13: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/13.jpg)
![Page 14: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/14.jpg)
??
![Page 15: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/15.jpg)
![Page 16: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/16.jpg)
![Page 17: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/17.jpg)
![Page 18: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/18.jpg)
![Page 19: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/19.jpg)
![Page 20: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/20.jpg)
Fewer function parameters
Less to remember
![Page 21: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/21.jpg)
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()
![Page 22: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/22.jpg)
Function scoping
$this->function_name()
OR
Class_Name::function_name()
![Page 23: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/23.jpg)
OrderAnd
Structure
![Page 24: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/24.jpg)
ReadabilityAnd
Maintainability
![Page 25: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/25.jpg)
![Page 26: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/26.jpg)
PHP Kinda Sucks ...
![Page 27: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/27.jpg)
PHP Kinda Sucks ...
http://phpsadness.com/
![Page 28: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/28.jpg)
![Page 29: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/29.jpg)
Return Value?
![Page 30: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/30.jpg)
What is FALSE as an INT?
![Page 31: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/31.jpg)
![Page 32: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/32.jpg)
Don’t be like PHP ...
![Page 33: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/33.jpg)
and pass errors in return values ...
![Page 34: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/34.jpg)
Throw Exceptions!
and pass errors in return values ...
![Page 35: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/35.jpg)
What does PHP do if I don’t check for errors?
![Page 36: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/36.jpg)
PHP keeps going, no matter what ...
![Page 37: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/37.jpg)
Death by exception
![Page 38: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/38.jpg)
Use Constants
![Page 39: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/39.jpg)
… and not Magic Numbers
![Page 40: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/40.jpg)
What are Magic Numbers?
![Page 41: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/41.jpg)
What are Magic Numbers?
if( $x == 32 ) for( range( 1, 52 ) as $card )
if( $x == ‘supercalifragilisticexpialidocious’ )
![Page 42: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/42.jpg)
Why are Magic Numbers bad?
if( $x == 32 ) for( range( 1, 52 ) as $card )
if( $x == ‘supercalifragilisticexpialidocious’ )
![Page 43: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/43.jpg)
Why are Magic Numbers bad?
if( $x == $freezing_point ) for( range( 1, $deck_size ) as $card )
if( $x == $song_name )
![Page 44: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/44.jpg)
Magic Numbers, WordPress Style
$cat_id = 7;
$user_id = 64;
$post_id = 527;
![Page 45: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/45.jpg)
Two versions of Constants
Global
Class
![Page 46: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/46.jpg)
BYO Filters
![Page 47: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/47.jpg)
![Page 48: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/48.jpg)
apply_filters( ‘name_of_my_filter’, $value_to_be_filtered );
e.g.
apply_filters( ‘hot_swap/use_cloning’, $cloning_enabled );
Using apply_filters()
![Page 49: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/49.jpg)
hot_swap/use_cloning
Naming Filters
my_awesome_plugin/options/save
hot_pocket/remove_from_microwave
search_plugin/results
hot_swap/excluded_post_types
![Page 50: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/50.jpg)
Only call apply_filters() once per filter
![Page 51: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/51.jpg)
Break out of WordPress
![Page 52: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/52.jpg)
![Page 53: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/53.jpg)
![Page 54: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/54.jpg)
![Page 55: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/55.jpg)
Code like everyone is stupid
![Page 56: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/56.jpg)
Code like everyone is stupid
Objects/classes
![Page 57: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/57.jpg)
Code like everyone is stupid
Objects/classes
Throwing exceptions
![Page 58: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/58.jpg)
Code like everyone is stupid
Objects/classes
Throwing exceptions
Constants
![Page 59: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/59.jpg)
Questions?
![Page 60: The Struggle is Real: Developing WordPress Plugins · The Struggle is Real: Developing WordPress Plugins Daniel Simanek < daniel.simanek@wisc.edu > Research and Graduate Education](https://reader033.vdocuments.site/reader033/viewer/2022042709/5f3d6a7720fa417f6e786bbe/html5/thumbnails/60.jpg)
The Struggle is Real: Developing WordPress PluginsDaniel Simanek <[email protected]>Research and Graduate Education