WordPress workflows with PHP Storm

Jimmy Smutek | WordCamp Lancaster, 2016

About Me

I'm Jimmy Smutek!!

I'm a web developer from Baltimore, Maryland.

I like 80's music, techno, drum machines, skateboards, PHP, WordPress, and the open web.

I work at a marketing and advertising agency called Ainsley & Co.

What I Do

At Ainsley we work with small to mid size companies.

We do all sorts of cool stuff, video, copy, design, web, etc.

We use WordPress for the majority of our web projects, and we build custom themes to match our clients needs.

Why PHP Storm?

Ewww

Configurable

Fortunately PHP Storm is ridiculously configurable.

So, why PHP Storm?

Everything I am going to show can be done with other tools.

  • Unifies most of my tools under one roof.
  • Highly configurable.
  • Very deep feature set that I've been able to grow into.
  • Not just for PHP

What kind of tools?

  • Code editor
  • Terminal
  • Debugging
  • Version control
  • Task runner (gulp, grunt, etc.)
  • Deployment
  • Live Templates
  • And lots more....

What I'll be covering

  • Project setup
  • Debugging
  • Live Templates
  • Jumping to function and variable definitions
  • Shortcuts
  • Compiling / Task running

Project setup

  • New project from existing files.
  • Let PHP Storm know it's a WordPress project
  • Optionally, set WordPress coding standards
  • Set up favorites
  • Set up version control
  • Set up task runner

Debugging Configuration

  • Add new PHP Remote Debug configuration
  • Add new server configuration
  • Enable xDebug
  • With VVV:
## ssh into vagrant box
vagrant ssh
## activate xDebug
xdebug_on
## exit
exit

Starting the Debugger

  • Set some break points
  • Tell PHP Storm to listen for incoming connections
  • Click the little bug
  • Refresh your browser and the debugger will stop code execution at the first breakpoint it encounters

Debugging Session

  • Use the debug console to step into, over, or out of code blocks
  • Evaluate expressions
  • Use console to run commands
  • Watch specific variables
  • Follow WordPress as it builds the page

Debugging is a great way to track down problems and learn how WordPress works.

Live Templates

  • Use Live Templates to quickly output commonly used code blocks
  • Repetitive tasks can be assigned to key commands and triggered with the tab key
  • An example of a prime candidate to setup as a Live Template?
new WP_Query();

Anatomy of a Live Template

  • Super easy to setup.

  • Some code
  • Optionally, some variables, defined as
$variable$

Anatomy of a Live Template

    $args = [
    'post_type' => '$type$',
    'posts_per_page' => $num$
    ];

    $query = new WP_Query($args);

    if($query->have_posts()) :

        while($query->have_posts()) : $query->the_post();

    // loop stuff

        endwhile; wp_reset_postdata(); // end while have posts

    endif; // end if have posts

More uses for Live Templates

  • Custom Post Types
  • Sidebars
  • ACF Stuff
  • Not just for PHP
  • Good for anything I do over, and over, and over!

Other Cool Things

  • Run Gulp & Grunt tasks, npm commands
  • Manage version control; commit, push, pull, branch
  • Deploy via FTP
  • Control Vagrant
  • WP CLI commands

 

 

That's just the tip of the iceberg.

Closing

Thanks so much for having me.

 

Twitter: @smutek

Slides & Resources:

https://smutek.net/wc-lancaster-2016/

Lancaster 2016

By smutek

Lancaster 2016

  • 3,003