Skip to content

Instantly share code, notes, and snippets.

@alexkingorg
alexkingorg / add-term-if-not-exists.php
Created September 14, 2012 18:35
Treat WordPress custom taxonomy as meta data
<?php
// check for a term and insert it if it doesn't exist
if (!get_term_by('slug', $term_slug, $taxonomy)) {
wp_insert_term(__($term_name, 'localization-key'), $taxonomy, array(
'slug' => $term_slug
));
}
@alexkingorg
alexkingorg / backfill-tweets.php
Created August 25, 2012 20:25
Import a list of tweet ids into Twitter Tools/WordPress.
<?php
foreach (file('/tweet-ids.txt') as $tweet_id) {
$tweet_id = trim($tweet_id);
$url = home_url('index.php').'?'.http_build_query(array(
'aktt_action' => 'import_tweet',
'tweet_id' => $tweet_id,
'social_api_key' => Social::option('system_cron_api_key')
), null, '&');
// error_log('Importing tweet '.$tweet_id.' '.$url);
@alexkingorg
alexkingorg / deploy.sh
Created August 16, 2012 13:12 — forked from dancameron/deploy.sh
Script to deploy from Github to WordPress.org Plugin Repository
#! /bin/bash
#
# Script to deploy from Github to WordPress.org Plugin Repository
#prompt for plugin slug
echo -e "Plugin Slug: \c"
read PLUGINSLUG
# main config, set off of plugin slug
CURRENTDIR=`pwd`
@alexkingorg
alexkingorg / favepersonal-right-gutter.css
Created August 13, 2012 19:30
FavePersonal wider right-side gutter
@media only screen and (min-width: 1009px) {
/* let's try a larger right-side gutter in desktop view */
.entry-content {
margin-right: 30px;
width: 480px;
}
/* except for gallery posts */
.format-gallery .entry-content {
margin-right: 0;
width: 510px;
@alexkingorg
alexkingorg / get-option-with-default.php
Created July 9, 2012 22:16
Sample options data accessor function with defaults.
<?php
// return a value from the options table if it exists,
// or return a default value
my_plugin_get_option($key) {
$defaults = array(
'foo' => 'some string',
'bar' => true,
'baz' => array(
@alexkingorg
alexkingorg / wp-fullscreen-preview-button.php
Last active October 6, 2015 22:27
Add a preview button to the WordPress fullscreen editor toolbar.
<?php
/*
Plugin Name: Fullscreen Preview Button
Description: Add a preview button to the fullscreen editor toolbar.
Version: 1.2
Author: Alex King
Author URI: http://alexking.org
License: GPL2
*/
@alexkingorg
alexkingorg / maybe-include-plugin.php
Created July 6, 2012 14:25
Conditional loading of a plugin within a WordPress theme.
<?php
// Run this code on 'after_theme_setup', when plugins have already been loaded.
add_action('after_setup_theme', 'my_load_plugin');
// This function loads the plugin.
function my_load_plugin() {
// Check to see if your plugin has already been loaded. This can be done in several
// ways - here are a few examples:
@alexkingorg
alexkingorg / cfct-template-file-globals.php
Created May 27, 2012 17:11
cfct_template_file() and Globals
<?php
/**
* Include a specific file based on directory and filename
*
* @param string $dir Directory the file will be in
* @param string $file Filename
* @param array $data pass in data to be extracted for use by the template
*
**/
function cfct_template_file($dir, $file, $data = array()) {
@alexkingorg
alexkingorg / wp-post-formats-as-categories.php
Created May 18, 2012 20:05
WordPress Post Formats as Categories
<?php
/*
Plugin Name: Formats as Categories
Plugin URI: http://alexking.org/projects/wordpress
Description: Have enabled post formats show up as categories for selection via XML-RPC clients (iPhone, Android, etc.).
Version: 1.0dev
Author: Crowd Favorite
Author URI: http://crowdfavorite.com
*/
@alexkingorg
alexkingorg / favepersonal-link-excerpt-full-content.php
Created April 1, 2012 18:44
Show full content in excerpt for all link posts in FavePersonal (or any Carrington Core theme).