Skip to content

Instantly share code, notes, and snippets.

View raphaelchaib's full-sized avatar

Raphael Chaib raphaelchaib

View GitHub Profile
@raphaelchaib
raphaelchaib / style.css
Created September 21, 2015 06:16
CSS: Desaturate elements with filter
img.desaturate {
-webkit-filter: grayscale(100%);
filter: grayscale(100%);
filter: gray;
filter: url("data:image/svg+xml;utf8,<svg version='1.1' xmlns='http://www.w3.org/2000/svg' height='0'><filter id='greyscale'><feColorMatrix type='matrix' values='0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0' /></filter></svg>#greyscale");
}
@raphaelchaib
raphaelchaib / script.js
Created August 21, 2015 22:54
JavaScript: Create regular expression string of input text to create search string match
var makeComp = (function(){
var accents = {
a: 'àáâãäåæ',
c: 'ç',
e: 'èéêëæ',
i: 'ìíîï',
n: 'ñ',
o: 'òóôõöø',
s: 'ß',
u: 'ùúûü',
@raphaelchaib
raphaelchaib / script.js
Created August 6, 2015 00:45
VTEX: User login functions
/**
* isVTEXUserIdentified
* Verifica se o usuário VTEX está identificado (quando o sistema identificou
* o usuário pelo e-mail, mas ele ainda não digitou sua senha).
*
* @return BOOL
* TRUE - Se se estiver identificado ou autenticado
* FALSE - Se não estiver identificado
*/
function isVTEXUserIdentified() {
$.slugify = function(text) {
return text.toString().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
.replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
.replace(/^-+/, '') // Trim - from start of text
.replace(/-+$/, ''); // Trim - from end of text
}
@raphaelchaib
raphaelchaib / main.js
Last active August 29, 2015 14:23
JavaScript: Get array of url params (jQuery)
$.urlParam = function(name, url){
var url = url || window.location.href;
var reg = new RegExp('[\?&]' + name + '=([^&#]*)', 'g');
var results, returnResult = new Array(), i = 0;
while(results = reg.exec(url)) {
returnResult[i] = results;
i++;
}
add_action( 'woocommerce_archive_description', 'woocommerce_category_image', 2 );
function woocommerce_category_image() {
if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo '<img src="' . $image . '" alt="" />';
}
@raphaelchaib
raphaelchaib / main.js
Created March 3, 2015 16:00
Javascript: New line to br tag function
function nl2br (str, is_xhtml) {
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2');
}
@raphaelchaib
raphaelchaib / functions.php
Created February 27, 2015 22:33
WordPress: Fix quick update with custom fields changing post_title or other fields
<?php
add_action( 'save_post', 'elo_people_custom_permalink' );
// add_filter( 'wp_insert_post_data', 'elo_people_custom_permalink' );
function elo_people_custom_permalink( $data, $postarr ) {
$post = get_post($data);
$exec_in = array('equipe', 'comunicador');
if( in_array($post->post_type, $exec_in) ) {
$post_title = get_post_meta($post->ID, '_people_nome', true);
$post_name = sanitize_title( $post_title );
@raphaelchaib
raphaelchaib / functions.php
Created February 20, 2015 14:44
WordPress: Add new columns to wp-admin posts list
<?php
/**
Add filter and action: Choose one
**/
// Add to all post types
// add_filter('manage_post_posts_columns', 'cg_new_columns_headers');
// add_action('manage_post_posts_custom_column', 'cg_new_columns_content', 10, 2);
@raphaelchaib
raphaelchaib / functions.php
Created February 19, 2015 19:26
Exclude from array by value
<?php
if(($key = array_search($del_val, $array)) !== false) {
unset($array[$key]);
}