<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gregory Grubbs &#187; wordpress</title>
	<atom:link href="http://gregorygrubbs.com/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://gregorygrubbs.com</link>
	<description>Attention in software development</description>
	<lastBuildDate>Mon, 12 Jul 2010 17:35:34 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Snippets with Emacs Lisp Power</title>
		<link>http://gregorygrubbs.com/wordpress/snippets-with-emacs-lisp-power/</link>
		<comments>http://gregorygrubbs.com/wordpress/snippets-with-emacs-lisp-power/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 06:00:51 +0000</pubDate>
		<dc:creator>Gregory Grubbs</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[E Text Editor]]></category>
		<category><![CDATA[Emacs Lisp]]></category>
		<category><![CDATA[Functional languages]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[TextMate]]></category>
		<category><![CDATA[yasnippet]]></category>

		<guid isPermaLink="false">http://gregorygrubbs.com/?p=415</guid>
		<description><![CDATA[ 
The YASnippet package for Emacs has some pretty awesome power for the developer, especially when you utilize the power of Emacs Lisp.  

YASnippet was inspired by TextMate, which was inspired by Emacs, in a highly-out-of-equilibrium whirlwind of self-referential creativity.  
The screencast above uses a set of snippets I originally took from this [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flickr.com/photos/26405526@N00/2188203168" title="As RAW as Winter"><img src="http://farm3.static.flickr.com/2165/2188203168_86a4d818f4.jpg" /></a> </p>
<p>The YASnippet package for Emacs has some pretty awesome power for the developer, especially when you utilize the power of Emacs Lisp.  </p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/HPT7pm8ot8M&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/HPT7pm8ot8M&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>YASnippet was inspired by TextMate, which was inspired by Emacs, in a highly-out-of-equilibrium whirlwind of self-referential creativity.  </p>
<p>The screencast above uses a set of snippets I originally took from <a href="http://top-frog.com/projects/wordpress-textmate-bundle/">this WordPress TextMate bundle</a>, created by Shawn Parker and Gordon Brander</p>
<p>The first snippet in the screencast illustrates YASnippet&#8217;s mirrors with transformation, in a WordPress plugin template.  The snippet calls Emacs Lisp functions as the plugin name is filled in to create the plugin URI, the &#8220;namespace&#8221; (used here as a prefix for function and variable names), and the primary class name for the plugin. </p>
<p>The second snippet writes a function skeleton, then calls Emacs Lisp at the end to move the generated function outside the current scope into a correct position in the file.  This snippet uses YASnippet&#8217;s fields with transformations syntax, but to do a sneaky thing: not transform the field, but move a region of generated text!</p>
<p>Following is the code for the snippets shown in the screencast, with no commentary.  So pipe up in the comments if you&#8217;re curious about how something works!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># -*- mode: snippet -*-
</span><span style="color: #666666; font-style: italic;"># name: WP Plugin
</span><span style="color: #666666; font-style: italic;"># key: plugin
</span><span style="color: #666666; font-style: italic;"># --
</span><span style="color: #666666; font-style: italic;">/*
Plugin Name: ${1:Plugin Name}
Plugin URI: http://${2:dynapse.com/plugins/}${1:$(gjg/sanitize text)}/
Description: ${3:Description}
Version: ${4:1.0}
Author: ${5:Gregory Grubbs}
Author URI: http://${6:gregorygrubbs.com/}
Namespace: ${1:$(gjg/acronyminize text)}_
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> $<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>$<span style="color: #009900;">&#40;</span>gjg<span style="color: #339933;">/</span>whitespace<span style="color: #339933;">-</span>to<span style="color: #339933;">-</span>underscore text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * constructor for $1
	 *
	 * The constructor is responsible for registering all hooks used
	 * by this class as as WordPress plugin
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		 $<span style="color: #cc66cc;">0</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// constructor</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
$$<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>$<span style="color: #009900;">&#40;</span>gjg<span style="color: #339933;">/</span>acronyminize text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> $<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>$<span style="color: #009900;">&#40;</span>gjg<span style="color: #339933;">/</span>whitespace<span style="color: #339933;">-</span>to<span style="color: #339933;">-</span>underscore text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Next, the add_action snippet, which moves a generated function at the end:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># -*- mode: snippet -*-
</span><span style="color: #666666; font-style: italic;"># name: add_action
</span><span style="color: #666666; font-style: italic;"># key: add_action
</span><span style="color: #666666; font-style: italic;"># --
</span>add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'${1:init}'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_${2:$1}'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">:</span>$$<span style="color: #009900;">&#40;</span>gjg<span style="color: #339933;">/</span>move<span style="color: #339933;">-</span>next<span style="color: #339933;">-</span>sexp<span style="color: #339933;">-</span>past<span style="color: #339933;">-</span>current<span style="color: #339933;">-</span>scope<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> my_$<span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And finally, (some of) the Emacs Lisp functions that the snippets call:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> gjg/acronyminize <span style="color: #66cc66;">&#40;</span>text <span style="color: #66cc66;">&amp;</span>optional do-capitalize<span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Make an acronym from the text 
do-capitalize: t means run text through capitalize function, nil will respect CamelCase
&quot;</span>
  <span style="color: #66cc66;">&#40;</span>save-excursion
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> case-fold-search <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>downcase
     <span style="color: #66cc66;">&#40;</span>replace-regexp-in-string
      <span style="color: #ff0000;">&quot;[^A-Z]&quot;</span> <span style="color: #ff0000;">&quot;&quot;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> do-capitalize <span style="color: #66cc66;">&#40;</span>capitalize text<span style="color: #66cc66;">&#41;</span> text<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">nil</span> t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> gjg/move-next-sexp-past-current-scope <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;kill sexp following point, move past current scope/sexp/function&quot;</span>
  <span style="color: #66cc66;">&#40;</span>beginning-of-line<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>beg <span style="color: #66cc66;">&#40;</span>point<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>re-search-forward <span style="color: #ff0000;">&quot;^[ <span style="color: #000099; font-weight: bold;">\t</span>]*function[ <span style="color: #000099; font-weight: bold;">\t</span>]+[^}]+?}&quot;</span> <span style="color: #66cc66;">&#40;</span>point-<span style="color: #b1b100;">max</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>mark-<span style="color: #b1b100;">defun</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#40;</span>kill-region <span style="color: #66cc66;">&#40;</span>point<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>mark<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>forward-line<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>yank<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>indent-region <span style="color: #66cc66;">&#40;</span>mark<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>point<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://gregorygrubbs.com/wordpress/snippets-with-emacs-lisp-power/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Emacs Power: remote servers and shell commands</title>
		<link>http://gregorygrubbs.com/wordpress/emacs-power-remote-servers-and-shell-commands/</link>
		<comments>http://gregorygrubbs.com/wordpress/emacs-power-remote-servers-and-shell-commands/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 17:26:40 +0000</pubDate>
		<dc:creator>Gregory Grubbs</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[geekhood]]></category>
		<category><![CDATA[power]]></category>
		<category><![CDATA[remote server]]></category>
		<category><![CDATA[secure shell]]></category>
		<category><![CDATA[tramp]]></category>

		<guid isPermaLink="false">http://gregorygrubbs.com/?p=372</guid>
		<description><![CDATA[
Emacs file and directory browsing 
Emacs has Dired, a great method for browsing directories; especially in combination with ido-mode, I prefer it to Windows Explorer, OS X Finder, Gnome Nautilus, or anything else I&#8217;ve used over the decades to browse file systems. You can quickly begin entering paths, and Dired helps you with directory and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flickr.com/photos/16230215@N08/2898797929" title="Come Together"><img src="http://farm4.static.flickr.com/3282/2898797929_f209eeb4a4.jpg" /></a></p>
<h4 id="sec-1">Emacs file and directory browsing </h4>
<p>Emacs has Dired, a great method for browsing directories; especially in combination with ido-mode, I prefer it to Windows Explorer, OS X Finder, Gnome Nautilus, or anything else I&#8217;ve used over the decades to browse file systems. You can quickly begin entering paths, and Dired helps you with directory and file name completion.<br />
<span id="more-372"></span></p>
<p>  As you browse directories, emacs lets you bookmark any path you may visit again. A very cool feature of emacs is the wide variety of shell-based modes: shell, term, interactive SQL, version control, recursive grep, and more.  When you are looking at a Dired buffer and invoke any of those commands, the shell is started in the directory you are looking at.</p>
<h4 id="sec-2">TRAMP: powerful remote file server access </h4>
<p>An emacs user will eventually discover that Dired becomes even more powerful with the built-in power of TRAMP (Transparent Remote (file) Access, Multiple Protocol).  This extends directory path syntax to include FTP, SSH, Rsync and other protocols for accessing remote files.</p>
<p>  An example of accessing a remote file on my development server <code>smeagol</code> from my laptop:</p>
<pre class="example">/ssh:gregj@smeagol:work/client1/web/index.php
</pre>
<p>  A directory on an FTP server is accessed the same way:</p>
<pre class="example">/ftp:ftpuser@ftp.example.com:
</pre>
<p>  Even sudo is considered a &#8216;protocol&#8217;; so to gain root access without leaving the comfort of your emacs session, use</p>
<pre class="example">/sudo::/etc/hosts
</pre>
<p>  Emacs even helps you browse remote servers, providing the same name completion you get on your local directories.</p>
<h4 id="sec-1">The amazing combo of TRAMP and shell commands</h4>
<p>  As wonderful as all this is, we are still in the realm of &#8220;mere&#8221; GUI editors that can browse remote servers. But we are dealing with emacs, the superset of all editors, so we expect even more.</p>
<p>  Imagine we are looking at a directory on a remote server at <code>/ssh:myuser@remote.com:web/public_html</code>, and decide to type</p>
<pre class="example">M-x shell
</pre>
<p>  What happens? Why, emacs looks at our current directory, sees that it is a TRAMP remote path, and just does the Right Thing&trade;: in this case, invokes ssh, sets the directory on the remote server to ~myuser/web/public_html, and sets us at the shell prompt.</p>
<p>  Similarly, if we invoke version control (<code>vc-dir</code>, for example), or recursive grep (<code>rgrep</code>), or most other shell-based commands, emacs will open a secure shell first, then run the vc command (<code>svn</code>, <code>git</code>, etc) or <code>grep</code> <b>on the remote server!!</b> So for example, if I innocently invoke <code>rgrep</code> at the root of a remote WordPress installation, the grep command looks through all the files from the remote server. If on the other hand I were accessing the server using something like <a href="http://fuse.sourceforge.net/sshfs.html">SSHFS</a>, all those files would be transferred to my local machine first and then searched!</p>
<h4 id="sec-3">Some examples </h4>
<p>  I&#8217;ll save my favorite uses of this magic called Dired with TRAMP for last.  I often need to access a development system or a live WordPress installation remotely. To access the SQL client, I found I often had to browse for the WordPress config file, open it, search for the database access info, open a SQL session using <code>M-x sql-mysql</code> and fill in all the prompts to authenticate to the MySQL server.  It&#8217;s great that emacs with TRAMP starts a shell on the remote machine, and initiates the mysql client on that machine.  But emacs allows you to do damn near anything you can imagine, so I realized I could write a function that does the following:</p>
<ol>
<li>
	Looks for wp-config.php in the current directory
  </li>
<li>
	If not found, moves up a directory until it either finds the file or reaches the root of the filesystem
  </li>
<li>
	If found, opens the config file and parses the database authentication parameters
  </li>
<li>
	Feeds those parameters to the sql-mysql function and
  </li>
<li>
	plops me into the MySQL prompt all logged in and ready to go!</p>
</li>
</ol>
<p>Another example: my iPod Touch has an SSH server running on it (don&#8217;t ask me how it got there). I have discovered that many apps use SQLite to store their data.  I have been losing weight lately, and have been using the excellent <a href="http://www.loseit.com/">Lose It!</a> app to track my meals and exercise.  The app gives me nice weekly summaries of my caloric intake, but does not give a weekly summary of my aerobic exercise.  Here&#8217;s how I get that information now:</p>
<ol>
<li>
	I have a nice bookmark to the Lose It! application directory at<br />
	<code>/scpc:mobile@172.16.17.118:/var/mobile/Applications/C6503545-700B-4395-9C8B-FE5B75CF6CD8/</code>,<br />
	so I hit the Return key on that bookmark and wait for Dired to show me the files there.
  </li>
<li>
	Browse to the Documents directory, wherein is stored the database for my personal history
  </li>
<li>
	Invoke <code>M-x sql-sqlite</code> and enter the database file <code>UserDatabaseV1.sql</code> (using dabbrev as a shortcut)
  </li>
<li>
	Wait for the SQLite prompt to appear, and run a lovely little SQL query using a YASnippets shortcut: </p>
</li>
</ol>
<pre class="src src-sql"><span style="color: #a020f0;">SELECT</span> <span style="color: #228b22;">date</span>(<span style="color: #0000ff;">'2001-01-01'</span>, <span style="color: #0000ff;">'+'</span> || <span style="color: #228b22;">Date</span> || <span style="color: #0000ff;">' day'</span>, <span style="color: #0000ff;">'-1 day'</span>, <span style="color: #0000ff;">'weekday 1'</span>, <span style="color: #0000ff;">'-7 day'</span>) <span style="color: #a020f0;">AS</span> Weekdate, strftime(<span style="color: #0000ff;">'%W'</span>,<span style="color: #228b22;">date</span>(<span style="color: #0000ff;">'2001-01-01'</span>, <span style="color: #0000ff;">'+'</span> || <span style="color: #228b22;">Date</span> || <span style="color: #0000ff;">' day'</span>, <span style="color: #0000ff;">'-1 day'</span>)) <span style="color: #a020f0;">AS</span> Week,   ExerciseName, ExerciseCategoryId, <span style="color: #da70d6;">SUM</span>(Minutes), <span style="color: #da70d6;">SUM</span>(CaloriesBurned)   <span style="color: #a020f0;">FROM</span> ExerciseLogEntries  <span style="color: #a020f0;">GROUP</span> <span style="color: #a020f0;">BY</span> Week;
</pre>
<h4 id="sec-4">Summary </h4>
<p>I hope that this post gives an idea of the power of TRAMP on emacs.  It should at least explain the occasional ecstatic post you may see from your geekier tweeps.</p>
<p>As a bonus, here&#8217;s what the above examples look like in use: it&#8217;s unbelievable how fast emacs makes you after a quick 15 years of study.</p>
<p><object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/UjPasLGWzD0&#038;hl=en&#038;fs=1&#038;color1=0x5d1719&#038;color2=0xcd311b"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/UjPasLGWzD0&#038;hl=en&#038;fs=1&#038;color1=0x5d1719&#038;color2=0xcd311b" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object></p>
<p>  And here&#8217;s my emacs lisp code that opens up a SQL prompt for any WordPress installation.  To use, eval the code and invoke <code>M-x gjg/sql-mysql-wordpress</code></p>
<pre class="src src-emacs-lisp">(<span style="color: #a020f0;">defun</span> <span style="color: #0000ff;">gjg/parse-wp-config-db</span> (wpconfig-path)
  <span style="color: #0000ff;">"Read in and parse the DB settings from a WordPress config file; binds 'global' vars for use by sql-mode"</span>
  (<span style="color: #a020f0;">save-excursion</span> <span style="color: #b22222;">;; </span><span style="color: #b22222;">will restore current buffer and default dir afterwards
  </span>    (set-buffer (get-buffer-create (generate-new-buffer-name <span style="color: #0000ff;">" wp-config.php"</span>)))
  (insert-file-contents wpconfig-path)
  <span style="color: #b22222;">;; </span><span style="color: #b22222;">in regex: subexpr 1 is variable name, subexpr 3 is value: DB_{HOST,NAME,PASSWORD,USER}
  </span>    (<span style="color: #a020f0;">while</span> (search-forward-regexp <span style="color: #0000ff;">"define\s*(\s*['\"]</span><span style="color: #0000ff; font-weight: bold;">\\</span><span style="color: #0000ff; font-weight: bold;">(</span><span style="color: #0000ff;">DB_</span><span style="color: #0000ff; font-weight: bold;">\\</span><span style="color: #0000ff; font-weight: bold;">(</span><span style="color: #0000ff;">HOST</span><span style="color: #0000ff; font-weight: bold;">\\</span><span style="color: #0000ff; font-weight: bold;">|</span><span style="color: #0000ff;">NAME</span><span style="color: #0000ff; font-weight: bold;">\\</span><span style="color: #0000ff; font-weight: bold;">|</span><span style="color: #0000ff;">PASSWORD</span><span style="color: #0000ff; font-weight: bold;">\\</span><span style="color: #0000ff; font-weight: bold;">|</span><span style="color: #0000ff;">USER</span><span style="color: #0000ff; font-weight: bold;">\\</span><span style="color: #0000ff; font-weight: bold;">)</span><span style="color: #0000ff; font-weight: bold;">\\</span><span style="color: #0000ff; font-weight: bold;">)</span><span style="color: #0000ff;">['\"]\s*,\s*['\"]</span><span style="color: #0000ff; font-weight: bold;">\\</span><span style="color: #0000ff; font-weight: bold;">(</span><span style="color: #0000ff;">[</span><span style="color: #0000ff;">^</span><span style="color: #0000ff;">'\"]*</span><span style="color: #0000ff; font-weight: bold;">\\</span><span style="color: #0000ff; font-weight: bold;">)</span><span style="color: #0000ff;">['\"]\s*)"</span> (point-max) 42   )
  (<span style="color: #a020f0;">cond</span>
  ((equal <span style="color: #0000ff;">"DB_HOST"</span> (match-string-no-properties 1))
  (setq sql-server (match-string-no-properties 3)))
  ((equal <span style="color: #0000ff;">"DB_NAME"</span> (match-string-no-properties 1))
  (setq sql-database (match-string-no-properties 3)))
  ((equal <span style="color: #0000ff;">"DB_PASSWORD"</span> (match-string-no-properties 1))
  (setq sql-password (match-string-no-properties 3)))
  ((equal <span style="color: #0000ff;">"DB_USER"</span> (match-string-no-properties 1))
  (setq sql-user (match-string-no-properties 3)))))
  (kill-buffer )))

  (<span style="color: #a020f0;">defun</span> <span style="color: #0000ff;">gjg/sql-mysql-wordpress</span> ()
  <span style="color: #0000ff;">"Find WordPress config file in current tree, log into WP database if found."</span>
  (interactive)
  (<span style="color: #a020f0;">let</span> ((mypath (locate-dominating-file default-directory <span style="color: #0000ff;">"wp-config.php"</span>)))
  (<span style="color: #a020f0;">if</span> mypath
  (<span style="color: #a020f0;">progn</span>
  (gjg/parse-wp-config-db (concat mypath <span style="color: #0000ff;">"wp-config.php"</span>))
  (pop-to-buffer (sql-connect-mysql))
  (setq sql-interactive-product 'mysql)
  (setq sql-buffer (current-buffer))
  (sql-interactive-mode)
  (<span style="color: #a020f0;">let*</span> ((match (string-match (nth 0 tramp-file-name-structure) mypath))
  (myformat (<span style="color: #a020f0;">if</span> (eq nil match)
  (format <span style="color: #0000ff;">" WordPress: local; %s; dbhost %s "</span>
  mypath
  sql-server
  )
  (format <span style="color: #0000ff;">" WordPress: Remote %s@%s %s; dbhost %s "</span>
  (match-string (nth 2 tramp-file-name-structure) mypath)
  (match-string (nth 3 tramp-file-name-structure) mypath)
  (match-string (nth 4 tramp-file-name-structure) mypath)
  sql-server))))
  (setq header-line-format myformat))
  )
  (message <span style="color: #0000ff;">"Did not find wp-config.php in current path"</span>))
  ))
</pre>
<p> LocalWords:  Dired emacs SQL Rsync smeagol pre rgrep WordPress MySQL iPod<br />
 LocalWords:  SQLite</p>
]]></content:encoded>
			<wfw:commentRss>http://gregorygrubbs.com/wordpress/emacs-power-remote-servers-and-shell-commands/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>One-button website publishing using WordPress-mu</title>
		<link>http://gregorygrubbs.com/wordpress/one-button-website-publishing-using-wordpress-mu/</link>
		<comments>http://gregorygrubbs.com/wordpress/one-button-website-publishing-using-wordpress-mu/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 00:50:48 +0000</pubDate>
		<dc:creator>Gregory Grubbs</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress-mu]]></category>
		<category><![CDATA[automated]]></category>
		<category><![CDATA[creation]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://gregorygrubbs.com/?p=174</guid>
		<description><![CDATA[
I&#8217;m kinda loving on WordPress MU.  One of my recent projects required building web sites that pulled from a shared database.  WordPress MU allowed me to create a one-button website builder for my client.  WordPress MU calls them blogs, but my client will map a unique domain to each blog, and, well, [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Create many from the one" href="http://flickr.com/photos/63989735@N00/2431138923"><img src="http://farm3.static.flickr.com/2299/2431138923_ff1f7aaa36.jpg" alt="" /></a></p>
<p>I&#8217;m kinda loving on WordPress MU.  One of my recent projects required building web sites that pulled from a shared database.  WordPress MU allowed me to create a one-button website builder for my client.  WordPress MU calls them blogs, but my client will map a unique domain to each blog, and, well, doesn&#8217;t use them as blogs at all.  So I&#8217;m calling them sites here.</p>
<p>By filling in three fields and clicking a button, my client creates a website that</p>
<ul>
<li> Associates metadata with the site that specifies filter criteria to select records from the shared database</li>
<li> Sets the permalink structure for the new site to a custom setting</li>
<li> Creates a key category for the new site, one that is used for the posts generated in a later step</li>
<li> Sets the theme</li>
<li> All the initial pages are created, including content.  The &#8220;slug&#8221; is set specifically to support the URL structure we want.  Page template is also set here because our design calls for a hierarchy of pages.</li>
<li> If the PageMash plugin is active (it is auto-activated for all new blogs using Plugin Commander), certain pages are hidden, and a specific order is set so that page navigation comes out looking good</li>
<li> The front page is set, because we are creating CMS sites, not blogs</li>
<li>Several hundred posts are generated out of the underlying shared non-WPMU database tables</li>
</ul>
<p>All of this takes something like 20 seconds, at which point the admin can visit the new site as a subdomain.  The theme has been applied, navigation works correctly, it is beauty.</p>
<p><span id="more-174"></span></p>
<p>Here&#8217;s how it is done in code.  All you need to do is register a function for the action hook that WordPress MU runs when a new blog is created.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> mypp_initialize_blog<span style="color: #009900;">&#40;</span><span style="color: #000088;">$blog_id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// first, switch to the new blog; we will undo this at the</span>
  <span style="color: #666666; font-style: italic;">// end of the function with restore_current_blog()</span>
  switch_to_blog<span style="color: #009900;">&#40;</span><span style="color: #000088;">$blog_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// add a blog option, here a filter with a default value</span>
  add_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$blog_id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'campus_selection_criteria'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;CampusStateID='CA'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// Set a custom permalink structure</span>
  <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>set_permalink_structure<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/%category%/%postname%'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>flush_rules<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_create_category'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      wp_create_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'schools'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// switch theme - this one specifies a child theme</span>
  switch_theme<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'corporate'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'tweaked-corporate'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// Prepare options used by the pageMash plugin, auto-activated for new sites</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'exclude_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000088;">$excludePagesList</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">else</span>
    <span style="color: #000088;">$excludePagesList</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'exclude_pages'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//if it's empty set as an empty array</span>
  <span style="color: #666666; font-style: italic;">// add pages to support the basic page structure</span>
  <span style="color: #666666; font-style: italic;">// NOTE: the full code is not shown, standard use of wp_insert post</span>
  <span style="color: #666666; font-style: italic;">// for each page:</span>
  <span style="color: #000088;">$newid</span> <span style="color: #339933;">=</span> wp_insert_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postdata</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$newid</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #339933;">!</span>is_wp_error<span style="color: #009900;">&#40;</span><span style="color: #000088;">$newid</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    add_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$newid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> IWANTOEXCLUDETHISPARTICULARPAGEFROMNAVIGATION <span style="color: #009900;">&#41;</span>
      <span style="color: #000088;">$excludePagesList</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$newid</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>THISPARTICULARPAGE <span style="color: #339933;">==</span> <span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'show_on_front'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'page_on_front'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$newid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// error handling if insert post failed</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">// end for each page</span>
  update_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'exclude_pages'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$excludePagesList</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// now generate posts for schools from the shared database</span>
  createSchoolAsPost<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$blog_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// we're done! restore our initial blog</span>
  restore_current_blog<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// function mypp_initialize_blog</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wpmu_new_blog'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mypp_initialize_blog'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://gregorygrubbs.com/wordpress/one-button-website-publishing-using-wordpress-mu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to get your command line PHP script working with WordPress-MU 2.7</title>
		<link>http://gregorygrubbs.com/wordpress/how-to-get-your-command-line-php-script-working-with-wordpress-mu-27/</link>
		<comments>http://gregorygrubbs.com/wordpress/how-to-get-your-command-line-php-script-working-with-wordpress-mu-27/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 16:47:23 +0000</pubDate>
		<dc:creator>Gregory Grubbs</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[wordpress-mu]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web server]]></category>
		<category><![CDATA[wpmu]]></category>

		<guid isPermaLink="false">http://gregorygrubbs.com/?p=160</guid>
		<description><![CDATA[
	OK, this one is obscure. I only post about what I can&#8217;t find on Google!
Until recently it has been possible to run command-line PHP scripts that include wp-config.php or wpmu-settings.php, in order to give those scripts access to WordPress globals like $wpdb, functions such as wp_insert_post etc.  
These scripts worked with WordPress-MU until recently [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flickr.com/photos/86639396@N00/125838823" title="To the moon, Ajax!"><img src="http://farm1.static.flickr.com/48/125838823_e1a4d43a62_m.jpg" /></a></p>
<p>	OK, this one is obscure. I only post about what I can&#8217;t find on Google!</p>
<p>Until recently it has been possible to run command-line PHP scripts that include wp-config.php or wpmu-settings.php, in order to give those scripts access to WordPress globals like $wpdb, functions such as wp_insert_post etc.  </p>
<p>These scripts worked with WordPress-MU until recently &#8212; now the scripts just exit with no output.  </p>
<p>The reason?  WPMU now initiates a redirect in the bootstrap process (search for &#8216;header( &#8220;Location: &#8220;&#8216;  in wpmu-settings.php).  A browser can follow that redirection, but a command line script cannot.  So, if you want to initiate scripts that run from the command line, you will have to get the web server involved by invoking a text browser such as curl, wget, or links.  </p>
<p>It&#8217;s best not to force your scripts to figure out where to find wp-config.php anyway.  I have taken to using a method suggested in <a href="http://wordpress.org/support/topic/190522">this thread</a>, as shown in the code sample below.  The good news is, you know that your script will work the same whether initiated from a plugin in a graphic browser, used in an Ajax call, or initiated from cron or the command line shell.</p>
<p>So instead of kicking your script off with something like</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>php <span style="color: #660033;">-q</span> myscript.php</pre></div></div>

<p>You will create the script as a proper plugin and do something like</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>curl <span style="color: #660033;">-d</span> <span style="color: #007800;">mypp_cmd</span>=status http:<span style="color: #000000; font-weight: bold;">//</span>mywpmusite.com</pre></div></div>

<p>Sample plugin code used for the above example follows.  The prefix for the functions is &#8216;mypp&#8217;, which of course stands for &#8216;MY Plugin Prefix&#8217; to create a unique namespace.  The code below returns results as JSON encoded, and calls die()/exit() at the end to prevent an entire page being created.  For log files run from cron, you may choose to return plain text instead.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #009933; font-style: italic;">/**
   * Add a query var for this plugin
   * This allows Ajax programs to operate without requiring file paths
   * Instead, Ajax functions look for the query var 'mypp_cmd'
   */</span>
  <span style="color: #000000; font-weight: bold;">function</span> mypp_query_vars<span style="color: #009900;">&#40;</span><span style="color: #000088;">$qvars</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$qvars</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'mypp_cmd'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$qvars</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// function mypp_query_vars</span>
&nbsp;
  <span style="color: #009933; font-style: italic;">/**
   * Handle AJAX requests in the template_redirect action
   * We recognize our requests from the query var 'mypp_cmd'
   * Here we allow GET requests using $_REQUEST; to restrict to POST, use $_POST instead
   */</span>
  <span style="color: #000000; font-weight: bold;">function</span> mypp_template_redirect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$cmd</span> <span style="color: #339933;">=</span> get_query_var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mypp_cmd'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cmd</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cmd</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'status'</span><span style="color: #339933;">:</span>
	<span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'status'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'success'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
				    <span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Sample status message'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
	<span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'status'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'success'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
				    <span style="color: #0000ff;">'msg'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Unknown command'</span><span style="color: #339933;">,</span>
				    <span style="color: #0000ff;">'cmd'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$cmd</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// switch $cmd</span>
      <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: text/x-json; charset=utf-8'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">print</span> <span style="color: #990000;">utf8_encode</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// $cmd is set</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// function mypp_template_redirect</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'query_vars'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mypp_query_vars'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_redirect'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mypp_template_redirect'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://gregorygrubbs.com/wordpress/how-to-get-your-command-line-php-script-working-with-wordpress-mu-27/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to change the number of posts shown in the WordPress admin area without hacking the core</title>
		<link>http://gregorygrubbs.com/wordpress/how-to-change-the-number-of-posts-shown-in-the-wordpress-admin-area-without-hacking-the-core/</link>
		<comments>http://gregorygrubbs.com/wordpress/how-to-change-the-number-of-posts-shown-in-the-wordpress-admin-area-without-hacking-the-core/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 13:24:49 +0000</pubDate>
		<dc:creator>Gregory Grubbs</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[edit posts]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://gregorygrubbs.com/?p=142</guid>
		<description><![CDATA[It is easy to go in and hack the core WordPress files to change the hard-coded number, but I wanted to find a way to do it with a hook.  That way, I could one day change the number of posts shown using controls in the interface.
Though there is no filter provided for the number [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_154" class="wp-caption alignnone" style="width: 510px"><img class="size-full wp-image-154" title="use the hook!" src="http://gregorygrubbs.com/wp-content/uploads/2009/03/2921148701_6d1985e27f-cropped.jpg" alt="use the hook!" width="500" height="248" /><p class="wp-caption-text">use the hook!</p></div>
<p>It is easy to go in and hack the core WordPress files to change the hard-coded number, but I wanted to find a way to do it with a hook.  That way, I could one day change the number of posts shown using controls in the interface.</p>
<p>Though there is no filter provided for the number of posts displayed, I hit upon a method of doing this which I would like to share.  Perhaps someone will point out a better way, but for now this is making me happy</p>
<p>The trick is to hijack the query string just for the query that produces the table of posts.  Here&#8217;s what I did:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**  * Extend the number of posts displayed in the Edit Posts  */</span> 
<span style="color: #000000; font-weight: bold;">function</span> dapl_query_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_string</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>   
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$pagenow</span><span style="color: #339933;">;</span>   
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>is_admin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$pagenow</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'edit.php'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$query_string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'posts_per_page=15'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'posts_per_page=100'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$query_string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$query_string</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>  
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'query_string'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'dapl_query_string'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://gregorygrubbs.com/wordpress/how-to-change-the-number-of-posts-shown-in-the-wordpress-admin-area-without-hacking-the-core/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to give all new WPMU blogs default properties, theme and pages</title>
		<link>http://gregorygrubbs.com/wordpress/how-to-give-wpmu-blogs-default-properties-theme-and-pages/</link>
		<comments>http://gregorygrubbs.com/wordpress/how-to-give-wpmu-blogs-default-properties-theme-and-pages/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 19:22:54 +0000</pubDate>
		<dc:creator>Gregory Grubbs</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wpmu]]></category>

		<guid isPermaLink="false">http://gregorygrubbs.com/?p=63</guid>
		<description><![CDATA[I&#8217;ve been developing an application on Wordpress-MU and thought I&#8217;d share a cool tip.
When new web sites are generated by my client, I wanted the experience to be painless; a one-button ready-to-go web site.
It turns out there is an action hook (of course there is!) when a new blog is created.  So let&#8217;s get down [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been developing an application on Wordpress-MU and thought I&#8217;d share a cool tip.</p>
<p>When new web sites are generated by my client, I wanted the experience to be painless; a one-button ready-to-go web site.</p>
<p>It turns out there is an action hook (of course there is!) when a new blog is created.  So let&#8217;s get down to the nitty gritty and see how to implement it.</p>
<p>I wanted to create a property that would apply to the new web site, which would allow my client to limit what data gets displayed on that site.  I also wanted to generate the basic set of pages that I am using to support the sites&#8217; URL structure.  Each page has a unique template that gives it some special navigation and content mojo.</p>
<p>So first I set the site-global option:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_blog_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$blog_id</span><span style="color: #339933;">,</span> 
	        <span style="color: #0000ff;">'campus_selection_criteria'</span><span style="color: #339933;">,</span> 
                <span style="color: #0000ff;">&quot;CampusStateID LIKE '%'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now for the pages with their templates.  In order to let wp_insert_post know which blog to use, we use a handy function call:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">switch_to_blog<span style="color: #009900;">&#40;</span><span style="color: #000088;">$blog_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We will also need to specify the theme we are using so that the starting theme will be selected and the templates will be correctly associated.</p>
<p>I can then create the pages as I would in Wordpress-non-MU.  The final step is to call add_action() to hook this code into the blog creation event.</p>
<p>Here is the code in its entirety</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> dscp_initialize_blog<span style="color: #009900;">&#40;</span><span style="color: #000088;">$blog_id</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   add_blog_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$blog_id</span><span style="color: #339933;">,</span> 
                   <span style="color: #0000ff;">'campus_selection_criteria'</span><span style="color: #339933;">,</span> 
                   <span style="color: #0000ff;">&quot;CampusStateID LIKE '%'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   switch_to_blog<span style="color: #009900;">&#40;</span><span style="color: #000088;">$blog_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #666666; font-style: italic;">// switch theme</span>
   switch_theme<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thematic'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mychildtheme'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$postdata</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post_parent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'post_status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'publish'</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'post_title'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'DESCRIPTIVE TITLE'</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'post_name'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'descriptive-title'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">/* the slug */</span>
   <span style="color: #0000ff;">'page_template'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'template-whatever.php'</span><span style="color: #339933;">,</span>
   <span style="color: #0000ff;">'post_type'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'page'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$newid</span> <span style="color: #339933;">=</span> wp_insert_post<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postdata</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$newid</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span>is_wp_error<span style="color: #009900;">&#40;</span><span style="color: #000088;">$newid</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      add_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$newid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// your error handling code</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wpmu_new_blog'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'dscp_initialize_blog'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://gregorygrubbs.com/wordpress/how-to-give-wpmu-blogs-default-properties-theme-and-pages/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to upgrade Wordpress SAFELY using Subversion and Rsync</title>
		<link>http://gregorygrubbs.com/wordpress/upgrading-wordpress-safely-using-subversion-and-rsync/</link>
		<comments>http://gregorygrubbs.com/wordpress/upgrading-wordpress-safely-using-subversion-and-rsync/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 17:01:20 +0000</pubDate>
		<dc:creator>Gregory Grubbs</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[repository]]></category>
		<category><![CDATA[rsync]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[upgrade]]></category>
		<category><![CDATA[upgrading]]></category>

		<guid isPermaLink="false">http://gregorygrubbs.magichome/?p=5</guid>
		<description><![CDATA[I keep all my Wordpress projects in a Subversion repository.  I also have a snapshot of unmodified &#8216;vanilla&#8217; releases kept in the same repository.
Now theoretically I should simply be able to use the svn merge command in a working directory.  But I have encountered serious problems, including file corruption warnings, when using svn [...]]]></description>
			<content:encoded><![CDATA[<p>I keep all my Wordpress projects in a Subversion repository.  I also have a snapshot of unmodified &#8216;vanilla&#8217; releases kept in the same repository.</p>
<p>Now theoretically I should simply be able to use the svn merge command in a working directory.  But I have encountered serious problems, including file corruption warnings, when using svn merge in an actively developed working directory.  Additionally, svn merge will delete files and directories that you added to the core Wordpress install.</p>
<p>The method outlined here will be safe <strong>even if you have hacked core    Wordpress files</strong>, as long as you are very careful in constructing your rsync command.</p>
<ol>
<li> Import and tag the latest Wordpress release into the repository
<pre class="src"><span style="color: #da70d6;">cd</span> /tmp
tar zxf /path/to/archive/wordpress-2.6.2.tar.gz
    OR
unzip /path/to/archive/wordpress-2.6.2.zip
svn import -m <span style="color: #0000ff;">"Vanilla 2.6.2"</span> wordpress file:///repository/wordpress/tags/2.6.2</pre>
</li>
<li> Remove the directory in /tmp
<pre class="src">rm -rf /tmp/wordpress</pre>
</li>
<li> Check out a fresh copy of your Wordpress project, and export a copy of the latest vanilla Wordpress
<pre class="src"><span style="color: #da70d6;">cd</span> /tmp
svn co --ignore-externals file:///repository/wordpress/projects/myhappyblog
svn export file:///repository/wordpress/tags/2.6.2 wordpress-2.6.2</pre>
</li>
<li> Do a <strong>dry run</strong> of rsync, starting with something like the following
<pre class="src">rsync --dry-run -av --delete --svn-exclude --exclude <span style="color: #0000ff;">'.svn/'</span> --exclude favicon.ico wordpress-2.6.2/ myhappyblog/|less -SiX</pre>
</li>
<li> Now begins an iterative process – carefully examine the output from the above rsync dry run, <strong>paying special attention to files       that will be deleted</strong>, since those will show you directories and files you have added.  Add those directories or files as required using multiple &#8216;–exclude&#8217; options.  Here is an example from a recent upgrade I did:
<pre class="src">rsync --dry-run -av --delete --svn-exclude --exclude <span style="color: #0000ff;">'.svn/'</span> --exclude favicon.ico --exclude <span style="color: #0000ff;">'images/'</span> --exclude <span style="color: #0000ff;">'wp-content/plugins/podpress'</span> --exclude <span style="color: #0000ff;">'wp-content/themes/sandbox'</span> --exclude <span style="color: #0000ff;">'wp-content/uploads'</span> wordpress-2.6.2/ myhappyblog/|less -SiX</pre>
</li>
<li> Once you are satisfied that you are not asking rsync to delete files and directories you need, run the command without &#8216;–dry-run&#8217;
<pre class="src">rsync -av --delete --svn-exclude --exclude <span style="color: #0000ff;">'.svn/'</span> --exclude favicon.ico --exclude <span style="color: #0000ff;">'images/'</span> --exclude <span style="color: #0000ff;">'wp-content/plugins/podpress'</span> --exclude <span style="color: #0000ff;">'wp-content/themes/sandbox'</span> --exclude <span style="color: #0000ff;">'wp-content/uploads'</span> wordpress-2.6.2/ myhappyblog/</pre>
</li>
<li> Now change to your project working directory and look at the output of &#8217;svn stat&#8217;, here including sample output:
<pre class="src">svn stat

M      wp-login.php
M      wp-includes/post.php
M      wp-includes/version.php
M      wp-includes/query.php
M      wp-includes/formatting.php
M      wp-includes/pluggable.php
M      wp-includes/widgets.php
M      wp-settings.php
M      wp-admin/includes/template.php
M      wp-admin/includes/image.php
M      wp-admin/import/textpattern.php
M      wp-admin/css/press-this-ie.css</pre>
</li>
<li> (conditional) In major upgrades, there will be Wordpress core file deletions and additions.  Handling these will require an extra couple commands, shown below.  These commands are only necessary if there are additions and deletions.
<pre class="src"><span style="color: #b22222;"># </span><span style="color: #b22222;">tell repository about deleted files that were removed by rsync
</span>svn remove --force <span style="color: #ff00ff;">`svn stat |egrep '^\!' | cut -d' ' -f2-999`</span>
<span style="color: #b22222;"># </span><span style="color: #b22222;">add new files to repository
</span>svn add <span style="color: #ff00ff;">`svn stat|egrep '^\?' | cut -d' ' -f2-999`</span></pre>
</li>
<li> You may choose to look through all the changes, or you may decide that the files that have been changed are safe (ie, unhacked Wordpress core files).Now you are ready to commit the changes to the repository.
<pre class="src">svn diff | less <span style="color: #b22222;"># </span><span style="color: #b22222;">optional
</span>svn commit -m <span style="color: #0000ff;">"Upgraded to Wordpress 2.6.2"</span></pre>
</li>
<li> At long last, you can go to the working directory where you are actively developing, and update that.  Once you have tested thoroughly, you will be ready to update your live site (possibly with the same &#8217;svn update&#8217; command).
<pre class="src"><span style="color: #da70d6;">cd</span> /path/to/my/development/myhappyblog
svn up</pre>
</li>
<li> Repeat from Step 3 for each of your SVN-managed Wordpress projects!</li>
<li> Drink.  Pray that Wordpress is not upgraded for at least another 6 months.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://gregorygrubbs.com/wordpress/upgrading-wordpress-safely-using-subversion-and-rsync/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
