Slide 1

Slide 1 text

Your Code Can be Poetry Too Introduction to WordPressCS

Slide 2

Slide 2 text

Hello! Juliette Reinders Folmer @jrf_nl @jrfnl @jrf @[email protected]

Slide 3

Slide 3 text

WordPressCS !== Code Style

Slide 4

Slide 4 text

WordPressCS === Coding Standards

Slide 5

Slide 5 text

WordPressCS === Quality Control

Slide 6

Slide 6 text

“ Only half of programming is coding. The other 90% is debugging.

Slide 7

Slide 7 text

hotblack

Slide 8

Slide 8 text

Marnhe du Plooy

Slide 9

Slide 9 text

Reviewing Code [1] function my_prefix_print_link( $url, $link_text ) { printf( '%2$s', $url, esc_html( $link_text ), ); }

Slide 10

Slide 10 text

Reviewing Code [1] function my_prefix_print_link( $url, $link_text ) { printf( '%2$s', $url, esc_html( $link_text ), ); }

Slide 11

Slide 11 text

Reviewing Code [2] function my_prefix_verify_answer() { if ( strpos( $_POST['phrase'], "It's a brand new day" ) != false ) { echo esc_html( 'Congratulations, you got it right!', 'domain' ); } else { printf( esc_html( 'Sorry, %s was the wrong answer', 'domain' ), $_POST['phrase'] ); } }

Slide 12

Slide 12 text

Reviewing Code [2] function my_prefix_verify_answer() { if ( strpos( $_POST['phrase'], "It's a brand new day" ) != false ) { echo esc_html( 'Congratulations, you got it right!', 'domain' ); } else { printf( esc_html( 'Sorry, %s was the wrong answer', 'domain' ), $_POST['phrase'] ); } }

Slide 13

Slide 13 text

Reviewing Code [3] function admin_page_header() { ?>

My Admin Page

Slide 14

Slide 14 text

Reviewing Code [3] function admin_page_header() { ?>

My Admin Page

Slide 15

Slide 15 text

Reviewing Code [4] function my_prefix_find_post( $search ) { global $wpdb, $id; $result = $wpdb->get_col( "SELECT post_id FROM $wpdb->posts WHERE post_title LIKE '$search';" ); foreach ( $result as $id ) { // Do something. } }

Slide 16

Slide 16 text

Reviewing Code [4] function my_prefix_find_post( $search ) { global $wpdb, $id; $result = $wpdb->get_col( "SELECT post_id FROM $wpdb->posts WHERE post_title LIKE '$search';" ); foreach ( $result as $id ) { // Do something. } }

Slide 17

Slide 17 text

How WordPressCS Can Help ✓ Security ✓ Interoperability ✓ WP Compatibility ✓ Internationalization ✓ Best Practices ✓ Documentation ✓ Consistency ✓ Readability ✓ PHP Compatibility

Slide 18

Slide 18 text

PHP • http://php.net/download Comp oser • https://getcomposer.org/download/ Install • Install via Composer: composer global require –dev wp-coding-standards/wpcs phpcompatibility/phpcompatibility-wp Update • Update via Composer: composer global update wp-coding-standards/wpcs --with-dependencies Run • vendor/bin/phpcs -ps . --standard=WordPress,PHPCompatibilityWP Install / Update

Slide 19

Slide 19 text

What's Included in WordPressCS 2.x ? PHP_CodeSniffer Generic PEAR PSR1, PSR2, PSR12 Squiz Zend WordPress WordPress WordPress-Core WordPress-Docs WordPress-Extra PHPCompatibilityWP PHPCompatibility PHPCompatibilityWP Composer PHPCS Plugin

Slide 20

Slide 20 text

WordPressCS 2.x vs 3.x Why is it taking so long ?????? • Re-architecture • Rules for modern PHP • PHP 7.4 • PHP 8.0 • PHP 8.1 • PHP 8.2

Slide 21

Slide 21 text

What Will Be Included in WordPressCS 3.x ? PHP_CodeSniffer Generic PEAR PSR1, PSR2, PSR12 Squiz Zend PHPCSUtils WordPress WordPress WordPress-Core WordPress-Docs WordPress-Extra PHPCSExtra Universal NormalizedArrays PHPCompatibility WP PHPCompatibility PHPCompatibility WP Composer PHPCS Plugin

Slide 22

Slide 22 text

Minimal Ruleset – phpcs.xml.dist Settings for Project X . /vendor/

Slide 23

Slide 23 text

Adding Configuration [1] ...

Slide 24

Slide 24 text

Adding Configuration [2] ...

Slide 25

Slide 25 text

Adding Configuration [3] ...

Slide 26

Slide 26 text

elvis santana PHPCS Pro-tips

Slide 27

Slide 27 text

Explain

Slide 28

Slide 28 text

phpcs --standard=WordPress --generator=Text (Markdown|HTML)

Slide 29

Slide 29 text

--filter=GitModified --filter=GitStaged

Slide 30

Slide 30 text

Thanks! Any questions ? Slides: https://speakerdeck.com/jrf @jrf_nl @jrfnl @jrf @[email protected]