Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Surviving WordPress’ English and PHP Bilingualism

jonradio
November 15, 2013

Surviving WordPress’ English and PHP Bilingualism

WordCamp Edmonton 2013
November 15, 2013
Jon Pearkins

jonradio

November 15, 2013
Tweet

Other Decks in Programming

Transcript

  1. Surviving WordPress’ English and PHP Bilingualism WordCamp Edmonton 2013 November

    15, 2013 Jon Pearkins http://jonradio.com/wordcamp/2013.pdf
  2. Surviving WordPress’ English and PHP Bilingualism About the Speaker: Jon

    Pearkins received one of UBC's first Computer Science degrees in 1974, then held technical and management positions in Edmonton's I.T. community until he retired in 2007. Since then, he has added 7 WordPress Plugins to the Plugin Directory, answered 1200 Support Forum questions, and volunteers as web- master and technical hosting guru for 6 web sites, having built his first web site in 1995.
  3. Surviving WordPress’ English and PHP Bilingualism About the Concept: WordPress

    is software written in the PHP computer programming language. English is the language used for PHP instructions and comments embedded by the WordPress developers. Knowledge of English and PHP lets you do a lot more with WordPress. Without it, you can still create a nice web site using WordPress, if you know and accept some limitations.
  4. Surviving WordPress’ English and PHP Bilingualism About the First Part:

    By my count, there are eight levels of WordPress web site development activities. They are numbered based on the amount of PHP and associated technical knowledge required to accomplish each. In fact, the first three can usually be done quite successfully without any such knowledge. Most Levels include tips on reducing Risk.
  5. Surviving WordPress’ English and PHP Bilingualism About the Second Part:

    Just like written English, PHP has words and punctuation. And rules about how to put those words and punctuation together. We will cover the basics. And some common mistakes to avoid. There are lots of free software tools and information sources that will help get you started, and soon become friends for life.
  6. Surviving WordPress’ English and PHP Bilingualism The evolution of web

    sites, from HTML to PHP • HTML • Style language and Cascading Style Sheets (.css) • JavaScript reacts instantly on your browser • PHP generates each web site page's HTML, Style and Javascript specifically for each web site visitor, based on his or her individual needs • .php files, not .html files
  7. WordPress Risk/Expertise Ladder Recommended Levels of Flexibility vs Reliability 1.

    Out of the Box 2. Using a Theme not written by WordPress 3. Installing Plugins 4. Writing a Child Theme 5. Writing a Shortcode 6. Changing a Plugin 7. Writing Your Own Plugin 8. Writing Your Own Theme
  8. 1. Out of the Box • Using just the options

    and settings provided by the WordPress Core • The WordPress Core keeps growing • Six Themes to choose from, with a seventh on the way: Twenty Thirteen Twenty Twelve Twenty Eleven Twenty Ten Classic Default Twenty Fourteen – available next year
  9. 2. Using a Theme not written by WordPress • Themes

    define the look of your site, some add new functionality/features, while others are specialized, e.g. - Real Estate listings • Over two thousand free themes in the WordPress Theme Directory • Thousands more, including a few Free ones, available elsewhere on-line • Some Paid sites are just “Front Men” for independent authors, taking no responsibility
  10. 3. Installing Plugins • Plugins add or change WordPress functionality

    • Nearly 30,000 free plugins in the WordPress Plugin Directory, though thousands do not work with the current version of WordPress • More, including a few Free ones, available elsewhere on-line, some by Theme authors to add functionality to their Themes • Some free plugins are used to sell paid plugins
  11. Plugins and Themes The Support Risk What Makes Them Break?

    • Different Admin or Visitor Usage exposes bug • A published security issue invites Hackers • The next version of the Plugin or Theme • The next version of WordPress • Changes to your web hosting software • Conflict with another Plugin or Theme
  12. Plugins and Themes The Support Risk “Who Yu Gonna Call?”

    • Finding the Guy or Girl who wrote it – moved on AKA “Abandoned Plugins/Themes” • Author lacks the time, interest or knowledge • DIY: find a fix on-line or figure it out yourself • Paid Themes and Plugins are no guarantee; some argue they are, in fact, a bigger risk
  13. Plugins and Themes Reducing the Support Risk Some Selection Criteria

    from the WordPress Plugin and Theme Directories: • Number of Downloads, both total and recent • Review Recent Support threads – Author responds? How helpful are the responses? • Supports your WordPress Version? – Only listed for Plugins in WordPress directories • Date last updated
  14. 4. Writing a Child Theme Modifying a Theme • Never

    directly modify a Theme; you will lose your changes when the Theme is updated • Create a Child Theme instead • Cross-Browser Testing is Essential • The scope of the changes to the Theme determines the required knowledge of PHP, CSS (Style definitions), HTML and WordPress Theme structure
  15. 5. Writing a Shortcode • Shortcodes are enclosed in square

    brackets • [gallery] shows images attached to a Post/Page • Shortcodes insert PHP into a Page, Post or, using Widgets, into a Sidebar, Header or Footer • Shortcodes are normally defined by writing your own Plugin, but.... • the Shortcode Exec PHP plugin provides a Tools page in WordPress Admin panels where Shortcodes can be defined
  16. 6. Changing a Plugin • Many plugins almost work, in

    the sense of doing exactly what you need • Getting the Plugin Author to change the next version of the plugin is often impossible • Looking at the plugin's files is the only way to know how difficult making the changes will be, as plugins vary in size from 10 to 10,000 lines • Archive all the plugin files BEFORE and AFTER you make the changes, for later reference • Test thoroughly, preferably on a test web server
  17. 7. Writing Your Own Plugin • Beyond the WordPress Plugin

    Directory • Custom functionality just for your web site(s) • The best way to tightly integrate an App into any WordPress-powered web site • Success or Failure often depends on Timing: most Plugins are mainly Event Driven, e.g. - triggered just before the Footer is displayed • WordPress Action and Filter Hooks knowledge
  18. 8. Writing Your Own Theme • A major undertaking •

    Everything you need to know to write a complex Plugin, plus another layer of knowledge • Cross Browser Testing is the Key to Success – Only exception: if all Site Visitors use the same browser and browser version • But coding with multiple browsers and devices in mind is an essential part of that body of knowledge required to write a Theme
  19. Cross Browser Testing How does your web site look on

    every different version of every different browser on every different device? – Internet Explorer, Firefox, Chrome, Safari, ... – Desktop, Laptop, Tablet, SmartPhone, ... – iPhone, Android, WindowsPhone, ... – Screen resolutions and Browser Window widths
  20. Cross Browser Testing • Build Your Own Cross Browser Testing

    Lab – Virtual Machine on one computer with some tablets and smartphones • Use an on-line Cross Browser Testing service – Probably need one each for traditional workstations and mobile devices • Combination probably works best
  21. Surviving WordPress’ English and PHP Bilingualism About the Second Part:

    Just like written English, PHP has words and punctuation. And rules about how to put those words and punctuation together. We will cover the basics. And some common mistakes to avoid. There are lots of free software tools and information sources that will help get you started, and soon become friends for life.
  22. A .php file • Begins in HTML mode, where you

    can code HTML, including embedded JavaScript and Style statements, just as you would in a .html file. No PHP code allowed. • <?php switches to PHP mode, where only valid PHP statements can be coded. • ?> switches to HTML mode
  23. PHP Punctuation • To output the HTML to start a

    Level 1 heading: echo '<h1>'; • Every PHP statement ends with a semi-colon “;” • Quotes and brackets must match – opening and closing: ' ', " ", { }, [ ], ( ) – must be the same type
  24. Variables • Variables allow PHP to store pieces of information,

    commonly known as Values • $start is a variable called “start” • global $start; indicates that $start is available to all functions and .php files that also contain a global $start; statement • DEFINE( 'START', 1 ); defines a global constant with a value of One
  25. How Many =? • Three === $start === 1 Is

    $start of type Integer and Value of One? • Two == $start == 1 Is $start a String or Number type of value One? • One = $start = 1 // $start is set to One Set $start to type Integer and Value of One.
  26. PHP Decision Making • if is the most common Logical

    Choice statement if ( 'large' === $size ) { echo 'two weeks'; } else { echo 'one week'; }
  27. PHP Decision Making • Nesting allows more than one Logical

    Choice if ( 'large' === $size ) { if ( $priority_shipment ) { echo 'two days'; } else { echo 'two weeks'; } } else { echo 'one week'; }
  28. PHP Decision Making • if can also test more than

    one Logical Choice if ( $priority_shipment && 'large' === $size ) { echo 'two days'; } else { echo 'one week'; }
  29. How Many =? The Biggest Beginner Mistake in PHP Coding:

    if ( $start = 1 ) is always wrong In fact, WordPress Coding Standards would have you write it, correctly, as: if ( 1 === $start ) Because, if you miswrote it with one =, it would fail if ( 1 = $start ) generates an error message
  30. PHP Functions function defines code “for later” function between( $var,

    $low, $high ) { return ( $var >= $low ) && ( $var <= $high ); } function doesn't do anything until you actually use the function you have just defined: if ( between( $month, 1, 12 ) ) { echo 'valid month'; Note: function sometimes defined after it is used
  31. PHP Comments /* */ and // let Developers explain things

    to anyone reading their PHP code /** * Add the WordPress logo menu. * * @param WP_Admin_Bar $wp_admin_bar */ function wp_admin_bar_wp_menu( $wp_admin_bar ) { // Add WordPress.org link $wp_admin_bar->add_menu( array(
  32. Four Software Tools • Notepad++ – http://notepad-plus-plus.org • FileZilla –

    https://filezilla-project.org • XAMPP – http://www.apachefriends.org/en/xampp.html • phpMyAdmin – http://www.phpmyadmin.net – http://localhost/phpmyadmin from XAMPP
  33. PHP Web Site References • http://www.php.net/manual/en/ is the official PHP

    reference manual • http://codex.wordpress.org/Function_Reference lists the PHP functions that WordPress adds, some of which are known as Template Tags because they are used in Themes • http://codex.wordpress.org is the official WordPress documentation