Child Theme and Plugin Development Cycle

I hope someone who has a better process than this shares some of their secrets.  I am a software engineer who has been developing for WordPress for a few years. I mostly have done projects that were outside of normal WordPress Development. For example, ported a Custom CMS into WordPress. I did custom landing pages with a WordPress backend.  For I while I have been editing my plugin code in place, under wp-content.  I make some changes.  I reload the page. Where the F*(&*^ are my changes?  Oh, I forgot to clear the browser cache.  I test my changes on another site.  I clear the browser cache.  Where are my changes? Oh, I forgot to clear the WordPress cache in use.  Still after clearing both caches, I had some issues with see my updates once in a while.  If I only changed a css file or a js file, it sometimes, did not update.  Mostly on odd days of the week, even when you change what day of the week it starts on.  You really have to watch this stuff.  Sometimes its date related.  Phase of the moon. Rain and inclement weather play a part, sometimes the bit bucket needs emptying.  It is always something.  See https://garyjohnson53.wordpress.com/2016/03/21/computer-problems/  for more suggestions.

So the first thing I do is move the source, to source control. Git is the flavor of the year (previously popular flavors are Mercurial, SVN, CVS, Source Safe ..). Then I document what I think should work. Here is the cycle I use:

– code
I make changes in the hope that one of my mistakes will prove useful, and to move towards my desired effect.  gmgj is the name of my plugin (also its folder etc)

– touch gmgj.php in plugin , functions.php in child theme
Just to be clear, in this case “Touch” is a programming term, where you use a utility to update the modified time of a file, even if you have not updated. The #MeTo has a very different use for the term.

– deactivate plugin, sometimes I have had to change the theme, but not so much
– move in new code

I use a bat file, sort of like this:
@echo off

cd "C:\path to source"
rem this is the touch
copy /b gmgj.php +,,
rem this is the move
xcopy "C:\path to source\*.*" "C:\path to WorPress \wp-content\plugins\gmgj\*.*" /s /r /y /q /d /EXCLUDE:excludeus.dat

rem delete the old zip and recreate the new zip, the zip file is what you upload to new WordPress Installations to install your plugin
del /Q C:\path to source\gmgj.zip
cd "C:\up a level\"
rem this includes some file extensions, excludes others, there are better ways rem to do this.
rem Why? I keep the project html file and other utility files in the same rem directory as the project
"C:\Program Files\7-Zip\7z.exe" a "gmgj.zip" -x!gmgj\*.html -x!gmgj\*.dat -i!gmgj\*.php -i!gmgj\*.css -i!gmgj\*.js -i!gmgj\*.JPG

excludeus.dat is:
*.html
*.dat

– hit wordpress plugin “Clear Cache for Me” on the admin dashboard
– I use the FANTASTIC utility Web Developer clear cache to clear the browser cache

– activate the plugin and cross all fingers and toes.  If that does not help:

– check php error log and start Browser developer tools and check for other errors
– use php error_log() and javascript console.log()
– if problems like not updating code
– admin logout , close browser

– delete plugin and upload via zip file
– start and stop apache and mysql, restart computer, get a coffee …
– roll version numbers
– ?
swing a rubber chicken

I would be remiss if I did not point out that when I calling things like wp_enqueue_style and wp_enqueue_script, I use the version parameter like this.  Please note, I did not originally come up with this idea.  When I looked at the source for a number of projects, the following appears to be standard practice.

$gmgj_js_url = plugins_url( 'gmgj_test.js', __FILE__ ); 
$gmgj_js_path = plugin_dir_path( 'gmgj_test.js');

wp_enqueue_script(
 'gmgj-test-js',
 $gmgj_js_url,
 array( 'jquery', 'jquery-effects-core' , 'jquery-effects-explode'),
 gmgjversion_id($gmgj_js_path),
 true
 );

This the magic that makes the version stuff work

function gmgjversion_id($pluginpath) {
 return filemtime($pluginpath);
 //return '012';
 }

Updating the child theme is similar.

 

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s