Skip to content

Instantly share code, notes, and snippets.

View kovshenin's full-sized avatar

Konstantin Kovshenin kovshenin

View GitHub Profile
@kovshenin
kovshenin / camptix-release.sh
Last active February 12, 2017 23:45
camptix-release.sh
#!/bin/bash
tag=${1:-trunk}
echo "Releasing CampTix Version: $tag"
d=`mktemp -d -t camptix`
git clone git@github.com:Automattic/camptix.git $d/git
svn co https://plugins.svn.wordpress.org/camptix/trunk $d/svn
cp -r $d/git/* $d/svn/
cd $d/svn
svn add .
svn commit -m "Sync with GitHub master."
@kovshenin
kovshenin / meanwhile.php
Created April 27, 2015 16:18
meanwhile.php
<?php
add_filter( 'pre_comment_content', function( $content ) {
if ( strlen( $content ) > 64000 )
wp_die( 'Invalid comment.' );
return $content;
} );
@kovshenin
kovshenin / formatting.php
Created October 2, 2014 15:03
Natural time
<?php
function wp_natural_time( $timestamp, $limit = 2 ) {
$from = time();
$diff = absint( $from - $timestamp );
if ( $diff < 1 )
return _x( 'now', 'time ago' );
$result = array();
<?php
$XHPROF_ROOT = '/home/kovshenin/xhprof';
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_lib.php";
include_once $XHPROF_ROOT . "/xhprof_lib/utils/xhprof_runs.php";
add_action( 'init', function() {
// Make sure it's in cache before we profile.
$post = get_post( $post_id );
$post_id = 1134;
Functon Name Calls Calls % Incl. Wall Time IWall% Excl. Wall Time EWall%
Run #1
profile_get_permalink_with_id 1,000 0.4% 323,009 48.3% 5,428 0.8%
profile_get_permalink_with_obj 1,000 0.4% 343,777 51.4% 9,017 1.3%
Run #2
profile_get_permalink_with_id 1,000 0.4% 416,239 50.0% 1,666 0.2%
profile_get_permalink_with_obj 1,000 0.4% 413,868 49.7% 5,640 0.7%
Run #3
profile_get_permalink_with_id 1,000 0.4% 464,560 52.7% 1,349 0.2%
I don't think it's about the conflict, consider two simple tables, say posts (p):
|| id ||
|| 1 ||
|| 2 ||
|| 3 ||
And term relationships (tr):
|| post_id || term_id ||
<?php
add_action( 'init', function() {
$total = 0;
for ( $i = 1; $i <= 500; $i++ ) {
$query = new WP_Query( array(
'posts_per_page' => 1,
'offset' => $i,
) );
@kovshenin
kovshenin / fix-my-date.php
Last active August 29, 2015 13:57
Did you know that WordPress appends a /date/ prefix to date archives if you use %post_id% in the permalinks structure? I didn't.
<?php
/**
* Plugin Name: Fix my /date/
*/
function fix_my_date() {
global $wp_rewrite;
$wp_rewrite->date_structure = '%year%/%monthnum%/%day%';
}
add_action( 'init', 'fix_my_date' );
<?php
/**
* Plugin Name: Reproduce #26533
*/
add_action( 'admin_bar_menu', function() {
global $wp_admin_bar;
$wp_admin_bar->add_menu( array(
'id' => 'foo',
'title' => '<span id="foo-icon" class="ab-item" style="height: 32px !important; width: 32px !important; display: block; background: red;"></span>',
<?php
/**
* Plugin Name: Static Templates
*
* If most of your site content is in .php template files, and you're tired of
* creating new pages, assigning them page templates, creating page templates
* then doing it all over again on production, this plugin is for you.
*
* Examples:
*