Upload
chad-windnagle
View
643
Download
0
Embed Size (px)
Citation preview
WordCamp Orlando, 2015 - Chad Windnagle
How To BeA Good Developer
Citizen
WordCamp Orlando, 2015 - Chad Windnagle
Quick Intro(disclaimer)
WordCamp Orlando, 2015 - Chad Windnagle
Not a Wordpress Guy
WordCamp Orlando, 2015 - Chad Windnagle
Actually a Joomla, Symfony, Laravel, and
PHP Guy.
WordCamp Orlando, 2015 - Chad Windnagle
8+ Years Working with Joomla & PHP
WordCamp Orlando, 2015 - Chad Windnagle
Now I work with Laravel (and WordPress)
WordCamp Orlando, 2015 - Chad Windnagle
PHP Frameworks
WordCamp Orlando, 2015 - Chad Windnagle
Good* Code
WordCamp Orlando, 2015 - Chad Windnagle
Object Orientation Programming
WordCamp Orlando, 2015 - Chad Windnagle
Documentation
WordCamp Orlando, 2015 - Chad Windnagle
Testing
WordCamp Orlando, 2015 - Chad Windnagle
These are a few of my favorite things.
WordCamp Orlando, 2015 - Chad Windnagle
I want to bring Modern PHP
techniques to WordPress Developers
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
No! Definitely Not.
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Let’s get started
WordCamp Orlando, 2015 - Chad Windnagle
Stop using themes for functionality.
WordCamp Orlando, 2015 - Chad Windnagle
Themes are for Presentation.
WordCamp Orlando, 2015 - Chad Windnagle
Only presentation.
WordCamp Orlando, 2015 - Chad Windnagle
Themes should never
• Touch $wp_query• Change the post content• Change the post title• Change the meta data• Change URL parameter• Change anything except CSS, javascript, and
markup
WordCamp Orlando, 2015 - Chad Windnagle
If your site will not function the same with a different theme, you are
doing it wrong.
WordCamp Orlando, 2015 - Chad Windnagle
“But I need functions.php!”
WordCamp Orlando, 2015 - Chad Windnagle
No you don’t. You need a plugin.
WordCamp Orlando, 2015 - Chad Windnagle
Plugins are easy to build.
WordCamp Orlando, 2015 - Chad Windnagle
Plugins can do everything
functions.php can do.
WordCamp Orlando, 2015 - Chad Windnagle
You can change themes without
affecting plugins, or needing functions.php
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
My first plugin experience:
WordCamp Orlando, 2015 - Chad Windnagle
Documentation and tutorials are everywhere.
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Google Results for Building WordPress
Plugins:
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Good PHP coding standards not so
much.
WordCamp Orlando, 2015 - Chad Windnagle
Most information I found:
• Not object oriented• Bad function names• Required Vendor prefixed• Inconsistent Code Style
WordCamp Orlando, 2015 - Chad Windnagle
How to Plugin The Right Way
WordCamp Orlando, 2015 - Chad Windnagle
Have some class
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
This is an application class.
WordCamp Orlando, 2015 - Chad Windnagle
A few things about this technique
WordCamp Orlando, 2015 - Chad Windnagle
This is not object oriented (not
really).
WordCamp Orlando, 2015 - Chad Windnagle
We keep the vendor prefix only on the
class name.
WordCamp Orlando, 2015 - Chad Windnagle
We put most add_action and
add_filter calls into the constructor.
WordCamp Orlando, 2015 - Chad Windnagle
Now we can do things like this:
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Major PHP Wins:• Object oriented code• Reusable Code• Entering into SOLID programming• DRY Methods. • Code that can be extended• Code that can be inherited• Flexible Coding FTW
WordCamp Orlando, 2015 - Chad Windnagle
Why have class?• Clean fast reusable code• Saves time & money• Happy developers & Happy users
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Javascript Injection
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Use WordPress’ Hook In your Plugin
Class:
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Executing Javascript From Markup
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Form Submissions
WordCamp Orlando, 2015 - Chad Windnagle
Handle Form Actions with a
Plugin
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Error HandlingGracefully
WordCamp Orlando, 2015 - Chad Windnagle
Let’s play catch
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Logging?
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Code Comprehension
WordCamp Orlando, 2015 - Chad Windnagle
Method Names That Make Sense
WordCamp Orlando, 2015 - Chad Windnagle
Verb-Based Methods:
WordCamp Orlando, 2015 - Chad Windnagle
Good Method Name:get Leads();
WordCamp Orlando, 2015 - Chad Windnagle
Can we do better?
WordCamp Orlando, 2015 - Chad Windnagle
leadsid | f_name | l_name1 | roy | rogers2 | robin | peters
recruitersid | f_name | l_name1 | hannah | mckay2 | carol | williams
leads_recruitersid | lead_id | recruiter_id1 | 1 | 12 | 2 | 1
WordCamp Orlando, 2015 - Chad Windnagle
Great Method Name:get Lead ById(1)
get Leads ByRecruiter(1)
get Recruiter ByLead(1)
WordCamp Orlando, 2015 - Chad Windnagle
Other ExamplesfindByRecruiter()
addRecruiterToLead()sortRecruitersByLead()
WordCamp Orlando, 2015 - Chad Windnagle
If-Statements
WordCamp Orlando, 2015 - Chad Windnagle
I (proudly) confess…
WordCamp Orlando, 2015 - Chad Windnagle
I haven’t written anelse statement in 2+
years.
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
My approach is:Validate FirstReturn EarlyProcess Last
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
2 Levels ofIndentation*
Not counting classes, try & catch, & method body
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
This will force you to:create more methods (DRY! don’t repeat
yourself)throw more exceptionsdo more error checking
think about code-scenarios less
WordCamp Orlando, 2015 - Chad Windnagle
Nitpicking.
WordCamp Orlando, 2015 - Chad Windnagle
Doc Blocks
WordCamp Orlando, 2015 - Chad Windnagle
Code Style (WP-CS)
WordCamp Orlando, 2015 - Chad Windnagle
php code sniffer
https://github.com/squizlabs/PHP_CodeSniffer
WordCamp Orlando, 2015 - Chad Windnagle
Install phpcsphp code-sniffer
WordCamp Orlando, 2015 - Chad Windnagle
wordpress code sniffer
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Fixing PHPCS Errors
WordCamp Orlando, 2015 - Chad Windnagle
WordCamp Orlando, 2015 - Chad Windnagle
Take Away Challenges
• No “else” keyword• 2 levels of indentation• No functionality in themes!
WordCamp Orlando, 2015 - Chad Windnagle
Resources
WordCamp Orlando, 2015 - Chad Windnagle
“Object Oriented Calisthenics”
WordCamp Orlando, 2015 - Chad Windnagle
PHP The Right Way
WordCamp Orlando, 2015 - Chad Windnagle
Thank You!Chad Windnagle
Software EngineerAdvanced Medical
@drmmr763
Credits• “Your Code Sucks, Let’s Fix It” - @rdohms /
doh.ms• PHPCS - SquizLabs