Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / wp-test-post-slash.php
Created September 20, 2012 16:33
WordPress unit test to verify that slashed data is saved properly for posts
<?php
/**
* @group post
* @group slashes
*/
class Tests_Post_Slashes extends WP_UnitTestCase {
function setUp() {
parent::setUp();
$this->author_id = $this->factory->user->create( array( 'role' => 'editor' ) );
@alexkingorg
alexkingorg / wp-test-postmeta-slash.php
Created September 20, 2012 20:53
WordPress unit test to verify that slashed data is saved properly for post meta
<?php
/**
* @group meta
* @group slashes
* @ticket 21767
*/
class Tests_Meta_Slashes extends WP_UnitTestCase {
function setUp() {
parent::setUp();
@alexkingorg
alexkingorg / wp-test-comment-slash.php
Created September 20, 2012 21:51
WordPress unit test to verify that slashed data is saved properly for comments
<?php
/**
* @group comment
* @group slashes
*/
class Tests_Comment_Slashes extends WP_UnitTestCase {
function setUp() {
parent::setUp();
// we need an admin user to bypass comment flood protection
@alexkingorg
alexkingorg / wp-add-thumbnail-support.php
Created October 2, 2012 19:38
Add thumbnail support for a post type without stomping old types.
$thumbnails = get_theme_support('post-thumbnails');
if (is_array($thumbnails)) {
add_theme_support('post-thumbnails', array_merge($thumbnails[0], array(self::$post_type)));
}
else if (!$thumbnails) {
add_theme_support('post-thumbnails', array(self::$post_type));
}
// else already enabled for all post types