Skip to content

Instantly share code, notes, and snippets.

View 2aces's full-sized avatar

2ACES 2aces

View GitHub Profile
@2aces
2aces / php
Created January 6, 2016 22:02
forces CDN subdomain for srcset file list on img element
// you MUST change static1 to your CDN subdomain as needed
function aafd_cdn_srcset($sources){
foreach ( $sources as $source ) {
$sources[ $source['value'] ][ 'url' ] = str_replace('http://www', 'https://static1', $sources[ $source['value'] ][ 'url' ]);
// you MAY use external domains as well
// $sources[ $source['value'] ][ 'url' ] = str_replace('http://www.example.com', 'https://static.examplecdnprovider.com', $sources[ $source['value'] ][ 'url' ]);
}
return $sources;
}
@2aces
2aces / woocommerce-correios-pac-cost-filter.php
Last active August 31, 2016 21:38
woocommerce-correios PAC cost filter
/**
* yourprefix_free_shipping_pac function.
* filters Woocommerce Correio's PAC shipping method cost to zero
*
* @access public
* @param array $arr Array with data sent by woocommerce-correios WC_Correios_International_Shipping and WC_Correios_Shipping classes
* @param int $instance_id sent by woocommerce-correios WC_Correios_International_Shipping and WC_Correios_Shipping classe
* @return array
*/
function yourprefix_free_shipping_pac($arr, $instance_id){
@2aces
2aces / gist:8ca21452faa690f3f0a289ef9b18ae47
Last active September 9, 2016 04:21
Filtro de custo do método PAC do plugin woocommerce-correios
/**
* yourprefix_free_shipping_pac function.
* filtra o custo do método de envio PAC no plugin Woocommerce Correios
*
* @access public
* @param array $arr Array com dados enviado pelas classes WC_Correios_International_Shipping e WC_Correios_Shipping do woocommerce-correios
* @param int $instance_id enviado pelas classes WC_Correios_International_Shipping and WC_Correios_Shipping do woocommerce-correios
* @return array
*/
function seuprefixo_pac_gratis($arr, $instance_id){
@2aces
2aces / .gitignore
Created October 9, 2016 21:12 — forked from salcode/.gitignore
WordPress .gitignore - this is my preferred gitignore file when working with WordPress. It ignores almost all files by default.
# -----------------------------------------------------------------
# .gitignore for WordPress @salcode
# ver 20160309
#
# From the root of your project run
# curl -O https://gist.githubusercontent.com/salcode/b515f520d3f8207ecd04/raw/.gitignore
# to download this file
#
# By default all files are ignored. You'll need to whitelist
# any mu-plugins, plugins, or themes you want to include in the repo.
@2aces
2aces / dm_redirect_admin_customizer.php
Last active November 3, 2016 00:34
allow customizer to use the mapped domain when WordPress MU Domain Mapping is set to "Redirect administration pages to site's original domain"
function dm_redirect_admin() {// line 607 on WordPress MU Domain Mapping 0.5.5.1
// don't redirect admin ajax calls
if ( strpos( $_SERVER['REQUEST_URI'], 'wp-admin/admin-ajax.php' ) !== false )
return;
global $wp_customize; // gets $wp_customize global
if ( get_site_option( 'dm_redirect_admin' ) && !isset($wp_customize) ) { // redirects to original url only if $wp_customize is not set
// redirect mapped domain admin page to original url
$url = get_original_url( 'siteurl' );
if ( false === strpos( $url, $_SERVER[ 'HTTP_HOST' ] ) ) {
wp_redirect( untrailingslashit( $url ) . $_SERVER[ 'REQUEST_URI' ] );
@2aces
2aces / add_category_to_body_class.php
Last active January 23, 2017 23:59
Add category or categories slug(s) as class(es) to a category archive or single post as answered on Stackexchange question https://wordpress.stackexchange.com/questions/253677/different-body-classes-for-each-category/253708#253708
// Adding categories name to body class on archives
add_filter('body_class','add_category_to_classes');
function add_category_to_classes( $classes ) {
if ( is_single() ) {
global $post;
// assigns post it to variable to avoid reading an array for every loop iteration
// maybe a micro optmization? Guilty as charged!
$post_id = $post->ID;
foreach( ( get_the_category( $post_id ) ) as $category ) {
@2aces
2aces / kbe-pt_BR.po
Created February 5, 2017 17:55
Correct PO file for brazilian translation of WP Knowledgebase plugin v1.1.4 ( https://wordpress.org/plugins/wp-knowledgebase/ ), with update strings from php files.
# Copyright (C) 2014
# This file is distributed under the same license as the package.
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: http://wordpress.org/tag/wp-knowledgebase\n"
"POT-Creation-Date: 2017-02-05 15:47-0200\n"
"PO-Revision-Date: 2017-02-05 15:51-0200\n"
"Last-Translator: Celso Bessa - 2Aces <celso.bessa@2aces.com.br>\n"
"Language-Team: \n"
@2aces
2aces / add-pages-to-wordpress-feed.php
Created February 17, 2017 13:39
Use this code snippet on functions.php file of a theme to add pages to a WordPress RSS feed.
/**
* 2a_feed_request function.
* adds any post type to RSS Feeds. In this example, we use 'post' and 'page' post types
*
* @access public
* @param mixed $qv
* @return array $qv filter $qv variable
*/
function 2a_feed_request($qv) {
if ( isset( $qv['feed'] ) && !isset( $qv['post_type'] ) ) {
@2aces
2aces / add-featured-image-to-wordpress-feed.php
Created February 17, 2017 18:58
Use this code snippet on functions.php file of a theme to add the featured image as a thumbnail to a WordPress RSS feed.
@2aces
2aces / fd-tiradentes-instagram-spider-1.txt
Last active March 25, 2017 14:22
instagram spider 1 fd em tiradentes
https://www.instagram.com/p/BR9WECTBBO2/
https://www.instagram.com/p/BR-3-n-gfxX/
https://www.instagram.com/p/BCvLrA3h68d/
https://www.instagram.com/p/BSAVqqOhRbx/
https://www.instagram.com/p/BC0S5MErQgs/
https://www.instagram.com/p/BRsxYu-lYbr/
https://www.instagram.com/p/BSBBjrhBCDA/
https://www.instagram.com/p/BSBXawBjB9v/
https://www.instagram.com/p/BSAVLi4hzSL/
https://www.instagram.com/p/BR_chtulGHT/