Skip to content

Instantly share code, notes, and snippets.

View zanematthew's full-sized avatar

Zane Matthew zanematthew

View GitHub Profile
@zanematthew
zanematthew / welcome.php
Created December 12, 2014 17:27
Note this is a snippet from a class, you can replace the $this-> with your params or hardcode them. Its all ran during admin_init.
<?php
/**
* Sends user to the start page on first activation, as well as each time the
* plugin is upgraded to a new version
*
* @access public
* @since 1.1
* @return void
*/
@zanematthew
zanematthew / gist:f8440442df8524a9dff0
Created December 12, 2014 17:31
Storing plugin version number on activation and deleting it during plugin deactivation.
<?php
/**
* Manging of version numbers when plugin is activated
*/
function MYPLUGIN_install() {
// Add Upgraded From Option
$current_version = get_option( MYPLUGIN_NAMESPACE . '_version' );
if ( $current_version ) {
@zanematthew
zanematthew / plugin.php
Last active August 29, 2015 14:11
Plugin Action Links
<?php
/**
* Add our links to the plugin page, these show under the plugin in the table view.
*
* @param $links(array) The links coming in as an array
* @param $current_plugin_file(string) This is the "plugin basename", i.e., my-plugin/plugin.php
*/
function my_plugin_action_links( $links, $current_plugin_file ){
if ( $current_plugin_file == 'my-plugin/plugin.php' ){
@zanematthew
zanematthew / related.php
Created June 10, 2015 13:07
The function can be placed into your functions.php, and the "usage" snippet can be used in any template/theme file.
fastcgi_cache_path /home/foo/site.com/cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
server {
# also use www here
server_name site.com;
access_log /home/foo/site.com/logs/access.log;
error_log /home/foo/site.com/logs/error.log;
@zanematthew
zanematthew / nginx.conf
Created July 3, 2015 01:18
Block direct EDD downloads for WordPress Networking
# Block direct EDD downloads for WordPress Networking
location ~ ^/wp-content/uploads/sites/(.*)/edd/(.*?)\.zip$ {
rewrite / permanent;
}
@zanematthew
zanematthew / Template Redirect Switch
Created August 28, 2011 02:31
Redirecting a template in WordPress using a switch. This is used inside of a plugin when you want to allow default template for a Custom Post Type your template is generating.
case ( is_tax( $my_taxonomies ) ):
global $wp_query;
if ( in_array( $wp_query->query_vars['taxonomy'], $my_taxonomies ) ) {
foreach ( $my_taxonomies as $taxonomy ) {
load_template( MY_PLUGIN_DIR . 'theme/archive-' . $k['type'] . '.php' );
// load_template( MY_PLUGIN_DIR . 'theme/taxonomy-' . $my_taxonomies. '.php' );
}
}
exit;
@zanematthew
zanematthew / Remind me!
Created August 28, 2011 05:05
When entering a directory show the last entered notes that are in Git. This is used as a quick reminder for a forgetful programmer.
#!/bin/bash
if [ ${PWD##*/} == task-tracker ]; then
echo `git notes show`
fi
@zanematthew
zanematthew / gist:1187330
Created September 1, 2011 21:28
My Git Config
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[color]
ui = auto
interactive = true
@zanematthew
zanematthew / gist:1218426
Created September 15, 2011 03:08
Template Redirect loopy
foreach( $this->post_type as $wtf ) {
$my_cpt = get_post_types( array( 'name' => $wtf['type']), 'objects' );
if ( is_tax( $wtf['taxonomies'] ) ) {
global $wp_query;
if ( in_array( $wp_query->query_vars['taxonomy'], $wtf['taxonomies'] ) ) {
if ( file_exists( MY_PLUGIN_DIR . 'theme/custom/' . $wtf['type'] . '-taxonomy.php' ) ) {
load_template( MY_PLUGIN_DIR . 'theme/custom/' . $wtf['type'] . '-taxonomy.php' );
} elseif ( file_exists( MY_PLUGIN_DIR . 'theme/default/taxonomy.php' ) ) {
load_template( MY_PLUGIN_DIR . 'theme/default/taxonomy.php' );