My Sublime Text Snippets.
Created
August 1, 2012 10:31
-
-
Save simonwheatley/3225684 to your computer and use it in GitHub Desktop.
Sublime Text Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[ | |
<div class='${1:updated}${2:error}'><p>$3</p></div> | |
]]></content> | |
<tabTrigger>adminnotice</tabTrigger> | |
</snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[ | |
error_log( "SW: $1 " ${2:. print_r( \$$3 , true )} ); | |
]]></content> | |
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> | |
<tabTrigger>el</tabTrigger> | |
<!-- Optional: Set a scope to limit where the snippet will trigger --> | |
<scope>source.php</scope> | |
<description>Handy error_log call format, with prefix to make it easier to grep for</description> | |
</snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[ | |
/* Copyright 2012 Code for the People Ltd | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation; either version 2 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
*/ | |
$1 | |
]]></content> | |
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> | |
<tabTrigger>gpl</tabTrigger> | |
<!-- Optional: Set a scope to limit where the snippet will trigger --> | |
<!-- <scope>source.python</scope> --> | |
<description>The GPL, with CFTP copyright</description> | |
</snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[/** | |
* Hooks the ${6:WP }$2 $3 $7 | |
* | |
* @return ${10:void} | |
**/ | |
function ${1:prefix}_${2:hook_name}( $11 ) { | |
$0 | |
} | |
add_${3:action}( '${2:hook_name}', '${1:prefix}_${2:hook_name}', ${4:null}, ${5:null} ); | |
]]></content> | |
<tabTrigger>hook</tabTrigger> | |
<scope>source.php</scope> | |
<description>WordPress hook and function</description> | |
</snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[<!-- $1 -->$0]]></content> | |
<tabTrigger>!</tabTrigger> | |
<scope>text.html</scope> | |
<description>HTML comment</description> | |
</snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- --> | |
<snippet> | |
<content><![CDATA[/** | |
* Hooks the ${7:WP }$1 $2 | |
* | |
* @${1} $2 | |
*${5: @param $4 | |
*} | |
* @return ${6:void} | |
* ${8:@author Simon Wheatley} | |
**/ | |
function ${1:action}_$2(${3: $4 }) { | |
$0 | |
} | |
]]></content> | |
<tabTrigger>maction</tabTrigger> | |
<scope>source.php</scope> | |
<description>Method hooking an action or filter</description> | |
</snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Regular method --> | |
<snippet> | |
<content><![CDATA[/** | |
* $6 | |
* | |
*${4: @param $3 | |
*} | |
* @return ${5:void} | |
* ${7:@author Simon Wheatley} | |
**/ | |
${8:static }function $1(${2: $3 }) { | |
$0 | |
} | |
]]></content> | |
<tabTrigger>method</tabTrigger> | |
<scope>source.php</scope> | |
<description>Class method</description> | |
</snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[ | |
/* | |
Plugin Name: ${1:Plugin Name} | |
Plugin URI: http://codeforthepeople.com/?plugin=${2} | |
Description: ${3:Description} | |
${4:Network: true | |
}Version: ${5:0.1} | |
Author: Code for the People Ltd | |
Author URI: http://codeforthepeople.com/ | |
*/ | |
/* Copyright 2012 Code for the People Ltd | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation; either version 2 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
*/} | |
$6 | |
]]></content> | |
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> | |
<tabTrigger>plugin_head</tabTrigger> | |
<!-- Optional: Set a scope to limit where the snippet will trigger --> | |
<scope>source.php</scope> | |
</snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[ | |
${1:<?${TM_PHP_OPEN_TAG:php} }if ( $3${4:->}have_posts() ) : while ( $3${4:->}have_posts() ) : $3${4:->}the_post();${2: ?>} | |
${5:<!-- post -->} | |
$1endwhile;$2 ${6: | |
${7:<!-- post navigation -->} | |
$1else:$2 | |
${0:<!-- no posts found -->} | |
}$1endif;$2 | |
]]></content> | |
<description>The Loop (SW)</description> | |
<tabTrigger>theloop</tabTrigger> | |
<scope>text.html</scope> | |
</snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[ | |
var_dump( \$$1 ); | |
$2 | |
]]></content> | |
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> | |
<tabTrigger>vd</tabTrigger> | |
<!-- Optional: Set a scope to limit where the snippet will trigger --> | |
<scope>source.php</scope> | |
<description>Quick and dirty var_dump call</description> | |
</snippet> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<snippet> | |
<content><![CDATA[ | |
/** | |
* $4 | |
* | |
* @package $0 | |
**/ | |
class $1 { | |
/** | |
* A version integer. | |
* | |
* @var int | |
**/ | |
var \$version; | |
/** | |
* Singleton stuff. | |
* | |
* @access @static | |
* | |
* @return $1 object | |
*/ | |
static public function init() { | |
static \$instance = false; | |
if ( ! \$instance ) | |
\$instance = new $1; | |
return \$instance; | |
} | |
/** | |
* Class constructor | |
* | |
* @return null | |
*/ | |
public function __construct() { | |
${2:add_action( 'admin_init', array( \$this, 'action_admin_init' ) ); | |
} | |
\$this->version = 1; | |
} | |
// HOOKS | |
// ===== | |
/** | |
* Hooks the WP action admin_init | |
* | |
* @action admin_init | |
* | |
* @return void | |
* @author Simon Wheatley | |
**/ | |
public function action_admin_init() { | |
\$this->maybe_upgrade(); | |
} | |
// CALLBACKS | |
// ========= | |
// UTILITIES | |
// ========= | |
/** | |
* Returns the URL for for a file/dir within this plugin. | |
* | |
* @param $path string The path within this plugin, e.g. '/js/clever-fx.js' | |
* @return string URL | |
* @author John Blackbourn | |
**/ | |
protected function plugin_url( \$file = '' ) { | |
return \$this->plugin( 'url', \$file ); | |
} | |
/** | |
* Returns the filesystem path for a file/dir within this plugin. | |
* | |
* @param $path string The path within this plugin, e.g. '/js/clever-fx.js' | |
* @return string Filesystem path | |
* @author John Blackbourn | |
**/ | |
protected function plugin_path( \$file = '' ) { | |
return \$this->plugin( 'path', \$file ); | |
} | |
/** | |
* Returns a version number for the given plugin file. | |
* | |
* @param $path string The path within this plugin, e.g. '/js/clever-fx.js' | |
* @return string Version | |
* @author John Blackbourn | |
**/ | |
protected function plugin_ver( \$file ) { | |
return filemtime( \$this->plugin_path( \$file ) ); | |
} | |
/** | |
* Returns the current plugin's basename, eg. 'my_plugin/my_plugin.php'. | |
* | |
* @return string Basename | |
* @author John Blackbourn | |
**/ | |
protected function plugin_base() { | |
return \$this->plugin( 'base' ); | |
} | |
/** | |
* Populates and returns the current plugin info. | |
* | |
* @author John Blackbourn | |
**/ | |
protected function plugin( \$item, \$file = '' ) { | |
if ( ! isset( \$this->plugin ) ) { | |
\$this->plugin = array( | |
'url' => plugin_dir_url( \$this->file ), | |
'path' => plugin_dir_path( \$this->file ), | |
'base' => plugin_basename( \$this->file ) | |
); | |
} | |
return \$this->plugin[ \$item ] . ltrim( \$file, '/' ); | |
} | |
/** | |
* Checks the DB structure is up to date, rewrite rules, | |
* theme image size options are set, etc. | |
* | |
* @return void | |
**/ | |
public function maybe_upgrade() { | |
global \$wpdb; | |
\$option_name = '$3_version'; | |
\$version = get_option( \$option_name, 0 ); | |
if ( \$version == \$this->version ) | |
return; | |
// if ( \$version < 1 ) { | |
// error_log( "$0: …" ); | |
// } | |
// N.B. Remember to increment \$this->version above when you add a new IF | |
update_option( \$option_name, \$this->version ); | |
error_log( "$0: Done upgrade, now at version " . \$this->version ); | |
} | |
} | |
// Initiate the singleton | |
${1}::init(); | |
]]></content> | |
<description>Singleton Class for WP</description> | |
<tabTrigger>wpsingleton</tabTrigger> | |
<scope>text.html</scope> | |
</snippet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment