Skip to content

Instantly share code, notes, and snippets.

Konstantin Kovshenin kovshenin

Block or report user

Report or block kovshenin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View edit-my-plugin-options.php
<?php
add_filter( 'map_meta_cap', function( $caps, $cap ) {
if ( $cap == 'edit_my_plugin_options' ) {
$c = is_multisite() ? 'manage_site_options' : 'manage_options';
$caps = array( $c );
}
return $caps;
}, 10, 2 );
if ( current_user_can( 'edit_my_plugin_options' ) ) { ... }
@kovshenin
kovshenin / subscribers-count.php
Created Nov 19, 2015
Get subscribers count via the MailChimp API.
View subscribers-count.php
<?php
/**
* Get subscribers count via the MailChimp API.
*/
function mailchimp_get_subscribers_count() {
$cache_key = 'mailchimp-subscribers';
$api_key = '';
$username = '';
$dc = '';
$list_id = '';
@kovshenin
kovshenin / array-callables.php
Created Nov 17, 2015
Some array callables for WordPress
View array-callables.php
<?php
function __array_append( $item ) {
return function( $array ) use ( $item ) {
$array[] = $item;
return $array;
};
}
function __array_set( $key, $value ) {
return function( $array ) use ( $key, $value ) {
@kovshenin
kovshenin / camptix-release.sh
Last active Feb 12, 2017
camptix-release.sh
View 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."
View meanwhile.php
<?php
add_filter( 'pre_comment_content', function( $content ) {
if ( strlen( $content ) > 64000 )
wp_die( 'Invalid comment.' );
return $content;
} );
View formatting.php
<?php
function wp_natural_time( $timestamp, $limit = 2 ) {
$from = time();
$diff = absint( $from - $timestamp );
if ( $diff < 1 )
return _x( 'now', 'time ago' );
$result = array();
View profile.php
<?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;
View gist:2bcd348dbc77281d7bc7
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%
View gist:69431d4e6e437b692256
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 ||
View test.php
<?php
add_action( 'init', function() {
$total = 0;
for ( $i = 1; $i <= 500; $i++ ) {
$query = new WP_Query( array(
'posts_per_page' => 1,
'offset' => $i,
) );
You can’t perform that action at this time.