Skip to content

Instantly share code, notes, and snippets.

View kovshenin's full-sized avatar

Konstantin Kovshenin kovshenin

View GitHub Profile
@kovshenin
kovshenin / query.sql
Created December 29, 2011 23:17
Change the year of all posts in a particular category to 2012
UPDATE wp_posts AS p
JOIN wp_term_relationships AS tr ON tr.object_id = p.id
JOIN wp_term_taxonomy AS tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
JOIN wp_terms AS t ON tt.term_id = t.term_id
SET p.post_date = REPLACE(p.post_date, YEAR(p.post_date), 2012)
WHERE t.slug = 'my-category-slug' AND tt.taxonomy = 'category';
@kovshenin
kovshenin / birthday.php
Created January 16, 2012 11:11
A birthday gift I got from my brother :)
<?php
require 'classes/household.php';
require 'classes/birthday.class.php';
require 'classes/birthday.boy.class.php';
require 'classes/friend.php';
$K = new Birthday_Boy();
foreach ( $K->check_phone()->check_im()->check_social() as $greetings ) {
@kovshenin
kovshenin / plugin-file.php
Created January 17, 2012 11:16
WP_Plugin class concept
<?php
/*
Plugin Name: WP_Plugin class test
Description: Tosting things out, again.
Author: Konstantin Kovshenin
Version: 1.0
Author URI: http://kovshenin.com
*/
class WP_Plugin {
@kovshenin
kovshenin / image-shortcode.php
Created March 6, 2012 06:41
Image shortcode for WordPress
<?php
/**
* Image shortcode callback
*
* Enables the [kovshenin_image] shortcode, pseudo-TimThumb but creates resized and cropped image files
* from existing media library entries. Usage:
* [kovshenin_image src="http://example.org/wp-content/uploads/2012/03/image.png" width="100" height="100"]
*
* @uses image_make_intermediate_size
*/
@kovshenin
kovshenin / options.php
Created April 23, 2012 12:12
Reusable Settings API fields
<?php
/**
* Text Field
*
* A simple text field callback to use with the Settings API. Don't forget to pass in
* the arguments array. Here's an example call to add_settings_field() :
*
* add_settings_field( 'my_option', __( 'My Option' ), 'foo_field_text', 'theme_options', 'general', array(
* 'name' => 'my_theme_options[my_option]',
* 'value' => $options['my_option'], // assuming $options is declared
<?php
/*
* Plugin Name: Foo Bar
*/
add_action( 'save_post', 'my_save_post' );
function my_save_post( $post_id ) {
if ( wp_is_post_revision( $post_id ) )
return;
<?php
add_action( 'init', 'my_remove_post_dates' );
function my_remove_post_dates() {
if ( ! in_array( get_current_blog_id(), array( 21, 22 ) ) )
return;
add_filter( 'the_date', '__return_null', 99 );
add_filter( 'the_time', '__return_null', 99 );
add_filter( 'the_modified_date', '__return_null', 99 );
}
<?php
add_action( 'pre_get_posts', 'my_pre_get_posts' );
function my_pre_get_posts( $query ) {
if ( ! $query->is_main_query() )
return;
$woo_search = woo_dynamic_search_header();
if ( isset( $woo_search['query_args'] ) )
foreach ( $woo_search['query_args'] as $key => $value )
$query->set( $key, $value );
<?php
/*
* Plugin Name: Oh noes, not another SEO plugin!
* License: GPLv3 http://www.gnu.org/copyleft/gpl.html
*/
add_filter( 'wp_title', function( $title ) {
if ( is_singular() ) $title .= ' &mdash; ' . get_bloginfo( 'name' );
if ( is_archive() ) $title = sprintf( ' Archives: %s &mdash; %s', $title, get_bloginfo( 'name' ) );
if ( is_home() ) $title = sprintf( '%s &mdash; %s', get_bloginfo( 'name' ), get_bloginfo( 'description' ) );
if ( is_search() ) $title = sprintf( 'Searching for: %s &mdash; %s', get_search_query( true ), get_bloginfo( 'description' ) );
<?php
/*
* Plugin Name: Foo
*/
add_image_size( 'my-rss-thumbnail', 292, 136, true );
add_action( 'rss2_item', 'my_rss2_item' );
function my_rss2_item() {
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(), 'my-rss-thumbnail' );
if ( ! $thumbnail ) return;