Skip to content

Instantly share code, notes, and snippets.

View richardsweeney's full-sized avatar

Richard Sweeney richardsweeney

View GitHub Profile
@richardsweeney
richardsweeney / production.rb
Created January 27, 2016 13:07
capistrano production config
set :stage, :production
role :app, %w{user@127.0.0.1}
set :deploy_to, '/usr/share/nginx/capistrano/'
set :linked_files, %w{local-config.php content/object-cache.php content/debug.log robots.txt}
set :branch, "master"
@richardsweeney
richardsweeney / deploy.rb
Created January 27, 2016 13:05
capistrano basic config
set :application, 'capistrano'
set :repo_url, 'git@gitlab.com:capistrano/wordpress.git'
set :scm, :git
set :ssh_options, { :forward_agent => true, }
set :deploy_via, :remote_cache
set :copy_exclude, [".git", ".DS_Store", ".gitignore", ".gitmodules"]
set :linked_dirs, %w{content/uploads content/cache}
@richardsweeney
richardsweeney / pre-get-posts-wc-cat-stuff.php
Last active December 16, 2015 12:25
pre get posts WC category stuff
<?php
add_action( 'pre_get_posts', function( $query ) {
if ( ! $query->is_main_query() ) {
return;
}
// Du måste också se till att det är rätt query på något sätt,
// annars kommer alla queries påverkas av detta.
// Kanske is_tax( 'product_cat' ) ??
@richardsweeney
richardsweeney / remove-custom-metabox.php
Created September 4, 2015 11:11
You know that weird query that takes ages and you have no idea why the hell WP is doing it: "SELECT DISTINCT meta_key FROM $wpdb->postmeta WHERE meta_key NOT BETWEEN '_' AND '_z' HAVING meta_key NOT LIKE '_' ORDER BY meta_key LIMIT 30"
<?php
add_action( 'admin_menu' , function() {
foreach ( get_post_types() as $post_type ) {
remove_meta_box( 'postcustom' , $post_type , 'normal' );
}
});
<?php
if ( '' != $query->query_vars['search'] ) {
$meta_term = str_replace( '*', '', $query->query_vars['search'] );
$query->query_fields = 'DISTINCT SQL_CALC_FOUND_ROWS wp_users.ID';
$query->query_from = "FROM $wpdb->users LEFT JOIN $wpdb->usermeta ON $wpdb->usermeta.user_id = $wpdb->users.ID";
$query->query_where .= " OR display_name LIKE '%$meta_term%' OR ($wpdb->usermeta.meta_key = 'first_name' AND $wpdb->usermeta.meta_value = '{$meta_term}') OR ($wpdb->usermeta.meta_key = 'last_name' AND $wpdb->usermeta.meta_value = '{$meta_term}')";
}
@richardsweeney
richardsweeney / menu-item-classes-from-page-id.php
Created July 4, 2014 07:37
get current menu item classes from page ID
<?php
add_filter( 'nav_menu_css_class' , 'get_nav_classes' , 10 , 2 );
function get_nav_classes( $classes, $item ) {
global $post;
if ( 'page' != get_post_type() ) {
return $classes;
}
$link_page_id = get_post_meta( $item->ID, '_menu_item_object_id', true );
if ( $post->ID == $link_page_id ) {
@richardsweeney
richardsweeney / wordpress-menu-filter.php
Created September 2, 2013 10:44
Wordpress menu filter thingy
<?php
/** Show children only of current page */
function olab_nav_menu_objects_start_in( $sorted_menu_items, $args ) {
switch ( $args->menu_id ) {
case 'sidebar-menu' :
$current = false;
$last_parent = false;
$menu = array();
@richardsweeney
richardsweeney / gist:6410870
Last active December 22, 2015 03:29
Proxy requests for files not found to production/staging server. Useful for working with WordPress (or Drupal, or whatever), so you don't have to download all uploaded files when you grab a production database.
RewriteCond %{HTTP_HOST} ([_0-9a-zA-Z-.]+)\.(dev|local)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) http://example.com/$1 [R=302,L]
@richardsweeney
richardsweeney / olab-class-meta-box.php
Last active December 16, 2015 18:09
The beginning of a class to create + save meta boxes + fields.
<?php
class Olab_Meta_Box {
public $id, $title, $meta_box;
/** An array of elements to be rendered in the meta box */
public $elements = array();
/** An array of repeatable elements to be rendered in the meta box */
@richardsweeney
richardsweeney / lovely-loop.js
Last active December 16, 2015 10:49
Lovely JS loop :: Remy Sharp to blame
var nodes = [ 1, 2, 3, 4, 5 ],
length = nodes.length,
i = 0;
for ( ; i < length; i++ ) {
( function ( node ) {
// oooohhhh!
})( nodes[i] );
}