Skip to content

Instantly share code, notes, and snippets.

View raphaelchaib's full-sized avatar

Raphael Chaib raphaelchaib

View GitHub Profile
@raphaelchaib
raphaelchaib / app.js
Created August 15, 2013 14:52
Javascript: Select text inside element (can be used with hover, focus, etc)
function SelectText(element) {
var text = document.getElementById(element);
if ($.browser.msie) {
var range = document.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if ($.browser.mozilla || $.browser.opera) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(text);
@raphaelchaib
raphaelchaib / schema.sql
Created August 28, 2013 20:17
MySQL: WHILE statement schema (Need to finish it)
DELIMITER $$
CREATE PROCEDURE fillPaisesNome()
BEGIN
DECLARE paisesNoName INT;
DECLARE controle INT;
SET paisesNoName = (SELECT COUNT(*) FROM `io_paises` WHERE `io_paises`.`nome` IS NULL);
SET controle = 0;
WHILE controle < paisesNoName DO
UPDATE `io_paises` AS `pais`
@raphaelchaib
raphaelchaib / functions.php
Created September 2, 2013 17:26
PHP: Simple random password generator
<?php
function randomPassword($length = 10) {
$alphabet = 'abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789';
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < $length; $i++) {
$n = rand(0, $alphaLength);
$pass = $alphabet[$n];
}
@raphaelchaib
raphaelchaib / functions.php
Last active December 29, 2015 07:59
[Always display WooCommerce variable product price] If all prices for a product’s variations are the same then variation price will not be displayed. But if it is the only displayed price then you are in trouble. To overcome this situation you can edit your template functions.php file like this:
<?php
// Display variation's price even if min and max prices are the same
add_filter('woocommerce_available_variation', 'variationPriceFix', 10, 3);
function variationPriceFix ($value, $object = null, $variation = null) {
if ($value['price_html'] == '') {
$value['price_html'] = '<span class="price">' . $variation->get_price_html() . '</span>';
}
return $value;
}
@raphaelchaib
raphaelchaib / functions.php
Created December 11, 2013 06:18
WordPress: Remove update nag
<?php
// remove update nag
if ( !current_user_can( 'edit_users' ) ) {
add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
}
@raphaelchaib
raphaelchaib / functions.php
Created December 11, 2013 06:19
WordPress: Change WordPress dashboard colors If you ever wanted to be able to change WordPress dashboard colors (as well as font or even display) without having to edit WordPress core files, you’ll like this hack for sure. The following example features a basic style change (grey header is replaced by a blue one) but you can easily add as many s…
<?php
// Change wp-admin colors
add_action('admin_head', 'custom_colors');
function custom_colors() {
echo '<style type="text/css">#wphead{background:#069}</style>';
}
@raphaelchaib
raphaelchaib / functions.php
Created December 12, 2013 16:18
WooCommerce: Changes how price is displayed
<?php
// Changes how price is displayed
add_filter( 'woocommerce_get_price_html', 'wpa83367_price_html', 100, 2 );
function wpa83367_price_html( $price, $product ){
$return = str_replace( '<ins>', 'Por: <ins>', $price );
$return = str_replace( '<del>', '<small class="price-from">De: <del>', $return );
$return = str_replace( '</del>', '</del></small><br/>', $return );
@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",
@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 / 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>';