Skip to content

Instantly share code, notes, and snippets.

Avatar

Andrés Villarreal andrezrv

View GitHub Profile
View fix-yoast-smart-issue.php
<?php // Ignore this line.
add_action( 'save_post', 'nice_fix_yoast_seo_loading', -999 );
add_action( 'delete_post', 'nice_fix_yoast_seo_loading', -999 );
function nice_fix_yoast_seo_loading() {
if ( ! class_exists( 'WPSEO_Link_Watcher' ) ) {
return;
}
nice_loader( 'includes/public/theming/' );
@andrezrv
andrezrv / fix-demo-importer-toggle.css
Created Jul 26, 2017
Fix toggle inner in demo importer.
View fix-demo-importer-toggle.css
body.nice-framework-page-demos .nice-toggle .nice-toggle-inner {
height: auto !important;
border: 2px solid transparent !important;
}
@andrezrv
andrezrv / airplane-mode-google-fonts.php
Created Feb 2, 2017
For WordPress, prevent Airplane Mode plugin from blocking Google Fonts.
View airplane-mode-google-fonts.php
<?php
// Prevent Airplane Mode from blocking Google Fonts.
add_filter( 'airplane_mode_parse_style', function( $value, $parsed ) {
if ( 'fonts.googleapis.com' === $parsed ) {
$value = false;
}
return $value;
}, 10, 2 );
@andrezrv
andrezrv / get-admin-path.php
Created Oct 30, 2014
Obtain path to wp-admin directory in WordPress.
View get-admin-path.php
<?php
/**
* Obtain the path to the admin directory.
*
* @return string
*/
function my_plugin_get_admin_path() {
// Replace the site base URL with the absolute path to its installation directory.
$admin_path = str_replace( get_bloginfo( 'url' ) . '/', ABSPATH, get_admin_url() );
@andrezrv
andrezrv / submodules.sh
Created Jul 3, 2014
Using Git submodules.
View submodules.sh
# CREATE: On the root folder of a Git repository:
$ git submodule add git@bitbucket.org:nicethemes/<repo>.git location/of/submodule
# Cloning a repo that contains submodules:
$ git clone --recursive git@bitbucket.org:nicethemes/<repo>.git location/of/repo
# Or:
$ git clone git@bitbucket.org:nicethemes/<repo>.git location/of/repo
$ git submodule init
$ git submodule update
@andrezrv
andrezrv / remove-query-args.php
Last active Aug 29, 2015
Remove query arguments from any enqueued scripts.
View remove-query-args.php
<?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;
}
View wpsc-meta-util-example.php
<?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;
View fix-sample.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
View activate-plugins-by-stage.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 ( defined( 'WP_STAGE' ) && 'local' == WP_STAGE ) {
$local_plugins = array(
'wordpress-beta-tester/wp-beta-tester.php',
'wordpress-importer/wordpress-importer.php',
@andrezrv
andrezrv / wp-config.php
Created Apr 21, 2014
Basic model of a wp-config.php file for different stages
View wp-config.php
<?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' );