SVN in a Git world

I mostly use the Git version control system in my workflow. The one exception is for WordPress.org plugin repos that still use SVN. Since I rarely use it I just spent a ton of time re-learning how to deal with it to update my Featured Authors Widget plugin. Here are my notes. This is mostly to jog my own memory later but maybe someone will find this helpful.

  1. Spin up a local development environment.
  2. Navigate to the plugins directory in terminal
  3. Check out trunk into an appropriately named directory with

    svn co http://plugins.svn.wordpress.org/example-plugin/trunk example-plugin

    (that URL comes from the plugin repo on wordpress.org)

  4. Update the plugin as necessary
  5. Commit your changes back to the repo with

    svn ci -m ‘updated readme after testing on WP 4.0.1’

  6. Go enjoy another cup of coffee.
Posted in Uncategorized | Leave a comment

New WordPress plugin: Featured Authors Widget

I’ve posted up a plugin to the WordPress.org repository, Featured Authors Widget. I built it for Article-3.com but it’s a useful plugin for anyone with a multi-author WordPress site that wants to showcase particular authors.

You can read the full details here or just head over to WordPress.org to download it.

Posted in Uncategorized | Leave a comment

Big fun with preg_replace_callback

I had a job that required creating a custom input filter for Drupal. It turns out to be pretty easy but I had a heck of a time finding documentation on it that made much sense to me so here’s my explanation of how to do it. The magic is all done by the PHP function preg_replace_callback() which takes as its arguments a regular expression (pattern) to search for, a callback function to take the stuff the expression finds and return you altered text to put in its place, and the big honking block of text to search through. So let’s start simple:

$text = <a href="http://www.php.net/preg_replace_callback">preg_replace_callback</a>('/hello/', '_smallWorld', $text);
function _smallWorld($match){
$world = 'world'; return $world;
}

All this will do is scan through $text and for each instance of hello with world. You can just use preg_replace for that. But it gets a lot more interesting when you start adding options to your regex like the very useful collapsible text module for Drupal:

function collapse_text_process($text) {
$text = <a href="http://www.php.net/preg_replace_callback">preg_replace_callback</a>('/
\[                     # look for an opening bracket collapse # followed by the word `collapse`
(\ collapsed)?         # followed by (optionally) a space and the word `collapsed` (captured)
(?:\ style=([^\] ]*))? # followed by (optionally) a space and a style, consisting of any # characters except a close bracket (captured)
(?:\ title=([^\]]*))?  # followed by (optionally) a space and a title, consisting of any # characters except a close bracket (captured)
\]                     # followed by a closing bracket (.+?)
# then capture as few characters as possible until \[\/collapse\]
# a closing "tag", which is a slash followed by `collapse` in brackets
#and then after the regex delimiter, we'll turn on 3 regex options
#s so dot matches all characters, m to match embedded newlines
#x so we can do free spacing and add these wonderful comments
/smx', "_collapse_text_replace_callback", $text);
return $text;
}

We’ll pause a second to review that regex. What this means is that editors can do all sorts of things from the simple

[collapse] hello world [/collapse]

to the complete

[collapse collapsed style=yellow title=big news]
Hello World [/collapse]

The result is passed to your callback function, _collapse_text_replace_callback as an array. Element 0 is the full match. So

function _collapse_text_replace_callback($matches) {
global $base_url; $collapsed = ($matches[1] == ' collapsed');
$style = <a href="http://www.php.net/trim">trim</a>($matches[2]); $title = <a href="http://www.php.net/trim">trim</a>($matches[3]);
$interior = $matches[4];
//the authors of this module do lots of cool stuff in here, check it out.
return drupal_render($form);
}

So in the simple use case, the first element doesn’t contain collapsed so that’s false so do x. In the more complicated use, it does so do y. Likewise, the more complex use strings for $style, and $title.

Posted in Uncategorized | Leave a comment

Galleria 1.2 Module

I just posted a first pass at updating the Galleria module http://drupal.org/node/802206 for Drupal to use the new Galleria 1.2 code. If you’re a Galleria user, have a look. I’m not sure that it makes any sense to continue it as a module since it’s so easy to implement it in your Drupal Theme and all the magic happens in your Galleria Theme now.

Posted in Uncategorized | Leave a comment