Skip to content

Instantly share code, notes, and snippets.

@aaroneaton
aaroneaton / upgrade.php
Last active December 12, 2015 07:48
WP:Plugin option upgrade
<?php
class MyPlugin{
const
OPTION_NAME = 'my_plugin_options',
VERSION = '1.0';
protected
$options = null,
@aaroneaton
aaroneaton / functions.php
Last active December 12, 2015 07:58
WP:Class Autoloading
<?php
/**
* Autoloads the requested class. PSR-0 compliant
*
* @since 1.0
* @param string $classname The name of the class
*/
public static function autoload( $classname ) {
$filename = dirname( __FILE__ ) .
@aaroneaton
aaroneaton / cpt.php
Last active December 12, 2015 12:38
WP:Saving meta fields as post title
<?php
public function save_staff_title( $staff_title ) {
$first = $_POST[META_PREFIX . 'first-name'];
$last = $_POST[META_PREFIX . 'last-name'];
if ( $_POST['post_type'] == 'staff' )
$staff_title = $last . ', ' . $first;
return $staff_title;
@aaroneaton
aaroneaton / Post meta title.php
Last active December 16, 2015 07:19
Saving a meta field as the post title
<?php
public function save_title( $title ) {
if ( $_POST['post_type'] == 'my_post_type' ){
$title = $_POST['_meta_program-title'];
}
return $title;
}
@aaroneaton
aaroneaton / cat_posts.php
Last active December 16, 2015 15:19
Getting one post from multiple categories
<?php
function query_features() {
global $query;
// Setup arguments for our query
$agencies = array(
'extension' => 'AgriLife Extension',
'research' => 'AgriLife Research',
'college' => 'College of Agriculture &amp; Life Sciences',
@aaroneaton
aaroneaton / functions.php
Created June 20, 2013 23:50
Copy and paste into your child theme functions.php to allow anonymous users to make use of the control panel.
<?php
remove_action('et_header_top','et_chameleon_control_panel');
add_action('et_header_top','demo06_chameleon_control_panel');
function demo06_chameleon_control_panel(){
if ( get_option('chameleon_show_control_panel') <> 'on' ) return;
global $et_bg_texture_urls, $et_google_fonts; ?>
<div id="et-control-panel">
<div id="control-panel-main">
<a id="et-control-close" href="#"></a>
<?php
$last_char = null;
foreach( $documents as $document ) {
// Gets the first character of the post title
$this_char = strtoupper( substr( $document->post_title, 0, 1 ) );
// If this character is different than the last, insert the seperator with anchor
<?php
// Disables sticky Strict Standards warnings. Good for poorly developed plugins.
// Put this file in mu-plugins
if ( WP_DEBUG ) {
error_reporting( E_ALL & ~E_STRICT );
}
@aaroneaton
aaroneaton / provision-post.sh
Last active November 2, 2016 08:01
Setup themes & plugins after VVV provision
# Get rid of the default crap
wp site empty --yes
# Remove Hello Dolly (sorry Matt)
wp plugin uninstall hello
# Install Genesis framework
wp theme install <super-secret-url-for-genesis>
# Install plugins available in repo
@aaroneaton
aaroneaton / copy-files.sh
Last active December 28, 2015 09:59
Iterates over the contents of blogs.dir and copies them to wp-content/sites.
#! /bin/bash
shopt -s dotglob
shopt -s nullglob
array=(*/)
echo "Copying ${#array[@]} directories"
for dir in "${array[@]}"; do
# if /uploads/sites doesn't exist, you should create it
cp -r $dir/files ../uploads/sites/$dir
echo "Copied ${dir}"