Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrés Villarreal andrezrv

View GitHub Profile
@andrezrv
andrezrv / activate-plugins-by-server.php
Last active Aug 29, 2015
Activate plugins by checking the IP address of the server where our site is running.
View activate-plugins-by-server.php
<?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 / override-cdn-file-extensions.php
Created Apr 7, 2014
Limit file extensions to load from CDN when using Stage WP CDN plugin.
View override-cdn-file-extensions.php
<?php
/**
* Limit file extensions to load from CDN.
*/
function override_cdn_file_extensions() {
return array( 'jpe?g', 'gif', 'png', 'bmp' );
}
add_filter( 'stage_wp_cdn_extensions', 'override_cdn_file_extensions' );
@andrezrv
andrezrv / show-current-stage.php
Last active Aug 29, 2015
Show info for current stage in admin toolbar.
View show-current-stage.php
<?php
/**
* Show info for current stage in admin toolbar.
*/
function show_current_stage_info( $wp_admin_bar ) {
if ( defined( 'WP_STAGE' ) && WP_STAGE != '%%WP_STAGE%%' ) {
$args = array(
'id' => 'current-stage',
'title' => '<span class="dashicons dashicons-admin-site" style="font-family: \'dashicons\'; font-size: 20px; margin-right: 5px;"></span> Current stage: ' . WP_STAGE,
'meta' => array( 'class' => 'current-stage' ),
View auto-activate-jetpack-modules.php
<?php
/**
* Auto activate Jetpack modules.
*/
function activate_jetpack_modules( $modules ){
$modules = array(
'widget-visibility',
'custom-css',
);
return $modules;
View blacklist-jetpack-modules.php
<?php
/**
* Blacklist Jetpack modules.
*/
function blacklist_jetpack_modules( $modules ){
$jp_mods_to_disable = array(
'contact-form',
'shortlinks',
);
@andrezrv
andrezrv / remove-google-analytics-warning.php
Last active Aug 29, 2015
Remove warning from Google Analytics for WordPress in network admin.
View remove-google-analytics-warning.php
<?php
/**
* Remove Google Analytics warning from network admin.
*/
function remove_analytics_warning_from_network_admin() {
if ( is_network_admin() ) {
global $ga_admin;
remove_filter( 'admin_footer', array( $ga_admin, 'warning' ) );
}
}
@andrezrv
andrezrv / avoid-wp-mail-when-local.php
Created Apr 7, 2014
Avoid sending mails when working locally.
View avoid-wp-mail-when-local.php
<?php
/**
* Avoid sending mails when working locally.
*/
if ( ! function_exists( 'wp_mail' )
&& defined( 'WP_STAGE' )
&& 'local' == WP_STAGE
&& ( ! defined( 'WP_MAIL_LOCAL' ) || true !== WP_MAIL_LOCAL )
) {
function wp_mail( $to, $subject, $message, $headers = '' ) {
@andrezrv
andrezrv / local-plugins.php
Last active Aug 29, 2015
A loader for plugins that should run only in local stages. Have a local-plugins folder containing plugins into wp-content, and a local-config.php called from wp-config.php in your local stage. Then declare the relative path of your local plugins and load them.
View local-plugins.php
<?php
/*
Plugin name: Local Plugins
Description: A loader for plugins that should run only in local stages.
Author: Andrés Villarreal
Author URI: http://about.me/andrezrv
Version: 1.0
License: GPL2
*/
function local_plugins_setup() {
@andrezrv
andrezrv / jquery.animate-number.js
Last active Aug 29, 2015
A very simple animation for numbers.
View jquery.animate-number.js
jQuery( document ).ready( function( $ ) {
$.fn.animate_number = function( options ) {
options.fromNumber = options.fromNumber ? options.fromNumber : 0;
options.toNumber = options.toNumber ? options.toNumber : 0;
options.rounding = options.rounding ? options.rounding : 0;
options.thousands = options.thousands ? options.thousands : '';
options.decimals = options.decimals ? options.decimals : '.';
options.element = this;
@andrezrv
andrezrv / Vagrantfile.rb
Created Feb 11, 2014
Add CPUs to Vagrant VM
View Vagrantfile.rb
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--memory", "3072"]
v.customize ["modifyvm", :id, "--cpus", "4"]
v.customize ["modifyvm", :id, "--ioapic", "on"]
end