Skip to content

Instantly share code, notes, and snippets.

View kovshenin's full-sized avatar

Konstantin Kovshenin kovshenin

View GitHub Profile
<?php
/*
Plugin Name: No-IP
Plugin URI: http://wordpress.org/support/topic/37363
Description: Causes WordPress to NOT save the IP address from ANY commenter. WordPress will instead record all comment IP addresses as '127.0.0.1'
Author: WP-Forums
Author URI: http://wordpress.org/support/
Version: 0.1
*/
<?php
$args = array(
'post_type' => 'post',
'tax_query' => array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'operator' => 'NOT IN'
'terms' => get_post_format_slugs(),
)
<?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>',
@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
add_action( 'init', function() {
$total = 0;
for ( $i = 1; $i <= 500; $i++ ) {
$query = new WP_Query( array(
'posts_per_page' => 1,
'offset' => $i,
) );
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 ||
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%
<?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;
@kovshenin
kovshenin / code1.php
Created July 16, 2011 12:36
WordPress Dashboard Feed Reader
<?php
add_action( 'wp_dashboard_setup', 'my_dashboard_setup' );
function my_dashboard_setup() {
wp_add_dashboard_widget('themefm-dashboard-reader', 'Latest from Theme.fm' , 'my_dashboard_content', $control_callback = null);
}
function my_dashboard_content() {
echo "<p>Dashboard Widget Content</p>";
}
<?php query_posts($query_string . '&cat=-3,-8'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post">
<!-- Display the Title as a link to the Post's permalink. -->
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>