Skip to content

Instantly share code, notes, and snippets.

View Rarst's full-sized avatar
Otherwise occupied.

Andrey Savchenko Rarst

Otherwise occupied.
View GitHub Profile
@Rarst
Rarst / nice-labels.php
Last active May 3, 2017 06:43
"Nice numbers" implementation for pretty range of numerical labels on graph
<?php
// @link http://books.google.com/books?id=fvA7zLEFWZgC&pg=PA61&lpg=PA61#v=onepage&q&f=false
function nice_labels( $min, $max, $ticks = 5 ) {
$range = nice_number( $max, false );
$d = nice_number( $range / ( $ticks - 1 ) );
$graphmin = floor( $min / $d ) * $d;
$graphmax = ceil( $max / $d ) * $d;
$nfrac = max( array( - floor( log( $d, 10 ) ), 0 ) );
@Rarst
Rarst / deprecated.md
Last active February 21, 2023 11:21
WordPress coding standards configuration for PhpStorm

Now Native

PhpStorm now bundles WordPress coding style natively, starting from version 8.

  1. Go to Project Settings > Code Style > PHP.
  2. Select Set From... (top right of window) > Predefined Style > WordPress.

No longer need to muck with this import! :)

@Rarst
Rarst / r-debug.php
Last active February 3, 2024 17:30
R Debug (set of dump helpers for debug)
<?php
/*
Plugin Name: R Debug
Description: Set of dump helpers for debug.
Author: Andrey "Rarst" Savchenko
Author URI: https://www.rarst.net/
License: MIT
*/
@Rarst
Rarst / readme.md
Last active January 28, 2020 02:51
Walker class for WordPress custom menu integration in Twitter Bootstrap navbar
@Rarst
Rarst / .maintenance
Created April 21, 2012 12:36
WordPress maintenance mode
<?php
function is_user_logged_in() {
$loggedin = false;
foreach ( (array) $_COOKIE as $cookie => $value ) {
if ( stristr($cookie, 'wordpress_logged_in_') )
$loggedin = true;
}
return $loggedin;
}
if ( ! stristr($_SERVER['REQUEST_URI'], '/wp-admin') && ! stristr($_SERVER['REQUEST_URI'], '/wp-login.php') && ! is_user_logged_in() )
@Rarst
Rarst / wordpress.less
Created April 26, 2012 20:04
WordPress colors vars in LESS
// Logo
// http://wordpress.org/about/logos/
@wp_logo_blue: #21759B;
@wp_logo_orange: #D54E21;
@wp_logo_grey: #464646;
// Admin
// http://dotorgstyleguide.wordpress.com/outline/colors/
@Rarst
Rarst / class-oh-shuddup.php
Created June 14, 2012 17:35
Shuts up deprecated messages for specific functions
<?php
Oh_Shuddup::on_load( array( 'get_theme_data' ) );
/**
* Shuts up deprecated messages for specific functions.
*/
class Oh_Shuddup {
static $functions;
@Rarst
Rarst / backtrace-error-handler.php
Created October 4, 2012 19:31
Error handler with WordPress backtrace in message.
<?php
set_error_handler( 'backtrace_error_handler', error_reporting() );
function backtrace_error_handler( $errno, $errstr, $errfile, $errline, $errcontext ) {
// handle @
if( 0 === error_reporting() )
return false;
<?php
/*
Plugin Name: Disable plugins when doing local dev
Description: If the WP_LOCAL_DEV constant is true, disables plugins that you specify
Version: 0.1
License: GPL version 2 or any later version
Author: Mark Jaquith
Author URI: http://coveredwebservices.com/
*/
@Rarst
Rarst / in_main_query.php
Created January 16, 2013 23:08
Mark WordPress posts in query if they are in main or secondary.
<?php
add_action( 'loop_start', 'mark_posts_with_query' );
function mark_posts_with_query( $query ) {
$in_main_query = $query->is_main_query();
foreach ( $query->posts as $post ) {