Skip to content

Instantly share code, notes, and snippets.

View andrezrv's full-sized avatar

Andrés Villarreal andrezrv

View GitHub Profile
@andrezrv
andrezrv / remove-google-analytics-warning.php
Last active August 29, 2015 13:58
Remove warning from Google Analytics for WordPress in network admin.
<?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 / blacklist-jetpack-modules.php
Created April 7, 2014 19:50
Disallow Jetpack modules.
<?php
/**
* Blacklist Jetpack modules.
*/
function blacklist_jetpack_modules( $modules ){
$jp_mods_to_disable = array(
'contact-form',
'shortlinks',
);
@andrezrv
andrezrv / auto-activate-jetpack-modules.php
Created April 7, 2014 19:51
Auto activate Jetpack modules.
<?php
/**
* Auto activate Jetpack modules.
*/
function activate_jetpack_modules( $modules ){
$modules = array(
'widget-visibility',
'custom-css',
);
return $modules;
@andrezrv
andrezrv / show-current-stage.php
Last active August 29, 2015 13:58
Show info for current stage in admin toolbar.
<?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' ),
@andrezrv
andrezrv / override-cdn-file-extensions.php
Created April 7, 2014 19:57
Limit file extensions to load from CDN when using Stage WP CDN plugin.
<?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 / 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;