Skip to content

Instantly share code, notes, and snippets.

View andrezrv's full-sized avatar

Andrés Villarreal andrezrv

View GitHub Profile
@andrezrv
andrezrv / activate-plugins-by-server.php
Last active August 29, 2015 14:00
Activate plugins by checking the IP address of the server where our site is running.
<?php
add_filter( 'option_active_plugins', 'activate_local_plugins' );
/**
* Add our local plugins to the list of active plugins.
*/
function activate_local_plugins( $plugins ) {
if ( '127.0.0.1' == $_SERVER['SERVER_ADDR'] ) {
$local_plugins = array(
'wordpress-beta-tester/wp-beta-tester.php',
'wordpress-importer/wordpress-importer.php',
@andrezrv
andrezrv / wp-config.php
Created April 21, 2014 04:33
Basic model of a wp-config.php file for different stages
<?php
/**
* Load different configuration files for different stages.
*/
if ( file_exists( $local_config = dirname( __FILE__ ) . '/local-config.php' ) ) {
require $local_config; // Configurations for your local stage only.
define( 'WP_STAGE', 'local' );
} elseif ( file_exists( $staging_config = dirname( __FILE__ ) . '/staging-config.php' ) ) {
require $staging_config; // Configurations for your testing stage only.
define( 'WP_STAGE', 'staging' );
<?php
add_filter( 'option_active_plugins', 'activate_local_plugins' );
/**
* Add our local plugins to the list of active plugins.
*/
function activate_local_plugins( $plugins ) {
if ( defined( 'WP_STAGE' ) && 'local' == WP_STAGE ) {
$local_plugins = array(
'wordpress-beta-tester/wp-beta-tester.php',
'wordpress-importer/wordpress-importer.php',
<?php
// Remove users and meta data.
function fix_wpsc_clear_customer_meta() {
global $wpdb;
require_once( ABSPATH . 'wp-admin/includes/user.php' );
$purge_count = 200;
$sql = "
SELECT user_id
FROM {$wpdb->usermeta}
WHERE
<?php
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
add_action( 'wp_ajax_wpsc_migrate_anonymous_user', '_wpsc_meta_migrate_anonymous_user_worker' );
add_action( 'wp_ajax_nopriv_wpsc_migrate_anonymous_user', '_wpsc_meta_migrate_anonymous_user_worker' );
function _wpsc_meta_migrate_anonymous_user_worker() {
global $wpdb;
@andrezrv
andrezrv / remove-query-args.php
Last active August 29, 2015 14:01
Remove query arguments from any enqueued scripts.
<?php
/**
* Remove query arguments from any enqueued scripts.
*/
function remove_query_args( $src ) {
if ( strpos( $src, 'ver=' ) ) {
$src = remove_query_arg( 'ver', $src );
}
return $src;
}
@andrezrv
andrezrv / sql-variables.txt
Created June 24, 2013 17:00
How to use MySQL variables
mysql> SELECT @min_price:=MIN(price),@max_price:=MAX(price) FROM shop;
mysql> SELECT * FROM shop WHERE price=@min_price OR price=@max_price;
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0003 | D | 1.25 |
| 0004 | D | 19.95 |
+---------+--------+-------+
@andrezrv
andrezrv / move-wordpress.sql
Created June 24, 2013 21:44
How to Move WordPress Blog to New Domain or Location
SELECT @old_domain := 'http://www.old-domain.com' , @new_domain := 'http://www.new-domain.com';
UPDATE wp_options SET option_value = replace(option_value, @old_domain, @new_domain) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, @old_domain, @new_domain);
UPDATE wp_posts SET post_content = replace(post_content, @old_domain, @new_domain);
@andrezrv
andrezrv / config.rb
Last active December 21, 2015 07:39
Custom configuration file for WP-Stack, loading a new set of tasks from db-tasks.rb and shared-tasks.rb.
# Customize according to your needed configuration
set :application, "Application Name"
set :repository, "git@github.com:user/repo.git"
set :db_repository, 'git@github.com:user/repo-db.git'
set :scm, :git
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
# This assumes you're using Git. Needed to run tasks in db-tasks.rb
set :git_user_name, "user"
@andrezrv
andrezrv / MyObject.groovy
Last active December 23, 2015 20:29
How to test exceptions in Grails using Spock.
package myapp.mypackage
/**
* Just an example of a domain class.
* @author andrezrv
*/
class MyObject {
String name