Skip to content

Instantly share code, notes, and snippets.

@maor
maor / 0_reuse_code.js
Created May 17, 2014 13:12
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
[{
"id": "571",
"type": "0",
"user": "RedAlertAdminApp-95.35.61",
"date": "09\/07\/2014 - 09:01:58",
"message": "Rockets Attack : Moatza Ezorit Eshkol",
"count": 9
}, {
"id": "570",
"type": "0",
<?php
/*
Plugin Name: Just Give Me Berlin.
Plugin URI: http://www.berlin.de/en/
Description: Berlin. Nuff said.
Author: A Berliner
Author URI: http://www.findme.in/berlin
Version: 0.0
*/
function maor_image_proportions_classes($attr, $attachment) {
$image = wp_get_attachment_image_src( $attachment->ID, 'full', false );
if ( ! $image )
return $attr;
list( $src, $width, $height ) = $image;
$attr['class'] .= ( $height > $width ) ? ' wp-image-portrait' : ' wp-image-landscape';
add_action( 'pre_get_posts', 'mc_modify_query_rand_posts' );
function mc_modify_query_rand_posts( $query ) {
if ( ! is_admin() && $query->is_main_query() )
$query->set( 'orderby', 'rand' );
}
<?php
function maor_twitter_run_wp_user_search_query() {
/* There's a reason we're adding the action from here, you'll see later why. */
add_action( 'pre_user_query', 'maor_twitter_help_main' );
/* Create a new WP_User_Query object, limit recordset to 10 */
$wp_user_search = new WP_User_Query(
array(
'number' => 10
<?php
/* [http://on.fb.me/UAe3H9] */
/*
* Posts that have the 'mc_order_key' custom field, and that their (numeric) value is low
* will be shown first. If you wish to reverse the order, change the 'order' parameter to
* 'DESC'. Also make sure to change the meta key.
*/
function mc_reorder_search_results( $query ) {
<?php
/* Plugin Name: P2 Force Login
* Description: Force logged-out users to log-in in order to view the P2
* Author: Maor Chasen
* Author URI: http://maorchasen.com/
* Version: 1.0
*/
function p2fl_force_login() {
is_user_logged_in() || auth_redirect();
@maor
maor / sliced-query.php
Created October 26, 2012 13:39
How WP queries date-based archives
if ( $q['m'] ) {
$q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']);
$where .= " AND YEAR($wpdb->posts.post_date)=" . substr($q['m'], 0, 4);
if ( strlen($q['m']) > 5 )
$where .= " AND MONTH($wpdb->posts.post_date)=" . substr($q['m'], 4, 2);
if ( strlen($q['m']) > 7 )
$where .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($q['m'], 6, 2);
if ( strlen($q['m']) > 9 )
$where .= " AND HOUR($wpdb->posts.post_date)=" . substr($q['m'], 8, 2);
if ( strlen($q['m']) > 11 )
@maor
maor / jetpack-comments-rtl.css
Last active December 10, 2015 00:39
RTL support for Jetpack's Comments Module
/* RTL support for Jetpack's Comments Module */
body.rtl #respond form {
direction: rtl;
}