Skip to content

Instantly share code, notes, and snippets.

View raphaelchaib's full-sized avatar

Raphael Chaib raphaelchaib

View GitHub Profile
@raphaelchaib
raphaelchaib / gist:f9a083a03e06123b9177
Created January 13, 2015 14:13
Make GIT forget index files and then, on new commit, respect .gitignore
The series of commands below will remove all of the items from the Git Index (not from the working directory or local repo), and then updates the Git Index, while respecting git ignores. PS. Index = Cache
First:
git rm -r --cached .
git add .
Then:
git commit -am "Remove ignored files"
@raphaelchaib
raphaelchaib / custom.js
Created August 13, 2014 16:25
WooCommerce / Javascript: This code transform the WooCommerce Categories List Widget in an accordion.
jQuery(document).ready(function($) {
$(".widget .product-categories > li > .children li").each(function() {
if($(this).has(".children")) {
if(!($(this).hasClass("current-cat-parent"))) {
$(this).find(".children").first().attr("style", "display:none;")
.siblings("a").attr("href", "javascript:void(0);");
}
}
});
@raphaelchaib
raphaelchaib / functions.php
Last active August 29, 2015 14:05
WordPress: Create custom permalink based on custom field or other value.
<?php
add_filter( 'wp_insert_post_data', 'cg_custom_insert_post_data' );
function cg_custom_insert_post_data( $data ) {
//You can make some checks here before modify the post data.
//For example, limit the changes to revista post type
if( 'revista' == $data['post_type'] ) {
$edicao_num = 'Edição: '.$_POST['_edicao_num'];
$data['post_name'] = sanitize_title( $edicao_num );
}
return $data;
@raphaelchaib
raphaelchaib / script.js
Created August 8, 2014 21:16
jQuery: Smooth Scroll
$(document).ready(function(){
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
@raphaelchaib
raphaelchaib / functions.php
Created May 15, 2014 17:19
WooCommerce: Filter gateways by product ID
<?php
// Filter gateways by product ID
add_filter('woocommerce_available_payment_gateways', 'cg_filter_gateways', 1);
function cg_filter_gateways($gateways) {
global $woocommerce;
$authorized_products = array(1,2,5);
$gateways_to_unset = array('paypal', 'cielo');
$unset_gateways = true;
@raphaelchaib
raphaelchaib / functions.php
Created March 24, 2014 14:59
WordPress: Adjust site to viewport. iPad calculate the site width by landscape view, and it makes the site to get cut in the portrait view. This is the default schema for WordPress, but can be modified to work in another plataforms.
<?php
/* Viewport meta tag */
add_action( 'wp_head', 'cg_viewport_meta' );
function cg_viewport_meta() {
if( is_ipad() ) :
echo '<meta name="viewport" content="width=device-width; initial-scale=0.8" />';
else :
echo '<meta name="viewport" content="width=device-width;" />';
endif;
@raphaelchaib
raphaelchaib / functions.php
Created March 21, 2014 19:43
WooCommerce: Hide standard shipping option when free shipping is available
<?php
// Hide standard shipping option when free shipping is available
add_filter( 'woocommerce_available_shipping_methods', 'hide_standard_shipping_when_free_is_available' , 10, 1 );
/**
* Hide Standard Shipping option when free shipping is available
*
* @param array $available_methods
*/
@raphaelchaib
raphaelchaib / functions.php
Created March 7, 2014 19:21
WooCommerce: Change add_to_cart button to "Read More" button
<?php
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_action( 'woocommerce_after_shop_loop_item', 'cg_loop_add_to_cart', 10 );
function cg_loop_add_to_cart() {
// global $product;
// echo '<form action="' . esc_url( get_permalink( $product->id ) ) . '" method="get">
// <button type="submit" class="single_add_to_cart_button button alt">View More</button>
// </form>';
@raphaelchaib
raphaelchaib / wp-config.php
Created February 20, 2014 13:20
WordPress: When WordPress can't find the content folder (wp-content). More info: http://wordpress.org/support/topic/cannot-find-content-directory-wp-content
<?php
if(is_admin()) {
add_filter('filesystem_method', create_function('$a', 'return "direct";' ));
define( 'FS_CHMOD_DIR', 0751 );
}
@raphaelchaib
raphaelchaib / Fetch.sublime-settings
Created January 7, 2014 11:30
SublimeText's Fetch plugin configuration file
{
"files":
{
"Equalizer": "http://raw.github.com/darkwing/Equalizer/master/Source/Equalizer.js",
"Normalizer": "http://raw.github.com/necolas/normalize.css/master/normalize.css",
"Timthumb": "http://timthumb.googlecode.com/svn/trunk/timthumb.php",
"jQuery": "http://code.jquery.com/jquery.min.js",
"jQuery Animate Shadow": "http://www.bitstorm.org/jquery/shadow-animation/archive/jquery.animate-shadow-min.js",
"jQuery Autosize": "http://raw.github.com/jackmoore/autosize/master/jquery.autosize-min.js",
"jQuery Black and White": "http://raw.github.com/GianlucaGuarini/jQuery.BlackAndWhite/master/jquery.BlackAndWhite.js",